Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 00a90d56dc | |||
| 15aa249f3c |
+77
-8
@@ -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>,
|
||||||
|
|
||||||
@@ -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
|
// 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");
|
||||||
@@ -217,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 => {
|
||||||
@@ -273,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 {
|
||||||
@@ -283,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