diff --git a/Cargo.lock b/Cargo.lock index 4a78f38..205bf6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bare-metal" @@ -74,10 +74,10 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +source = "git+https://github.com/uorocketry/chrono#02c0d2a797d91b724e9f3df19e5493f850934584" dependencies = [ "num-traits", + "serde", ] [[package]] @@ -161,9 +161,9 @@ checksum = "a62ec9ff5f7965e4d7280bd5482acd20aadb50d632cf6c1d74493856b011fa73" [[package]] name = "critical-section" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f64009896348fc5af4222e9cf7d7d82a95a256c634ebcf61c53e4ea461422242" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" [[package]] name = "defmt" @@ -185,7 +185,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -227,7 +227,7 @@ checksum = "984bc6eca246389726ac2826acc2488ca0fe5fcd6b8d9b48797021951d76a125" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -240,7 +240,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.1", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -347,21 +347,21 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-core", "futures-task", @@ -395,9 +395,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.5" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] name = "heapless" @@ -425,9 +425,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", "hashbrown", @@ -506,9 +506,10 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "messages" version = "0.1.0" -source = "git+https://github.com/uorocketry/messages#4cfab78740cf0e9f7d623feb0140ff0a4321c8f2" +source = "git+https://github.com/uorocketry/messages#5b9b56735beba4449d72e5ec074389d3363775a7" dependencies = [ "bitflags 2.6.0", + "chrono", "defmt", "derive_more", "fugit", @@ -521,7 +522,7 @@ dependencies = [ [[package]] name = "messages-proc-macros-lib" version = "0.1.0" -source = "git+https://github.com/uorocketry/messages#4cfab78740cf0e9f7d623feb0140ff0a4321c8f2" +source = "git+https://github.com/uorocketry/messages#5b9b56735beba4449d72e5ec074389d3363775a7" dependencies = [ "quote", "serde", @@ -580,9 +581,9 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pin-project-lite" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "pin-utils" @@ -592,9 +593,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "portable-atomic" -version = "1.7.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" [[package]] name = "postcard" @@ -657,9 +658,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] @@ -721,14 +722,14 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] name = "rtic-monotonics" -version = "2.0.2" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e17f88319061d17d3b99997263397b176e3260177e2b4ff4ffed0078d97894c" +checksum = "f1cb90bcfdbbacf3ca37340cdab52ec2de5611c744095ef7889e9c50c233b748" dependencies = [ "cfg-if", "cortex-m", @@ -838,22 +839,22 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.210" +version = "1.0.213" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.213" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -923,8 +924,7 @@ dependencies = [ [[package]] name = "stm32h7xx-hal" version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bd869329be25440b24e2b3583a1c016151b4a54bc36d96d82af7fcd9d010b98" +source = "git+https://github.com/uorocketry/stm32h7xx-hal#412160269f1729d55bc52de17463695db2c6bc6c" dependencies = [ "bare-metal 1.0.0", "cast", @@ -978,9 +978,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" dependencies = [ "proc-macro2", "quote", @@ -1012,29 +1012,29 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "vcell" diff --git a/Cargo.toml b/Cargo.toml index 590ed96..8cb4cf7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = ["boards/*", "examples/*", "crates/*"] default-members = ["boards/*", "examples/*"] [workspace.dependencies.stm32h7xx-hal] -version = "0.16.0" +git = "https://github.com/uorocketry/stm32h7xx-hal" # We use 35 even though we have the 33. features = ["defmt", "rt", "stm32h735", "can", "rtc"] @@ -58,7 +58,7 @@ version = "0.2" version = "0.4" [workspace.dependencies.chrono] -version = "0.4.0" +git = "https://github.com/uorocketry/chrono" default-features = false [workspace.dependencies.heapless] @@ -71,4 +71,4 @@ version = "0.5.0" git = "https://github.com/uorocketry/messages" [workspace.dependencies.defmt-test] -version = "0.3.2" \ No newline at end of file +version = "0.3.2" diff --git a/boards/pressure/src/data_manager.rs b/boards/pressure/src/data_manager.rs index c9312b8..2729860 100644 --- a/boards/pressure/src/data_manager.rs +++ b/boards/pressure/src/data_manager.rs @@ -114,44 +114,46 @@ impl DataManager { 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); - } - messages::sensor::SensorData::EkfNav2(_) => { - self.ekf_nav_2 = Some(data); - } - messages::sensor::SensorData::EkfQuat(_) => { - self.ekf_quat = Some(data); - } - messages::sensor::SensorData::GpsVel(_) => { - self.gps_vel = Some(data); - } - messages::sensor::SensorData::GpsVelAcc(_) => { - self.gps_vel_acc = Some(data); - } - 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::sensor::SensorData::SbgData(ref sbg_data) => match sbg_data{ + messages::sensor::SbgData::EkfNavAcc(_) => { + self.ekf_nav_acc = Some(data); + } + messages::sensor::SbgData::GpsPosAcc(_) => { + self.gps_pos_acc = Some(data); + } + messages::sensor::SbgData::Air(_) => { + self.air = Some(data); + } + messages::sensor::SbgData::EkfNav1(_) => { + self.ekf_nav_1 = Some(data); + } + messages::sensor::SbgData::EkfNav2(_) => { + self.ekf_nav_2 = Some(data); + } + messages::sensor::SbgData::EkfQuat(_) => { + self.ekf_quat = Some(data); + } + messages::sensor::SbgData::GpsVel(_) => { + self.gps_vel = Some(data); + } + messages::sensor::SbgData::GpsVelAcc(_) => { + self.gps_vel_acc = Some(data); + } + messages::sensor::SbgData::Imu1(_) => { + self.imu_1 = Some(data); + } + messages::sensor::SbgData::Imu2(_) => { + self.imu_2 = Some(data); + } + messages::sensor::SbgData::UtcTime(_) => { + self.utc_time = Some(data); + } + messages::sensor::SbgData::GpsPos1(_) => { + self.gps_pos_1 = Some(data); + } + messages::sensor::SbgData::GpsPos2(_) => { + self.gps_pos_2 = Some(data); + } } messages::sensor::SensorData::RecoverySensing(_) => { self.recovery_sensing = Some(data); diff --git a/boards/pressure/src/main.rs b/boards/pressure/src/main.rs index 3479d7f..d703bc0 100644 --- a/boards/pressure/src/main.rs +++ b/boards/pressure/src/main.rs @@ -9,9 +9,7 @@ use chrono::NaiveDate; use common_arm::*; use communication::{CanCommandManager, CanDataManager}; use communication::{RadioDevice, RadioManager}; -use core::cell::RefCell; use core::num::{NonZeroU16, NonZeroU8}; -use cortex_m::interrupt::Mutex; use data_manager::DataManager; use defmt::info; use fdcan::{ @@ -324,12 +322,14 @@ mod app { ) } - #[task(priority = 3, shared = [&em])] - async fn generate_random_messages(cx: generate_random_messages::Context) { + #[task(priority = 3, shared = [&em, rtc])] + async fn generate_random_messages(mut cx: generate_random_messages::Context) { loop { cx.shared.em.run(|| { let message = Message::new( - 0, + cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, messages::state::State::new(messages::state::StateData::Initializing), ); @@ -341,7 +341,7 @@ mod app { } } - #[task(priority = 3, shared = [data_manager, &em])] + #[task(priority = 3, shared = [data_manager, &em, rtc])] async fn reset_reason_send(mut cx: reset_reason_send::Context) { let reason = cx .shared @@ -364,7 +364,9 @@ mod app { stm32h7xx_hal::rcc::ResetReason::WindowWatchdogReset => sensor::ResetReason::WindowWatchdogReset, }; let message = - messages::Message::new(Mono::now().ticks(), COM_ID, sensor::Sensor::new(x)); + messages::Message::new(cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, sensor::Sensor::new(x)); cx.shared.em.run(|| { spawn!(send_gs, message)?; @@ -375,7 +377,7 @@ mod app { } } - #[task(shared = [data_manager, &em])] + #[task(shared = [data_manager, &em, rtc])] async fn state_send(mut cx: state_send::Context) { let state_data = cx .shared @@ -384,7 +386,9 @@ mod app { cx.shared.em.run(|| { if let Some(x) = state_data { let message = - Message::new(Mono::now().ticks(), COM_ID, messages::state::State::new(x)); + Message::new(cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, messages::state::State::new(x)); spawn!(send_gs, message)?; } // if there is none we still return since we simply don't have data yet. Ok(()) @@ -434,9 +438,23 @@ 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) { info!("Queueing message"); - let message = messages::Message::new(Mono::now().ticks(), COM_ID, d.into()); - info!("{:?}", message); - // send_in::spawn(message).ok(); + send_gs_intermediate::spawn(d.into()).ok(); + } + + #[task(priority = 3, shared = [rtc, &em])] + async fn send_gs_intermediate(mut cx: send_gs_intermediate::Context, m: Data) + { + cx.shared.em.run(|| { + cx.shared.rtc.lock(|rtc| { + let message = messages::Message::new( + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()), + COM_ID, + m, + ); + spawn!(send_gs, message)?; + Ok(()) + }) + }); } #[task(priority = 2, binds = FDCAN1_IT0, shared = [can_command_manager, data_manager, &em])] @@ -554,4 +572,4 @@ mod app { sbg.set_low(); }); } -} +} \ No newline at end of file diff --git a/boards/pressure/src/types.rs b/boards/pressure/src/types.rs index e854fb6..1c9a889 100644 --- a/boards/pressure/src/types.rs +++ b/boards/pressure/src/types.rs @@ -1,3 +1,3 @@ -use messages::sender::{Sender, Sender::CommunicationBoard}; +use messages::node::{Node, Node::PressureBoard}; -pub static COM_ID: Sender = CommunicationBoard; +pub static COM_ID: Node = PressureBoard; diff --git a/boards/strain/src/data_manager.rs b/boards/strain/src/data_manager.rs index c9312b8..2729860 100644 --- a/boards/strain/src/data_manager.rs +++ b/boards/strain/src/data_manager.rs @@ -114,44 +114,46 @@ impl DataManager { 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); - } - messages::sensor::SensorData::EkfNav2(_) => { - self.ekf_nav_2 = Some(data); - } - messages::sensor::SensorData::EkfQuat(_) => { - self.ekf_quat = Some(data); - } - messages::sensor::SensorData::GpsVel(_) => { - self.gps_vel = Some(data); - } - messages::sensor::SensorData::GpsVelAcc(_) => { - self.gps_vel_acc = Some(data); - } - 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::sensor::SensorData::SbgData(ref sbg_data) => match sbg_data{ + messages::sensor::SbgData::EkfNavAcc(_) => { + self.ekf_nav_acc = Some(data); + } + messages::sensor::SbgData::GpsPosAcc(_) => { + self.gps_pos_acc = Some(data); + } + messages::sensor::SbgData::Air(_) => { + self.air = Some(data); + } + messages::sensor::SbgData::EkfNav1(_) => { + self.ekf_nav_1 = Some(data); + } + messages::sensor::SbgData::EkfNav2(_) => { + self.ekf_nav_2 = Some(data); + } + messages::sensor::SbgData::EkfQuat(_) => { + self.ekf_quat = Some(data); + } + messages::sensor::SbgData::GpsVel(_) => { + self.gps_vel = Some(data); + } + messages::sensor::SbgData::GpsVelAcc(_) => { + self.gps_vel_acc = Some(data); + } + messages::sensor::SbgData::Imu1(_) => { + self.imu_1 = Some(data); + } + messages::sensor::SbgData::Imu2(_) => { + self.imu_2 = Some(data); + } + messages::sensor::SbgData::UtcTime(_) => { + self.utc_time = Some(data); + } + messages::sensor::SbgData::GpsPos1(_) => { + self.gps_pos_1 = Some(data); + } + messages::sensor::SbgData::GpsPos2(_) => { + self.gps_pos_2 = Some(data); + } } messages::sensor::SensorData::RecoverySensing(_) => { self.recovery_sensing = Some(data); diff --git a/boards/strain/src/main.rs b/boards/strain/src/main.rs index 3479d7f..d703bc0 100644 --- a/boards/strain/src/main.rs +++ b/boards/strain/src/main.rs @@ -9,9 +9,7 @@ use chrono::NaiveDate; use common_arm::*; use communication::{CanCommandManager, CanDataManager}; use communication::{RadioDevice, RadioManager}; -use core::cell::RefCell; use core::num::{NonZeroU16, NonZeroU8}; -use cortex_m::interrupt::Mutex; use data_manager::DataManager; use defmt::info; use fdcan::{ @@ -324,12 +322,14 @@ mod app { ) } - #[task(priority = 3, shared = [&em])] - async fn generate_random_messages(cx: generate_random_messages::Context) { + #[task(priority = 3, shared = [&em, rtc])] + async fn generate_random_messages(mut cx: generate_random_messages::Context) { loop { cx.shared.em.run(|| { let message = Message::new( - 0, + cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, messages::state::State::new(messages::state::StateData::Initializing), ); @@ -341,7 +341,7 @@ mod app { } } - #[task(priority = 3, shared = [data_manager, &em])] + #[task(priority = 3, shared = [data_manager, &em, rtc])] async fn reset_reason_send(mut cx: reset_reason_send::Context) { let reason = cx .shared @@ -364,7 +364,9 @@ mod app { stm32h7xx_hal::rcc::ResetReason::WindowWatchdogReset => sensor::ResetReason::WindowWatchdogReset, }; let message = - messages::Message::new(Mono::now().ticks(), COM_ID, sensor::Sensor::new(x)); + messages::Message::new(cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, sensor::Sensor::new(x)); cx.shared.em.run(|| { spawn!(send_gs, message)?; @@ -375,7 +377,7 @@ mod app { } } - #[task(shared = [data_manager, &em])] + #[task(shared = [data_manager, &em, rtc])] async fn state_send(mut cx: state_send::Context) { let state_data = cx .shared @@ -384,7 +386,9 @@ mod app { cx.shared.em.run(|| { if let Some(x) = state_data { let message = - Message::new(Mono::now().ticks(), COM_ID, messages::state::State::new(x)); + Message::new(cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, messages::state::State::new(x)); spawn!(send_gs, message)?; } // if there is none we still return since we simply don't have data yet. Ok(()) @@ -434,9 +438,23 @@ 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) { info!("Queueing message"); - let message = messages::Message::new(Mono::now().ticks(), COM_ID, d.into()); - info!("{:?}", message); - // send_in::spawn(message).ok(); + send_gs_intermediate::spawn(d.into()).ok(); + } + + #[task(priority = 3, shared = [rtc, &em])] + async fn send_gs_intermediate(mut cx: send_gs_intermediate::Context, m: Data) + { + cx.shared.em.run(|| { + cx.shared.rtc.lock(|rtc| { + let message = messages::Message::new( + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()), + COM_ID, + m, + ); + spawn!(send_gs, message)?; + Ok(()) + }) + }); } #[task(priority = 2, binds = FDCAN1_IT0, shared = [can_command_manager, data_manager, &em])] @@ -554,4 +572,4 @@ mod app { sbg.set_low(); }); } -} +} \ No newline at end of file diff --git a/boards/strain/src/types.rs b/boards/strain/src/types.rs index e854fb6..7ebc58c 100644 --- a/boards/strain/src/types.rs +++ b/boards/strain/src/types.rs @@ -1,3 +1,3 @@ -use messages::sender::{Sender, Sender::CommunicationBoard}; +use messages::node::{Node, Node::StrainBoard}; -pub static COM_ID: Sender = CommunicationBoard; +pub static COM_ID: Node = StrainBoard; diff --git a/boards/temperature/src/data_manager.rs b/boards/temperature/src/data_manager.rs index c9312b8..2729860 100644 --- a/boards/temperature/src/data_manager.rs +++ b/boards/temperature/src/data_manager.rs @@ -114,44 +114,46 @@ impl DataManager { 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); - } - messages::sensor::SensorData::EkfNav2(_) => { - self.ekf_nav_2 = Some(data); - } - messages::sensor::SensorData::EkfQuat(_) => { - self.ekf_quat = Some(data); - } - messages::sensor::SensorData::GpsVel(_) => { - self.gps_vel = Some(data); - } - messages::sensor::SensorData::GpsVelAcc(_) => { - self.gps_vel_acc = Some(data); - } - 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::sensor::SensorData::SbgData(ref sbg_data) => match sbg_data{ + messages::sensor::SbgData::EkfNavAcc(_) => { + self.ekf_nav_acc = Some(data); + } + messages::sensor::SbgData::GpsPosAcc(_) => { + self.gps_pos_acc = Some(data); + } + messages::sensor::SbgData::Air(_) => { + self.air = Some(data); + } + messages::sensor::SbgData::EkfNav1(_) => { + self.ekf_nav_1 = Some(data); + } + messages::sensor::SbgData::EkfNav2(_) => { + self.ekf_nav_2 = Some(data); + } + messages::sensor::SbgData::EkfQuat(_) => { + self.ekf_quat = Some(data); + } + messages::sensor::SbgData::GpsVel(_) => { + self.gps_vel = Some(data); + } + messages::sensor::SbgData::GpsVelAcc(_) => { + self.gps_vel_acc = Some(data); + } + messages::sensor::SbgData::Imu1(_) => { + self.imu_1 = Some(data); + } + messages::sensor::SbgData::Imu2(_) => { + self.imu_2 = Some(data); + } + messages::sensor::SbgData::UtcTime(_) => { + self.utc_time = Some(data); + } + messages::sensor::SbgData::GpsPos1(_) => { + self.gps_pos_1 = Some(data); + } + messages::sensor::SbgData::GpsPos2(_) => { + self.gps_pos_2 = Some(data); + } } messages::sensor::SensorData::RecoverySensing(_) => { self.recovery_sensing = Some(data); diff --git a/boards/temperature/src/main.rs b/boards/temperature/src/main.rs index d3564e4..d703bc0 100644 --- a/boards/temperature/src/main.rs +++ b/boards/temperature/src/main.rs @@ -9,9 +9,7 @@ use chrono::NaiveDate; use common_arm::*; use communication::{CanCommandManager, CanDataManager}; use communication::{RadioDevice, RadioManager}; -use core::cell::RefCell; use core::num::{NonZeroU16, NonZeroU8}; -use cortex_m::interrupt::Mutex; use data_manager::DataManager; use defmt::info; use fdcan::{ @@ -324,12 +322,14 @@ mod app { ) } - #[task(priority = 3, shared = [&em])] - async fn generate_random_messages(cx: generate_random_messages::Context) { + #[task(priority = 3, shared = [&em, rtc])] + async fn generate_random_messages(mut cx: generate_random_messages::Context) { loop { cx.shared.em.run(|| { let message = Message::new( - 0, + cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, messages::state::State::new(messages::state::StateData::Initializing), ); @@ -341,7 +341,7 @@ mod app { } } - #[task(priority = 3, shared = [data_manager, &em])] + #[task(priority = 3, shared = [data_manager, &em, rtc])] async fn reset_reason_send(mut cx: reset_reason_send::Context) { let reason = cx .shared @@ -364,7 +364,9 @@ mod app { stm32h7xx_hal::rcc::ResetReason::WindowWatchdogReset => sensor::ResetReason::WindowWatchdogReset, }; let message = - messages::Message::new(Mono::now().ticks(), COM_ID, sensor::Sensor::new(x)); + messages::Message::new(cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, sensor::Sensor::new(x)); cx.shared.em.run(|| { spawn!(send_gs, message)?; @@ -375,7 +377,7 @@ mod app { } } - #[task(shared = [data_manager, &em])] + #[task(shared = [data_manager, &em, rtc])] async fn state_send(mut cx: state_send::Context) { let state_data = cx .shared @@ -384,7 +386,9 @@ mod app { cx.shared.em.run(|| { if let Some(x) = state_data { let message = - Message::new(Mono::now().ticks(), COM_ID, messages::state::State::new(x)); + Message::new(cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, messages::state::State::new(x)); spawn!(send_gs, message)?; } // if there is none we still return since we simply don't have data yet. Ok(()) @@ -434,9 +438,23 @@ 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) { info!("Queueing message"); - let message = messages::Message::new(Mono::now().ticks(), COM_ID, d.into()); - info!("{:?}", message); - // send_in::spawn(message).ok(); + send_gs_intermediate::spawn(d.into()).ok(); + } + + #[task(priority = 3, shared = [rtc, &em])] + async fn send_gs_intermediate(mut cx: send_gs_intermediate::Context, m: Data) + { + cx.shared.em.run(|| { + cx.shared.rtc.lock(|rtc| { + let message = messages::Message::new( + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()), + COM_ID, + m, + ); + spawn!(send_gs, message)?; + Ok(()) + }) + }); } #[task(priority = 2, binds = FDCAN1_IT0, shared = [can_command_manager, data_manager, &em])] diff --git a/boards/temperature/src/types.rs b/boards/temperature/src/types.rs index e854fb6..551ed32 100644 --- a/boards/temperature/src/types.rs +++ b/boards/temperature/src/types.rs @@ -1,3 +1,3 @@ -use messages::sender::{Sender, Sender::CommunicationBoard}; +use messages::node::{Node, Node::TemperatureBoard}; -pub static COM_ID: Sender = CommunicationBoard; +pub static COM_ID: Node = TemperatureBoard; diff --git a/crates/common-arm/Cargo.toml b/crates/common-arm/Cargo.toml index 7e6902d..c629dc4 100644 --- a/crates/common-arm/Cargo.toml +++ b/crates/common-arm/Cargo.toml @@ -23,4 +23,8 @@ defmt-test = { workspace = true } [[test]] name = "example" +harness = false + +[lib] +name = "common_arm" harness = false \ No newline at end of file diff --git a/crates/common-arm/src/lib.rs b/crates/common-arm/src/lib.rs index 247094f..4896d13 100644 --- a/crates/common-arm/src/lib.rs +++ b/crates/common-arm/src/lib.rs @@ -1,4 +1,5 @@ #![no_std] +#![no_main] //! //! This crate contains common code. Any code that is not platform specific should be put in diff --git a/examples/rtic-playground/src/data_manager.rs b/examples/rtic-playground/src/data_manager.rs index c9312b8..2729860 100644 --- a/examples/rtic-playground/src/data_manager.rs +++ b/examples/rtic-playground/src/data_manager.rs @@ -114,44 +114,46 @@ impl DataManager { 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); - } - messages::sensor::SensorData::EkfNav2(_) => { - self.ekf_nav_2 = Some(data); - } - messages::sensor::SensorData::EkfQuat(_) => { - self.ekf_quat = Some(data); - } - messages::sensor::SensorData::GpsVel(_) => { - self.gps_vel = Some(data); - } - messages::sensor::SensorData::GpsVelAcc(_) => { - self.gps_vel_acc = Some(data); - } - 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::sensor::SensorData::SbgData(ref sbg_data) => match sbg_data{ + messages::sensor::SbgData::EkfNavAcc(_) => { + self.ekf_nav_acc = Some(data); + } + messages::sensor::SbgData::GpsPosAcc(_) => { + self.gps_pos_acc = Some(data); + } + messages::sensor::SbgData::Air(_) => { + self.air = Some(data); + } + messages::sensor::SbgData::EkfNav1(_) => { + self.ekf_nav_1 = Some(data); + } + messages::sensor::SbgData::EkfNav2(_) => { + self.ekf_nav_2 = Some(data); + } + messages::sensor::SbgData::EkfQuat(_) => { + self.ekf_quat = Some(data); + } + messages::sensor::SbgData::GpsVel(_) => { + self.gps_vel = Some(data); + } + messages::sensor::SbgData::GpsVelAcc(_) => { + self.gps_vel_acc = Some(data); + } + messages::sensor::SbgData::Imu1(_) => { + self.imu_1 = Some(data); + } + messages::sensor::SbgData::Imu2(_) => { + self.imu_2 = Some(data); + } + messages::sensor::SbgData::UtcTime(_) => { + self.utc_time = Some(data); + } + messages::sensor::SbgData::GpsPos1(_) => { + self.gps_pos_1 = Some(data); + } + messages::sensor::SbgData::GpsPos2(_) => { + self.gps_pos_2 = Some(data); + } } messages::sensor::SensorData::RecoverySensing(_) => { self.recovery_sensing = Some(data); diff --git a/examples/rtic-playground/src/main.rs b/examples/rtic-playground/src/main.rs index f81829d..d703bc0 100644 --- a/examples/rtic-playground/src/main.rs +++ b/examples/rtic-playground/src/main.rs @@ -9,9 +9,7 @@ use chrono::NaiveDate; use common_arm::*; use communication::{CanCommandManager, CanDataManager}; use communication::{RadioDevice, RadioManager}; -use core::cell::RefCell; use core::num::{NonZeroU16, NonZeroU8}; -use cortex_m::interrupt::Mutex; use data_manager::DataManager; use defmt::info; use fdcan::{ @@ -324,12 +322,14 @@ mod app { ) } - #[task(priority = 3, shared = [&em])] - async fn generate_random_messages(cx: generate_random_messages::Context) { + #[task(priority = 3, shared = [&em, rtc])] + async fn generate_random_messages(mut cx: generate_random_messages::Context) { loop { cx.shared.em.run(|| { let message = Message::new( - 0, + cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, messages::state::State::new(messages::state::StateData::Initializing), ); @@ -341,7 +341,7 @@ mod app { } } - #[task(priority = 3, shared = [data_manager, &em])] + #[task(priority = 3, shared = [data_manager, &em, rtc])] async fn reset_reason_send(mut cx: reset_reason_send::Context) { let reason = cx .shared @@ -364,7 +364,9 @@ mod app { stm32h7xx_hal::rcc::ResetReason::WindowWatchdogReset => sensor::ResetReason::WindowWatchdogReset, }; let message = - messages::Message::new(Mono::now().ticks(), COM_ID, sensor::Sensor::new(x)); + messages::Message::new(cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, sensor::Sensor::new(x)); cx.shared.em.run(|| { spawn!(send_gs, message)?; @@ -375,7 +377,7 @@ mod app { } } - #[task(shared = [data_manager, &em])] + #[task(shared = [data_manager, &em, rtc])] async fn state_send(mut cx: state_send::Context) { let state_data = cx .shared @@ -384,7 +386,9 @@ mod app { cx.shared.em.run(|| { if let Some(x) = state_data { let message = - Message::new(Mono::now().ticks(), COM_ID, messages::state::State::new(x)); + Message::new(cx.shared.rtc.lock(|rtc| { + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()) + }), COM_ID, messages::state::State::new(x)); spawn!(send_gs, message)?; } // if there is none we still return since we simply don't have data yet. Ok(()) @@ -434,9 +438,23 @@ 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) { info!("Queueing message"); - let message = messages::Message::new(Mono::now().ticks(), COM_ID, d.into()); - info!("{:?}", message); - // send_in::spawn(message).ok(); + send_gs_intermediate::spawn(d.into()).ok(); + } + + #[task(priority = 3, shared = [rtc, &em])] + async fn send_gs_intermediate(mut cx: send_gs_intermediate::Context, m: Data) + { + cx.shared.em.run(|| { + cx.shared.rtc.lock(|rtc| { + let message = messages::Message::new( + messages::FormattedNaiveDateTime(rtc.date_time().unwrap()), + COM_ID, + m, + ); + spawn!(send_gs, message)?; + Ok(()) + }) + }); } #[task(priority = 2, binds = FDCAN1_IT0, shared = [can_command_manager, data_manager, &em])] @@ -477,34 +495,15 @@ mod app { }); } - // #[task(priority = 3, binds = UART4, local = [just_fired: bool = false], shared = [&em, radio_manager])] - // fn radio_rx(mut cx: radio_rx::Context) { - // if *cx.local.just_fired { - // *cx.local.just_fired = false; - // return; - // } - // info!("Radio Rx"); - - // cx.shared.radio_manager.lock(|radio_manager| { - // cx.shared.em.run(|| { - // // cortex_m::interrupt::free(|cs| { - // let m = radio_manager.receive_message()?; - // *cx.local.just_fired = true; - // info!("Received message {}", m.clone()); - // spawn!(send_command_internal, m)?; - // // })?; - // Ok(()) - // }); - // }); - // } - #[task( priority = 3, binds = FDCAN2_IT0, shared = [&em, can_data_manager, data_manager])] fn can_data(mut cx: can_data::Context) { cx.shared.can_data_manager.lock(|can| { - cx.shared.em.run(|| { - can.process_data()?; - Ok(()) - }); + { + cx.shared.em.run(|| { + can.process_data()?; + Ok(()) + }) + } }); } @@ -573,4 +572,4 @@ mod app { sbg.set_low(); }); } -} +} \ No newline at end of file diff --git a/examples/rtic-playground/src/types.rs b/examples/rtic-playground/src/types.rs index e854fb6..551ed32 100644 --- a/examples/rtic-playground/src/types.rs +++ b/examples/rtic-playground/src/types.rs @@ -1,3 +1,3 @@ -use messages::sender::{Sender, Sender::CommunicationBoard}; +use messages::node::{Node, Node::TemperatureBoard}; -pub static COM_ID: Sender = CommunicationBoard; +pub static COM_ID: Node = TemperatureBoard;