Skip to content
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
1 change: 1 addition & 0 deletions swiftnav/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ thiserror = "2.0.17"
[dev-dependencies]
float_eq = "1.0.1"
proptest = "1.9.0"
nmea = "0.7"

# This tells docs.rs to include the katex header for math formatting
# To do this locally
Expand Down
28 changes: 25 additions & 3 deletions swiftnav/src/nmea/gga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl GGA {
let second = f64::from(self.time.second());
let second_fracs = f64::from(self.time.nanosecond()) / 1_000_000_000.0;

let timestamp = format!("{hour}{minute}{:.2}", second + second_fracs);
let timestamp = format!("{hour:0>2}{minute:0>2}{:05.2}", second + second_fracs);

let (lat_deg, lat_mins) = self.llh.latitude_degree_decimal_minutes();
let lat_hemisphere = self.llh.latitudinal_hemisphere();
Expand Down Expand Up @@ -165,6 +165,28 @@ impl GGA {
mod test {
use super::*;

#[test]
#[allow(clippy::float_cmp, reason = "testing exact parsing")]
fn nmea_crate_can_parse_gga_sentence() {
let gga = GGA::builder()
.sat_in_use(12)
.time(DateTime::from_timestamp(1_761_351_489, 89_999_999).unwrap())
.gps_quality(GPSQuality::SPS)
.hdop(0.9)
.llh(super::LLHDegrees::new(37.7749, -122.4194, 10.0))
.build();

let parse_result =
::nmea::parse_str(&gga.to_sentence()).expect("Failed to parse GGA sentence");

let ::nmea::ParseResult::GGA(parsed_gga) = parse_result else {
panic!("Parsed result is not a GGA sentence");
};

assert_eq!(parsed_gga.latitude.unwrap(), 37.7749);
assert_eq!(parsed_gga.longitude.unwrap(), -122.4194);
}

#[test]
fn gga_can_be_turned_into_an_nmea_sentence() {
let gga = GGA::builder()
Expand All @@ -179,7 +201,7 @@ mod test {

assert_eq!(
sentence,
"$GPGGA,0189.00,3746.4940000,N,12225.1640000,W,1,12,0.9,0.0,M,,,*01\r\n"
"$GPGGA,001809.00,3746.4940000,N,12225.1640000,W,1,12,0.9,0.0,M,,,*01\r\n"
);
}

Expand All @@ -200,7 +222,7 @@ mod test {

assert_eq!(
sentence,
"$GPGGA,0189.00,3403.1320000,N,01814.6220000,W,2,8,1.2,0.0,M,1.00,2,42*1C\r\n"
"$GPGGA,001809.00,3403.1320000,N,01814.6220000,W,2,8,1.2,0.0,M,1.00,2,42*1C\r\n"
);
}

Expand Down