+ get_channel_info command

This commit is contained in:
2024-10-06 23:54:18 -04:00
parent ed68cbdae2
commit 1f01f14e4c
2 changed files with 28 additions and 7 deletions

View File

@@ -2,11 +2,10 @@ mod xm;
mod hw; mod hw;
use text_io::scan; use text_io::scan;
use xm::packet::XMPacket;
use xm::command::{XMCommand, send_command}; use xm::command::{XMCommand, send_command};
use hw::serial::xm_pcr_serial; use hw::serial::xm_pcr_serial;
use std::time::Duration; use std::time::Duration;
use std::io::{self, Write}; use std::io;
fn main() -> Result<(), io::Error> { fn main() -> Result<(), io::Error> {
let port_name: &str = "/dev/ttyUSB0"; // Adjust as per your system let port_name: &str = "/dev/ttyUSB0"; // Adjust as per your system
@@ -25,7 +24,8 @@ fn main() -> Result<(), io::Error> {
println!("1. Power Radio On"); println!("1. Power Radio On");
println!("2. Power Radio Off"); println!("2. Power Radio Off");
println!("3. Select Channel"); println!("3. Select Channel");
println!("4. Get Radio ID"); println!("4. Get Channel Info");
println!("5. Get Radio ID");
println!("0. Exit"); println!("0. Exit");
let a: i32; let a: i32;
@@ -67,6 +67,23 @@ fn main() -> Result<(), io::Error> {
} }
}, },
4 => { 4 => {
println!("Enter the channel number (0-255): ");
let channel: u8;
scan!("{}", channel);
match send_command(&mut *port, XMCommand::get_channel_info(channel), timeout, true) {
Ok(Some(response)) => {
println!("Received valid XM packet: {}", response);
},
Ok(None) => {
println!("No response expected.");
},
Err(e) => {
eprintln!("Error: {}", e);
}
}
}
5 => {
match send_command(&mut *port, XMCommand::get_radio_id(), timeout, true) { match send_command(&mut *port, XMCommand::get_radio_id(), timeout, true) {
Ok(Some(serial_number_str)) => { Ok(Some(serial_number_str)) => {
println!("Received valid XMRadioID: {}", serial_number_str); println!("Received valid XMRadioID: {}", serial_number_str);

View File

@@ -8,22 +8,26 @@ use crate::xm::radio_id::XMRadioID;
pub struct XMCommand; pub struct XMCommand;
impl XMCommand { impl XMCommand {
#[allow(dead_code)] #[allow(dead_code)] // Remember to take these out after being implemented
pub fn power_on() -> XMPacket { pub fn power_on() -> XMPacket {
XMPacket::new(vec![0x00, 0x10, 0x10, 0x10, 0x01]) XMPacket::new(vec![0x00, 0x10, 0x10, 0x10, 0x01])
} }
#[allow(dead_code)] #[allow(dead_code)] // Remember to take these out after being implemented
pub fn power_off() -> XMPacket { pub fn power_off() -> XMPacket {
XMPacket::new(vec![0x01, 0x00]) XMPacket::new(vec![0x01, 0x00])
} }
#[allow(dead_code)] #[allow(dead_code)] // Remember to take these out after being implemented
pub fn select_channel(channel: u8) -> XMPacket { pub fn select_channel(channel: u8) -> XMPacket {
XMPacket::new(vec![0x10, 0x02, channel, 0x00, 0x00, 0x01]) XMPacket::new(vec![0x10, 0x02, channel, 0x00, 0x00, 0x01])
} }
#[allow(dead_code)] #[allow(dead_code)] // Remember to take these out after being implemented
pub fn get_radio_id() -> XMPacket { pub fn get_radio_id() -> XMPacket {
XMPacket::new(vec![0x31]) XMPacket::new(vec![0x31])
} }
#[allow(dead_code)] // Remember to take these out after being implemented
pub fn get_channel_info(channel: u8) -> XMPacket {
XMPacket::new(vec![0x25, 0x08, channel, 0x00])
}
} }
pub fn send_command(port: &mut dyn SerialPort, command: XMPacket, timeout: Duration, expect_response: bool) -> Result<Option<String>, io::Error> { pub fn send_command(port: &mut dyn SerialPort, command: XMPacket, timeout: Duration, expect_response: bool) -> Result<Option<String>, io::Error> {