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

add feature for serdes #30

Merged
merged 4 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions ublox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ chrono = { version = "0.4.19", default-features = false, features = [] }
bitflags = "1.2.1"
ublox_derive = { path = "../ublox_derive", version = "0.0.4" }
num-traits = { version = "0.2.12", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive"] }
gwbres marked this conversation as resolved.
Show resolved Hide resolved

[build-dependencies]

Expand Down
4 changes: 4 additions & 0 deletions ublox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "use-serde")]
gwbres marked this conversation as resolved.
Show resolved Hide resolved
#[macro_use]
extern crate serde;

pub use crate::{
error::{DateTimeError, MemWriterError, ParserError},
parser::{FixedLinearBuffer, Parser, ParserIter, UnderlyingBuffer},
Expand Down
16 changes: 16 additions & 0 deletions ublox/src/ubx_packets/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ struct NavSolution {
#[ubx(from, rest_reserved)]
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub enum GpsFix {
NoFix = 0,
DeadReckoningOnly = 1,
Expand All @@ -332,6 +333,7 @@ pub enum GpsFix {
#[ubx(from, rest_reserved)]
bitflags! {
/// Navigation Status Flags
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub struct NavStatusFlags: u8 {
/// position and velocity valid and within DOP and ACC Masks
const GPS_FIX_OK = 1;
Expand Down Expand Up @@ -395,6 +397,7 @@ pub enum MapMatchingStatus {
#[ubx(from, rest_reserved)]
#[repr(u8)]
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
enum NavStatusFlags2 {
Acquisition = 0,
Tracking = 1,
Expand Down Expand Up @@ -532,6 +535,7 @@ impl fmt::Debug for NavSatSvFlags {
}

#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub enum NavSatQualityIndicator {
NoSignal,
Searching,
Expand All @@ -542,13 +546,15 @@ pub enum NavSatQualityIndicator {
}

#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub enum NavSatSvHealth {
Healthy,
Unhealthy,
Unknown(u8),
}

#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub enum NavSatOrbitSource {
NoInfoAvailable,
Ephemeris,
Expand Down Expand Up @@ -693,6 +699,7 @@ struct CfgOdo {
#[ubx(from, into_raw, rest_reserved)]
bitflags! {
#[derive(Default)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub struct OdoCogFilterFlags: u8 {
/// Odometer enabled flag
const USE_ODO = 0x01;
Expand All @@ -710,6 +717,7 @@ bitflags! {
#[ubx(from_unchecked, into_raw, rest_error)]
#[repr(u8)]
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub enum OdoProfile {
Running = 0,
Cycling = 1,
Expand Down Expand Up @@ -983,6 +991,7 @@ struct CfgAnt {
#[ubx(from, into_raw, rest_reserved)]
bitflags! {
#[derive(Default)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub struct AntFlags: u16 {
/// Enable supply voltage control signal
const SVCS = 0x01;
Expand All @@ -1001,6 +1010,7 @@ bitflags! {
#[ubx(into_raw, rest_reserved)]
bitflags! {
/// Battery backed RAM sections to clear
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub struct NavBbrMask: u16 {
const EPHEMERIS = 1;
const ALMANACH = 2;
Expand Down Expand Up @@ -1038,6 +1048,7 @@ impl NavBbrPredefinedMask {
/// Reset Type
#[repr(u8)]
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub enum ResetMode {
/// Hardware reset (Watchdog) immediately
HardwareResetImmediately = 0,
Expand Down Expand Up @@ -1119,13 +1130,15 @@ struct CfgPrtUart {
#[ubx(from_unchecked, into_raw, rest_error)]
#[repr(u8)]
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub enum UartPortId {
Uart1 = 1,
Uart2 = 2,
Usb = 3,
}

#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub struct UartMode {
data_bits: DataBits,
parity: Parity,
Expand Down Expand Up @@ -1161,6 +1174,7 @@ impl From<u32> for UartMode {
}

#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub enum DataBits {
Seven,
Eight,
Expand Down Expand Up @@ -1191,6 +1205,7 @@ impl From<u32> for DataBits {
}

#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub enum Parity {
Even,
Odd,
Expand Down Expand Up @@ -1223,6 +1238,7 @@ impl From<u32> for Parity {
}

#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub enum StopBits {
One,
OneHalf,
Expand Down
2 changes: 2 additions & 0 deletions ublox/src/ubx_packets/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use chrono::prelude::*;
use core::convert::TryFrom;

/// Represents a world position, can be constructed from NavPosLlh and NavPosVelTime packets.
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy)]
pub struct Position {
/// Logitude in degrees
Expand All @@ -17,6 +18,7 @@ pub struct Position {
}

#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "use-serde", derive(Serialize, Deserialize))]
pub struct Velocity {
/// m/s over the ground
pub speed: f64,
Expand Down