From ceb003e07e53b6590b22bd0d5c3656fe8ad8fbef Mon Sep 17 00:00:00 2001 From: linuswck Date: Wed, 10 Apr 2024 16:47:33 +0800 Subject: [PATCH] cmd_handler: Add msg_type params to report & settings --- src/net/cmd_handler.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/net/cmd_handler.rs b/src/net/cmd_handler.rs index 5b9cf3a..c08401b 100644 --- a/src/net/cmd_handler.rs +++ b/src/net/cmd_handler.rs @@ -26,6 +26,8 @@ use smoltcp::iface::SocketHandle; pub enum ResponseEnum { #[default] Reserved, + Settings, + Report, Acknowledge, InvalidDatatype, InvalidCmd, @@ -150,6 +152,7 @@ pub struct Cmd { #[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)] pub struct StatusReport { ts: u32, + msg_type: ResponseEnum, laser: LdStatusReport, thermostat: TecStatusReport, } @@ -161,6 +164,7 @@ pub struct StatusReportObj { #[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)] pub struct SettingsSummary { + msg_type: ResponseEnum, laser: LdSettingsSummary, thermostat: ThermostatSettingsSummary, } @@ -188,6 +192,7 @@ pub fn send_response(buffer: &mut [u8], msg_type: ResponseEnum, msg: MsgType, so pub fn send_settings_summary(buffer: &mut [u8], laser: &mut LdDrive, thermostat: &mut Thermostat, socket: &mut SocketHandle){ let settings_summary = SettingsSummaryObj { json: SettingsSummary { + msg_type: ResponseEnum::Settings, laser: laser.get_settings_summary(), thermostat: thermostat.get_settings_summary(), } @@ -203,6 +208,7 @@ pub fn send_status_report(buffer: &mut [u8], laser: &mut LdDrive, thermostat: &m let status_report = StatusReportObj { json: StatusReport { ts: sys_timer::now(), + msg_type: ResponseEnum::Report, laser: laser.get_status_report(), thermostat: thermostat.get_status_report(), } @@ -281,11 +287,9 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan } } Some(DeviceCmd::GetStatusReport) => { - send_response(buffer, ResponseEnum::Acknowledge, None, socket); send_status_report(buffer, laser, thermostat, socket); } Some(DeviceCmd::GetSettingsSummary) => { - send_response(buffer, ResponseEnum::Acknowledge, None, socket); send_settings_summary(buffer, laser, thermostat, socket); } Some(DeviceCmd::SaveFlashSettings) => {