Change frequency inside get_smeter().
This commit is contained in:
+35
-52
@@ -115,11 +115,20 @@ struct Rig {
|
|||||||
data_bits: DataBits,
|
data_bits: DataBits,
|
||||||
stop_bits: StopBits,
|
stop_bits: StopBits,
|
||||||
parity: Parity,
|
parity: Parity,
|
||||||
s_meter_cat: String
|
s_meter_cat: String,
|
||||||
|
freq_cat: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a rig struct
|
// 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 {
|
Rig {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
baud_rate,
|
baud_rate,
|
||||||
@@ -128,20 +137,21 @@ fn build_rig(name: &str, baud_rate: u32, data_bits: u8, stop_bits: u8, parity: &
|
|||||||
6 => DataBits::Six,
|
6 => DataBits::Six,
|
||||||
7 => DataBits::Seven,
|
7 => DataBits::Seven,
|
||||||
8 => DataBits::Eight,
|
8 => DataBits::Eight,
|
||||||
_ => DataBits::Eight
|
_ => DataBits::Eight,
|
||||||
},
|
},
|
||||||
stop_bits: match stop_bits {
|
stop_bits: match stop_bits {
|
||||||
1 => StopBits::One,
|
1 => StopBits::One,
|
||||||
2 => StopBits::Two,
|
2 => StopBits::Two,
|
||||||
_ => StopBits::One
|
_ => StopBits::One,
|
||||||
},
|
},
|
||||||
parity: match parity {
|
parity: match parity {
|
||||||
"none" => Parity::None,
|
"none" => Parity::None,
|
||||||
"odd" => Parity::Odd,
|
"odd" => Parity::Odd,
|
||||||
"even" => Parity::Even,
|
"even" => Parity::Even,
|
||||||
_ => Parity::None,
|
_ => 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/
|
// 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", 9600, 8, 2, "none", "SM"),
|
"qmx" => build_rig("qmx", 9600, 8, 2, "none", "SM", "FA"),
|
||||||
"ic-7300" => build_rig("ic-7300", 115200, 8, 1, "none", "1502"),
|
//"ic-7300" => build_rig("ic-7300", 115200, 8, 1, "none", "1502"),
|
||||||
_ => {
|
_ => {
|
||||||
// This prints a message every loop but that's OK.
|
// This prints a message every loop but that's OK.
|
||||||
println!("Rig '{x}' in rig list. Using default connection values.");
|
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
|
// 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
|
// Get the serial connection info for the rig name
|
||||||
let rig = get_rig(rig_name);
|
let rig = get_rig(rig_name);
|
||||||
|
|
||||||
@@ -174,10 +183,21 @@ fn get_smeter(comport: &str, rig_name: &str) -> String {
|
|||||||
.open()
|
.open()
|
||||||
.expect("Failed to open port");
|
.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!
|
// Duh, you need the ";" on the end!
|
||||||
// let output = "FA14075000;"; // set VFO A frequency
|
// let output = "FA14075000;"; // set VFO A frequency
|
||||||
// let output = "FA;"; // ask for VFO A frequency
|
// let output = "FA;"; // ask for VFO A frequency
|
||||||
let output = format!("{};", rig.s_meter_cat);//"SM;"; // ask for S-meter reading
|
let output = format!("{};", rig.s_meter_cat); //"SM;"; // ask for S-meter reading
|
||||||
// What are we actually sending?
|
// What are we actually sending?
|
||||||
//dbg!(output.as_bytes());
|
//dbg!(output.as_bytes());
|
||||||
|
|
||||||
@@ -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
|
// Write row to a file
|
||||||
fn write_row(str_arr: [String; 5], file: &String, fmt: &str) -> Result<(), Box<dyn Error>> {
|
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
|
// From https://docs.rs/csv/latest/csv/tutorial/index.html#writing-csv
|
||||||
@@ -341,9 +327,6 @@ fn main() {
|
|||||||
} //todo!()
|
} //todo!()
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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
|
// Simple test loop to make sure we are getting values each time
|
||||||
@@ -354,7 +337,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, &rig);
|
let s_val = get_smeter(&com, &rig, frequency);
|
||||||
//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