1
0
forked from M-Labs/kirdy

cmd_handler: Add msg_type params to report & settings

This commit is contained in:
linuswck 2024-04-10 16:47:33 +08:00
parent 10873f4791
commit ceb003e07e

View File

@ -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) => {