nmea_parser/gnss/
mod.rs

1/*
2Copyright 2020 Timo Saarinen
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17//! GNSS data structures
18
19pub(crate) mod gga;
20pub(crate) mod gll;
21pub(crate) mod gns;
22pub(crate) mod gsa;
23pub(crate) mod gsv;
24pub(crate) mod rmc;
25pub(crate) mod vtg;
26pub(crate) mod alm;
27pub(crate) mod dtm;
28pub(crate) mod mss;
29pub(crate) mod stn;
30pub(crate) mod vbw;
31pub(crate) mod zda;
32pub(crate) mod dpt;
33pub(crate) mod dbs;
34pub(crate) mod mtw;
35pub(crate) mod vhw;
36pub(crate) mod hdt;
37pub(crate) mod mwv;
38
39use super::*;
40pub use gga::{GgaData, GgaQualityIndicator};
41pub use gll::GllData;
42pub use gns::GnsData;
43pub use gsa::{GsaData, GsaFixMode};
44pub use gsv::GsvData;
45pub use rmc::RmcData;
46use serde::Serialize;
47pub use vtg::VtgData;
48pub use alm::AlmData;
49pub use dtm::DtmData;
50pub use mss::MssData;
51pub use stn::StnData;
52pub use vbw::VbwData;
53pub use zda::ZdaData;
54pub use dpt::DptData;
55pub use dbs::DbsData;
56pub use mtw::MtwData;
57pub use vhw::VhwData;
58pub use hdt::HdtData;
59pub use mwv::MwvData;
60
61// -------------------------------------------------------------------------------------------------
62
63/// Navigation system, identified with NMEA GNSS sentence prefix (e.g. $BDGGA)
64#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
65pub enum NavigationSystem {
66    /// Combination of several satellite systems
67    Combination, // GNxxx
68
69    /// American GPS
70    Gps, // GPxxx
71
72    /// Russian GLONASS
73    Glonass, // GLxxx
74
75    /// European Galileo
76    Galileo, // GAxxx
77
78    // Chinese BeiDou
79    Beidou, // BDxxx
80
81    // Indian NavIC
82    Navic, // GIxxx
83
84    // Japanese Qzss
85    Qzss, // QZxxx
86
87    /// Proprietary manufacturer specific message
88    Proprietary, // PMMM, P usually followed by a three character manufacturer code
89
90    // Some other
91    Other,
92}
93
94impl core::fmt::Display for NavigationSystem {
95    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
96        match self {
97            NavigationSystem::Combination => write!(f, "combination"),
98            NavigationSystem::Gps => write!(f, "GPS"),
99            NavigationSystem::Glonass => write!(f, "GLONASS"),
100            NavigationSystem::Galileo => write!(f, "Galileo"),
101            NavigationSystem::Beidou => write!(f, "BeiDou"),
102            NavigationSystem::Navic => write!(f, "Navic"),
103            NavigationSystem::Qzss => write!(f, "QZSS"),
104            NavigationSystem::Proprietary => write!(f, "proprietary"),
105            NavigationSystem::Other => write!(f, "other"),
106        }
107    }
108}
109
110impl core::str::FromStr for NavigationSystem {
111    type Err = ParseError;
112
113    fn from_str(talker_id: &str) -> Result<Self, Self::Err> {
114        if talker_id.is_empty() {
115            return Err(ParseError::InvalidSentence(
116                "Invalid talker identifier".to_string(),
117            ));
118        }
119        if &talker_id[0..1] == "P" {
120            Ok(Self::Proprietary)
121        } else {
122            if talker_id.len() < 2 {
123                return Err(ParseError::InvalidSentence(
124                    "Invalid talker identifier".to_string(),
125                ));
126            }
127            match &talker_id[0..2] {
128                "GN" => Ok(Self::Combination),
129                "GP" => Ok(Self::Gps),
130                "GL" => Ok(Self::Glonass),
131                "GA" => Ok(Self::Galileo),
132                "BD" => Ok(Self::Beidou),
133                "GI" => Ok(Self::Navic),
134                "QZ" => Ok(Self::Qzss),
135                _ => Ok(Self::Other),
136            }
137        }
138    }
139}
140
141// -------------------------------------------------------------------------------------------------
142/// VTG/GLL FAA mode (NMEA 2.3 standard has this information)
143#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
144pub enum FaaMode {
145    /// Autonomous mode (automatic 2D/3D)
146    Autonomous,
147
148    /// Differential GPS mode (DGPS).
149    Differential,
150
151    /// Estimated (dead-reckoning) data.
152    Estimated,
153
154    /// No valid data available.
155    NotValid,
156
157    /// Simulated data.
158    Simulator,
159}
160
161impl FaaMode {
162    pub fn new(val: &str) -> Result<FaaMode, String> {
163        match val {
164            "A" => Ok(FaaMode::Autonomous),
165            "D" => Ok(FaaMode::Differential),
166            "E" => Ok(FaaMode::Estimated),
167            "N" => Ok(FaaMode::NotValid),
168            _ => Err(format!("Unrecognized FAA information value: {}", val)),
169        }
170    }
171}
172
173impl core::fmt::Display for FaaMode {
174    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
175        match self {
176            FaaMode::Autonomous => write!(f, "A"),
177            FaaMode::Differential => write!(f, "D"),
178            FaaMode::Estimated => write!(f, "E"),
179            FaaMode::NotValid => write!(f, "N"),
180            _ => write!(f, "?"),
181        }
182    }
183}