From 5eda664a47e0d3a0537de9f529a7704b790a4127 Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Thu, 16 Jan 2025 13:55:19 +0100 Subject: [PATCH] Fix: Handle options of nmea messages --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a02e87c..122b9d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,7 +102,7 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "gps_parser" -version = "0.2.0" +version = "0.3.1" dependencies = [ "chrono", "nmea-parser", diff --git a/Cargo.toml b/Cargo.toml index 73d3078..f5332d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gps_parser" -version = "0.3.0" +version = "0.3.1" edition = "2021" [dependencies] diff --git a/src/lib.rs b/src/lib.rs index 1768034..6a736e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,13 +50,25 @@ impl GpsParser { match parser.parse_sentence(&line)? { ParsedMessage::Gga(gga) => { parsed_gga = true; - res.lat = gga.latitude.unwrap(); - res.lon = gga.longitude.unwrap(); - res.timestamp = gga.timestamp.unwrap(); + res.lat = match gga.latitude { + Some(value) => value, + _none => 0.0, + }; + res.lon = match gga.longitude { + Some(value) => value, + _none => 0.0, + }; + res.timestamp = match gga.timestamp { + Some(value) => value, + _none => Utc::now(), + }; }, ParsedMessage::Vtg(vtg) => { parsed_vtg = true; - res.speed = vtg.sog_kph.unwrap(); + res.speed = match vtg.sog_kph { + Some(value) => value, + _none => 0.0, + }; }, _ => { }