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)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author, version, about = "ASMR: Automatic S-Meter Reader")]
|
#[command(author, version, about = "ASMR: Automatic S-Meter Reader")]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
/// Output file path
|
||||||
|
#[arg(short = 'r', long, default_value = "qmx")]
|
||||||
|
rig: Option<String>,
|
||||||
|
|
||||||
/// Rig COM port
|
/// Rig COM port
|
||||||
#[arg(short = 'c', long)]
|
#[arg(short = 'c', long)]
|
||||||
com: Option<String>,
|
com: Option<String>,
|
||||||
@@ -24,7 +28,7 @@ struct Cli {
|
|||||||
#[arg(short = 'g', long)]
|
#[arg(short = 'g', long)]
|
||||||
gps: Option<String>,
|
gps: Option<String>,
|
||||||
|
|
||||||
/// Format
|
/// Output file path
|
||||||
#[arg(short = 'o', long)]
|
#[arg(short = 'o', long)]
|
||||||
file: Option<String>,
|
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/
|
// https://kevinlynagh.com/notes/match-vs-lookup/
|
||||||
fn get_rig(x: &str) -> Rig {
|
fn get_rig(x: &str) -> Rig {
|
||||||
match x {
|
match x {
|
||||||
"qmx" => build_rig("qmx", 4800, 8, 2, "none"),
|
"qmx" => build_rig("qmx", 4800, 8, 2, "none"),
|
||||||
_ => 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
|
// Read S-meter
|
||||||
fn get_smeter(comport: &str) -> String {
|
fn get_smeter(comport: &str, rig_name: &str) -> String {
|
||||||
let mut port = serialport::new(comport, 4800)
|
|
||||||
.data_bits(DataBits::Eight)
|
// Get the serial connection info for the rig name
|
||||||
.stop_bits(StopBits::Two)
|
let rig = get_rig(rig_name);
|
||||||
.parity(Parity::None)
|
|
||||||
|
// 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))
|
.timeout(Duration::from_millis(100))
|
||||||
.open()
|
.open()
|
||||||
.expect("Failed to open port");
|
.expect("Failed to open port");
|
||||||
@@ -261,6 +275,17 @@ fn main() {
|
|||||||
// Arguments
|
// Arguments
|
||||||
let cli = Cli::parse();
|
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 {
|
let com = match cli.com {
|
||||||
Some(com) => com,
|
Some(com) => com,
|
||||||
None => {
|
None => {
|
||||||
@@ -317,7 +342,7 @@ fn main() {
|
|||||||
// Set the requested frequency
|
// Set the requested frequency
|
||||||
set_freq(&com, 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
|
// Simple test loop to make sure we are getting values each time
|
||||||
//for _i in 1..11 {
|
//for _i in 1..11 {
|
||||||
@@ -327,7 +352,7 @@ fn main() {
|
|||||||
// Get datestamp
|
// Get datestamp
|
||||||
let date = Local::now();
|
let date = Local::now();
|
||||||
// Get S-meter
|
// Get S-meter
|
||||||
let s_val = get_smeter(&com);
|
let s_val = get_smeter(&com, &rig);
|
||||||
//println!("{a}");
|
//println!("{a}");
|
||||||
match s_val.parse::<i32>() {
|
match s_val.parse::<i32>() {
|
||||||
// Simple graph as we go. Eventually this will be replaced.
|
// Simple graph as we go. Eventually this will be replaced.
|
||||||
|
|||||||
Reference in New Issue
Block a user