sat-rs/satrs-example/src/hk.rs

38 lines
875 B
Rust
Raw Normal View History

2023-08-15 21:07:15 +02:00
use derive_new::new;
2024-01-30 23:59:29 +01:00
use satrs_core::spacepackets::ByteConversionError;
2023-08-15 21:07:15 +02:00
2022-12-19 17:03:26 +01:00
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum AcsHkIds {
TestMgmSet = 1,
}
2023-08-15 21:07:15 +02:00
#[derive(Debug, new, Copy, Clone)]
pub struct HkUniqueId {
2024-01-30 23:59:29 +01:00
target_id: u32,
set_id: u32,
2023-08-15 21:07:15 +02:00
}
impl HkUniqueId {
2024-01-30 23:48:46 +01:00
#[allow(dead_code)]
2024-01-30 23:59:29 +01:00
pub fn target_id(&self) -> u32 {
self.target_id
}
#[allow(dead_code)]
pub fn set_id(&self) -> u32 {
self.set_id
2023-08-15 21:07:15 +02:00
}
2024-01-30 23:59:29 +01:00
pub fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError> {
2023-08-15 21:07:15 +02:00
if buf.len() < 8 {
2024-01-30 23:59:29 +01:00
return Err(ByteConversionError::ToSliceTooSmall {
found: buf.len(),
expected: 8,
});
2023-08-15 21:07:15 +02:00
}
2024-01-30 23:59:29 +01:00
buf[0..4].copy_from_slice(&self.target_id.to_be_bytes());
buf[4..8].copy_from_slice(&self.set_id.to_be_bytes());
2023-08-15 21:07:15 +02:00
2024-01-30 23:59:29 +01:00
Ok(8)
2023-08-15 21:07:15 +02:00
}
}