Display packet structs on debug output
This commit is contained in:
@@ -143,6 +143,16 @@ impl TryFrom<&u8> for RPCCommand {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RPCCommand {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::SendWiFiSettings => write!(f, "SendWiFiSettings"),
|
||||
Self::RequestCurrentState => write!(f, "RequestCurrentState"),
|
||||
Self::RequestDeviceInformation => write!(f, "RequestDeviceInformation"),
|
||||
Self::RequestScannedWiFiNetworks => write!(f, "RequestScannedWiFiNetworks"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn calculate_checksum(data: &[u8]) -> u8 {
|
||||
// Pass data as full packet, with header, but without checksum byte
|
||||
@@ -266,12 +276,12 @@ 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"),
|
||||
Self::CurrentState(current_state_packet) => write!(f, "{}", ¤t_state_packet),
|
||||
Self::ErrorState(error_state_packet) => write!(f, "{}", &error_state_packet),
|
||||
Self::RequestCurrentState(request_current_state_packet) => write!(f, "{}", &request_current_state_packet),
|
||||
Self::RequestDeviceInformation(request_device_information_packet) => write!(f, "{}", &request_device_information_packet),
|
||||
Self::RequestScannedWiFiNetworks(request_scanned_wifi_networks_packet) => write!(f, "{}", &request_scanned_wifi_networks_packet),
|
||||
Self::RPCResult(rpc_result_packet) => write!(f, "{}", &rpc_result_packet),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -306,6 +316,15 @@ impl ImprovDataFromPacket for CurrentStatePacket {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for CurrentStatePacket {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,
|
||||
"CurrentStatePacket {{\n current_state: {}\n}}",
|
||||
self.current_state,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ErrorStatePacket {
|
||||
pub error_state: ErrorState,
|
||||
}
|
||||
@@ -328,6 +347,15 @@ impl ImprovDataFromPacket for ErrorStatePacket {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ErrorStatePacket {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,
|
||||
"ErrorStatePacket {{\n error_state: {}\n}}",
|
||||
self.error_state,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SendWiFiSettingsPacket {
|
||||
pub ssid: String,
|
||||
pub password: String,
|
||||
@@ -356,6 +384,16 @@ impl ImprovDataToPacket for SendWiFiSettingsPacket {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for SendWiFiSettingsPacket {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,
|
||||
"SendWiFiSettingsPacket {{\n ssid: {}\n password: {}\n}}",
|
||||
self.ssid,
|
||||
self.password,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RequestCurrentStatePacket {
|
||||
}
|
||||
|
||||
@@ -372,6 +410,14 @@ impl ImprovDataToPacket for RequestCurrentStatePacket {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RequestCurrentStatePacket {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,
|
||||
"RequestCurrentStatePacket {{ }}",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RequestDeviceInformationPacket {
|
||||
}
|
||||
|
||||
@@ -388,6 +434,14 @@ impl ImprovDataToPacket for RequestDeviceInformationPacket {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RequestDeviceInformationPacket {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,
|
||||
"RequestDeviceInformationPacket {{ }}",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RequestScannedWiFiNetworksPacket {
|
||||
}
|
||||
|
||||
@@ -404,6 +458,14 @@ impl ImprovDataToPacket for RequestScannedWiFiNetworksPacket {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RequestScannedWiFiNetworksPacket {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,
|
||||
"RequestScannedWiFiNetworksPacket {{ }}",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RPCResultPacket {
|
||||
pub command_responded_to: RPCCommand,
|
||||
pub results: Vec<String>,
|
||||
@@ -449,3 +511,13 @@ impl ImprovDataFromPacket for RPCResultPacket {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RPCResultPacket {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,
|
||||
"RPCResultPacket {{\n command_responded_to: {}\n results: {:#?}\n}}",
|
||||
self.command_responded_to,
|
||||
self.results,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -171,6 +171,11 @@ impl SerialInterface {
|
||||
pub fn recv(&mut self) -> Result<ImprovPacket> {
|
||||
let result_bytes = self.recv_bytes().context("Failed to receive improv packet bytes")?;
|
||||
let improv_packet = ImprovPacket::try_from_bytes(&result_bytes).context("Failed to read improv packet bytes into ImprovPacket struct")?;
|
||||
|
||||
if log_enabled!(Level::Debug) {
|
||||
debug!("Received packet struct:\n{}", &improv_packet);
|
||||
}
|
||||
|
||||
return Ok(improv_packet);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user