From 0fffecf5b9c36a1e069e6f18f0c650ccb8afc7f3 Mon Sep 17 00:00:00 2001 From: mattbk Date: Thu, 10 Sep 2026 19:31:15 -0500 Subject: [PATCH] Set frequency. --- result.csv | 20 -------------------- src/main.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 21 deletions(-) delete mode 100644 result.csv diff --git a/result.csv b/result.csv deleted file mode 100644 index 4731251..0000000 --- a/result.csv +++ /dev/null @@ -1,20 +0,0 @@ -time,lat,lon,000 -time,lat,lon,004 -time,lat,lon,008 -time,lat,lon,004 -time,lat,lon,010 -time,lat,lon,011 -time,lat,lon,002 -time,lat,lon,003 -time,lat,lon,009 -time,lat,lon,010 -time,lat,lon,006 -time,lat,lon,006 -time,lat,lon,008 -time,lat,lon,010 -time,lat,lon,007 -time,lat,lon,004 -time,lat,lon,003 -time,lat,lon,006 -time,lat,lon,006 -time,lat,lon,005 diff --git a/src/main.rs b/src/main.rs index 898d280..57d560b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,10 +22,15 @@ struct Cli { com: Option, /// Format - #[arg(short = 'f', long, default_value = "result.csv")] + #[arg(short = 'o', long, default_value = "result.csv")] file: Option, + + /// Frequency + #[arg(short = 'f', long)] + freq: Option, } +// Read S-meter fn get_smeter(comport: &str) -> String { let mut port = serialport::new(comport, 4800) .data_bits(DataBits::Eight) @@ -71,6 +76,41 @@ fn get_smeter(comport: &str) -> String { } } +// Set frequency +fn set_freq(comport: &str, freq: u32) -> String { + let mut port = serialport::new(comport, 4800) + .data_bits(DataBits::Eight) + .stop_bits(StopBits::Two) + .parity(Parity::None) + .timeout(Duration::from_millis(100)) + .open() + .expect("Failed to open port"); + + // Duh, you need the ";" on the end! + //let output = "FA14075000;"; // set VFO A frequency + let output = format!("FA{};", freq); + //println!("{output}"); + + match port.write(output.as_bytes()) { + Ok(_) => { + std::io::stdout().flush().unwrap(); + } + Err(ref e) if e.kind() == ErrorKind::TimedOut => (), + Err(e) => eprintln!("{:?}", e) + } + + let mut buf = [0u8; 1024]; + match port.read(&mut buf) { + Ok(_) => { + return format!("Frequency set."); + } + Err(_) => { + return format!("Failed to set frequency."); + } + + } +} + // Write row to a file fn write_row(str_arr: [String; 4], file: &String, fmt: &str) -> Result<(), Box> { // From https://docs.rs/csv/latest/csv/tutorial/index.html#writing-csv @@ -99,6 +139,7 @@ fn write_row(str_arr: [String; 4], file: &String, fmt: &str) -> Result<(), Box frequency, + None => { + return; + } //todo!() + }; + + // Set the requested frequency + set_freq(&com, frequency); + // Simple test loop to make sure we are getting values each time for _i in 1..11 { let s_val = get_smeter(&com);