Handle device commands

This commit is contained in:
clerie 2024-12-18 21:42:43 +01:00
parent cd3282a69d
commit 945c8386ad

View File

@ -30,6 +30,8 @@ use tokio_serial;
#[derive(Subcommand, Clone)]
enum DeviceCommands {
/// Request current state
State,
/// Set wifi credentials
SetWifi {
/// SSID of the network
@ -39,6 +41,12 @@ enum DeviceCommands {
},
}
impl Default for DeviceCommands {
fn default() -> Self {
return Self::State;
}
}
#[derive(Subcommand, Clone)]
enum Commands {
/// List available serial devices
@ -120,6 +128,8 @@ async fn main() -> Result<()>{
.fold(String::new(), |a, b| a + &b + &String::from("\n")));
},
Commands::Device {path, baud_rate, device_command} => {
match &device_command.clone().unwrap_or_default() {
DeviceCommands::State => {
let request_current_state_packet = (RequestCurrentStateCommand {}).to_raw_packet();
println!("{}", hex::encode(&request_current_state_packet.to_bytes()));
@ -155,6 +165,11 @@ async fn main() -> Result<()>{
if let ImprovPacket::ErrorState(error_state) = ImprovPacket::try_from_raw_packet(&raw_packet).unwrap() {
println!("Error state: {}", &error_state.error_state);
}
},
DeviceCommands::SetWifi {ssid, password} => {
println!("Not implemented");
}
};
},
};