From 0c9571f290d2e96f9285dd812e26bd9817380185 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 15 Oct 2022 20:51:21 +0200 Subject: [PATCH] impl EcssEnumeration for Event --- fsrc-core/src/events.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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;