Skip to content

Commit

Permalink
feat: serde support for AircraftState and Alert
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-meier committed Sep 22, 2023
1 parent 6d67c75 commit 8b9d556
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions opentaws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ is-it-maintained-open-issues = { repository = "aeronautical-informatics/openTAWS
maintenance = { status = "actively-developed" }

[features]
default = ["use-serde"]
use-serde = [
"dep:serde",
"heapless/serde",
"nalgebra/serde-serialize-no-std",
"uom/use_serde",
]

[dependencies]
lazy_static = { version = "1", default-features = false, features = [
Expand All @@ -30,6 +37,9 @@ lazy_static = { version = "1", default-features = false, features = [
heapless = "0.7.16"
hash32 = "0.2.1"
nalgebra = { version = "0.32.2", default-features = false, features = ["libm"] }
serde = { version = "*", optional = true, default-features = false, features = [
"derive",
] }
uom = { git = "https://github.com/moritz-meier/uom.git", branch = "fix-missing-libm", default-features = false, features = [
"f64",
"si",
Expand Down
2 changes: 2 additions & 0 deletions opentaws/src/aircraft_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub type NormalizedAircraftState = AircraftState<Normalized>;

/// Represents the current state of an aircraft
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "use-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AircraftState<T = ()> {
/// Time when this aircraft state was emitted
timestamp: Time,
Expand Down Expand Up @@ -340,6 +341,7 @@ AircrafState: {{

/// Represents a flight segment
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "use-serde", derive(serde::Serialize, serde::Deserialize))]
pub enum FlightSegment {
/// The aircraft is in cruise flight situation
Cruise,
Expand Down
7 changes: 7 additions & 0 deletions opentaws/src/alerts.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use hash32::Hash;
use heapless::FnvIndexMap;

#[cfg(feature = "use-serde")]
use serde::{Deserialize, Serialize};

use crate::prelude::*;

/// TAWS Alert levels
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub enum AlertLevel {
/// The level or category of alert for conditions that require immediate flight crew awareness
/// and immediate flight crew response.
Expand All @@ -21,6 +25,7 @@ pub enum AlertLevel {

/// Represents a TAWS alert
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub struct Alert<AlertSource: TawsAlertSource> {
/// The source resp. the TAWS functionallity which emitted this alert
pub source: AlertSource,
Expand Down Expand Up @@ -65,6 +70,7 @@ impl<AlertSource: TawsAlertSource> From<Alert<AlertSource>> for (AlertSource, Al

/// Represents a set of [Alerts](Alert) by their [AlertSource](Alert::AlertSource)
#[derive(Debug)]
//#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub struct Alerts<Alert: TawsAlert>
where
Alert::AlertSource: Hash,
Expand Down Expand Up @@ -133,6 +139,7 @@ mod tests {
use hash32::{Hash, Hasher};

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
enum TestClass {
A,
B,
Expand Down
1 change: 1 addition & 0 deletions opentaws/src/class_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::prelude::*;
pub use {ffac::*, /*flta::*,*/ mode1::*, mode3::*, pda::*};

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "use-serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(non_camel_case_types)]
pub enum ClassC_Source {
Ffac,
Expand Down

0 comments on commit 8b9d556

Please sign in to comment.