Skip to content

Commit

Permalink
Merge pull request #14 from nsforth/13-gpgga-without-altitude-not-parsed
Browse files Browse the repository at this point in the history
Altitude in GGA is optional field now. Closing issue #13
  • Loading branch information
nsforth authored Dec 2, 2024
2 parents 4d1835f + 4d94d1b commit 2b75536
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
14 changes: 3 additions & 11 deletions src/gga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct GGA {
/// Horizontal dilusion of presicion. Indicates precision of solution.
pub hdop: f32,
/// Altitude over ground, typically WGS-84.
pub altitude: Altitude,
pub altitude: Option<Altitude>,
/// The difference between reference ellipsoid surface and mean-sea-level.
pub geoidal_separation: Option<f32>,
/// DGPS data age. None if DGPS not in use.
Expand Down Expand Up @@ -56,16 +56,8 @@ impl GGA {
Some(gps_quality),
Some(sat_in_use),
Some(hdop),
Some(altitude),
) = (
time,
latitude,
longitude,
gps_quality,
sat_in_use,
hdop,
altitude,
) {
) = (time, latitude, longitude, gps_quality, sat_in_use, hdop)
{
Ok(Some(GGA {
source,
time,
Expand Down
51 changes: 50 additions & 1 deletion tests/parsing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use core::convert::TryFrom;
use nmea0183::coords;
use nmea0183::coords::Hemisphere;
use nmea0183::coords::Latitude;
use nmea0183::coords::Longitude;
use nmea0183::datetime;
use nmea0183::satellite;
use nmea0183::FixType;
Expand All @@ -12,6 +15,7 @@ use nmea0183::PMTKSPF;
use nmea0183::RMC;
use nmea0183::VTG;
use nmea0183::{ParseResult, Parser, Source};

#[test]
fn test_too_long_sentence() {
let line = "$01234567890123456789012345678901234567890123456789012345678901234567890123456789";
Expand Down Expand Up @@ -171,7 +175,7 @@ fn test_correct_gga() {
gps_quality: GPSQuality::DGPS,
sat_in_use: 7,
hdop: 0.6,
altitude: coords::Altitude { meters: 9.0 },
altitude: Some(coords::Altitude { meters: 9.0 }),
geoidal_separation: Some(18.0),
age_dgps: None,
dgps_station_id: None
Expand All @@ -184,6 +188,51 @@ fn test_correct_gga() {
assert!(parsed);
}

#[test]
fn test_correct_gga_without_altitude() {
let mut p = Parser::new();
let sentence = b"$GPGGA,160545,5008.6263,N,01422.4224,E,1,03,3.6,,M,45.0,M,,*61\r\n";
let mut parsed = false;
for b in sentence.iter() {
let r = p.parse_from_byte(*b);
if r.is_some() {
assert_eq!(
r.unwrap(),
Ok(ParseResult::GGA(Some(GGA {
source: Source::GPS,
time: datetime::Time {
hours: 16,
minutes: 5,
seconds: 45.0
},
latitude: Latitude {
degrees: 50,
minutes: 8,
seconds: 37.578,
hemisphere: Hemisphere::North
},
longitude: Longitude {
degrees: 14,
minutes: 22,
seconds: 25.344,
hemisphere: Hemisphere::East
},
gps_quality: GPSQuality::GPS,
sat_in_use: 3,
hdop: 3.6,
altitude: None,
geoidal_separation: Some(45.0),
age_dgps: None,
dgps_station_id: None
})))
);
parsed = true;
break;
}
}
assert!(parsed);
}

#[test]
fn test_correct_rmc2() {
let mut p = Parser::new();
Expand Down

0 comments on commit 2b75536

Please sign in to comment.