Skip to content

Commit

Permalink
Fix: Build Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSprenger committed May 14, 2024
1 parent 2a22612 commit f83838d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 19 deletions.
59 changes: 49 additions & 10 deletions boards/communication/src/data_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ 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_SIZE, MAX_STATE_SIZE,
};
use postcard;

Check warning on line 8 in boards/communication/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

this import is redundant

warning: this import is redundant --> boards/communication/src/data_manager.rs:8:1 | 8 | use postcard; | ^^^^^^^^^^^^^ help: remove it entirely | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports = note: `#[warn(clippy::single_component_path_imports)]` on by default

const MAX_RADIO_MSG: u8 = 255;

Check warning on line 10 in boards/communication/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

constant `MAX_RADIO_MSG` is never used

warning: constant `MAX_RADIO_MSG` is never used --> boards/communication/src/data_manager.rs:10:7 | 10 | const MAX_RADIO_MSG: u8 = 255; | ^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default

#[derive(Clone)]
pub struct DataManager {
pub message_queue: HistoryBuffer<Message, 32>,
pub logging_rate: Option<RadioRate>,
pub state: Option<StateData>,
}

impl DataManager {
pub fn new() -> Self {
Self {
message_queue: HistoryBuffer::new(),
logging_rate: Some(RadioRate::Slow), // start slow.
state: None,
}
}

Expand All @@ -29,22 +34,54 @@ impl DataManager {
return RadioRate::Slow;

Check warning on line 34 in boards/communication/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> boards/communication/src/data_manager.rs:34:9 | 34 | return RadioRate::Slow; | ^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return help: remove `return` | 34 - return RadioRate::Slow; 34 + RadioRate::Slow |
}

pub fn stuff_messages(&mut self) -> Option<Vec<u8, 255>> {
pub fn stuff_messages(&mut self) -> Result<Vec<u8, 255>, postcard::Error> {
let mut bytes: Vec<u8, 255> = Vec::new();
for el in self.message_queue.oldest_ordered() {
bytes.extend_from_slice(el.to_bytes())
match el.data {
messages::Data::Command(_) => {
if bytes.len() + MAX_COMMAND_SIZE <= MAX_SIZE {
bytes.extend(postcard::to_vec::<messages::Message, MAX_COMMAND_SIZE>(el)?);
} else {
break;
}
}
messages::Data::Health(_) => {
if bytes.len() + MAX_HEALTH_SIZE <= MAX_SIZE {
bytes.extend(postcard::to_vec::<messages::Message, MAX_HEALTH_SIZE>(el)?);
} else {
break;
}
}
messages::Data::Sensor(_) => {
if bytes.len() + MAX_SENSOR_SIZE <= MAX_SIZE {
bytes.extend(postcard::to_vec::<messages::Message, MAX_SENSOR_SIZE>(el)?);
} else {
break;
}
}
messages::Data::State(_) => {
if bytes.len() + MAX_STATE_SIZE <= MAX_SIZE {
bytes.extend(postcard::to_vec::<messages::Message, MAX_STATE_SIZE>(el)?);
} else {
break;
}
}
messages::Data::Log(_) => {
if bytes.len() + MAX_LOG_SIZE <= MAX_SIZE {
bytes.extend(postcard::to_vec::<messages::Message, MAX_LOG_SIZE>(el)?);
} else {
break;
}
}
}
}
if bytes.len() > 0 {

Check warning on line 78 in boards/communication/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

length comparison to zero

warning: length comparison to zero --> boards/communication/src/data_manager.rs:78:12 | 78 | if bytes.len() > 0 { | ^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!bytes.is_empty()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero = note: `#[warn(clippy::len_zero)]` on by default
return Some(bytes);
return Ok(bytes);
}
None
return Err(postcard::Error::WontImplement);

Check warning on line 81 in boards/communication/src/data_manager.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> boards/communication/src/data_manager.rs:81:9 | 81 | return Err(postcard::Error::WontImplement); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return help: remove `return` | 81 - return Err(postcard::Error::WontImplement); 81 + Err(postcard::Error::WontImplement) |
}

pub fn clone_states(&self) -> [Option<StateData>; 1] {
[self.state.clone()]
}
pub fn handle_data(&mut self, data: Message) {
self.message_queue.write(data);
match data.data {
messages::Data::Command(command) => match command.data {
messages::command::CommandData::RadioRateChange(command_data) => {
Expand All @@ -54,7 +91,9 @@ impl DataManager {
messages::command::CommandData::DeployMain(_) => {}
messages::command::CommandData::PowerDown(_) => {}
},
_ => {}
_ => {
self.message_queue.write(data);
}
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions boards/communication/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,10 @@ mod app {
});
}

/// Receives a log message from the custom logger so that it can be sent over the radio.
pub fn queue_gs_message(d: impl Into<Data>) {
let message = Message::new(&monotonics::now(), COM_ID, d.into());

send_gs::spawn(message).ok();
let bytes = postcard::to_vec(&message).unwrap();
spawn!(send_gs, bytes).ok();
}

/**
Expand All @@ -245,7 +244,7 @@ mod app {
fn sd_dump(cx: sd_dump::Context, m: Vec<u8, 255>) {
let manager = cx.local.sd_manager;
cx.shared.em.run(|| {
let mut buf: [u8; 255] = m.into_array()?;
let mut buf: [u8; 255] = [0; 255];
let msg_ser = postcard::to_slice_cobs(&m, &mut buf)?;
if let Some(mut file) = manager.file.take() {
manager.write(&mut file, &msg_ser)?;

Check warning on line 250 in boards/communication/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> boards/communication/src/main.rs:250:42 | 250 | manager.write(&mut file, &msg_ser)?; | ^^^^^^^^ help: change this to: `msg_ser` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
Expand All @@ -263,16 +262,17 @@ mod app {
*/
#[task(shared = [data_manager, &em])]
fn sensor_send(mut cx: sensor_send::Context) {
let (sensors, logging_rate) = cx.shared.data_manager.lock(|data_manager| {
let (stuffed_messages, logging_rate) = cx.shared.data_manager.lock(|data_manager| {
(
data_manager.stuff_messages(),
data_manager.get_logging_rate(),
)
});

cx.shared.em.run(|| {
spawn!(send_gs, sensors.clone())?;
spawn!(sd_dump, sensors)?;
let bytes = postcard::to_vec(&stuffed_messages?)?;
spawn!(send_gs, bytes.clone())?;
spawn!(sd_dump, bytes)?;
Ok(())
});
match logging_rate {
Expand All @@ -294,7 +294,8 @@ mod app {
cx.shared.em.run(|| {
if let Some(x) = state_data {
let message = Message::new(&monotonics::now(), COM_ID, State::new(x));
spawn!(send_gs, message)?;
let bytes = postcard::to_vec(&message).unwrap();
spawn!(send_gs, bytes)?;
} // if there is none we still return since we simply don't have data yet.
Ok(())
});
Expand All @@ -315,7 +316,8 @@ mod app {
Health::new(health_manager.monitor.data.clone(), state),
)
});
spawn!(send_gs, msg)?;
let bytes = postcard::to_vec(&msg).unwrap();
spawn!(send_gs, bytes)?;
spawn_after!(report_health, ExtU64::secs(5))?;
Ok(())
});
Expand Down

0 comments on commit f83838d

Please sign in to comment.