diff --git a/Cargo.lock b/Cargo.lock index 7423de4..702acde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -79,6 +79,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + [[package]] name = "arrayvec" version = "0.7.8" @@ -89,13 +95,27 @@ checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56" name = "asmr" version = "0.1.0" dependencies = [ + "anyhow", "chrono", "clap", "csv", "io", "iter", "nmea", + "riglib", "serialport", + "tokio", +] + +[[package]] +name = "async-trait" +version = "0.1.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", ] [[package]] @@ -184,6 +204,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + [[package]] name = "cc" version = "1.4.5" @@ -200,6 +226,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + [[package]] name = "chrono" version = "0.4.45" @@ -486,6 +518,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + [[package]] name = "find-msvc-tools" version = "0.1.12" @@ -952,6 +994,15 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.34" @@ -973,6 +1024,31 @@ version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" +[[package]] +name = "mio" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "mio-serial" +version = "5.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d4ba3f20276f21b7cad3f1b54c97489cf096a3894fd627cc6951cb3abdd4c60" +dependencies = [ + "log", + "mio", + "nix 0.31.3", + "serialport", + "windows-sys 0.61.2", +] + [[package]] name = "nix" version = "0.26.4" @@ -984,6 +1060,18 @@ dependencies = [ "libc", ] +[[package]] +name = "nix" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d" +dependencies = [ + "bitflags 2.13.1", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "nmea" version = "0.8.0" @@ -1073,6 +1161,29 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + [[package]] name = "paste" version = "1.0.15" @@ -1146,6 +1257,137 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags 2.13.1", +] + +[[package]] +name = "riglib" +version = "0.1.0" +source = "git+https://github.com/chadsbrown/riglib.git#b8adc13dc715652470509ae5ec6965ab8a2b8aa9" +dependencies = [ + "riglib-core", + "riglib-elecraft", + "riglib-flex", + "riglib-icom", + "riglib-kenwood", + "riglib-transport", + "riglib-yaesu", +] + +[[package]] +name = "riglib-core" +version = "0.1.0" +source = "git+https://github.com/chadsbrown/riglib.git#b8adc13dc715652470509ae5ec6965ab8a2b8aa9" +dependencies = [ + "async-trait", + "thiserror", + "tokio", +] + +[[package]] +name = "riglib-elecraft" +version = "0.1.0" +source = "git+https://github.com/chadsbrown/riglib.git#b8adc13dc715652470509ae5ec6965ab8a2b8aa9" +dependencies = [ + "async-trait", + "bytes", + "riglib-core", + "riglib-text-io", + "riglib-transport", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "riglib-flex" +version = "0.1.0" +source = "git+https://github.com/chadsbrown/riglib.git#b8adc13dc715652470509ae5ec6965ab8a2b8aa9" +dependencies = [ + "async-trait", + "bytes", + "riglib-core", + "riglib-transport", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "riglib-icom" +version = "0.1.0" +source = "git+https://github.com/chadsbrown/riglib.git#b8adc13dc715652470509ae5ec6965ab8a2b8aa9" +dependencies = [ + "async-trait", + "bytes", + "riglib-core", + "riglib-transport", + "thiserror", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "riglib-kenwood" +version = "0.1.0" +source = "git+https://github.com/chadsbrown/riglib.git#b8adc13dc715652470509ae5ec6965ab8a2b8aa9" +dependencies = [ + "async-trait", + "bytes", + "riglib-core", + "riglib-text-io", + "riglib-transport", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "riglib-text-io" +version = "0.1.0" +source = "git+https://github.com/chadsbrown/riglib.git#b8adc13dc715652470509ae5ec6965ab8a2b8aa9" +dependencies = [ + "riglib-core", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "riglib-transport" +version = "0.1.0" +source = "git+https://github.com/chadsbrown/riglib.git#b8adc13dc715652470509ae5ec6965ab8a2b8aa9" +dependencies = [ + "async-trait", + "riglib-core", + "thiserror", + "tokio", + "tokio-serial", + "tracing", +] + +[[package]] +name = "riglib-yaesu" +version = "0.1.0" +source = "git+https://github.com/chadsbrown/riglib.git#b8adc13dc715652470509ae5ec6965ab8a2b8aa9" +dependencies = [ + "async-trait", + "bytes", + "riglib-core", + "riglib-text-io", + "riglib-transport", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "rustc-hex" version = "2.1.0" @@ -1355,7 +1597,7 @@ dependencies = [ "io-kit-sys", "libudev", "mach2", - "nix", + "nix 0.26.4", "scopeguard", "unescaper", "windows-sys 0.52.0", @@ -1367,6 +1609,16 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + [[package]] name = "slab" version = "0.4.12" @@ -1379,6 +1631,16 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9be42f50aa861c555654aa3a37f52f4b1074bacf4e48fe0ef7fa584e80f1f0f" +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + [[package]] name = "stable_deref_trait" version = "1.2.1" @@ -1481,6 +1743,62 @@ dependencies = [ "time-core", ] +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.5", +] + +[[package]] +name = "tokio-serial" +version = "5.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd00f5f8b1e01c3e5afccd9e42ed80c2ad2df6d007877f29f8592c62e69cd116" +dependencies = [ + "cfg-if", + "futures-core", + "futures-sink", + "log", + "mio-serial", + "serialport", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml_datetime" version = "1.1.1+spec-1.1.0" @@ -1511,6 +1829,37 @@ dependencies = [ "winnow", ] +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + [[package]] name = "typenum" version = "1.20.1" @@ -1586,6 +1935,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + [[package]] name = "wasm-bindgen" version = "0.2.128" diff --git a/Cargo.toml b/Cargo.toml index 7131809..d487dcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,7 @@ io = "0.0.2" iter = "0.1.0" nmea = "0.8.0" serialport = "4.10.0" +riglib = { git = "https://github.com/chadsbrown/riglib.git" } +tokio = { version = "1", features = ["full"] } +anyhow = "1.0.104" diff --git a/src/main.rs b/src/main.rs index c8efc0b..68a4c17 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,9 @@ use std::io::ErrorKind; use std::io::Write; use std::thread::sleep; use std::time::Duration; +use riglib::{Rig as Rig_riglib, ReceiverId, RigEvent}; +use riglib::kenwood::KenwoodBuilder; +use riglib::kenwood::models::ts_590s; /// Command-line arguments using Clap. #[derive(Parser, Debug)] @@ -160,7 +163,7 @@ fn build_rig( fn get_rig(x: &str) -> Rig { match x { "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", "FA"), _ => { // This prints a message every loop but that's OK. println!("Rig '{x}' in rig list. Using default connection values."); @@ -184,7 +187,9 @@ fn get_smeter(comport: &str, rig_name: &str, frequency: u32) -> String { .expect("Failed to open port"); // Set the requested frequency - let output = format!("{}{};", rig.freq_cat, frequency); + // let output = "FA00014075000;"; // set VFO A frequency + let output = format!("{}{:011};", rig.freq_cat, frequency); + // dbg!(&output); match port.write(output.as_bytes()) { Ok(_) => { @@ -195,8 +200,6 @@ fn get_smeter(comport: &str, rig_name: &str, frequency: u32) -> String { } // Duh, you need the ";" on the end! - // let output = "FA14075000;"; // set VFO A frequency - // let output = "FA;"; // ask for VFO A frequency let output = format!("{};", rig.s_meter_cat); //"SM;"; // ask for S-meter reading // What are we actually sending? //dbg!(output.as_bytes()); @@ -259,11 +262,12 @@ fn write_row(str_arr: [String; 5], file: &String, fmt: &str) -> Result<(), Box anyhow::Result<()> { // Arguments let cli = Cli::parse(); - let rig = match cli.rig { + let rig_name = match cli.rig { Some(rig) => { println!("Connecting to rig {}", rig); rig @@ -284,7 +288,7 @@ fn main() { println!("{}", p.port_name); } println!("\nMissing `-c` rig port argument, use one listed above."); - return; + return Ok(()); } //todo!() }; @@ -298,7 +302,7 @@ fn main() { println!("{}", p.port_name); } println!("\nMissing `-g` GPS port argument, use one listed above."); - return; + return Ok(()); } //todo!() }; @@ -316,19 +320,28 @@ fn main() { let frequency = match cli.freq { Some(frequency) => frequency, None => { - return; + return Ok(()); } //todo!() }; let wait: u16 = match cli.wait { Some(wait) => wait, None => { - return; + return Ok(()); } //todo!() }; println!("Press Ctrl + C to quit"); + let rig1 = KenwoodBuilder::new(ts_590s()) + .serial_port(&com) + .build() + .await?; + + let info = rig1.info(); + println!("Connected: {} {}\n", info.manufacturer, info.model_name); + let rx = ReceiverId::VFO_A; + // Simple test loop to make sure we are getting values each time //for _i in 1..11 { loop { @@ -337,18 +350,26 @@ fn main() { // Get datestamp let date = Local::now(); // Get S-meter - let s_val = get_smeter(&com, &rig, frequency); + //let s_val = get_smeter(&com, &rig_name, frequency); + let s_val = rig1.get_s_meter(rx).await?; //println!("{a}"); - match s_val.parse::() { - // Simple graph as we go. Eventually this will be replaced. - Ok(n) => println!( + let n = s_val as i32; + println!( "{} {} {}", date.format("%Y-%m-%d %H:%M:%S").to_string(), s_val, "#".repeat(n.try_into().unwrap()) - ), - Err(_e) => todo!(), - } + ); + // match s_val { + // // Simple graph as we go. Eventually this will be replaced. + // Ok(n) => println!( + // "{} {} {}", + // date.format("%Y-%m-%d %H:%M:%S").to_string(), + // s_val, + // "#".repeat(n.try_into().unwrap()) + // ), + // Err(_e) => todo!(), + //} // If they provided a file name if file_out != "no file" { if let Err(err) = write_row( @@ -368,4 +389,5 @@ fn main() { } sleep(Duration::from_millis((wait as u64 * 1000) - 1000)); } + Ok(()) }