Skip to content

Commit

Permalink
Split SBG messages to radio based communication only.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSprenger committed Oct 26, 2024
1 parent 1923447 commit df6b6db
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
2 changes: 2 additions & 0 deletions proptest-regressions/lib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 } })) }) }
25 changes: 21 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,16 +79,32 @@ 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! {
#[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);
}

}
}
}
}
29 changes: 24 additions & 5 deletions src/sensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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]
Expand Down Expand Up @@ -245,7 +264,7 @@ pub struct RecoverySensing {
impl Sensor {
pub fn new(data: impl Into<SensorData>) -> Self {
Sensor {
// component_id: 0,
component_id: 0,
data: data.into(),
}
}
Expand Down

0 comments on commit df6b6db

Please sign in to comment.