From caefdfe131ce85fe57084e3f516695e7eb08b581 Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Mon, 9 Mar 2026 10:17:44 +0100 Subject: [PATCH] simdata: implement bundle streams --- src/events.rs | 3 ++- src/lib.rs | 5 +--- src/simdata.rs | 68 ++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 60 insertions(+), 16 deletions(-) diff --git a/src/events.rs b/src/events.rs index e104a95..7ea7b1d 100644 --- a/src/events.rs +++ b/src/events.rs @@ -96,7 +96,8 @@ impl From for SensorSource { match value { StreamType::Annotations => Self::Annotations, StreamType::GPS => Self::GPS, - StreamType::IMU => Self::IMU + StreamType::IMU => Self::IMU, + StreamType::Bundle => unimplemented!() } } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 59a9a4c..41aaa9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,11 +8,8 @@ pub mod animation; pub mod idle; pub mod logging; pub mod graphics; - -#[cfg(feature="simulation")] +pub mod tracing; pub mod storage; - -#[cfg(feature="simulation")] pub mod simdata; extern crate alloc; diff --git a/src/simdata.rs b/src/simdata.rs index 3d2f094..acf841c 100644 --- a/src/simdata.rs +++ b/src/simdata.rs @@ -6,6 +6,7 @@ pub trait RmpData: Sized { } pub trait EventRecord: RmpData { + fn stream_id() -> StreamType; fn field_count() -> usize; } @@ -28,14 +29,15 @@ impl From for SimDataError { } } -#[derive(Debug)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum StreamType { IMU, GPS, - Annotations + Annotations, + Bundle } -impl TryFrom for StreamType { +impl TryFrom for StreamType { type Error = (); fn try_from(value: i8) -> Result { @@ -43,6 +45,7 @@ impl TryFrom for StreamType { 1 => Ok(StreamType::IMU), 2 => Ok(StreamType::GPS), 3 => Ok(StreamType::Annotations), + 4 => Ok(StreamType::Bundle), _ => Err(()) } } @@ -53,7 +56,8 @@ impl From for i8 { match value { StreamType::IMU => 1, StreamType::GPS => 2, - StreamType::Annotations => 3 + StreamType::Annotations => 3, + StreamType::Bundle => 4 } } } @@ -65,19 +69,48 @@ pub struct StreamIndex { impl RmpData for StreamIndex { fn from_rmp(reader: &mut Reader) -> Result>> { - rmp::decode::read_array_len(reader).map(|count| { - Self { - count: count as usize - } - }).map_err(|_| { SimDataError::StreamIndexMissing }) + if rmp::decode::read_u16(reader)? != 0xDA1A { + Err(SimDataError::StreamIndexMissing) + } else { + rmp::decode::read_array_len(reader).map(|count| { + Self { + count: count as usize + } + }).map_err(|err| { SimDataError::DecodeError(err) }) + } } fn write_rmp(&self, writer: &mut Writer) -> Result<(), ValueWriteError> { + rmp::encode::write_u16(writer, 0xDA1A)?; rmp::encode::write_array_len(writer, self.count as u32)?; Ok(()) } } + + +#[derive(Debug)] +pub struct BundleEventHeader { + pub id: StreamType, +} + +impl RmpData for BundleEventHeader { + fn from_rmp(reader: &mut Reader) -> Result>> { + let meta = rmp::decode::read_i8(reader)?; + if let Ok(id) = meta.try_into() { + Ok(Self { + id + }) + } else { + Err(SimDataError::EventHeaderMissing) + } + } + + fn write_rmp(&self, writer: &mut Writer) -> Result<(), ValueWriteError> { + rmp::encode::write_i8(writer, self.id.into()) + } +} + #[derive(Debug)] pub struct StreamHeader { pub id: StreamType, @@ -97,8 +130,9 @@ impl RmpData for StreamHeader { } } - fn write_rmp(&self, _writer: &mut Writer) -> Result<(), ValueWriteError> { - todo!() + fn write_rmp(&self, writer: &mut Writer) -> Result<(), ValueWriteError> { + rmp::encode::write_ext_meta(writer, self.size as u32, self.id.into())?; + Ok(()) } } @@ -158,12 +192,20 @@ impl EventRecord for GPSReading { fn field_count() -> usize { 2 } + + fn stream_id() -> StreamType { + StreamType::GPS + } } impl EventRecord for IMUReading { fn field_count() -> usize { 6 } + + fn stream_id() -> StreamType { + StreamType::IMU + } } impl RmpData for GPSReading { @@ -239,4 +281,8 @@ impl EventRecord for AnnotationReading { fn field_count() -> usize { 1 } + + fn stream_id() -> StreamType { + StreamType::Annotations + } } \ No newline at end of file