From 1f01f14e4cfa11180026f59f30a2fa12883dc149 Mon Sep 17 00:00:00 2001 From: William Date: Sun, 6 Oct 2024 23:54:18 -0400 Subject: [PATCH] + get_channel_info command --- src/main.rs | 23 ++++++++++++++++++++--- src/xm/command.rs | 12 ++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index d820a39..b14da55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,11 +2,10 @@ mod xm; mod hw; use text_io::scan; -use xm::packet::XMPacket; use xm::command::{XMCommand, send_command}; use hw::serial::xm_pcr_serial; use std::time::Duration; -use std::io::{self, Write}; +use std::io; fn main() -> Result<(), io::Error> { 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!("2. Power Radio Off"); println!("3. Select Channel"); - println!("4. Get Radio ID"); + println!("4. Get Channel Info"); + println!("5. Get Radio ID"); println!("0. Exit"); let a: i32; @@ -67,6 +67,23 @@ fn main() -> Result<(), io::Error> { } }, 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) { Ok(Some(serial_number_str)) => { println!("Received valid XMRadioID: {}", serial_number_str); diff --git a/src/xm/command.rs b/src/xm/command.rs index 3e18342..7b2450b 100644 --- a/src/xm/command.rs +++ b/src/xm/command.rs @@ -8,22 +8,26 @@ use crate::xm::radio_id::XMRadioID; pub struct XMCommand; impl XMCommand { - #[allow(dead_code)] + #[allow(dead_code)] // Remember to take these out after being implemented pub fn power_on() -> XMPacket { 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 { 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 { 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 { 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, io::Error> {