+ get_channel_info command
This commit is contained in:
23
src/main.rs
23
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);
|
||||
|
@@ -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<Option<String>, io::Error> {
|
||||
|
Reference in New Issue
Block a user