gps_parser/src/main.rs
2021-06-22 06:46:37 +02:00

61 lines
2.3 KiB
Rust

use std::io::prelude::*;
use std::io::BufReader;
use std::fs::File;
use nmea_parser::*;
fn main() -> std::io::Result<()> {
let f = File::open("/dev/ttyACM0")?;
let mut reader = BufReader::new(f);
let mut line = String::new();
let mut parser = NmeaParser::new();
loop {
let len = reader.read_line(&mut line)?;
if len > 1 {
match parser.parse_sentence(&line) {
Ok(msg) => {
match msg {
ParsedMessage::Gga(gga) => {
println!("Source: {}", gga.source);
println!("Latitude: {:.3}°", gga.latitude.unwrap());
println!("Longitude: {:.3}°", gga.longitude.unwrap());
match gga.satellite_count {
Some(sat_count) => {
println!("Satellite count: {}", sat_count);
},
None => {
println!("No satellites in sight");
}
}
match gga.timestamp {
Some(timestamp) => {
println!("Timestamp: {}", timestamp);
},
None => {
println!("No timestamp
")
}
}
},
// ParsedMessage::Gsa(gsa) => {
// println!("{}", gsa.mode1_automatic)
// }
_ => {
}
}
},
Err(_err) => {}
}
}
line.clear();
}
}
// $GNRMC,204607.00,A,5222.24380,N,01351.13504,E,0.103,,210621,,,A*62
// $GNVTG,,T,,M,0.103,N,0.191,K,A*36
// $GNGGA,204607.00,5222.24380,N,01351.13504,E,1,08,1.29,29.2,M,41.8,M,,*7C
// $GNGSA,A,3,04,09,06,03,07,26,,,,,,,1.90,1.29,1.39*1E
// $GPGSV,4,1,13,02,40,283,19,03,08,126,08,04,39,073,27,06,44,232,31*77
// $GNGLL,5222.24380,N,01351.13504,E,204607.00,A,A*7F