Skip to content

Commit

Permalink
Merge pull request #20 from uorocketry/messages-improvements
Browse files Browse the repository at this point in the history
Add support for Typescript bindings and update SBG fields
  • Loading branch information
jonapap authored May 1, 2023
2 parents 3a3854f + d1ad75d commit 54a99be
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"cmake.configureOnOpen": false,
"cSpell.words": [
"UART"
],
"cortex-debug.variableUseNaturalFormat": true,
"cmake.sourceDirectory": "${workspaceFolder}/libraries/sbg-rs/sbgECom"
}
90 changes: 90 additions & 0 deletions Cargo.lock

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

21 changes: 17 additions & 4 deletions boards/main/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,23 @@ mod app {
fn sensor_send(cx: sensor_send::Context) {
cx.shared.em.run(|| {
let sbg = Sbg {
accel: 9.8,
speed: 0.0,
pressure: 100.1,
height: 200.4,
accel_x: 0.0,
accel_y: 0.0,
accel_z: 0.0,
velocity_n: 0.0,
velocity_e: 0.0,
velocity_d: 0.0,
pressure: 0.0,
height: 0.0,
roll: 0.0,
yaw: 0.0,
pitch: 0.0,
latitude: 0.0,
longitude: 0.0,
quant_w: 0.0,
quant_x: 0.0,
quant_y: 0.0,
quant_z: 0.0,
};

let message = Message::new(&monotonics::now(), MainBoard, Sensor::new(9, sbg));
Expand Down
1 change: 1 addition & 0 deletions libraries/messages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bindings/
7 changes: 6 additions & 1 deletion libraries/messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ edition = "2021"
derive_more = "0.99.17"
serde = { workspace = true }
defmt = "0.3.2"
fugit = "0.3.6"
fugit = "0.3.6"
ts-rs = { version = "6.2.1", optional = true }

[features]
std = []
ts = ["std", "dep:ts-rs"]
13 changes: 12 additions & 1 deletion libraries/messages/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![no_std]
#![cfg_attr(not(feature = "std"), no_std)]

//! # HYDRA Messages
//!
Expand All @@ -12,12 +12,17 @@ use derive_more::From;
use fugit::Instant;
use serde::{Deserialize, Serialize};

#[cfg(feature = "ts")]
use ts_rs::TS;

pub mod sender;
pub mod sensor;

/// Topmost message. Encloses all the other possible messages, and is the only thing that should
/// be sent over the wire.
#[derive(Serialize, Deserialize, Clone, Debug, Format)]
#[cfg_attr(feature = "ts", derive(TS))]
#[cfg_attr(feature = "ts", ts(export))]
pub struct Message {
/// Time in milliseconds since epoch. Note that the epoch here can be arbitrary and is not the
/// Unix epoch.
Expand All @@ -31,20 +36,26 @@ pub struct Message {
}

#[derive(Serialize, Deserialize, Clone, Debug, From, Format)]
#[cfg_attr(feature = "ts", derive(TS))]
#[cfg_attr(feature = "ts", ts(export))]
#[serde(rename_all = "lowercase")]
pub enum Data {
State(State),
Sensor(Sensor),
}

#[derive(Serialize, Deserialize, Clone, Debug, Format)]
#[cfg_attr(feature = "ts", derive(TS))]
#[cfg_attr(feature = "ts", ts(export))]
pub enum Status {
Uninitialized,
Initializing,
Running,
}

#[derive(Serialize, Deserialize, Clone, Debug, Format)]
#[cfg_attr(feature = "ts", derive(TS))]
#[cfg_attr(feature = "ts", ts(export))]
pub struct State {
pub status: Status,
pub has_error: bool,
Expand Down
5 changes: 5 additions & 0 deletions libraries/messages/src/sender.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use defmt::Format;
use serde::{Deserialize, Serialize};

#[cfg(feature = "ts")]
use ts_rs::TS;

#[derive(Serialize, Deserialize, Clone, Debug, Format)]
#[cfg_attr(feature = "ts", derive(TS))]
#[cfg_attr(feature = "ts", ts(export))]
pub enum Sender {
GroundStation,
MainBoard,
Expand Down
28 changes: 25 additions & 3 deletions libraries/messages/src/sensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,45 @@ use defmt::Format;
use derive_more::From;
use serde::{Deserialize, Serialize};

#[cfg(feature = "ts")]
use ts_rs::TS;

#[derive(Serialize, Deserialize, Clone, Debug, Format)]
#[cfg_attr(feature = "ts", derive(TS))]
#[cfg_attr(feature = "ts", ts(export))]
pub struct Sensor {
pub component_id: u8,
pub data: SensorData,
}

#[derive(Serialize, Deserialize, Clone, Debug, From, Format)]
#[cfg_attr(feature = "ts", derive(TS))]
#[cfg_attr(feature = "ts", ts(export))]
pub enum SensorData {
Sbg(Sbg),
}

#[derive(Serialize, Deserialize, Clone, Debug, Format)]
#[cfg_attr(feature = "ts", derive(TS))]
#[cfg_attr(feature = "ts", ts(export))]
pub struct Sbg {
pub accel: f32,
pub speed: f32,
pub accel_x: f32,
pub accel_y: f32,
pub accel_z: f32,
pub velocity_n: f32,
pub velocity_e: f32,
pub velocity_d: f32,
pub pressure: f32,
pub height: f32,
pub height: f64,
pub roll: f32,
pub yaw: f32,
pub pitch: f32,
pub latitude: f64,
pub longitude: f64,
pub quant_w: f32,
pub quant_x: f32,
pub quant_y: f32,
pub quant_z: f32,
}

impl Sensor {
Expand Down

0 comments on commit 54a99be

Please sign in to comment.