Fix: Handle options of nmea messages
This commit is contained in:
20
src/lib.rs
20
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,
|
||||
};
|
||||
},
|
||||
_ => {
|
||||
}
|
||||
|
Reference in New Issue
Block a user