Skip to content
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

Update boards, timestamp, and sender to node. #2

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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", "arbitrary"], default-features = false}

[dev-dependencies]
proptest = "1.2.0"
Expand All @@ -26,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"]
6 changes: 3 additions & 3 deletions messages-proc-macros-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ 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))]
#[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.
Expand All @@ -20,4 +20,4 @@ pub fn common_derives(args: TokenStream, input: TokenStream) -> TokenStream {

output.extend(input);
output
}
}
4 changes: 2 additions & 2 deletions src/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::sender::Sender;
use crate::node::Node;
use derive_more::From;
use messages_proc_macros_lib::common_derives;

Expand Down Expand Up @@ -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]
Expand Down
21 changes: 10 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
#![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.

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;
Expand All @@ -28,14 +29,12 @@

/// 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,
Expand All @@ -52,10 +51,10 @@
}

impl Message {
pub fn new(timestamp: u32, sender: Sender, data: impl Into<Data>) -> Self {
pub fn new(timestamp: NaiveDateTime, node: Node, data: impl Into<Data>) -> Self {
Message {
timestamp: timestamp,
sender,
timestamp,
node,
data: data.into(),
}
}
Expand All @@ -66,9 +65,9 @@
use crate::{Message, MAX_SIZE};
use proptest::prelude::*;

proptest! {

Check failure on line 68 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test

the trait bound `Message: Arbitrary` is not satisfied
#[test]
fn message_size(msg: Message) {

Check failure on line 70 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test

the trait bound `Message: Arbitrary` is not satisfied
let bytes = postcard::to_allocvec(&msg).unwrap();

dbg!(msg);
Expand Down
19 changes: 19 additions & 0 deletions src/node.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use messages_proc_macros_lib::common_derives;

#[common_derives]
#[derive(Copy)]
pub enum Node {
PressureBoard,
TemperatureBoard,
StrainBoard,
}

impl From<Node> for u16 {
fn from(node: Node) -> Self {
match node {
Node::PressureBoard => 0,
Node::TemperatureBoard => 1,
Node::StrainBoard => 2,
}
}
}
30 changes: 0 additions & 30 deletions src/sender.rs

This file was deleted.

Loading