Compare commits
2 Commits
52a829a9a8
...
00a90d56dc
| Author | SHA1 | Date | |
|---|---|---|---|
| 00a90d56dc | |||
| 15aa249f3c |
+77
-8
@@ -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>,
|
||||
|
||||
@@ -104,12 +108,66 @@ fn get_loc(port: String) -> [f64; 2] {
|
||||
}
|
||||
}
|
||||
|
||||
// Rig struct
|
||||
struct Rig {
|
||||
name: String,
|
||||
baud_rate: u32,
|
||||
data_bits: DataBits,
|
||||
stop_bits: StopBits,
|
||||
parity: Parity,
|
||||
}
|
||||
|
||||
// Create a rig struct
|
||||
fn build_rig(name: &str, baud_rate: u32, data_bits: u8, stop_bits: u8, parity: &str) -> Rig {
|
||||
Rig {
|
||||
name: name.to_string(),
|
||||
baud_rate,
|
||||
data_bits: match data_bits {
|
||||
5 => DataBits::Five,
|
||||
6 => DataBits::Six,
|
||||
7 => DataBits::Seven,
|
||||
8 => DataBits::Eight,
|
||||
_ => DataBits::Eight
|
||||
},
|
||||
stop_bits: match stop_bits {
|
||||
1 => StopBits::One,
|
||||
2 => StopBits::Two,
|
||||
_ => StopBits::One
|
||||
},
|
||||
parity: match parity {
|
||||
"none" => Parity::None,
|
||||
"odd" => Parity::Odd,
|
||||
"even" => Parity::Even,
|
||||
_ => Parity::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get rig connection info
|
||||
// https://kevinlynagh.com/notes/match-vs-lookup/
|
||||
fn get_rig(x: &str) -> Rig {
|
||||
match x {
|
||||
"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");
|
||||
@@ -217,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 => {
|
||||
@@ -273,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 {
|
||||
@@ -283,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