diff --git a/proptest-regressions/lib.txt b/proptest-regressions/lib.txt index d6468cc..5b1f508 100644 --- a/proptest-regressions/lib.txt +++ b/proptest-regressions/lib.txt @@ -5,3 +5,5 @@ # It is recommended to check this file in to source control so that # everyone who runs the test benefits from these saved cases. cc 61b4824c090c01db4b55ba9e9fcc0fb7bbb6843574b2b802fbc377e8f839c62d # shrinks to msg = Message { timestamp: FormattedNaiveDateTime(-0001-01-01T00:00:00.000000001), node: PressureBoard, data: Sensor(Sensor { data: EkfNavAcc(EkfNavAcc { status: EkfStatus { status: 268435456 }, velocity_std_dev: Some([0.0, 0.0, 0.0]), position_std_dev: Some([-0.0, 0.0, 0.0]) }) }) } +cc 1b5e64b2da76dcb68777a6b6564de7a77d5f4b6ab26e1f36432e2df7d11f828b # shrinks to msg = Message { timestamp: FormattedNaiveDateTime(0000-01-01T00:00:00.000000001), node: PressureBoard, data: Sensor(Sensor { component_id: 0, data: Imu2(Imu2 { temperature: Some(0.0), delta_velocity: Some([0.0, 0.0, 0.0]), delta_angle: Some([0.0, 0.0, 0.0]) }) }) } +cc dba5d5b40143101de3363dadb069654a4e5b62704479ee3824b993edba0b0efd # shrinks to msg = Message { timestamp: FormattedNaiveDateTime(0000-01-01T00:00:00), node: PressureBoard, data: Sensor(Sensor { component_id: 0, data: SbgData(EkfQuat(EkfQuat { time_stamp: 268435456, quaternion: Some([0.0, 0.0, 0.0, 0.0]), euler_std_dev: Some([0.0, 0.0, 0.0]), status: EkfStatus { status: 268435456 } })) }) } diff --git a/src/lib.rs b/src/lib.rs index f98e69c..871f7ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,8 @@ pub mod sensor; pub mod sensor_status; pub mod state; -pub const MAX_SIZE: usize = 64; +pub const MAX_SIZE_CAN: usize = 64; +pub const MAX_SIZE_RADIO: usize = 255; pub use logging::{ErrorContext, Event, Log, LogLevel}; use defmt::Format; @@ -78,7 +79,7 @@ impl Message { #[cfg(all(test, feature = "std"))] mod test { - use crate::{Message, MAX_SIZE}; + use crate::{Message, MAX_SIZE_CAN, MAX_SIZE_RADIO}; use proptest::prelude::*; proptest! { @@ -86,8 +87,24 @@ mod test { fn message_size(msg: Message) { let bytes = postcard::to_allocvec(&msg).unwrap(); - dbg!(msg); - assert!(dbg!(bytes.len()) <= MAX_SIZE); + dbg!(msg.clone()); + + match msg.data { + crate::Data::Sensor(sensor) => { + match sensor.data { + crate::sensor::SensorData::SbgData(_) => { + assert!(bytes.len() <= MAX_SIZE_RADIO); + } + _ => { + assert!(bytes.len() <= MAX_SIZE_CAN); + } + } + } + _ => { + assert!(bytes.len() <= MAX_SIZE_CAN); + } + + } } } } diff --git a/src/sensor.rs b/src/sensor.rs index 9d93f43..e931dea 100644 --- a/src/sensor.rs +++ b/src/sensor.rs @@ -7,13 +7,35 @@ use messages_proc_macros_lib::common_derives; #[common_derives] pub struct Sensor { /// Used to differentiate between multiple components on the same sender. Unused right now. - // pub component_id: u8, + pub component_id: u8, pub data: SensorData, } #[common_derives] #[derive(From)] pub enum SensorData { + // UtcTime(UtcTime), + // Air(Air), + // EkfQuat(EkfQuat), + // EkfNav1(EkfNav1), + // EkfNav2(EkfNav2), + // EkfNavAcc(EkfNavAcc), + // Imu1(Imu1), + // Imu2(Imu2), + NavPosLlh(NavPosLlh), + // GpsVel(GpsVel), + // GpsVelAcc(GpsVelAcc), + // GpsPos1(GpsPos1), + // GpsPos2(GpsPos2), + // GpsPosAcc(GpsPosAcc), + ResetReason(ResetReason), + RecoverySensing(RecoverySensing), + SbgData(SbgData), +} + +#[common_derives] +#[derive(From)] +pub enum SbgData { UtcTime(UtcTime), Air(Air), EkfQuat(EkfQuat), @@ -22,14 +44,11 @@ pub enum SensorData { EkfNavAcc(EkfNavAcc), Imu1(Imu1), Imu2(Imu2), - NavPosLlh(NavPosLlh), GpsVel(GpsVel), GpsVelAcc(GpsVelAcc), GpsPos1(GpsPos1), GpsPos2(GpsPos2), GpsPosAcc(GpsPosAcc), - ResetReason(ResetReason), - RecoverySensing(RecoverySensing), } #[common_derives] @@ -245,7 +264,7 @@ pub struct RecoverySensing { impl Sensor { pub fn new(data: impl Into) -> Self { Sensor { - // component_id: 0, + component_id: 0, data: data.into(), } }