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

Feat: GST sentence #124

Merged
merged 6 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmt-03 = ["dep:defmt", "heapless/defmt-03"]

all-sentences = ["GNSS", "waypoint", "maritime", "water", "vendor-specific", "other"]
# GNSS specific sentences related to the possition or speed relative to the ground
GNSS = ["APA", "ALM", "GBS", "GGA", "GLL", "GNS", "GSA", "GSV", "RMC", "VTG"]
GNSS = ["APA", "ALM", "GBS", "GGA", "GLL", "GNS", "GSA", "GST", "GSV", "RMC", "VTG"]

waypoint = ["AAM", "BOD", "BWC", "BWW", "WNC", "ZFO", "ZTG"]
maritime = ["waypoint", "water"]
Expand Down Expand Up @@ -123,6 +123,10 @@ GNS = []
# feature: GNSS
GSA = []

# GST - GPS Pseudorange Noise Statistics
# feature: GNSS
GST = []

# GSV - Satellites in view
# feature: GNSS
GSV = []
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//! - GLL *
//! - GNS *
//! - GSA *
//! - GST
//! - GSV *
//! - HDT
//! - MDA
Expand Down
11 changes: 11 additions & 0 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub enum ParseResult {
GLL(GllData),
GNS(GnsData),
GSA(GsaData),
GST(GstData),
GSV(GsvData),
HDT(HdtData),
MDA(MdaData),
Expand Down Expand Up @@ -152,6 +153,7 @@ impl From<&ParseResult> for SentenceType {
ParseResult::GLL(_) => SentenceType::GLL,
ParseResult::GNS(_) => SentenceType::GNS,
ParseResult::GSA(_) => SentenceType::GSA,
ParseResult::GST(_) => SentenceType::GST,
ParseResult::GSV(_) => SentenceType::GSV,
ParseResult::HDT(_) => SentenceType::HDT,
ParseResult::MDA(_) => SentenceType::MDA,
Expand Down Expand Up @@ -309,6 +311,15 @@ pub fn parse_str(sentence_input: &str) -> Result<ParseResult, Error> {
}
}
}
SentenceType::GST => {
cfg_if! {
if #[cfg(feature = "GST")] {
parse_gst(nmea_sentence).map(ParseResult::GST)
} else {
return Err(Error::DisabledSentence);
}
}
}
SentenceType::GSV => {
cfg_if! {
if #[cfg(feature = "GSV")] {
Expand Down
2 changes: 2 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
| ParseResult::BOD(_)
| ParseResult::DBK(_)
| ParseResult::GBS(_)
| ParseResult::GST(_)

Check warning on line 377 in src/parser.rs

View check run for this annotation

Codecov / codecov/patch

src/parser.rs#L377

Added line #L377 was not covered by tests
| ParseResult::AAM(_)
| ParseResult::APA(_)
| ParseResult::ALM(_)
Expand Down Expand Up @@ -679,6 +680,7 @@
/// - [`SentenceType::GGA`]
/// - [`SentenceType::GNS`]
/// - [`SentenceType::GSA`]
/// - [`SentenceType::GST`]
/// - [`SentenceType::GSV`]
///
/// ### Course
Expand Down
130 changes: 130 additions & 0 deletions src/sentences/gst.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
use crate::{parse::NmeaSentence, sentences::utils::parse_hms, Error, SentenceType};
use chrono::NaiveTime;
use nom::{character::complete::char, combinator::opt, number::complete::float, IResult};

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

/// GST - GPS Pseudorange Noise Statistics
/// ```text
/// 1 2 3 4 5 6 7 8 9
/// | | | | | | | | |
/// $ --GST,hhmmss.ss,x,x,x,x,x,x,x*hh<CR><LF>
/// ```
/// Example: `$GPGST,182141.000,15.5,15.3,7.2,21.8,0.9,0.5,0.8*54`
///
/// 1. UTC time of associated GGA fix
/// 2. Total RMS standard deviation of ranges inputs to the navigation solution
/// 3. Standard deviation (meters) of semi-major axis of error ellipse
/// 4. Standard deviation (meters) of semi-minor axis of error ellipse
/// 5. Orientation of semi-major axis of error ellipse (true north degrees)
/// 6. Standard deviation (meters) of latitude error
/// 7. Standard deviation (meters) of longitude error
/// 8. Standard deviation (meters) of altitude error
/// 9. Checksum

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[derive(Debug, PartialEq)]
pub struct GstData {
#[cfg_attr(feature = "defmt-03", defmt(Debug2Format))]
pub time: Option<NaiveTime>,
pub rms_sd: Option<f32>,
pub ellipse_semi_major_sd: Option<f32>,
pub ellipse_semi_minor_sd: Option<f32>,
pub err_ellipse_orientation: Option<f32>,
pub lat_sd: Option<f32>,
pub long_sd: Option<f32>,
pub alt_sd: Option<f32>,
}

fn do_parse_gst(i: &str) -> IResult<&str, GstData> {
let (i, time) = opt(parse_hms)(i)?;
let (i, _) = char(',')(i)?;

let (i, rms_sd) = opt(float)(i)?;
let (i, _) = char(',')(i)?;

let (i, ellipse_semi_major_sd) = opt(float)(i)?;
let (i, _) = char(',')(i)?;

let (i, ellipse_semi_minor_sd) = opt(float)(i)?;
let (i, _) = char(',')(i)?;

let (i, err_ellipse_orientation) = opt(float)(i)?;
let (i, _) = char(',')(i)?;

let (i, lat_sd) = opt(float)(i)?;
let (i, _) = char(',')(i)?;

let (i, long_sd) = opt(float)(i)?;
let (i, _) = char(',')(i)?;

let (i, alt_sd) = opt(float)(i)?;

Ok((
i,
GstData {
time,
rms_sd,
ellipse_semi_major_sd,
ellipse_semi_minor_sd,
err_ellipse_orientation,
lat_sd,
long_sd,
alt_sd,
},
))
}
pub fn parse_gst(sentence: NmeaSentence) -> Result<GstData, Error> {
if sentence.message_id != SentenceType::GST {
Err(Error::WrongSentenceHeader {
expected: SentenceType::GST,
found: sentence.message_id,

Check warning on line 83 in src/sentences/gst.rs

View check run for this annotation

Codecov / codecov/patch

src/sentences/gst.rs#L81-L83

Added lines #L81 - L83 were not covered by tests
})
} else {
Ok(do_parse_gst(sentence.data)?.1)
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{parse::parse_nmea_sentence, Error};

fn run_parse_gst(line: &str) -> Result<GstData, Error> {
let s = parse_nmea_sentence(line).expect("GST sentence initial parse failed");
assert_eq!(s.checksum, s.calc_checksum());
parse_gst(s)
}

#[test]
fn test_parse_gst() {
assert_eq!(
GstData {
time: NaiveTime::from_hms_micro_opt(18, 21, 41, 00),
rms_sd: Some(15.5),
ellipse_semi_major_sd: Some(15.3),
ellipse_semi_minor_sd: Some(7.2),
err_ellipse_orientation: Some(21.8),
lat_sd: Some(0.9),
long_sd: Some(0.5),
alt_sd: Some(0.8),
},
run_parse_gst("$GPGST,182141.000,15.5,15.3,7.2,21.8,0.9,0.5,0.8*54").unwrap()
);
assert_eq!(
GstData {
time: None,
rms_sd: None,
ellipse_semi_major_sd: None,
ellipse_semi_minor_sd: None,
err_ellipse_orientation: None,
lat_sd: None,
long_sd: None,
alt_sd: None,
},
run_parse_gst("$GPGST,,,,,,,,*57").unwrap()
);
}
}
2 changes: 2 additions & 0 deletions src/sentences/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod gga;
pub mod gll;
pub mod gns;
pub mod gsa;
pub mod gst;
pub mod gsv;
pub mod hdt;
pub mod mda;
Expand Down Expand Up @@ -49,6 +50,7 @@ pub use {
gns::{parse_gns, GnsData},
gnss_type::GnssType,
gsa::{parse_gsa, GsaData},
gst::{parse_gst, GstData},
gsv::{parse_gsv, GsvData},
hdt::{parse_hdt, HdtData},
mda::{parse_mda, MdaData},
Expand Down
2 changes: 2 additions & 0 deletions tests/all_supported_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ fn test_all_supported_messages() {
(SentenceType::GNS, "$GPGNS,224749.00,3333.4268304,N,11153.3538273,W,D,19,0.6,406.110,-26.294,6.0,0138,S,*46"),
// GSA
(SentenceType::GSA, "$GPGSA,A,3,23,31,22,16,03,07,,,,,,,1.8,1.1,1.4*3E"),
// GST
(SentenceType::GST, "$GPGST,182141.000,15.5,15.3,7.2,21.8,0.9,0.5,0.8*54"),
// GSV
(SentenceType::GSV, "$GPGSV,3,1,12,01,49,196,41,03,71,278,32,06,02,323,27,11,21,196,39*72"),
// HDT
Expand Down
Loading