Add request device information and implement base of RPCResult

This commit is contained in:
2024-12-18 21:59:55 +01:00
parent 945c8386ad
commit 5bfe2bde5a
2 changed files with 68 additions and 3 deletions

View File

@@ -19,6 +19,7 @@ use improv_setup::improv::{
RawPacket,
ImprovPacket,
RequestCurrentStateCommand,
RequestDeviceInformationPacket,
};
use log::{
debug,
@@ -39,6 +40,8 @@ enum DeviceCommands {
/// Password for the SSID
password: String,
},
/// Request device info
Info,
}
impl Default for DeviceCommands {
@@ -168,7 +171,26 @@ async fn main() -> Result<()>{
},
DeviceCommands::SetWifi {ssid, password} => {
println!("Not implemented");
}
},
DeviceCommands::Info => {
let request_device_information_packet = (RequestDeviceInformationPacket {}).to_raw_packet();
let mut serial_interface = tokio_serial::new(path, *baud_rate).open().unwrap();
serial_interface.write(&request_device_information_packet.to_bytes()).unwrap();
let mut buffer: Vec<u8> = Vec::new();
serial_interface.read_to_end(&mut buffer);
let improv_packet_offset = find_begin_of_improv_packet(&buffer).unwrap();
let improv_packet_end = improv_packet_offset + 10 + <u8 as Into<usize>>::into(buffer[improv_packet_offset+8]);
let raw_packet = RawPacket::try_from_bytes(&buffer[improv_packet_offset..improv_packet_end].to_vec()).unwrap();
if let ImprovPacket::RPCResult(rpc_result) = ImprovPacket::try_from_raw_packet(&raw_packet).unwrap() {
println!("Received RPCResult");
}
},
};
},