From dffdb604de2b0059aed318db0704e8294cabdfce Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Tue, 1 Oct 2024 20:22:14 -0400 Subject: [PATCH 01/15] Update boards, timestamp, and sender to node. --- Cargo.toml | 1 + messages-proc-macros-lib/src/lib.rs | 2 +- src/command.rs | 4 ++-- src/lib.rs | 21 ++++++++++---------- src/node.rs | 19 ++++++++++++++++++ src/sender.rs | 30 ----------------------------- 6 files changed, 33 insertions(+), 44 deletions(-) create mode 100644 src/node.rs delete mode 100644 src/sender.rs diff --git a/Cargo.toml b/Cargo.toml index 0aa4c36..50df5ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ bitflags = { version = "2.3.1", features = ["serde"] } proptest = { version = "1.2.0", optional = true } proptest-derive = { version = "0.3.0", optional = true } messages-proc-macros-lib = { path = "messages-proc-macros-lib" } +chrono = {version = "0.4.0", features = ["serde"], default-features = false} [dev-dependencies] proptest = "1.2.0" diff --git a/messages-proc-macros-lib/src/lib.rs b/messages-proc-macros-lib/src/lib.rs index 93861be..3201a9b 100644 --- a/messages-proc-macros-lib/src/lib.rs +++ b/messages-proc-macros-lib/src/lib.rs @@ -8,7 +8,7 @@ pub fn common_derives(args: TokenStream, input: TokenStream) -> TokenStream { #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] #[cfg_attr(feature = "ts", derive(ts_rs::TS))] #[cfg_attr(feature = "ts", ts(export))] - #[cfg_attr(test, derive(proptest_derive::Arbitrary))] + #[cfg_attr(all(test, feature = "std"), derive(proptest_derive::Arbitrary))] }); // Allow to omit the defmt::Format derive. Useful if this should be manually implemented. diff --git a/src/command.rs b/src/command.rs index eb76a78..32b2703 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1,4 +1,4 @@ -use crate::sender::Sender; +use crate::node::Node; use derive_more::From; use messages_proc_macros_lib::common_derives; @@ -39,7 +39,7 @@ pub struct DeployMain { #[common_derives] #[derive(From)] pub struct PowerDown { - pub board: Sender, // This isn't proper naming !! This is the board to be powered down. Changes name of sender.rs to board.rs. + pub board: Node, // This isn't proper naming !! This is the board to be powered down. Changes name of sender.rs to board.rs. } #[common_derives] diff --git a/src/lib.rs b/src/lib.rs index 910acc7..950c11b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,17 +7,18 @@ //! and ground-station communication. use crate::command::Command; -use crate::sender::Sender; +use crate::node::Node; use crate::sensor::Sensor; use crate::state::State; use derive_more::From; /// This is to help control versions. pub use mavlink; +use chrono::NaiveDateTime; use messages_proc_macros_lib::common_derives; pub mod command; mod logging; -pub mod sender; +pub mod node; pub mod sensor; pub mod sensor_status; pub mod state; @@ -28,14 +29,12 @@ pub use logging::{ErrorContext, Event, Log, LogLevel}; /// Topmost message. Encloses all the other possible messages, and is the only thing that should /// be sent over the wire. -#[common_derives] +#[common_derives("NoFormat")] pub struct Message { - /// Time in milliseconds since epoch. Note that the epoch here can be arbitrary and is not the - /// Unix epoch. - pub timestamp: u32, + pub timestamp: NaiveDateTime, /// The original sender of this message. - pub sender: Sender, + pub node: Node, /// The data contained in this message. pub data: Data, @@ -52,16 +51,16 @@ pub enum Data { } impl Message { - pub fn new(timestamp: u32, sender: Sender, data: impl Into) -> Self { + pub fn new(timestamp: NaiveDateTime, node: Node, data: impl Into) -> Self { Message { - timestamp: timestamp, - sender, + timestamp, + node, data: data.into(), } } } -#[cfg(test)] +#[cfg(all(test, feature = "std"))] mod test { use crate::{Message, MAX_SIZE}; use proptest::prelude::*; diff --git a/src/node.rs b/src/node.rs new file mode 100644 index 0000000..a58236b --- /dev/null +++ b/src/node.rs @@ -0,0 +1,19 @@ +use messages_proc_macros_lib::common_derives; + +#[common_derives] +#[derive(Copy)] +pub enum Node { + PressureBoard, + TemperatureBoard, + StrainBoard, +} + +impl From for u16 { + fn from(node: Node) -> Self { + match node { + Node::PressureBoard => 0, + Node::TemperatureBoard => 1, + Node::StrainBoard => 2, + } + } +} diff --git a/src/sender.rs b/src/sender.rs deleted file mode 100644 index 8610893..0000000 --- a/src/sender.rs +++ /dev/null @@ -1,30 +0,0 @@ -use messages_proc_macros_lib::common_derives; - -// I don't agree with the naming, We can use these as Ids to sent commands to that specific board. -#[common_derives] -#[derive(Copy)] -pub enum Sender { - GroundStation, - SensorBoard, - RecoveryBoard, - CommunicationBoard, - PowerBoard, - CameraBoard, - BeaconBoard, - GpsBoard, -} - -impl From for u16 { - fn from(sender: Sender) -> Self { - match sender { - Sender::GroundStation => 0, - Sender::SensorBoard => 1, - Sender::RecoveryBoard => 2, - Sender::CommunicationBoard => 3, - Sender::PowerBoard => 4, - Sender::CameraBoard => 5, - Sender::BeaconBoard => 6, - Sender::GpsBoard => 7, - } - } -} From 5ebd97c528b92089e321abfacff88797f10cef97 Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Tue, 1 Oct 2024 21:47:30 -0400 Subject: [PATCH 02/15] Remove proptest. --- messages-proc-macros-lib/src/lib.rs | 2 +- src/lib.rs | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/messages-proc-macros-lib/src/lib.rs b/messages-proc-macros-lib/src/lib.rs index 3201a9b..f7d6333 100644 --- a/messages-proc-macros-lib/src/lib.rs +++ b/messages-proc-macros-lib/src/lib.rs @@ -8,7 +8,7 @@ pub fn common_derives(args: TokenStream, input: TokenStream) -> TokenStream { #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] #[cfg_attr(feature = "ts", derive(ts_rs::TS))] #[cfg_attr(feature = "ts", ts(export))] - #[cfg_attr(all(test, feature = "std"), derive(proptest_derive::Arbitrary))] + // #[cfg_attr(test, derive(proptest_derive::Arbitrary))] }); // Allow to omit the defmt::Format derive. Useful if this should be manually implemented. diff --git a/src/lib.rs b/src/lib.rs index 950c11b..5da067c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,18 +60,18 @@ impl Message { } } -#[cfg(all(test, feature = "std"))] -mod test { - use crate::{Message, MAX_SIZE}; - use proptest::prelude::*; +// #[cfg(test)] +// mod test { +// use crate::{Message, MAX_SIZE}; +// use proptest::prelude::*; - proptest! { - #[test] - fn message_size(msg: Message) { - let bytes = postcard::to_allocvec(&msg).unwrap(); +// proptest! { +// #[test] +// fn message_size(msg: Message) { +// let bytes = postcard::to_allocvec(&msg).unwrap(); - dbg!(msg); - assert!(dbg!(bytes.len()) <= MAX_SIZE); - } - } -} +// dbg!(msg); +// assert!(dbg!(bytes.len()) <= MAX_SIZE); +// } +// } +// } From 212342456ae9575737dd4a34537560db4e87302f Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Wed, 2 Oct 2024 18:54:15 -0400 Subject: [PATCH 03/15] Update attributes. --- Cargo.toml | 2 +- messages-proc-macros-lib/src/lib.rs | 2 +- src/lib.rs | 26 +++++++++++++------------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 50df5ef..71cb2e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ bitflags = { version = "2.3.1", features = ["serde"] } proptest = { version = "1.2.0", optional = true } proptest-derive = { version = "0.3.0", optional = true } messages-proc-macros-lib = { path = "messages-proc-macros-lib" } -chrono = {version = "0.4.0", features = ["serde"], default-features = false} +chrono = {version = "0.4.0", features = ["serde", "arbitrary"], default-features = false} [dev-dependencies] proptest = "1.2.0" diff --git a/messages-proc-macros-lib/src/lib.rs b/messages-proc-macros-lib/src/lib.rs index f7d6333..afd8eca 100644 --- a/messages-proc-macros-lib/src/lib.rs +++ b/messages-proc-macros-lib/src/lib.rs @@ -8,7 +8,7 @@ pub fn common_derives(args: TokenStream, input: TokenStream) -> TokenStream { #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] #[cfg_attr(feature = "ts", derive(ts_rs::TS))] #[cfg_attr(feature = "ts", ts(export))] - // #[cfg_attr(test, derive(proptest_derive::Arbitrary))] + #[cfg_attr(std, derive(proptest_derive::Arbitrary))] }); // Allow to omit the defmt::Format derive. Useful if this should be manually implemented. diff --git a/src/lib.rs b/src/lib.rs index 5da067c..950c11b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,18 +60,18 @@ impl Message { } } -// #[cfg(test)] -// mod test { -// use crate::{Message, MAX_SIZE}; -// use proptest::prelude::*; +#[cfg(all(test, feature = "std"))] +mod test { + use crate::{Message, MAX_SIZE}; + use proptest::prelude::*; -// proptest! { -// #[test] -// fn message_size(msg: Message) { -// let bytes = postcard::to_allocvec(&msg).unwrap(); + proptest! { + #[test] + fn message_size(msg: Message) { + let bytes = postcard::to_allocvec(&msg).unwrap(); -// dbg!(msg); -// assert!(dbg!(bytes.len()) <= MAX_SIZE); -// } -// } -// } + dbg!(msg); + assert!(dbg!(bytes.len()) <= MAX_SIZE); + } + } +} From c13ffb565d54c9c368498fa70c09c089fd15dafa Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Wed, 2 Oct 2024 20:01:26 -0400 Subject: [PATCH 04/15] :( --- Cargo.toml | 2 +- messages-proc-macros-lib/src/lib.rs | 4 ++-- src/lib.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 71cb2e2..a1ff90d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,4 +27,4 @@ postcard = { version = "1.0.4", features = ["alloc"] } [features] default = ["mavlink/embedded-hal-02", "mavlink/uorocketry"] -std = ["mavlink/std", "mavlink/tcp", "mavlink/udp", "mavlink/direct-serial", "mavlink/serde", "dep:proptest", "dep:proptest-derive"] +std = ["chrono/std", "mavlink/std", "mavlink/tcp", "mavlink/udp", "mavlink/direct-serial", "mavlink/serde", "dep:proptest", "dep:proptest-derive"] diff --git a/messages-proc-macros-lib/src/lib.rs b/messages-proc-macros-lib/src/lib.rs index afd8eca..0189974 100644 --- a/messages-proc-macros-lib/src/lib.rs +++ b/messages-proc-macros-lib/src/lib.rs @@ -3,7 +3,7 @@ use quote::quote; /// Simple macro to easily add derives that are common for the messages crates. #[proc_macro_attribute] -pub fn common_derives(args: TokenStream, input: TokenStream) -> TokenStream { +pub fn common_derives(args: TokenStream, input: TokenStream) -> TokenStream { let mut output = TokenStream::from(quote! { #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] #[cfg_attr(feature = "ts", derive(ts_rs::TS))] @@ -20,4 +20,4 @@ pub fn common_derives(args: TokenStream, input: TokenStream) -> TokenStream { output.extend(input); output -} +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 950c11b..05f0744 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(all(not(feature = "std"), not(test)), no_std)] #![no_main] -//! # HYDRA Messages +//! # Messages //! //! This crate contains all the message definitions that will be used for inter-board communication //! and ground-station communication. @@ -29,7 +29,7 @@ pub use logging::{ErrorContext, Event, Log, LogLevel}; /// Topmost message. Encloses all the other possible messages, and is the only thing that should /// be sent over the wire. -#[common_derives("NoFormat")] +#[common_derives(NoFormat)] pub struct Message { pub timestamp: NaiveDateTime, @@ -60,7 +60,7 @@ impl Message { } } -#[cfg(all(test, feature = "std"))] +#[cfg(test)] mod test { use crate::{Message, MAX_SIZE}; use proptest::prelude::*; From ad735b14aca0f355fa59c95afbd2ead99a4795ea Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Wed, 2 Oct 2024 20:06:03 -0400 Subject: [PATCH 05/15] ? --- Cargo.toml | 4 ++-- messages-proc-macros-lib/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a1ff90d..50df5ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ bitflags = { version = "2.3.1", features = ["serde"] } proptest = { version = "1.2.0", optional = true } proptest-derive = { version = "0.3.0", optional = true } messages-proc-macros-lib = { path = "messages-proc-macros-lib" } -chrono = {version = "0.4.0", features = ["serde", "arbitrary"], default-features = false} +chrono = {version = "0.4.0", features = ["serde"], default-features = false} [dev-dependencies] proptest = "1.2.0" @@ -27,4 +27,4 @@ postcard = { version = "1.0.4", features = ["alloc"] } [features] default = ["mavlink/embedded-hal-02", "mavlink/uorocketry"] -std = ["chrono/std", "mavlink/std", "mavlink/tcp", "mavlink/udp", "mavlink/direct-serial", "mavlink/serde", "dep:proptest", "dep:proptest-derive"] +std = ["mavlink/std", "mavlink/tcp", "mavlink/udp", "mavlink/direct-serial", "mavlink/serde", "dep:proptest", "dep:proptest-derive"] diff --git a/messages-proc-macros-lib/src/lib.rs b/messages-proc-macros-lib/src/lib.rs index 0189974..cb9666f 100644 --- a/messages-proc-macros-lib/src/lib.rs +++ b/messages-proc-macros-lib/src/lib.rs @@ -8,7 +8,7 @@ pub fn common_derives(args: TokenStream, input: TokenStream) -> TokenStream { #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] #[cfg_attr(feature = "ts", derive(ts_rs::TS))] #[cfg_attr(feature = "ts", ts(export))] - #[cfg_attr(std, derive(proptest_derive::Arbitrary))] + #[cfg_attr(test, derive(proptest_derive::Arbitrary))] }); // Allow to omit the defmt::Format derive. Useful if this should be manually implemented. From 0da954107013057cfbaa386ac48980092e81108f Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Fri, 4 Oct 2024 19:51:02 -0400 Subject: [PATCH 06/15] ew --- Cargo.toml | 4 ++-- src/lib.rs | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 50df5ef..a1ff90d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ bitflags = { version = "2.3.1", features = ["serde"] } proptest = { version = "1.2.0", optional = true } proptest-derive = { version = "0.3.0", optional = true } messages-proc-macros-lib = { path = "messages-proc-macros-lib" } -chrono = {version = "0.4.0", features = ["serde"], default-features = false} +chrono = {version = "0.4.0", features = ["serde", "arbitrary"], default-features = false} [dev-dependencies] proptest = "1.2.0" @@ -27,4 +27,4 @@ postcard = { version = "1.0.4", features = ["alloc"] } [features] default = ["mavlink/embedded-hal-02", "mavlink/uorocketry"] -std = ["mavlink/std", "mavlink/tcp", "mavlink/udp", "mavlink/direct-serial", "mavlink/serde", "dep:proptest", "dep:proptest-derive"] +std = ["chrono/std", "mavlink/std", "mavlink/tcp", "mavlink/udp", "mavlink/direct-serial", "mavlink/serde", "dep:proptest", "dep:proptest-derive"] diff --git a/src/lib.rs b/src/lib.rs index 05f0744..2ad296d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,16 +22,47 @@ pub mod node; pub mod sensor; pub mod sensor_status; pub mod state; - +use chrono::{NaiveDate, NaiveTime}; +#[cfg(test)] +use proptest::prelude::*; pub const MAX_SIZE: usize = 64; pub use logging::{ErrorContext, Event, Log, LogLevel}; +use defmt::Format; + +#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] +pub struct FormattedNaiveDateTime(pub NaiveDateTime); + +impl Format for FormattedNaiveDateTime { + fn format(&self, fmt: defmt::Formatter) { + defmt::write!(fmt, ""); + } +} + +#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] +pub struct ArbitraryNaiveDateTime(pub FormattedNaiveDateTime); + +#[cfg(test)] +impl Arbitrary for ArbitraryNaiveDateTime { + type Parameters = (); + type Strategy = BoxedStrategy; + + fn arbitrary_with(_: Self::Parameters) -> Self::Strategy { + (0..=9999i32, 1u32..=12, 1u32..=31, 0u32..24, 0u32..60, 0u32..60, 0u32..1_000_000_000) + .prop_map(|(year, month, day, hour, minute, second, nanosecond)| { + ArbitraryNaiveDateTime( + FormattedNaiveDateTime(NaiveDate::from_ymd(year, month, day).and_hms_nano(hour, minute, second, nanosecond)) + ) + }) + .boxed() + } +} /// Topmost message. Encloses all the other possible messages, and is the only thing that should /// be sent over the wire. #[common_derives(NoFormat)] pub struct Message { - pub timestamp: NaiveDateTime, + pub timestamp: ArbitraryNaiveDateTime, /// The original sender of this message. pub node: Node, @@ -51,7 +82,7 @@ pub enum Data { } impl Message { - pub fn new(timestamp: NaiveDateTime, node: Node, data: impl Into) -> Self { + pub fn new(timestamp: ArbitraryNaiveDateTime, node: Node, data: impl Into) -> Self { Message { timestamp, node, From 48c0c94833293a8cb51c79a7f775809f27f9262c Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Fri, 4 Oct 2024 20:46:11 -0400 Subject: [PATCH 07/15] :( --- Cargo.toml | 2 +- src/lib.rs | 27 +++------------------------ 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a1ff90d..6f5890d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ bitflags = { version = "2.3.1", features = ["serde"] } proptest = { version = "1.2.0", optional = true } proptest-derive = { version = "0.3.0", optional = true } messages-proc-macros-lib = { path = "messages-proc-macros-lib" } -chrono = {version = "0.4.0", features = ["serde", "arbitrary"], default-features = false} +chrono = {git = "https://github.com/uorocketry/chrono", features = ["serde", "arbitrary"], default-features = false} [dev-dependencies] proptest = "1.2.0" diff --git a/src/lib.rs b/src/lib.rs index 2ad296d..d45b504 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,9 +22,7 @@ pub mod node; pub mod sensor; pub mod sensor_status; pub mod state; -use chrono::{NaiveDate, NaiveTime}; -#[cfg(test)] -use proptest::prelude::*; + pub const MAX_SIZE: usize = 64; pub use logging::{ErrorContext, Event, Log, LogLevel}; @@ -39,30 +37,11 @@ impl Format for FormattedNaiveDateTime { } } -#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] -pub struct ArbitraryNaiveDateTime(pub FormattedNaiveDateTime); - -#[cfg(test)] -impl Arbitrary for ArbitraryNaiveDateTime { - type Parameters = (); - type Strategy = BoxedStrategy; - - fn arbitrary_with(_: Self::Parameters) -> Self::Strategy { - (0..=9999i32, 1u32..=12, 1u32..=31, 0u32..24, 0u32..60, 0u32..60, 0u32..1_000_000_000) - .prop_map(|(year, month, day, hour, minute, second, nanosecond)| { - ArbitraryNaiveDateTime( - FormattedNaiveDateTime(NaiveDate::from_ymd(year, month, day).and_hms_nano(hour, minute, second, nanosecond)) - ) - }) - .boxed() - } -} - /// Topmost message. Encloses all the other possible messages, and is the only thing that should /// be sent over the wire. #[common_derives(NoFormat)] pub struct Message { - pub timestamp: ArbitraryNaiveDateTime, + pub timestamp: NaiveDateTime, /// The original sender of this message. pub node: Node, @@ -82,7 +61,7 @@ pub enum Data { } impl Message { - pub fn new(timestamp: ArbitraryNaiveDateTime, node: Node, data: impl Into) -> Self { + pub fn new(timestamp: NaiveDateTime, node: Node, data: impl Into) -> Self { Message { timestamp, node, From a582c246b8648235c503a82ca41fd65da11c7b58 Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Sat, 5 Oct 2024 14:53:38 -0400 Subject: [PATCH 08/15] please --- Cargo.toml | 7 +++++-- src/lib.rs | 14 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6f5890d..d78e99b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,14 +17,17 @@ mavlink = { git = "https://github.com/uorocketry/rust-mavlink.git", features = [ bitflags = { version = "2.3.1", features = ["serde"] } proptest = { version = "1.2.0", optional = true } proptest-derive = { version = "0.3.0", optional = true } +proptest-arbitrary-interop = { version = "0.1.0", optional = true } messages-proc-macros-lib = { path = "messages-proc-macros-lib" } -chrono = {git = "https://github.com/uorocketry/chrono", features = ["serde", "arbitrary"], default-features = false} +# chrono = { git = "https://github.com/uorocketry/chrono", features = ["serde", "arbitrary"], default-features = false} +chrono = { path = "C:\\Users\\noahr\\Documents\\Rocketry\\chrono", features = ["serde", "arbitrary"], default-features = false } [dev-dependencies] proptest = "1.2.0" proptest-derive = "0.3.0" postcard = { version = "1.0.4", features = ["alloc"] } +proptest-arbitrary-interop = "0.1.0" [features] default = ["mavlink/embedded-hal-02", "mavlink/uorocketry"] -std = ["chrono/std", "mavlink/std", "mavlink/tcp", "mavlink/udp", "mavlink/direct-serial", "mavlink/serde", "dep:proptest", "dep:proptest-derive"] +std = ["chrono/std", "mavlink/std", "mavlink/tcp", "mavlink/udp", "mavlink/direct-serial", "mavlink/serde", "dep:proptest-arbitrary-interop", "dep:proptest", "dep:proptest-derive"] diff --git a/src/lib.rs b/src/lib.rs index d45b504..1145dd8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ use crate::state::State; use derive_more::From; /// This is to help control versions. pub use mavlink; -use chrono::NaiveDateTime; +use chrono::{NaiveDate, FixedOffset, NaiveDateTime}; use messages_proc_macros_lib::common_derives; pub mod command; @@ -29,6 +29,9 @@ pub use logging::{ErrorContext, Event, Log, LogLevel}; use defmt::Format; #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] +#[cfg_attr(feature = "ts", derive(ts_rs::TS))] +#[cfg_attr(feature = "ts", ts(export))] +#[cfg_attr(all(feature = "std", test), derive(proptest_derive::Arbitrary))] pub struct FormattedNaiveDateTime(pub NaiveDateTime); impl Format for FormattedNaiveDateTime { @@ -39,9 +42,12 @@ impl Format for FormattedNaiveDateTime { /// Topmost message. Encloses all the other possible messages, and is the only thing that should /// be sent over the wire. -#[common_derives(NoFormat)] +#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] +#[cfg_attr(feature = "ts", derive(ts_rs::TS))] +#[cfg_attr(feature = "ts", ts(export))] +#[cfg_attr(all(feature = "std", test), derive(proptest_derive::Arbitrary))] pub struct Message { - pub timestamp: NaiveDateTime, + pub timestamp: FormattedNaiveDateTime, /// The original sender of this message. pub node: Node, @@ -61,7 +67,7 @@ pub enum Data { } impl Message { - pub fn new(timestamp: NaiveDateTime, node: Node, data: impl Into) -> Self { + pub fn new(timestamp: FormattedNaiveDateTime, node: Node, data: impl Into) -> Self { Message { timestamp, node, From 596f4fc33fe640e5222cae3969d64fa9e8751870 Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Sat, 5 Oct 2024 16:15:05 -0400 Subject: [PATCH 09/15] :/ --- messages-proc-macros-lib/src/lib.rs | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/messages-proc-macros-lib/src/lib.rs b/messages-proc-macros-lib/src/lib.rs index 0189974..88af14b 100644 --- a/messages-proc-macros-lib/src/lib.rs +++ b/messages-proc-macros-lib/src/lib.rs @@ -8,7 +8,7 @@ pub fn common_derives(args: TokenStream, input: TokenStream) -> TokenStream { #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] #[cfg_attr(feature = "ts", derive(ts_rs::TS))] #[cfg_attr(feature = "ts", ts(export))] - #[cfg_attr(std, derive(proptest_derive::Arbitrary))] + #[cfg_attr(all(feature = "std", test), derive(proptest_derive::Arbitrary))] }); // Allow to omit the defmt::Format derive. Useful if this should be manually implemented. diff --git a/src/lib.rs b/src/lib.rs index 39e6762..c1d9fa4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,7 +77,7 @@ impl Message { } } -#[cfg(test)] +#[cfg(all(test, feature = "std"))] mod test { use crate::{Message, MAX_SIZE}; use proptest::prelude::*; From 664d26d80da52c3234033e299421fd9979c58ea1 Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Sat, 5 Oct 2024 16:19:28 -0400 Subject: [PATCH 10/15] lib --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index d65b3e3..fc0d05f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +proc-macro = true + [dependencies] derive_more = "0.99.17" serde = {version = "1.0.150", default-features = false, features = ["derive"]} From a71b04e5294381470ef2ec216f55d92019e7fcfa Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Sat, 5 Oct 2024 16:26:49 -0400 Subject: [PATCH 11/15] idk --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fc0d05f..d65b3e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,9 +5,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -proc-macro = true - [dependencies] derive_more = "0.99.17" serde = {version = "1.0.150", default-features = false, features = ["derive"]} From 763dbb4ca6f5e27600e3dfbb6dfcb6be6c7fe42d Mon Sep 17 00:00:00 2001 From: NoahSprenger Date: Sat, 5 Oct 2024 17:06:15 -0400 Subject: [PATCH 12/15] lib --- Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index d65b3e3..0999014 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +name = "messages" +path = "src/lib.rs" + [dependencies] derive_more = "0.99.17" serde = {version = "1.0.150", default-features = false, features = ["derive"]} From 1923447bba0ae6b12cb2f9703c09587027b8ded0 Mon Sep 17 00:00:00 2001 From: Noah Sprenger Date: Sat, 5 Oct 2024 17:20:49 -0400 Subject: [PATCH 13/15] fix --- Makefile.toml | 7 +------ proptest-regressions/lib.txt | 7 +++++++ src/lib.rs | 1 - 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 proptest-regressions/lib.txt diff --git a/Makefile.toml b/Makefile.toml index ae30f26..535a2b4 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,8 +1,3 @@ -[env] -CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true - -[config] -default_to_workspace = false # ----------------------- # Host Testing @@ -10,5 +5,5 @@ default_to_workspace = false [tasks.test-messages] command = "cargo" -args = ["test", "-p", "messages", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}", "--features", "std", "--no-default-features"] +args = ["test", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}", "--features", "std", "--no-default-features"] env = {RUST_MIN_STACK = "8388608"} diff --git a/proptest-regressions/lib.txt b/proptest-regressions/lib.txt new file mode 100644 index 0000000..d6468cc --- /dev/null +++ b/proptest-regressions/lib.txt @@ -0,0 +1,7 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# 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]) }) }) } diff --git a/src/lib.rs b/src/lib.rs index c1d9fa4..f98e69c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,4 @@ #![cfg_attr(all(not(feature = "std"), not(test)), no_std)] -#![no_main] //! # Messages //! From df6b6db62e8652ab403fa359d7678747ebd6cadf Mon Sep 17 00:00:00 2001 From: Noah Sprenger Date: Sat, 26 Oct 2024 11:34:36 -0400 Subject: [PATCH 14/15] Split SBG messages to radio based communication only. --- proptest-regressions/lib.txt | 2 ++ src/lib.rs | 25 +++++++++++++++++++++---- src/sensor.rs | 29 ++++++++++++++++++++++++----- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/proptest-regressions/lib.txt b/proptest-regressions/lib.txt index d6468cc..5b1f508 100644 --- a/proptest-regressions/lib.txt +++ b/proptest-regressions/lib.txt @@ -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 } })) }) } diff --git a/src/lib.rs b/src/lib.rs index f98e69c..871f7ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -78,7 +79,7 @@ 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! { @@ -86,8 +87,24 @@ mod 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); + } + + } } } } diff --git a/src/sensor.rs b/src/sensor.rs index 9d93f43..e931dea 100644 --- a/src/sensor.rs +++ b/src/sensor.rs @@ -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), @@ -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] @@ -245,7 +264,7 @@ pub struct RecoverySensing { impl Sensor { pub fn new(data: impl Into) -> Self { Sensor { - // component_id: 0, + component_id: 0, data: data.into(), } } From c4b4b3178ceb05fa374be2a722bc07057c55727c Mon Sep 17 00:00:00 2001 From: Noah Sprenger Date: Sat, 26 Oct 2024 11:42:07 -0400 Subject: [PATCH 15/15] Format and remove ts bindings. --- .github/workflows/build.yml | 2 +- Makefile.toml | 2 +- messages-proc-macros-lib/src/lib.rs | 2 -- src/lib.rs | 10 +++------- src/node.rs | 2 +- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8a9f59a..dc74e31 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,6 +60,6 @@ jobs: name: "Run Host Tests" with: command: make - args: test-messages + args: test diff --git a/Makefile.toml b/Makefile.toml index 535a2b4..bef49ec 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -3,7 +3,7 @@ # Host Testing # ----------------------- -[tasks.test-messages] +[tasks.test] command = "cargo" args = ["test", "--target", "${CARGO_MAKE_RUST_TARGET_TRIPLE}", "--features", "std", "--no-default-features"] env = {RUST_MIN_STACK = "8388608"} diff --git a/messages-proc-macros-lib/src/lib.rs b/messages-proc-macros-lib/src/lib.rs index 88af14b..8031b3f 100644 --- a/messages-proc-macros-lib/src/lib.rs +++ b/messages-proc-macros-lib/src/lib.rs @@ -6,8 +6,6 @@ use quote::quote; pub fn common_derives(args: TokenStream, input: TokenStream) -> TokenStream { let mut output = TokenStream::from(quote! { #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] - #[cfg_attr(feature = "ts", derive(ts_rs::TS))] - #[cfg_attr(feature = "ts", ts(export))] #[cfg_attr(all(feature = "std", test), derive(proptest_derive::Arbitrary))] }); diff --git a/src/lib.rs b/src/lib.rs index 871f7ef..31cd75c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,10 +9,10 @@ use crate::command::Command; use crate::node::Node; use crate::sensor::Sensor; use crate::state::State; +use chrono::NaiveDateTime; use derive_more::From; /// This is to help control versions. pub use mavlink; -use chrono::{NaiveDate, FixedOffset, NaiveDateTime}; use messages_proc_macros_lib::common_derives; @@ -26,12 +26,10 @@ pub mod state; pub const MAX_SIZE_CAN: usize = 64; pub const MAX_SIZE_RADIO: usize = 255; -pub use logging::{ErrorContext, Event, Log, LogLevel}; use defmt::Format; +pub use logging::{ErrorContext, Event, Log, LogLevel}; #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] -#[cfg_attr(feature = "ts", derive(ts_rs::TS))] -#[cfg_attr(feature = "ts", ts(export))] #[cfg_attr(all(feature = "std", test), derive(proptest_derive::Arbitrary))] pub struct FormattedNaiveDateTime(pub NaiveDateTime); @@ -44,8 +42,6 @@ impl Format for FormattedNaiveDateTime { /// Topmost message. Encloses all the other possible messages, and is the only thing that should /// be sent over the wire. #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] -#[cfg_attr(feature = "ts", derive(ts_rs::TS))] -#[cfg_attr(feature = "ts", ts(export))] #[cfg_attr(all(feature = "std", test), derive(proptest_derive::Arbitrary))] pub struct Message { pub timestamp: FormattedNaiveDateTime, @@ -103,7 +99,7 @@ mod test { _ => { assert!(bytes.len() <= MAX_SIZE_CAN); } - + } } } diff --git a/src/node.rs b/src/node.rs index a58236b..92c363d 100644 --- a/src/node.rs +++ b/src/node.rs @@ -5,7 +5,7 @@ use messages_proc_macros_lib::common_derives; pub enum Node { PressureBoard, TemperatureBoard, - StrainBoard, + StrainBoard, } impl From for u16 {