Handle device commands
This commit is contained in:
parent
cd3282a69d
commit
945c8386ad
15
src/main.rs
15
src/main.rs
@ -30,6 +30,8 @@ use tokio_serial;
|
|||||||
|
|
||||||
#[derive(Subcommand, Clone)]
|
#[derive(Subcommand, Clone)]
|
||||||
enum DeviceCommands {
|
enum DeviceCommands {
|
||||||
|
/// Request current state
|
||||||
|
State,
|
||||||
/// Set wifi credentials
|
/// Set wifi credentials
|
||||||
SetWifi {
|
SetWifi {
|
||||||
/// SSID of the network
|
/// SSID of the network
|
||||||
@ -39,6 +41,12 @@ enum DeviceCommands {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for DeviceCommands {
|
||||||
|
fn default() -> Self {
|
||||||
|
return Self::State;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Subcommand, Clone)]
|
#[derive(Subcommand, Clone)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
/// List available serial devices
|
/// List available serial devices
|
||||||
@ -120,6 +128,8 @@ async fn main() -> Result<()>{
|
|||||||
.fold(String::new(), |a, b| a + &b + &String::from("\n")));
|
.fold(String::new(), |a, b| a + &b + &String::from("\n")));
|
||||||
},
|
},
|
||||||
Commands::Device {path, baud_rate, device_command} => {
|
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();
|
let request_current_state_packet = (RequestCurrentStateCommand {}).to_raw_packet();
|
||||||
|
|
||||||
println!("{}", hex::encode(&request_current_state_packet.to_bytes()));
|
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() {
|
if let ImprovPacket::ErrorState(error_state) = ImprovPacket::try_from_raw_packet(&raw_packet).unwrap() {
|
||||||
println!("Error state: {}", &error_state.error_state);
|
println!("Error state: {}", &error_state.error_state);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
DeviceCommands::SetWifi {ssid, password} => {
|
||||||
|
println!("Not implemented");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user