Cut the program down to absolute minimum I need. #1
+3
-1
@@ -1,9 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "RUST_NMEA_PARSER"
|
name = "gpsll"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serialport = "4.2"
|
serialport = "4.2"
|
||||||
nmea = {version = "0.6", features = ["GGA"]}
|
nmea = {version = "0.6", features = ["GGA"]}
|
||||||
|
clap = { version = "4", features = ["derive"] }
|
||||||
|
chrono = "0.4.45"
|
||||||
|
|
||||||
|
|||||||
+36
-13
@@ -2,14 +2,46 @@ use nmea::Nmea;
|
|||||||
use nmea::SentenceType;
|
use nmea::SentenceType;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
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() {
|
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
|
// Inifnite loop until I add controls
|
||||||
while 1 == 1 {
|
while 1 == 1 {
|
||||||
let mut nmea = Nmea::default();
|
let mut nmea = Nmea::default();
|
||||||
|
|
||||||
// Harcode port for dev
|
// 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 for GPS streaming
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
@@ -26,7 +58,6 @@ fn main() {
|
|||||||
let data = String::from_utf8_lossy(&buf[..n]);
|
let data = String::from_utf8_lossy(&buf[..n]);
|
||||||
|
|
||||||
for line in data.lines() {
|
for line in data.lines() {
|
||||||
//println!("{}", line.to_string());
|
|
||||||
|
|
||||||
// Check sentence type
|
// Check sentence type
|
||||||
let sentence_type = match nmea.parse(line) {
|
let sentence_type = match nmea.parse(line) {
|
||||||
@@ -38,10 +69,6 @@ fn main() {
|
|||||||
|
|
||||||
// Only keep the GLL sentences
|
// Only keep the GLL sentences
|
||||||
if sentence_type == SentenceType::GLL {
|
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 {
|
let lat = match nmea.latitude {
|
||||||
Some(lat) => lat,
|
Some(lat) => lat,
|
||||||
None => todo!()
|
None => todo!()
|
||||||
@@ -50,19 +77,15 @@ fn main() {
|
|||||||
Some(lon) => lon,
|
Some(lon) => lon,
|
||||||
None => todo!()
|
None => todo!()
|
||||||
} ;
|
} ;
|
||||||
println!("{lat}, {lon}");
|
let date = Local::now();
|
||||||
// }
|
println!("{}, {lat}, {lon}", date.format("%Y-%m-%d %H:%M:%S"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => break,
|
Err(_) => break,
|
||||||
}
|
}
|
||||||
|
|
||||||
thread::sleep(Duration::from_millis(200));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user