cmd_handler: Add cmd to get temp adc polling interval

This commit is contained in:
linuswck 2024-10-10 13:41:15 +08:00
parent 31e108a4b5
commit 51b82e0447
1 changed files with 31 additions and 1 deletions

View File

@ -17,7 +17,7 @@ use crate::{device::{dfu, hw_rev::HWRev, sys_timer},
thermostat::{ad7172::FilterType, thermostat::{ad7172::FilterType,
pid_state::PidSettings::*, pid_state::PidSettings::*,
thermostat::{StatusReport as TecStatusReport, TempAdcFilter, Thermostat, thermostat::{StatusReport as TecStatusReport, TempAdcFilter, Thermostat,
ThermostatSettingsSummary}}, ThermostatSettingsSummary, Time}},
DeviceSettings, IpSettings, State}; DeviceSettings, IpSettings, State};
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)] #[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
@ -27,6 +27,7 @@ pub enum ResponseEnum {
Settings, Settings,
Report, Report,
HwRev, HwRev,
Interval,
Acknowledge, Acknowledge,
InvalidDatatype, InvalidDatatype,
InvalidSettings, InvalidSettings,
@ -119,6 +120,7 @@ enum ThermostatCmdEnum {
SetPidUpdateInterval, // Update Interval is set based on the sampling rate of ADC SetPidUpdateInterval, // Update Interval is set based on the sampling rate of ADC
// Temperature ADC // Temperature ADC
ConfigTempAdcFilter, ConfigTempAdcFilter,
GetPollInterval,
// TempMon // TempMon
SetTempMonUpperLimit, SetTempMonUpperLimit,
SetTempMonLowerLimit, SetTempMonLowerLimit,
@ -181,6 +183,17 @@ pub struct SettingsSummaryObj {
json: SettingsSummary, json: SettingsSummary,
} }
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
pub struct IntervalType {
msg_type: ResponseEnum,
interval: Time,
}
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
pub struct IntervalObj {
json: IntervalType,
}
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)] #[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
pub struct HwRevType { pub struct HwRevType {
msg_type: ResponseEnum, msg_type: ResponseEnum,
@ -258,6 +271,20 @@ pub fn send_hw_rev(buffer: &mut [u8], hw_rev_o: &mut HWRev, socket: &mut SocketH
num_bytes += 1; num_bytes += 1;
net::eth_send(buffer, num_bytes, *socket); net::eth_send(buffer, num_bytes, *socket);
} }
pub fn send_interval(buffer: &mut [u8], interval: Time, socket: &mut SocketHandle) {
let hw_rev = IntervalObj {
json: IntervalType {
msg_type: ResponseEnum::Interval,
interval: interval,
},
};
let mut num_bytes = hw_rev.get_json("/json", buffer).unwrap();
buffer[num_bytes] = b'\n';
num_bytes += 1;
net::eth_send(buffer, num_bytes, *socket);
}
// Use a minimal struct for high speed cmd ctrl to reduce processing overhead // Use a minimal struct for high speed cmd ctrl to reduce processing overhead
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)] #[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
pub struct TecSetICmdJson { pub struct TecSetICmdJson {
@ -777,6 +804,9 @@ pub fn execute_cmd(
); );
} }
}, },
Some(ThermostatCmdEnum::GetPollInterval) => {
send_interval(buffer, thermostat.get_poll_interval(), socket)
}
Some(ThermostatCmdEnum::SetTempMonUpperLimit) => match cmd.json.data_f32 { Some(ThermostatCmdEnum::SetTempMonUpperLimit) => match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket); send_response(buffer, ResponseEnum::Acknowledge, None, socket);