Working snapshot.
This commit is contained in:
+28
-14
@@ -22,16 +22,15 @@ struct Cli {
|
||||
}
|
||||
|
||||
// Function to get the location
|
||||
fn get_loc(port:String, fmt:String) -> String {
|
||||
|
||||
fn get_loc(port: String, fmt: String) -> String {
|
||||
let mut nmea = Nmea::default();
|
||||
|
||||
// Harcode port for dev
|
||||
//let port_name = "/dev/tty.usbmodem1301";
|
||||
let port_name = port;
|
||||
|
||||
//fn read_loc(com: &str) -> &str {
|
||||
//println!("Reading from {port_name}");
|
||||
//fn read_loc(com: &str) -> &str {
|
||||
//println!("Reading from {port_name}");
|
||||
|
||||
let port = serialport::new(port_name, 9600)
|
||||
.timeout(Duration::from_millis(1000))
|
||||
@@ -67,11 +66,20 @@ fn get_loc(port:String, fmt:String) -> String {
|
||||
let date = Local::now();
|
||||
//println!("{}, {lat}, {lon}", date.format("%Y-%m-%d %H:%M:%S"));
|
||||
if fmt == "csv" {
|
||||
return format!("{},{:.8},{:.8}", date.format("%Y-%m-%d %H:%M:%S"), lat, lon);
|
||||
return format!(
|
||||
"{},{:.8},{:.8}",
|
||||
date.format("%Y-%m-%d %H:%M:%S"),
|
||||
lat,
|
||||
lon
|
||||
);
|
||||
} else if fmt == "ssv" {
|
||||
return format!("\"{}\" {:.8} {:.8}", date.format("%Y-%m-%d %H:%M:%S"), lat, lon);
|
||||
return format!(
|
||||
"\"{}\" {:.8} {:.8}",
|
||||
date.format("%Y-%m-%d %H:%M:%S"),
|
||||
lat,
|
||||
lon
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,13 +87,18 @@ fn get_loc(port:String, fmt:String) -> String {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return format!("wut");
|
||||
// https://github.com/serialport/serialport-rs#listing-available-ports
|
||||
let ports = serialport::available_ports().expect("No ports found!");
|
||||
println!("Available Ports:");
|
||||
for p in ports {
|
||||
println!("{}", p.port_name);
|
||||
}
|
||||
|
||||
return format!("\nCould not connect to port. Is it listed above?");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
|
||||
// Arguments
|
||||
let cli = Cli::parse();
|
||||
|
||||
@@ -110,10 +123,11 @@ fn main() {
|
||||
} //todo!()
|
||||
};
|
||||
|
||||
|
||||
// Run the function
|
||||
let result = get_loc(com, fmt);
|
||||
println!("{result}");
|
||||
|
||||
// Max rate is about 1 measurement per second
|
||||
//loop {
|
||||
let result = get_loc(com.clone(), fmt.clone());
|
||||
println!("{result}");
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user