Set up framework for different rigs to be used. See #8.
This commit is contained in:
+35
-10
@@ -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<String>,
|
||||
|
||||
/// Rig COM port
|
||||
#[arg(short = 'c', long)]
|
||||
com: Option<String>,
|
||||
@@ -24,7 +28,7 @@ struct Cli {
|
||||
#[arg(short = 'g', long)]
|
||||
gps: Option<String>,
|
||||
|
||||
/// Format
|
||||
/// Output file path
|
||||
#[arg(short = 'o', long)]
|
||||
file: Option<String>,
|
||||
|
||||
@@ -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::<i32>() {
|
||||
// Simple graph as we go. Eventually this will be replaced.
|
||||
|
||||
Reference in New Issue
Block a user