Change frequency inside get_smeter().
This commit is contained in:
+32
-49
@@ -115,11 +115,20 @@ struct Rig {
|
||||
data_bits: DataBits,
|
||||
stop_bits: StopBits,
|
||||
parity: Parity,
|
||||
s_meter_cat: String
|
||||
s_meter_cat: String,
|
||||
freq_cat: String,
|
||||
}
|
||||
|
||||
// Create a rig struct
|
||||
fn build_rig(name: &str, baud_rate: u32, data_bits: u8, stop_bits: u8, parity: &str, s_meter_cat: &str) -> Rig {
|
||||
fn build_rig(
|
||||
name: &str,
|
||||
baud_rate: u32,
|
||||
data_bits: u8,
|
||||
stop_bits: u8,
|
||||
parity: &str,
|
||||
s_meter_cat: &str,
|
||||
freq_cat: &str,
|
||||
) -> Rig {
|
||||
Rig {
|
||||
name: name.to_string(),
|
||||
baud_rate,
|
||||
@@ -128,12 +137,12 @@ fn build_rig(name: &str, baud_rate: u32, data_bits: u8, stop_bits: u8, parity: &
|
||||
6 => DataBits::Six,
|
||||
7 => DataBits::Seven,
|
||||
8 => DataBits::Eight,
|
||||
_ => DataBits::Eight
|
||||
_ => DataBits::Eight,
|
||||
},
|
||||
stop_bits: match stop_bits {
|
||||
1 => StopBits::One,
|
||||
2 => StopBits::Two,
|
||||
_ => StopBits::One
|
||||
_ => StopBits::One,
|
||||
},
|
||||
parity: match parity {
|
||||
"none" => Parity::None,
|
||||
@@ -141,7 +150,8 @@ fn build_rig(name: &str, baud_rate: u32, data_bits: u8, stop_bits: u8, parity: &
|
||||
"even" => Parity::Even,
|
||||
_ => Parity::None,
|
||||
},
|
||||
s_meter_cat: s_meter_cat.to_string()
|
||||
s_meter_cat: s_meter_cat.to_string(),
|
||||
freq_cat: freq_cat.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,19 +159,18 @@ 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", 9600, 8, 2, "none", "SM"),
|
||||
"ic-7300" => build_rig("ic-7300", 115200, 8, 1, "none", "1502"),
|
||||
"qmx" => build_rig("qmx", 9600, 8, 2, "none", "SM", "FA"),
|
||||
//"ic-7300" => build_rig("ic-7300", 115200, 8, 1, "none", "1502"),
|
||||
_ => {
|
||||
// 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", "SM")
|
||||
},
|
||||
build_rig("qmx", 9600, 8, 2, "none", "SM", "FA")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read S-meter
|
||||
fn get_smeter(comport: &str, rig_name: &str) -> String {
|
||||
|
||||
fn get_smeter(comport: &str, rig_name: &str, frequency: u32) -> String {
|
||||
// Get the serial connection info for the rig name
|
||||
let rig = get_rig(rig_name);
|
||||
|
||||
@@ -174,6 +183,17 @@ fn get_smeter(comport: &str, rig_name: &str) -> String {
|
||||
.open()
|
||||
.expect("Failed to open port");
|
||||
|
||||
// Set the requested frequency
|
||||
let output = format!("{}{};", rig.freq_cat, frequency);
|
||||
|
||||
match port.write(output.as_bytes()) {
|
||||
Ok(_) => {
|
||||
std::io::stdout().flush().unwrap();
|
||||
}
|
||||
Err(ref e) if e.kind() == ErrorKind::TimedOut => (),
|
||||
Err(e) => eprintln!("{:?}", e),
|
||||
}
|
||||
|
||||
// Duh, you need the ";" on the end!
|
||||
// let output = "FA14075000;"; // set VFO A frequency
|
||||
// let output = "FA;"; // ask for VFO A frequency
|
||||
@@ -210,40 +230,6 @@ fn get_smeter(comport: &str, rig_name: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
// Set frequency
|
||||
fn set_freq(comport: &str, freq: u32) -> String {
|
||||
let mut port = serialport::new(comport, 4800)
|
||||
.data_bits(DataBits::Eight)
|
||||
.stop_bits(StopBits::Two)
|
||||
.parity(Parity::None)
|
||||
.timeout(Duration::from_millis(100))
|
||||
.open()
|
||||
.expect("Failed to open port");
|
||||
|
||||
// Duh, you need the ";" on the end!
|
||||
//let output = "FA14075000;"; // set VFO A frequency
|
||||
let output = format!("FA{};", freq);
|
||||
//println!("{output}");
|
||||
|
||||
match port.write(output.as_bytes()) {
|
||||
Ok(_) => {
|
||||
std::io::stdout().flush().unwrap();
|
||||
}
|
||||
Err(ref e) if e.kind() == ErrorKind::TimedOut => (),
|
||||
Err(e) => eprintln!("{:?}", e),
|
||||
}
|
||||
|
||||
let mut buf = [0u8; 1024];
|
||||
match port.read(&mut buf) {
|
||||
Ok(_) => {
|
||||
return format!("Frequency set.");
|
||||
}
|
||||
Err(_) => {
|
||||
return format!("Failed to set frequency.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write row to a file
|
||||
fn write_row(str_arr: [String; 5], file: &String, fmt: &str) -> Result<(), Box<dyn Error>> {
|
||||
// From https://docs.rs/csv/latest/csv/tutorial/index.html#writing-csv
|
||||
@@ -341,9 +327,6 @@ fn main() {
|
||||
} //todo!()
|
||||
};
|
||||
|
||||
// Set the requested frequency
|
||||
set_freq(&com, frequency);
|
||||
|
||||
println!("Press Ctrl + C to quit");
|
||||
|
||||
// Simple test loop to make sure we are getting values each time
|
||||
@@ -354,7 +337,7 @@ fn main() {
|
||||
// Get datestamp
|
||||
let date = Local::now();
|
||||
// Get S-meter
|
||||
let s_val = get_smeter(&com, &rig);
|
||||
let s_val = get_smeter(&com, &rig, frequency);
|
||||
//println!("{a}");
|
||||
match s_val.parse::<i32>() {
|
||||
// Simple graph as we go. Eventually this will be replaced.
|
||||
|
||||
Reference in New Issue
Block a user