Set frequency.
This commit is contained in:
-20
@@ -1,20 +0,0 @@
|
|||||||
time,lat,lon,000
|
|
||||||
time,lat,lon,004
|
|
||||||
time,lat,lon,008
|
|
||||||
time,lat,lon,004
|
|
||||||
time,lat,lon,010
|
|
||||||
time,lat,lon,011
|
|
||||||
time,lat,lon,002
|
|
||||||
time,lat,lon,003
|
|
||||||
time,lat,lon,009
|
|
||||||
time,lat,lon,010
|
|
||||||
time,lat,lon,006
|
|
||||||
time,lat,lon,006
|
|
||||||
time,lat,lon,008
|
|
||||||
time,lat,lon,010
|
|
||||||
time,lat,lon,007
|
|
||||||
time,lat,lon,004
|
|
||||||
time,lat,lon,003
|
|
||||||
time,lat,lon,006
|
|
||||||
time,lat,lon,006
|
|
||||||
time,lat,lon,005
|
|
||||||
|
+52
-1
@@ -22,10 +22,15 @@ struct Cli {
|
|||||||
com: Option<String>,
|
com: Option<String>,
|
||||||
|
|
||||||
/// Format
|
/// Format
|
||||||
#[arg(short = 'f', long, default_value = "result.csv")]
|
#[arg(short = 'o', long, default_value = "result.csv")]
|
||||||
file: Option<String>,
|
file: Option<String>,
|
||||||
|
|
||||||
|
/// Frequency
|
||||||
|
#[arg(short = 'f', long)]
|
||||||
|
freq: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read S-meter
|
||||||
fn get_smeter(comport: &str) -> String {
|
fn get_smeter(comport: &str) -> String {
|
||||||
let mut port = serialport::new(comport, 4800)
|
let mut port = serialport::new(comport, 4800)
|
||||||
.data_bits(DataBits::Eight)
|
.data_bits(DataBits::Eight)
|
||||||
@@ -71,6 +76,41 @@ fn get_smeter(comport: &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; 4], file: &String, fmt: &str) -> Result<(), Box<dyn Error>> {
|
fn write_row(str_arr: [String; 4], 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
|
||||||
@@ -99,6 +139,7 @@ fn write_row(str_arr: [String; 4], file: &String, fmt: &str) -> Result<(), Box<d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main funtion
|
||||||
fn main() {
|
fn main() {
|
||||||
// Arguments
|
// Arguments
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
@@ -124,6 +165,16 @@ fn main() {
|
|||||||
} //todo!()
|
} //todo!()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let frequency = match cli.freq {
|
||||||
|
Some(frequency) => frequency,
|
||||||
|
None => {
|
||||||
|
return;
|
||||||
|
} //todo!()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set the requested frequency
|
||||||
|
set_freq(&com, frequency);
|
||||||
|
|
||||||
// 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 {
|
||||||
let s_val = get_smeter(&com);
|
let s_val = get_smeter(&com);
|
||||||
|
|||||||
Reference in New Issue
Block a user