Read all packets until device is configured
This commit is contained in:
parent
9a3e034fce
commit
833901aecb
@ -263,6 +263,19 @@ impl ImprovPacket {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ImprovPacket {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::CurrentState(_) => write!(f, "CurrentStatePacket"),
|
||||
Self::ErrorState(_) => write!(f, "ErrorStatePacket"),
|
||||
Self::RequestCurrentState(_) => write!(f, "RequestCurrentStatePacket"),
|
||||
Self::RequestDeviceInformation(_) => write!(f, "RequestDeviceInformationPacket"),
|
||||
Self::RequestScannedWiFiNetworks(_) => write!(f, "RequestScannedWiFiNetworksPacket"),
|
||||
Self::RPCResult(_) => write!(f, "RPCResultPacket"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CurrentStatePacket {
|
||||
pub current_state: CurrentState,
|
||||
}
|
||||
|
29
src/main.rs
29
src/main.rs
@ -8,6 +8,7 @@ use clap::{
|
||||
};
|
||||
use env_logger;
|
||||
use improv_setup::improv::{
|
||||
CurrentState,
|
||||
RawPacket,
|
||||
ImprovPacket,
|
||||
SendWiFiSettingsPacket,
|
||||
@ -117,12 +118,30 @@ async fn main() -> Result<()>{
|
||||
|
||||
serial_interface.send(&send_wifi_settings_packet).context("Failed to send improv packet")?;
|
||||
|
||||
let result_bytes = serial_interface.recv_bytes().context("Couldn't receive any improv packet")?;
|
||||
let raw_packet = RawPacket::try_from_bytes(&result_bytes).context("Failed to deserialize packet")?;
|
||||
loop {
|
||||
let result_bytes = serial_interface.recv_bytes().context("Couldn't receive any improv packet")?;
|
||||
let improv_packet = ImprovPacket::try_from_bytes(&result_bytes).context("Failed to read packet")?;
|
||||
|
||||
if let ImprovPacket::RPCResult(rpc_result) = ImprovPacket::try_from_raw_packet(&raw_packet).context("Failed to read packet")? {
|
||||
for r in rpc_result.results {
|
||||
println!("{}", &r);
|
||||
match improv_packet {
|
||||
ImprovPacket::RPCResult(rpc_result) => {
|
||||
for r in rpc_result.results {
|
||||
println!("{}", &r);
|
||||
}
|
||||
break;
|
||||
},
|
||||
ImprovPacket::CurrentState(current_state) => {
|
||||
match current_state.current_state {
|
||||
CurrentState::Ready => println!("Device not configured"),
|
||||
CurrentState::Provisioning => println!("Trying to connect to network…"),
|
||||
CurrentState::Provisioned => println!("Connected"),
|
||||
}
|
||||
},
|
||||
ImprovPacket::ErrorState(error_state) => {
|
||||
println!("Error: {}", &error_state.error_state);
|
||||
},
|
||||
e => {
|
||||
println!("Unexpected response: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user