Display visible WiFi networks
This commit is contained in:
parent
e03dbe7165
commit
249b33c74e
@ -126,6 +126,7 @@ pub enum RPCCommand {
|
||||
SendWifiSettings = 0x01,
|
||||
RequestCurrentState = 0x02,
|
||||
RequestDeviceInformation = 0x03,
|
||||
RequestScannedWiFiNetworks = 0x04,
|
||||
}
|
||||
|
||||
impl TryFrom<&u8> for RPCCommand {
|
||||
@ -136,6 +137,7 @@ impl TryFrom<&u8> for RPCCommand {
|
||||
0x01 => Ok(Self::SendWifiSettings),
|
||||
0x02 => Ok(Self::RequestCurrentState),
|
||||
0x03 => Ok(Self::RequestDeviceInformation),
|
||||
0x04 => Ok(Self::RequestScannedWiFiNetworks),
|
||||
_ => Err(anyhow!("Cannot convert to RPC command")),
|
||||
}
|
||||
}
|
||||
@ -240,6 +242,7 @@ pub enum ImprovPacket {
|
||||
ErrorState(ErrorStatePacket),
|
||||
RequestCurrentState(RequestCurrentStatePacket),
|
||||
RequestDeviceInformation(RequestDeviceInformationPacket),
|
||||
RequestScannedWiFiNetworks(RequestScannedWiFiNetworksPacket),
|
||||
RPCResult(RPCResultPacket),
|
||||
}
|
||||
|
||||
@ -339,6 +342,22 @@ impl ImprovDataToPacket for RequestDeviceInformationPacket {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RequestScannedWiFiNetworksPacket {
|
||||
}
|
||||
|
||||
impl ImprovDataPacketType for RequestScannedWiFiNetworksPacket {
|
||||
const packet_type: PacketType = PacketType::RPCCommand;
|
||||
}
|
||||
|
||||
impl ImprovDataToPacket for RequestScannedWiFiNetworksPacket {
|
||||
fn to_bytes(self: &Self) -> Vec<u8> {
|
||||
let mut out = Vec::new();
|
||||
out.push(RPCCommand::RequestScannedWiFiNetworks as u8);
|
||||
out.push(0x00); // rpc command payload length
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RPCResultPacket {
|
||||
pub command_responded_to: RPCCommand,
|
||||
pub results: Vec<String>,
|
||||
|
26
src/main.rs
26
src/main.rs
@ -12,6 +12,7 @@ use improv_setup::improv::{
|
||||
ImprovPacket,
|
||||
RequestCurrentStatePacket,
|
||||
RequestDeviceInformationPacket,
|
||||
RequestScannedWiFiNetworksPacket,
|
||||
};
|
||||
use improv_setup::serial;
|
||||
use tokio_serial;
|
||||
@ -30,6 +31,8 @@ enum DeviceCommands {
|
||||
},
|
||||
/// Request device info
|
||||
Info,
|
||||
/// WiFi networks visible to device
|
||||
Scan,
|
||||
}
|
||||
|
||||
impl Default for DeviceCommands {
|
||||
@ -118,6 +121,29 @@ async fn main() -> Result<()>{
|
||||
}
|
||||
}
|
||||
},
|
||||
DeviceCommands::Scan => {
|
||||
let request_scanned_wifi_networks_packet = RequestScannedWiFiNetworksPacket {};
|
||||
|
||||
let mut serial_interface = serial::SerialInterface::new(path, *baud_rate).context("Couldn't init serial interface")?;
|
||||
|
||||
serial_interface.send(&request_scanned_wifi_networks_packet).context("Failed to send improv packet")?;
|
||||
|
||||
loop {
|
||||
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")?;
|
||||
|
||||
if let ImprovPacket::RPCResult(rpc_result) = ImprovPacket::try_from_raw_packet(&raw_packet).context("Failed to read packet")? {
|
||||
if rpc_result.results.len() <= 0 {
|
||||
break;
|
||||
}
|
||||
println!("{:<25} {:>3} {}", &rpc_result.results[0], &rpc_result.results[1], match rpc_result.results[2].as_str() {
|
||||
"YES" => "secure",
|
||||
"NO" => "open",
|
||||
_ => "",
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user