Wait for one location and then exit.

This commit is contained in:
mattbk
2026-09-07 18:04:48 -05:00
parent 86c5720fb4
commit 80ba685a95
+28 -10
View File
@@ -2,6 +2,7 @@ use nmea::Nmea;
use nmea::SentenceType; use nmea::SentenceType;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use std::todo;
use clap::Parser; use clap::Parser;
use chrono::Local; use chrono::Local;
@@ -32,22 +33,36 @@ fn main() {
return; return;
} //todo!() } //todo!()
} ; } ;
//fn read_loc(com: &str) -> &str {
println!("Reading from {com:?}"); println!("Reading from {com:?}");
// Inifnite loop until I add controls // Infinite loop until I add controls
while 1 == 1 { //loop {
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(); let port_name = com.clone();
// let port1_name = com.clone();
// let mut port1 = serialport::new(port1_name, 115_200)
// .timeout(Duration::from_millis(10000))
// .open()
// .expect("Failed to open port");
// let mut serial_buf: Vec<u8> = vec![0; 32];
// port1.read(serial_buf.as_mut_slice()).expect("Found no data!");
// dbg!(serial_buf);
// Thread for GPS streaming // Thread for GPS streaming
thread::spawn(move || { //thread::spawn(move || {
let port = serialport::new(port_name, 9600) let port = serialport::new(port_name, 9600)
.timeout(Duration::from_millis(1000)) .timeout(Duration::from_millis(1000))
.open(); .open();
if let Ok(mut serial) = port { if let Ok(mut serial) = port {
let mut buf = [0u8; 1024]; let mut buf = [0u8; 1024];
@@ -62,7 +77,8 @@ fn main() {
let sentence_type = match nmea.parse(line) { let sentence_type = match nmea.parse(line) {
Ok(sentence_type) => sentence_type, Ok(sentence_type) => sentence_type,
Err(_) => { Err(_) => {
return; break;
//return;
} }
}; };
@@ -70,23 +86,25 @@ fn main() {
if sentence_type == SentenceType::GLL { if sentence_type == SentenceType::GLL {
let lat = match nmea.latitude { let lat = match nmea.latitude {
Some(lat) => lat, Some(lat) => lat,
None => todo!() None => -9999.25
} ; } ;
let lon = match nmea.longitude { let lon = match nmea.longitude {
Some(lon) => lon, Some(lon) => lon,
None => todo!() None => -9999.25
} ; } ;
let date = Local::now(); let date = Local::now();
println!("{}, {lat}, {lon}", date.format("%Y-%m-%d %H:%M:%S")); println!("{}, {lat}, {lon}", date.format("%Y-%m-%d %H:%M:%S"));
return;
} }
} }
} }
Err(_) => break, Err(_) => {}, // lol that I can just not put a return in?
} }
} }
} }
}); //});
} }
} //}