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

@@ -117,6 +117,7 @@ impl std::fmt::Display for ErrorState {
pub enum RPCCommand {
SendWifiSettings = 0x01,
RequestCurrentState = 0x02,
RequestDeviceInformation = 0x03,
}
pub fn calculate_checksum(data: &[u8]) -> u8 {
@@ -216,6 +217,8 @@ pub enum ImprovPacket {
CurrentStateResponse(CurrentStateResponse),
ErrorState(ErrorStatePacket),
RequestCurrentStateCommand(RequestCurrentStateCommand),
RequestDeviceInformation(RequestDeviceInformationPacket),
RPCResult(RPCResultPacket),
}
impl ImprovPacket {
@@ -224,8 +227,8 @@ impl ImprovPacket {
PacketType::CurrentState => Ok(ImprovPacket::CurrentStateResponse(CurrentStateResponse::try_from_raw_packet(raw_packet)?)),
PacketType::ErrorState => Ok(ImprovPacket::ErrorState(ErrorStatePacket::try_from_raw_packet(raw_packet)?)),
//PacketType::RPCCommand => _,
//PacketType::RPCResult => _,
_ => Err("Conversion into packet type {} not implemented"),
PacketType::RPCResult => Ok(ImprovPacket::RPCResult(RPCResultPacket::try_from_raw_packet(raw_packet)?)),
_ => Err("Conversion into packet type not implemented"),
}
}
}
@@ -297,3 +300,43 @@ impl ImprovDataToPacket for RequestCurrentStateCommand {
return out;
}
}
pub struct RequestDeviceInformationPacket {
}
impl ImprovDataPacketType for RequestDeviceInformationPacket {
const packet_type: PacketType = PacketType::RPCCommand;
}
impl ImprovDataToPacket for RequestDeviceInformationPacket {
fn to_bytes(self: &Self) -> Vec<u8> {
let mut out = Vec::new();
out.push(RPCCommand::RequestDeviceInformation as u8);
out.push(0x00); // rpc command payload length
return out;
}
}
pub struct RPCResultPacket {
results: Vec<String>,
}
impl ImprovDataPacketType for RPCResultPacket {
const packet_type: PacketType = PacketType::RPCResult;
}
impl ImprovDataFromPacket for RPCResultPacket {
type Error = &'static str;
fn try_from_raw_packet(raw_packet: &RawPacket) -> Result<Self, Self::Error>{
if raw_packet.r#type != Self::packet_type {
return Err("Packet is not RPCResult");
}
let results: Vec<String> = Vec::new();
return Ok(Self {
results: results,
})
}
}