Show datetime; take port from an argument.
This commit is contained in:
+36
-13
@@ -2,14 +2,46 @@ use nmea::Nmea;
|
||||
use nmea::SentenceType;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use clap::Parser;
|
||||
use chrono::Local;
|
||||
|
||||
/// Command-line arguments using Clap.
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about = "A tool for echoing latitude and longitude from a GPS USB dongle..")]
|
||||
struct Cli {
|
||||
|
||||
/// COM port
|
||||
#[arg(short = 'c', long)]
|
||||
com: Option<String>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
let cli = Cli::parse();
|
||||
|
||||
|
||||
|
||||
let com = match cli.com {
|
||||
Some(com) => com,
|
||||
None => {
|
||||
let ports = serialport::available_ports().expect("No ports found!");
|
||||
println!("Avaiable Ports:");
|
||||
for p in ports {
|
||||
println!("{}", p.port_name);
|
||||
}
|
||||
println!("\nMissing `-c` port argument, use one listed above.");
|
||||
return;
|
||||
} //todo!()
|
||||
} ;
|
||||
println!("Reading from {com:?}");
|
||||
|
||||
// Inifnite loop until I add controls
|
||||
while 1 == 1 {
|
||||
let mut nmea = Nmea::default();
|
||||
|
||||
// Harcode port for dev
|
||||
let port_name = "/dev/tty.usbmodem1301";
|
||||
//let port_name = "/dev/tty.usbmodem1301";
|
||||
let port_name = com.clone();
|
||||
|
||||
// Thread for GPS streaming
|
||||
thread::spawn(move || {
|
||||
@@ -26,7 +58,6 @@ fn main() {
|
||||
let data = String::from_utf8_lossy(&buf[..n]);
|
||||
|
||||
for line in data.lines() {
|
||||
//println!("{}", line.to_string());
|
||||
|
||||
// Check sentence type
|
||||
let sentence_type = match nmea.parse(line) {
|
||||
@@ -38,10 +69,6 @@ fn main() {
|
||||
|
||||
// Only keep the GLL sentences
|
||||
if sentence_type == SentenceType::GLL {
|
||||
//nmea.parse(line).unwrap();
|
||||
//println!("{:?}", nmea.latitude);
|
||||
// if let Some(nmea.latitude) = x {
|
||||
// println!("Matched {:?}!", x);
|
||||
let lat = match nmea.latitude {
|
||||
Some(lat) => lat,
|
||||
None => todo!()
|
||||
@@ -50,19 +77,15 @@ fn main() {
|
||||
Some(lon) => lon,
|
||||
None => todo!()
|
||||
} ;
|
||||
println!("{lat}, {lon}");
|
||||
// }
|
||||
let date = Local::now();
|
||||
println!("{}, {lat}, {lon}", date.format("%Y-%m-%d %H:%M:%S"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user