Skip to content

Commit

Permalink
Merge pull request #4 from uorocketry/clean-project
Browse files Browse the repository at this point in the history
Testing Framework and Cleanup
  • Loading branch information
NoahSprenger authored Sep 30, 2024
2 parents 38173cf + 5456d8e commit 9ad8003
Show file tree
Hide file tree
Showing 29 changed files with 678 additions and 284 deletions.
58 changes: 58 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@ version = "0.7.16"
version = "0.5.0"

[workspace.dependencies.messages]
git = "https://github.com/uorocketry/messages"
git = "https://github.com/uorocketry/messages"

[workspace.dependencies.defmt-test]
version = "0.3.2"
19 changes: 17 additions & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ default_to_workspace = false

[tasks.test-host]
dependencies = [
"test-messages",
# "test-messages",
]

# -----------------------
Expand All @@ -19,9 +19,24 @@ dependencies = [

[tasks.test-device]
dependencies = [
"test-temperature-board",
"test-pressure-board",
"test-strain-board",
"test-common-arm",
]

[tasks.test-common-arm]
command = "cargo"
args = ["test", "-p", "common-arm-test", "${@}"]
args = ["test", "-p", "common-arm", "${@}"]

[tasks.test-temperature-board]
command = "cargo"
args = ["test", "-p", "temperature", "${@}"]

[tasks.test-pressure-board]
command = "cargo"
args = ["test", "-p", "pressure", "${@}"]

[tasks.test-strain-board]
command = "cargo"
args = ["test", "-p", "strain", "${@}"]
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ uORocketry's rocket instrumentation system.

## Running code
`cargo run --bin {board}`

## Tests
- To run device tests `cargo make test-device`
- - `cargo make test-temperature-board`
- To run host tests `cargo make test-host`
13 changes: 12 additions & 1 deletion boards/pressure/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ rtic-sync = { workspace = true }
defmt-rtt = { workspace = true }
panic-probe = { workspace = true }
chrono = { workspace = true }
messages = {workspace = true}
messages = {workspace = true}

[dev-dependencies]
defmt-test = { workspace = true }

[[test]]
name = "sd"
harness = false

[[bin]]
name = "pressure"
harness = false
48 changes: 20 additions & 28 deletions boards/pressure/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use messages::mavlink::uorocketry::MavMessage;
use messages::mavlink::{self};
use messages::Message;
use postcard::from_bytes;
use stm32h7xx_hal::prelude::*;

/// Clock configuration is out of scope for this builder
/// easiest way to avoid alloc is to use no generics
Expand Down Expand Up @@ -41,20 +40,17 @@ impl CanCommandManager {
bit_rate_switching: false,
marker: None,
};
self.can.transmit(header, &payload)?;
self.can.transmit(header, payload)?;
Ok(())
}
pub fn process_data(&mut self, data_manager: &mut DataManager) -> Result<(), HydraError> {
let mut buf = [0u8; 64];
for message in self.can.receive0(&mut buf) {
match from_bytes::<Message>(&buf) {
Ok(data) => {
info!("Received message {}", data.clone());
data_manager.handle_command(data)?;
}
Err(e) => {
info!("Error: {:?}", e)
}
while self.can.receive0(&mut buf).is_ok() {
if let Ok(data) = from_bytes::<Message>(&buf) {
info!("Received message {}", data.clone());
data_manager.handle_command(data)?;
} else {
info!("Error: {:?}", from_bytes::<Message>(&buf).unwrap_err());
}
}
Ok(())
Expand Down Expand Up @@ -91,22 +87,18 @@ impl CanDataManager {
};
// self.can.abort(fdcan::Mailbox::_2); // this is needed if boards are not in sync (if they are not in sync that is a bigger problem)

stm32h7xx_hal::nb::block!(self.can.transmit(header, &payload))?;
stm32h7xx_hal::nb::block!(self.can.transmit(header, payload))?;

Ok(())
}
pub fn process_data(&mut self, data_manager: &mut DataManager) -> Result<(), HydraError> {
pub fn process_data(&mut self) -> Result<(), HydraError> {
let mut buf = [0u8; 64];
for message in self.can.receive0(&mut buf) {
match from_bytes::<Message>(&buf) {
Ok(data) => {
info!("Received message {}", data.clone());
crate::app::send_gs::spawn(data).ok();
// data_manager.handle_data(data);
}
Err(e) => {
info!("Error: {:?}", e)
}
while self.can.receive0(&mut buf).is_ok() {
if let Ok(data) = from_bytes::<Message>(&buf) {
info!("Received message {}", data.clone());
crate::app::send_gs::spawn(data).ok();
} else if let Err(e) = from_bytes::<Message>(&buf) {
info!("Error: {:?}", e);
}
}
self.can
Expand Down Expand Up @@ -182,20 +174,20 @@ impl RadioManager {
// Do we need the header?
match msg {
mavlink::uorocketry::MavMessage::POSTCARD_MESSAGE(msg) => {
return Ok(postcard::from_bytes::<Message>(&msg.message)?);
Ok(postcard::from_bytes::<Message>(&msg.message)?)
// weird Ok syntax to coerce to hydra error type.
}
mavlink::uorocketry::MavMessage::COMMAND_MESSAGE(command) => {
info!("{}", command.command);
return Ok(postcard::from_bytes::<Message>(&command.command)?);
Ok(postcard::from_bytes::<Message>(&command.command)?)
}
mavlink::uorocketry::MavMessage::HEARTBEAT(heartbeat) => {
mavlink::uorocketry::MavMessage::HEARTBEAT(_) => {
info!("Heartbeat");
return Err(mavlink::error::MessageReadError::Io.into());
Err(mavlink::error::MessageReadError::Io.into())
}
_ => {
error!("Error, ErrorContext::UnkownPostcardMessage");
return Err(mavlink::error::MessageReadError::Io.into());
Err(mavlink::error::MessageReadError::Io.into())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions boards/pressure/src/data_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl DataManager {
return rate_cln;
}
self.logging_rate = Some(RadioRate::Slow);
return RadioRate::Slow;
RadioRate::Slow
}

/// Do not clone instead take to reduce CPU load.
Expand Down Expand Up @@ -85,7 +85,7 @@ impl DataManager {
}

pub fn clone_reset_reason(&self) -> Option<ResetReason> {
self.reset_reason.clone()
self.reset_reason
}

pub fn set_reset_reason(&mut self, reset: ResetReason) {
Expand Down
Loading

0 comments on commit 9ad8003

Please sign in to comment.