Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
5eda664a47 | ||
299c4f5a5f | |||
|
96da5c9e74 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -102,7 +102,7 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
|
||||
|
||||
[[package]]
|
||||
name = "gps_parser"
|
||||
version = "0.1.0"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"nmea-parser",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "gps_parser"
|
||||
version = "0.1.0"
|
||||
version = "0.3.1"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
28
src/lib.rs
28
src/lib.rs
@ -6,10 +6,10 @@ use nmea_parser::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ParseResult {
|
||||
lat: f64,
|
||||
lon: f64,
|
||||
timestamp: DateTime<Utc>,
|
||||
speed: f64
|
||||
pub lat: f64,
|
||||
pub lon: f64,
|
||||
pub timestamp: DateTime<Utc>,
|
||||
pub speed: f64,
|
||||
}
|
||||
|
||||
pub struct GpsParser {
|
||||
@ -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,
|
||||
};
|
||||
},
|
||||
_ => {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user