impl EcssEnumeration for Event

This commit is contained in:
Robin Müller 2022-10-15 20:51:21 +02:00
parent 4d415cc0ad
commit 0c9571f290
No known key found for this signature in database
GPG Key ID: FC76078F520434A5

View File

@ -1,5 +1,8 @@
//! Event support module
use spacepackets::{ByteConversionError, SizeMissmatch};
use spacepackets::ecss::EcssEnumeration;
pub type GroupId = u16;
pub type UniqueId = u16;
pub type EventRaw = u32;
@ -91,6 +94,22 @@ impl TryFrom<EventRaw> for Event {
}
}
impl EcssEnumeration for Event {
fn pfc(&self) -> u8 {
32
}
fn write_to_bytes(&self, buf: &mut [u8]) -> Result<(), ByteConversionError> {
if buf.len() < self.byte_width() {
return Err(ByteConversionError::ToSliceTooSmall(SizeMissmatch {
found: buf.len(),
expected: self.byte_width()
}))
}
Ok(buf.copy_from_slice(self.raw().to_be_bytes().as_slice()))
}
}
#[cfg(test)]
mod tests {
use super::Event;