1
0
Fork 0

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
1 changed files with 6 additions and 2 deletions

View File

@ -26,6 +26,8 @@ use smoltcp::iface::SocketHandle;
pub enum ResponseEnum { pub enum ResponseEnum {
#[default] #[default]
Reserved, Reserved,
Settings,
Report,
Acknowledge, Acknowledge,
InvalidDatatype, InvalidDatatype,
InvalidCmd, InvalidCmd,
@ -150,6 +152,7 @@ pub struct Cmd {
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)] #[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
pub struct StatusReport { pub struct StatusReport {
ts: u32, ts: u32,
msg_type: ResponseEnum,
laser: LdStatusReport, laser: LdStatusReport,
thermostat: TecStatusReport, thermostat: TecStatusReport,
} }
@ -161,6 +164,7 @@ pub struct StatusReportObj {
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)] #[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
pub struct SettingsSummary { pub struct SettingsSummary {
msg_type: ResponseEnum,
laser: LdSettingsSummary, laser: LdSettingsSummary,
thermostat: ThermostatSettingsSummary, 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){ pub fn send_settings_summary(buffer: &mut [u8], laser: &mut LdDrive, thermostat: &mut Thermostat, socket: &mut SocketHandle){
let settings_summary = SettingsSummaryObj { let settings_summary = SettingsSummaryObj {
json: SettingsSummary { json: SettingsSummary {
msg_type: ResponseEnum::Settings,
laser: laser.get_settings_summary(), laser: laser.get_settings_summary(),
thermostat: thermostat.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 { let status_report = StatusReportObj {
json: StatusReport { json: StatusReport {
ts: sys_timer::now(), ts: sys_timer::now(),
msg_type: ResponseEnum::Report,
laser: laser.get_status_report(), laser: laser.get_status_report(),
thermostat: thermostat.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) => { Some(DeviceCmd::GetStatusReport) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
send_status_report(buffer, laser, thermostat, socket); send_status_report(buffer, laser, thermostat, socket);
} }
Some(DeviceCmd::GetSettingsSummary) => { Some(DeviceCmd::GetSettingsSummary) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
send_settings_summary(buffer, laser, thermostat, socket); send_settings_summary(buffer, laser, thermostat, socket);
} }
Some(DeviceCmd::SaveFlashSettings) => { Some(DeviceCmd::SaveFlashSettings) => {