From 00a90d56dc8bfb2aa2ba5904fa130d0f40d5e058 Mon Sep 17 00:00:00 2001 From: mattbk Date: Sat, 12 Sep 2026 10:59:27 -0500 Subject: [PATCH] Set up framework for different rigs to be used. See #8. --- src/main.rs | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 237e0e0..63f592e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,10 @@ use std::time::Duration; #[derive(Parser, Debug)] #[command(author, version, about = "ASMR: Automatic S-Meter Reader")] struct Cli { + /// Output file path + #[arg(short = 'r', long, default_value = "qmx")] + rig: Option, + /// Rig COM port #[arg(short = 'c', long)] com: Option, @@ -24,7 +28,7 @@ struct Cli { #[arg(short = 'g', long)] gps: Option, - /// Format + /// Output file path #[arg(short = 'o', long)] file: Option, @@ -143,17 +147,27 @@ fn build_rig(name: &str, baud_rate: u32, data_bits: u8, stop_bits: u8, parity: & // https://kevinlynagh.com/notes/match-vs-lookup/ fn get_rig(x: &str) -> Rig { match x { - "qmx" => build_rig("qmx", 4800, 8, 2, "none"), - _ => build_rig("qmx", 4800, 8, 2, "none"), + "qmx" => build_rig("qmx", 4800, 8, 2, "none"), + "ic-7300" => build_rig("ic-7300", 115200, 8, 1, "none"), + _ => { + // This prints a message every loop but that's OK. + println!("Rig '{x}' in rig list. Using default connection values."); + build_rig("qmx", 4800, 8, 2, "none") + }, } } // Read S-meter -fn get_smeter(comport: &str) -> String { - let mut port = serialport::new(comport, 4800) - .data_bits(DataBits::Eight) - .stop_bits(StopBits::Two) - .parity(Parity::None) +fn get_smeter(comport: &str, rig_name: &str) -> String { + + // Get the serial connection info for the rig name + let rig = get_rig(rig_name); + + // Set up the serial port + let mut port = serialport::new(comport, rig.baud_rate) + .data_bits(rig.data_bits) + .stop_bits(rig.stop_bits) + .parity(rig.parity) .timeout(Duration::from_millis(100)) .open() .expect("Failed to open port"); @@ -261,6 +275,17 @@ fn main() { // Arguments let cli = Cli::parse(); + let rig = match cli.rig { + Some(rig) => { + println!("Connecting to rig {}", rig); + rig + } + None => { + println!("No rig `-r` provided, using default (qmx)."); + "qmx".to_string() + } //todo!() + }; + let com = match cli.com { Some(com) => com, None => { @@ -317,7 +342,7 @@ fn main() { // Set the requested frequency set_freq(&com, frequency); - println!("Press Ctrl + C to quit."); + println!("Press Ctrl + C to quit"); // Simple test loop to make sure we are getting values each time //for _i in 1..11 { @@ -327,7 +352,7 @@ fn main() { // Get datestamp let date = Local::now(); // Get S-meter - let s_val = get_smeter(&com); + let s_val = get_smeter(&com, &rig); //println!("{a}"); match s_val.parse::() { // Simple graph as we go. Eventually this will be replaced.