From 4d94d1bb77e8ab80a5409d37689bd7bca113103b Mon Sep 17 00:00:00 2001 From: Nikita Staroverov Date: Mon, 2 Dec 2024 22:06:49 +0300 Subject: [PATCH] Altitude in GGA is optional field now. Closing issue #13 --- src/gga.rs | 14 +++---------- tests/parsing.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/gga.rs b/src/gga.rs index 6a69132..9e63c98 100644 --- a/src/gga.rs +++ b/src/gga.rs @@ -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, /// The difference between reference ellipsoid surface and mean-sea-level. pub geoidal_separation: Option, /// DGPS data age. None if DGPS not in use. @@ -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, diff --git a/tests/parsing.rs b/tests/parsing.rs index e0e446d..8c55db7 100644 --- a/tests/parsing.rs +++ b/tests/parsing.rs @@ -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; @@ -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"; @@ -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 @@ -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();