diff --git a/Cargo.lock b/Cargo.lock index fad6982..a2634ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -520,6 +520,7 @@ dependencies = [ "atomic-polyfill", "hash32", "rustc_version", + "serde", "spin 0.9.8", "stable_deref_trait", ] @@ -669,6 +670,7 @@ dependencies = [ "num-complex", "num-rational", "num-traits", + "serde", "simba", "typenum", ] @@ -701,6 +703,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ba157ca0885411de85d6ca030ba7e2a83a28636056c7c699b07c8b6f7383214" dependencies = [ "num-traits", + "serde", ] [[package]] @@ -748,6 +751,7 @@ dependencies = [ "heapless", "lazy_static", "nalgebra", + "serde", "uom", ] @@ -1231,6 +1235,7 @@ version = "0.35.0" source = "git+https://github.com/moritz-meier/uom.git?branch=fix-missing-libm#4afd75d1a46b7256db04e9551897a1e0219df2ef" dependencies = [ "num-traits", + "serde", "typenum", ] diff --git a/opentaws/Cargo.toml b/opentaws/Cargo.toml index daa51c5..e286f8d 100644 --- a/opentaws/Cargo.toml +++ b/opentaws/Cargo.toml @@ -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 = [ @@ -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", diff --git a/opentaws/src/aircraft_state.rs b/opentaws/src/aircraft_state.rs index 386c899..3d0a88d 100644 --- a/opentaws/src/aircraft_state.rs +++ b/opentaws/src/aircraft_state.rs @@ -31,6 +31,7 @@ pub type NormalizedAircraftState = AircraftState; /// Represents the current state of an aircraft #[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "use-serde", derive(serde::Serialize, serde::Deserialize))] pub struct AircraftState { /// Time when this aircraft state was emitted timestamp: Time, @@ -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, diff --git a/opentaws/src/alerts.rs b/opentaws/src/alerts.rs index 19e86d2..facc58f 100644 --- a/opentaws/src/alerts.rs +++ b/opentaws/src/alerts.rs @@ -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. @@ -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 { /// The source resp. the TAWS functionallity which emitted this alert pub source: AlertSource, @@ -65,6 +70,7 @@ impl From> 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 where Alert::AlertSource: Hash, @@ -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, diff --git a/opentaws/src/class_c.rs b/opentaws/src/class_c.rs index 65da407..f0d0154 100644 --- a/opentaws/src/class_c.rs +++ b/opentaws/src/class_c.rs @@ -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,