-
Notifications
You must be signed in to change notification settings - Fork 41
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 GST sentence parser #121
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
//! - GLL * | ||
//! - GNS * | ||
//! - GSA * | ||
//! - GST | ||
//! - GSV * | ||
//! - HDT | ||
//! - MDA | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,137 @@ | ||||||
use chrono::NaiveTime; | ||||||
|
||||||
use nom::{ | ||||||
character::complete::char, | ||||||
number::complete::float, | ||||||
combinator::opt, | ||||||
IResult, | ||||||
}; | ||||||
|
||||||
use crate::{parse::NmeaSentence, sentences::utils::parse_hms, Error, SentenceType}; | ||||||
|
||||||
#[cfg(feature = "serde")] | ||||||
use serde::{Deserialize, Serialize}; | ||||||
|
||||||
// GST - GPS Pseudorange Noise Statistics | ||||||
// | ||||||
// 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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// | ||||||
// 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, | ||||||
}) | ||||||
} 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() | ||||||
); | ||||||
} | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.