-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stuff Messages to increase throughput #107
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,25 @@ | ||
use common_arm::HydraError; | ||
use heapless::{HistoryBuffer, Vec}; | ||
use messages::command::RadioRate; | ||
use messages::state::StateData; | ||
use messages::Message; | ||
use messages::{MAX_COMMAND_SIZE, MAX_HEALTH_SIZE, MAX_LOG_SIZE, MAX_SENSOR_SIZE, MAX_STATE_SIZE}; | ||
use postcard; | ||
Check warning on line 7 in boards/communication/src/data_manager.rs GitHub Actions / clippythis import is redundant
|
||
|
||
const MAX_RADIO_MSG: usize = 255; | ||
|
||
#[derive(Clone)] | ||
pub struct DataManager { | ||
pub air: Option<Message>, | ||
pub ekf_nav_1: Option<Message>, | ||
pub ekf_nav_2: Option<Message>, | ||
pub ekf_nav_acc: Option<Message>, | ||
pub ekf_quat: Option<Message>, | ||
pub imu_1: Option<Message>, | ||
pub imu_2: Option<Message>, | ||
pub utc_time: Option<Message>, | ||
pub gps_vel: Option<Message>, | ||
pub gps_vel_acc: Option<Message>, | ||
pub gps_pos_1: Option<Message>, | ||
pub gps_pos_2: Option<Message>, | ||
pub gps_pos_acc: Option<Message>, | ||
pub state: Option<StateData>, | ||
pub message_queue: HistoryBuffer<Message, 64>, | ||
pub logging_rate: Option<RadioRate>, | ||
pub state: Option<StateData>, | ||
} | ||
|
||
impl DataManager { | ||
pub fn new() -> Self { | ||
Self { | ||
air: None, | ||
ekf_nav_1: None, | ||
ekf_nav_2: None, | ||
ekf_nav_acc: None, | ||
ekf_quat: None, | ||
imu_1: None, | ||
imu_2: None, | ||
utc_time: None, | ||
gps_vel: None, | ||
gps_vel_acc: None, | ||
gps_pos_1: None, | ||
gps_pos_2: None, | ||
gps_pos_acc: None, | ||
state: None, | ||
message_queue: HistoryBuffer::new(), | ||
logging_rate: Some(RadioRate::Slow), // start slow. | ||
state: None, | ||
} | ||
} | ||
|
||
|
@@ -49,77 +30,58 @@ | |
return rate_cln; | ||
} | ||
self.logging_rate = Some(RadioRate::Slow); | ||
return RadioRate::Slow; | ||
Check warning on line 33 in boards/communication/src/data_manager.rs GitHub Actions / clippyunneeded `return` statement
|
||
} | ||
|
||
/// Do not clone instead take to reduce CPU load. | ||
pub fn take_sensors(&mut self) -> [Option<Message>; 13] { | ||
[ | ||
self.air.take(), | ||
self.ekf_nav_1.take(), | ||
self.ekf_nav_2.take(), | ||
self.ekf_nav_acc.take(), | ||
self.ekf_quat.take(), | ||
self.imu_1.take(), | ||
self.imu_2.take(), | ||
self.utc_time.take(), | ||
self.gps_vel.take(), | ||
self.gps_vel_acc.take(), | ||
self.gps_pos_1.take(), | ||
self.gps_pos_2.take(), | ||
self.gps_pos_acc.take(), | ||
] | ||
} | ||
|
||
pub fn clone_states(&self) -> [Option<StateData>; 1] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should still be sending state messages, and I think we do since we don't treat it differently than any other message received (with the exception of commands). |
||
[self.state.clone()] | ||
} | ||
pub fn handle_data(&mut self, data: Message) { | ||
match data.data { | ||
messages::Data::Sensor(ref sensor) => match sensor.data { | ||
messages::sensor::SensorData::EkfNavAcc(_) => { | ||
self.ekf_nav_acc = Some(data); | ||
} | ||
messages::sensor::SensorData::GpsPosAcc(_) => { | ||
self.gps_pos_acc = Some(data); | ||
} | ||
messages::sensor::SensorData::Air(_) => { | ||
self.air = Some(data); | ||
} | ||
messages::sensor::SensorData::EkfNav1(_) => { | ||
self.ekf_nav_1 = Some(data); | ||
pub fn stuff_messages(&mut self) -> Result<Vec<u8, 255>, HydraError> { | ||
let mut bytes: Vec<u8, 255> = Vec::new(); | ||
for el in self.message_queue.oldest_ordered() { | ||
match el.data { | ||
messages::Data::Command(_) => { | ||
if bytes.len() + MAX_COMMAND_SIZE <= MAX_RADIO_MSG { | ||
bytes.extend(postcard::to_vec::<messages::Message, MAX_COMMAND_SIZE>(el)?); | ||
} else { | ||
break; | ||
} | ||
} | ||
messages::sensor::SensorData::EkfNav2(_) => { | ||
self.ekf_nav_2 = Some(data); | ||
messages::Data::Health(_) => { | ||
if bytes.len() + MAX_HEALTH_SIZE <= MAX_RADIO_MSG { | ||
bytes.extend(postcard::to_vec::<messages::Message, MAX_HEALTH_SIZE>(el)?); | ||
} else { | ||
break; | ||
} | ||
} | ||
messages::sensor::SensorData::EkfQuat(_) => { | ||
self.ekf_quat = Some(data); | ||
messages::Data::Sensor(_) => { | ||
if bytes.len() + MAX_SENSOR_SIZE <= MAX_RADIO_MSG { | ||
bytes.extend(postcard::to_vec::<messages::Message, MAX_SENSOR_SIZE>(el)?); | ||
} else { | ||
break; | ||
} | ||
} | ||
messages::sensor::SensorData::GpsVel(_) => { | ||
self.gps_vel = Some(data); | ||
messages::Data::State(_) => { | ||
if bytes.len() + MAX_STATE_SIZE <= MAX_RADIO_MSG { | ||
bytes.extend(postcard::to_vec::<messages::Message, MAX_STATE_SIZE>(el)?); | ||
} else { | ||
break; | ||
} | ||
} | ||
messages::sensor::SensorData::GpsVelAcc(_) => { | ||
self.gps_vel_acc = Some(data); | ||
messages::Data::Log(_) => { | ||
if bytes.len() + MAX_LOG_SIZE <= MAX_RADIO_MSG { | ||
bytes.extend(postcard::to_vec::<messages::Message, MAX_LOG_SIZE>(el)?); | ||
} else { | ||
break; | ||
} | ||
} | ||
messages::sensor::SensorData::Imu1(_) => { | ||
self.imu_1 = Some(data); | ||
} | ||
messages::sensor::SensorData::Imu2(_) => { | ||
self.imu_2 = Some(data); | ||
} | ||
messages::sensor::SensorData::UtcTime(_) => { | ||
self.utc_time = Some(data); | ||
} | ||
messages::sensor::SensorData::GpsPos1(_) => { | ||
self.gps_pos_1 = Some(data); | ||
} | ||
messages::sensor::SensorData::GpsPos2(_) => { | ||
self.gps_pos_2 = Some(data); | ||
} | ||
}, | ||
messages::Data::State(state) => { | ||
self.state = Some(state.data); | ||
} | ||
} | ||
if bytes.len() > 0 { | ||
Check warning on line 77 in boards/communication/src/data_manager.rs GitHub Actions / clippylength comparison to zero
|
||
return Ok(bytes); | ||
} | ||
return Err(HydraError::from("No messages to send")); | ||
Check warning on line 80 in boards/communication/src/data_manager.rs GitHub Actions / clippyunneeded `return` statement
|
||
} | ||
|
||
pub fn handle_data(&mut self, data: Message) { | ||
match data.data { | ||
messages::Data::Command(command) => match command.data { | ||
messages::command::CommandData::RadioRateChange(command_data) => { | ||
self.logging_rate = Some(command_data.rate); | ||
|
@@ -128,7 +90,9 @@ | |
messages::command::CommandData::DeployMain(_) => {} | ||
messages::command::CommandData::PowerDown(_) => {} | ||
}, | ||
_ => {} | ||
_ => { | ||
self.message_queue.write(data); | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also create another another send function that takes just a Message type and matches it to the needed size defined by the consts in the messages library. We should have a way to send messages that isn't stuffing.