Skip to content

Commit

Permalink
Update boards, timestamp, and sender to node. (#2)
Browse files Browse the repository at this point in the history
* Update boards, timestamp, and sender to node.

* Remove proptest.

* Update attributes.

* :(
  • Loading branch information
NoahSprenger authored Oct 3, 2024
1 parent b616b56 commit e976718
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 47 deletions.
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 @@ 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,
Expand All @@ -52,10 +51,10 @@ pub enum Data {
}

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 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.

0 comments on commit e976718

Please sign in to comment.