2023-01-11 10:30:03 +01:00
|
|
|
#[cfg(feature = "serde")]
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use spacepackets::ecss::{EcssEnumU16, EcssEnumeration};
|
2023-07-03 00:42:20 +02:00
|
|
|
use spacepackets::util::UnsignedEnum;
|
2023-08-18 10:21:15 +02:00
|
|
|
use spacepackets::ByteConversionError;
|
2023-01-11 10:30:03 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
|
|
pub struct ResultU16 {
|
|
|
|
group_id: u8,
|
|
|
|
unique_id: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ResultU16 {
|
|
|
|
pub const fn const_new(group_id: u8, unique_id: u8) -> Self {
|
|
|
|
Self {
|
|
|
|
group_id,
|
|
|
|
unique_id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn raw(&self) -> u16 {
|
|
|
|
((self.group_id as u16) << 8) | self.unique_id as u16
|
|
|
|
}
|
|
|
|
pub fn group_id(&self) -> u8 {
|
|
|
|
self.group_id
|
|
|
|
}
|
|
|
|
pub fn unique_id(&self) -> u8 {
|
|
|
|
self.unique_id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ResultU16> for EcssEnumU16 {
|
|
|
|
fn from(v: ResultU16) -> Self {
|
|
|
|
EcssEnumU16::new(v.raw())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 00:42:20 +02:00
|
|
|
impl UnsignedEnum for ResultU16 {
|
|
|
|
fn size(&self) -> usize {
|
|
|
|
core::mem::size_of::<u16>()
|
2023-01-11 10:30:03 +01:00
|
|
|
}
|
|
|
|
|
2023-07-03 00:42:20 +02:00
|
|
|
fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError> {
|
2023-01-11 10:30:03 +01:00
|
|
|
if buf.len() < 2 {
|
2023-08-18 10:21:15 +02:00
|
|
|
return Err(ByteConversionError::ToSliceTooSmall {
|
2023-01-11 10:30:03 +01:00
|
|
|
found: buf.len(),
|
|
|
|
expected: 2,
|
2023-08-18 10:21:15 +02:00
|
|
|
});
|
2023-01-11 10:30:03 +01:00
|
|
|
}
|
|
|
|
buf[0] = self.group_id;
|
|
|
|
buf[1] = self.unique_id;
|
2023-07-03 00:42:20 +02:00
|
|
|
Ok(self.size())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl EcssEnumeration for ResultU16 {
|
|
|
|
fn pfc(&self) -> u8 {
|
|
|
|
16
|
2023-01-11 10:30:03 +01:00
|
|
|
}
|
|
|
|
}
|