diff --git a/fsrc-core/src/events.rs b/fsrc-core/src/events.rs index be351b9..9df64fb 100644 --- a/fsrc-core/src/events.rs +++ b/fsrc-core/src/events.rs @@ -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 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;