2024-02-22 16:44:45 +08:00
|
|
|
use core::{fmt::Debug, marker::PhantomData};
|
2024-02-05 15:14:23 +08:00
|
|
|
use miniconf::{JsonCoreSlash, Tree};
|
2024-02-02 14:07:25 +08:00
|
|
|
use serde::{Deserialize, Serialize};
|
2024-02-05 15:14:23 +08:00
|
|
|
use uom::si::{
|
2024-03-18 15:41:31 +08:00
|
|
|
electric_current::{ampere, ElectricCurrent},
|
2024-02-06 15:20:23 +08:00
|
|
|
electric_potential::{volt, ElectricPotential},
|
2024-02-22 16:44:45 +08:00
|
|
|
electrical_resistance::{ohm, ElectricalResistance},
|
|
|
|
power::{milliwatt, Power},
|
|
|
|
thermodynamic_temperature::{degree_celsius, ThermodynamicTemperature}
|
2024-02-05 15:14:23 +08:00
|
|
|
};
|
2024-02-22 16:44:45 +08:00
|
|
|
use crate::{laser_diode::{laser_diode::{
|
2024-02-27 11:00:32 +08:00
|
|
|
LdDrive, LdSettingsSummary, StatusReport as LdStatusReport},
|
2024-02-22 16:44:45 +08:00
|
|
|
pd_responsitivity::ResponsitivityUnit
|
2024-02-19 15:08:00 +08:00
|
|
|
},
|
|
|
|
net::net,
|
2024-03-04 15:38:55 +08:00
|
|
|
thermostat::{ad7172::FilterType, thermostat::{StatusReport as TecStatusReport, TempAdcFilter}}
|
2024-02-19 15:08:00 +08:00
|
|
|
};
|
2024-02-23 11:38:26 +08:00
|
|
|
use crate::thermostat::thermostat::{Thermostat, ThermostatSettingsSummary};
|
2024-02-06 15:20:23 +08:00
|
|
|
use crate::thermostat::pid_state::PidSettings::*;
|
2024-02-23 11:38:26 +08:00
|
|
|
use crate::device::{dfu, sys_timer};
|
2024-03-08 16:30:15 +08:00
|
|
|
use log::{info, debug};
|
2024-03-05 16:44:28 +08:00
|
|
|
use crate::{DeviceSettings, State, IpSettings};
|
2024-03-06 16:29:02 +08:00
|
|
|
use smoltcp::iface::SocketHandle;
|
2024-02-02 14:07:25 +08:00
|
|
|
|
2024-03-08 16:30:15 +08:00
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
|
|
|
|
pub enum ResponseEnum {
|
|
|
|
#[default]
|
|
|
|
Reserved,
|
|
|
|
Acknowledge,
|
|
|
|
InvalidDatatype,
|
|
|
|
InvalidCmd,
|
|
|
|
HardReset,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type MsgType = Option<&'static str>;
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug)]
|
|
|
|
pub struct Response<'a> {
|
|
|
|
msg_type: ResponseEnum,
|
|
|
|
msg: Option<&'a str>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Response<'static>{
|
|
|
|
fn default() -> Self {
|
|
|
|
Response{
|
|
|
|
msg_type: ResponseEnum:: Reserved,
|
|
|
|
msg: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
|
|
|
|
pub struct ResponseObj<'a>{
|
|
|
|
#[serde(borrow)]
|
|
|
|
json: Response<'a>
|
|
|
|
}
|
|
|
|
|
2024-02-16 16:47:17 +08:00
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
|
|
|
|
enum DeviceCmd {
|
|
|
|
#[default]
|
|
|
|
Reserved,
|
2024-03-05 16:44:28 +08:00
|
|
|
SetIPSettings,
|
2024-02-23 11:38:26 +08:00
|
|
|
SetActiveReportMode,
|
|
|
|
GetStatusReport,
|
|
|
|
GetSettingsSummary,
|
2024-02-19 15:08:00 +08:00
|
|
|
Dfu,
|
2024-03-04 16:11:22 +08:00
|
|
|
SaveFlashSettings,
|
|
|
|
LoadFlashSettings,
|
|
|
|
HardReset,
|
2024-02-16 16:47:17 +08:00
|
|
|
}
|
|
|
|
|
2024-02-02 14:07:25 +08:00
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
|
|
|
|
enum LdCmdEnum {
|
|
|
|
#[default]
|
|
|
|
Reserved,
|
|
|
|
// LD Drive Related
|
2024-03-04 16:07:39 +08:00
|
|
|
SetDefaultPowerOn,
|
2024-02-02 14:07:25 +08:00
|
|
|
PowerUp,
|
|
|
|
PowerDown,
|
|
|
|
LdTermsShort,
|
|
|
|
LdTermsOpen,
|
|
|
|
SetI,
|
|
|
|
SetISoftLimit,
|
|
|
|
// PD Mon Related
|
|
|
|
SetPdResponsitivity,
|
|
|
|
SetPdDarkCurrent,
|
|
|
|
SetLdPwrLimit,
|
2024-02-23 11:38:26 +08:00
|
|
|
ClearAlarm,
|
2024-02-02 14:07:25 +08:00
|
|
|
}
|
|
|
|
|
2024-02-05 15:14:23 +08:00
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
|
|
|
|
enum ThermostatCmdEnum {
|
|
|
|
#[default]
|
|
|
|
Reserved,
|
2024-03-04 16:07:39 +08:00
|
|
|
SetDefaultPowerOn,
|
2024-02-05 15:14:23 +08:00
|
|
|
PowerUp,
|
|
|
|
PowerDown,
|
|
|
|
// TEC
|
|
|
|
SetTecMaxV,
|
|
|
|
SetTecMaxIPos,
|
|
|
|
SetTecMaxINeg,
|
|
|
|
SetTecIOut, // Constant Current Mode
|
2024-02-06 15:20:23 +08:00
|
|
|
SetTemperatureSetpoint,
|
2024-02-05 15:14:23 +08:00
|
|
|
// PID
|
2024-02-15 10:34:02 +08:00
|
|
|
SetPidEngage,
|
|
|
|
SetPidDisEngage,
|
2024-02-05 15:14:23 +08:00
|
|
|
SetPidKp,
|
|
|
|
SetPidKi,
|
|
|
|
SetPidKd,
|
|
|
|
SetPidOutMin,
|
|
|
|
SetPidOutMax,
|
|
|
|
SetPidUpdateInterval, // Update Interval is set based on the sampling rate of ADC
|
2024-02-27 11:00:32 +08:00
|
|
|
// Temperature ADC
|
|
|
|
ConfigTempAdcFilter,
|
2024-02-21 15:49:08 +08:00
|
|
|
// TempMon
|
|
|
|
SetTempMonUpperLimit,
|
|
|
|
SetTempMonLowerLimit,
|
|
|
|
ClearAlarm,
|
2024-02-05 15:14:23 +08:00
|
|
|
// Steinhart-Hart Equation
|
|
|
|
SetShT0,
|
|
|
|
SetShR0,
|
|
|
|
SetShBeta,
|
|
|
|
}
|
|
|
|
|
2024-03-08 16:30:15 +08:00
|
|
|
const ERR_MSG_MISSING_DATA_F32 : &str = "Required field \"data_f32\" does not exist";
|
|
|
|
const ERR_MSG_MISSING_DATA_BOOL: &str = "Required field \"bool\" does not exist";
|
|
|
|
const ERR_MSG_MISSING_IP_SETTINGS: &str = "Required field \"ip_settings\" does not exist";
|
|
|
|
const ERR_MSG_MISSING_TEMP_ADC_FILTER: &str = "Required field \"temp_adc_filter\" does not exist";
|
|
|
|
const ERR_MSG_MISSING_SINC5SINC1ODR: &str = "Required field \"sinc5sinc1odr\" does not exist";
|
|
|
|
const ERR_MSG_MISSING_SINC3ODR: &str = "Required field \"sinc3odr\" does not exist";
|
|
|
|
const ERR_MSG_MISSING_POSTFILTER: &str = "Required field \"PostFilter\" does not exist";
|
|
|
|
const ERR_MSG_MISSING_SINC3FINEODR: &str = "Required field \"sinc3fineodr\" does not exist";
|
|
|
|
|
2024-02-02 14:07:25 +08:00
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
|
|
|
|
pub struct CmdJsonObj{
|
2024-02-05 15:14:23 +08:00
|
|
|
laser_diode_cmd: Option<LdCmdEnum>,
|
|
|
|
thermostat_cmd: Option<ThermostatCmdEnum>,
|
2024-02-16 16:47:17 +08:00
|
|
|
device_cmd: Option<DeviceCmd>,
|
2024-02-19 15:08:00 +08:00
|
|
|
data_bool: Option<bool>,
|
2024-02-02 14:07:25 +08:00
|
|
|
data_f32: Option<f32>,
|
|
|
|
data_f64: Option<f64>,
|
2024-02-27 11:00:32 +08:00
|
|
|
temp_adc_filter: Option<TempAdcFilter>,
|
2024-03-05 16:44:28 +08:00
|
|
|
ip_settings: Option<IpSettings>,
|
2024-02-02 14:07:25 +08:00
|
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
|
|
|
|
pub struct Cmd {
|
|
|
|
json: CmdJsonObj
|
|
|
|
}
|
|
|
|
|
2024-02-19 15:08:00 +08:00
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
|
2024-02-23 11:38:26 +08:00
|
|
|
pub struct StatusReport {
|
|
|
|
ts: u32,
|
|
|
|
laser: LdStatusReport,
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat: TecStatusReport,
|
2024-02-23 11:38:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
|
|
|
|
pub struct StatusReportObj {
|
|
|
|
json: StatusReport
|
2024-02-19 15:08:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
|
2024-02-23 11:38:26 +08:00
|
|
|
pub struct SettingsSummary {
|
|
|
|
laser: LdSettingsSummary,
|
|
|
|
thermostat: ThermostatSettingsSummary,
|
2024-02-19 15:08:00 +08:00
|
|
|
}
|
|
|
|
|
2024-02-23 11:38:26 +08:00
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
|
|
|
|
pub struct SettingsSummaryObj {
|
|
|
|
json: SettingsSummary
|
|
|
|
}
|
|
|
|
|
2024-03-08 16:30:15 +08:00
|
|
|
pub fn send_response(buffer: &mut [u8], msg_type: ResponseEnum, msg: MsgType, socket: &mut SocketHandle){
|
|
|
|
let response = ResponseObj {
|
|
|
|
json: Response {
|
|
|
|
msg_type: msg_type,
|
|
|
|
msg: msg,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
debug!("{:?}", response.json);
|
|
|
|
|
2024-03-25 12:27:35 +08:00
|
|
|
let mut num_bytes = response.get_json("/json", buffer).unwrap();
|
|
|
|
buffer[num_bytes] = b'\n';
|
|
|
|
num_bytes += 1;
|
2024-03-08 16:30:15 +08:00
|
|
|
net::eth_send(buffer, num_bytes, *socket);
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:41:31 +08:00
|
|
|
pub fn send_settings_summary(buffer: &mut [u8], laser: &mut LdDrive, thermostat: &mut Thermostat, socket: &mut SocketHandle){
|
2024-02-23 11:38:26 +08:00
|
|
|
let settings_summary = SettingsSummaryObj {
|
|
|
|
json: SettingsSummary {
|
|
|
|
laser: laser.get_settings_summary(),
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat: thermostat.get_settings_summary(),
|
2024-02-23 11:38:26 +08:00
|
|
|
}
|
2024-02-19 15:08:00 +08:00
|
|
|
};
|
2024-03-25 12:27:35 +08:00
|
|
|
let mut num_bytes = settings_summary.get_json("/json", buffer).unwrap();
|
|
|
|
buffer[num_bytes] = b'\n';
|
|
|
|
num_bytes += 1;
|
2024-03-06 16:29:02 +08:00
|
|
|
net::eth_send(buffer, num_bytes, *socket);
|
2024-02-19 15:08:00 +08:00
|
|
|
}
|
|
|
|
|
2024-02-23 11:38:26 +08:00
|
|
|
|
2024-03-18 15:41:31 +08:00
|
|
|
pub fn send_status_report(buffer: &mut [u8], laser: &mut LdDrive, thermostat: &mut Thermostat, socket: &mut SocketHandle){
|
2024-02-23 11:38:26 +08:00
|
|
|
let status_report = StatusReportObj {
|
|
|
|
json: StatusReport {
|
|
|
|
ts: sys_timer::now(),
|
|
|
|
laser: laser.get_status_report(),
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat: thermostat.get_status_report(),
|
2024-02-23 11:38:26 +08:00
|
|
|
}
|
2024-02-19 15:08:00 +08:00
|
|
|
};
|
2024-03-25 12:27:35 +08:00
|
|
|
let mut num_bytes = status_report.get_json("/json", buffer).unwrap();
|
|
|
|
buffer[num_bytes] = b'\n';
|
|
|
|
num_bytes += 1;
|
2024-03-06 16:29:02 +08:00
|
|
|
net::eth_send(buffer, num_bytes, *socket);
|
2024-02-15 10:34:02 +08:00
|
|
|
}
|
|
|
|
|
2024-02-27 12:19:53 +08:00
|
|
|
// Use a minimal struct for high speed cmd ctrl to reduce processing overhead
|
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
|
|
|
|
pub struct TecSetICmdJson {
|
2024-02-27 16:26:05 +08:00
|
|
|
tec_set_i: f32
|
2024-02-27 12:19:53 +08:00
|
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
|
|
|
|
pub struct TecSetICmd {
|
|
|
|
json: TecSetICmdJson
|
|
|
|
}
|
|
|
|
|
2024-02-28 12:54:21 +08:00
|
|
|
/// Miniconf is very slow in debug builds (~3-4ms of cmd decoding time).
|
|
|
|
/// Make sure kirdy's firmware is flashed with release builds.
|
|
|
|
/// The received message must contain only one json cmd. TCP client should set TCP_NODELAY or equivalent flag in its TCP Socket
|
|
|
|
/// Settings to avoid unwanted buffering on TX Data and minimize TX latency.
|
2024-03-19 17:38:29 +08:00
|
|
|
pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHandle, laser: &mut LdDrive, thermostat: &mut Thermostat, state: &mut State, device_settings: &mut DeviceSettings, active_report: &mut bool){
|
2024-02-27 12:19:53 +08:00
|
|
|
let mut cmd = TecSetICmd {
|
|
|
|
json: TecSetICmdJson::default()
|
|
|
|
};
|
|
|
|
match cmd.set_json("/json", &buffer[0..buffer_size]){
|
|
|
|
Ok(_) => {
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_i(ElectricCurrent::new::<ampere>(cmd.json.tec_set_i));
|
2024-03-12 11:47:58 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-06 16:29:02 +08:00
|
|
|
return;
|
2024-02-27 12:19:53 +08:00
|
|
|
}
|
|
|
|
Err(_) => { /* Do Nothing */}
|
|
|
|
}
|
|
|
|
|
2024-02-02 14:07:25 +08:00
|
|
|
let mut cmd = Cmd {
|
|
|
|
json: CmdJsonObj::default()
|
|
|
|
};
|
|
|
|
match cmd.set_json("/json", &buffer[0..buffer_size]){
|
|
|
|
Ok(_) => {
|
2024-02-06 15:20:23 +08:00
|
|
|
info!("############ Laser Diode Command Received {:?}", cmd.json.laser_diode_cmd);
|
|
|
|
info!("############ Thermostat Command Received {:?}", cmd.json.thermostat_cmd);
|
2024-02-16 16:47:17 +08:00
|
|
|
info!("############ Device Command Received {:?}", cmd.json.device_cmd);
|
|
|
|
|
|
|
|
match cmd.json.device_cmd {
|
2024-03-05 16:44:28 +08:00
|
|
|
Some(DeviceCmd::SetIPSettings) => {
|
|
|
|
match cmd.json.ip_settings {
|
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-05 16:44:28 +08:00
|
|
|
device_settings.ip_settings = val;
|
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_IP_SETTINGS), socket);
|
2024-03-05 16:44:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-16 16:47:17 +08:00
|
|
|
Some(DeviceCmd::Dfu) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-02-16 16:47:17 +08:00
|
|
|
unsafe {
|
|
|
|
dfu::set_dfu_trigger();
|
|
|
|
}
|
2024-03-07 10:26:32 +08:00
|
|
|
*state = State::HardReset;
|
2024-02-16 16:47:17 +08:00
|
|
|
}
|
2024-02-23 11:38:26 +08:00
|
|
|
Some(DeviceCmd::SetActiveReportMode) => {
|
2024-02-19 15:08:00 +08:00
|
|
|
match cmd.json.data_bool{
|
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-19 17:38:29 +08:00
|
|
|
*active_report = val;
|
2024-02-19 15:08:00 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_BOOL), socket);
|
2024-02-19 15:08:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-23 11:38:26 +08:00
|
|
|
Some(DeviceCmd::GetStatusReport) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
send_status_report(buffer, laser, thermostat, socket);
|
2024-02-23 11:38:26 +08:00
|
|
|
}
|
|
|
|
Some(DeviceCmd::GetSettingsSummary) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
send_settings_summary(buffer, laser, thermostat, socket);
|
2024-02-23 11:38:26 +08:00
|
|
|
}
|
2024-03-04 16:11:22 +08:00
|
|
|
Some(DeviceCmd::SaveFlashSettings) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-06 16:29:02 +08:00
|
|
|
*state = State::SaveFlashSettings;
|
2024-03-04 16:11:22 +08:00
|
|
|
}
|
|
|
|
Some(DeviceCmd::LoadFlashSettings) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-06 16:29:02 +08:00
|
|
|
*state = State::LoadFlashSettings;
|
2024-03-04 16:11:22 +08:00
|
|
|
}
|
|
|
|
Some(DeviceCmd::HardReset) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
|
|
|
*state = State::PrepareForHardReset;
|
2024-03-04 16:11:22 +08:00
|
|
|
}
|
2024-02-16 16:47:17 +08:00
|
|
|
None => { /* Do Nothing */}
|
|
|
|
_ => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidCmd, None, socket);
|
|
|
|
debug!("Unimplemented Command")
|
2024-02-16 16:47:17 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-02 14:07:25 +08:00
|
|
|
|
|
|
|
match cmd.json.laser_diode_cmd {
|
2024-03-04 16:07:39 +08:00
|
|
|
Some(LdCmdEnum::SetDefaultPowerOn) => {
|
|
|
|
match cmd.json.data_bool {
|
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-04 16:07:39 +08:00
|
|
|
laser.set_default_pwr_on(val);
|
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_BOOL), socket);
|
2024-03-04 16:07:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(LdCmdEnum::PowerUp) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-02-02 14:07:25 +08:00
|
|
|
laser.power_up()
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(LdCmdEnum::PowerDown) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-02-02 14:07:25 +08:00
|
|
|
laser.power_down()
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(LdCmdEnum::LdTermsShort) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-02-02 14:07:25 +08:00
|
|
|
laser.ld_short();
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(LdCmdEnum::LdTermsOpen) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-02-02 14:07:25 +08:00
|
|
|
laser.ld_open();
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(LdCmdEnum::SetI) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-02 14:07:25 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
laser.ld_set_i(ElectricCurrent::new::<ampere>(val));
|
2024-02-02 14:07:25 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-02 14:07:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(LdCmdEnum::SetISoftLimit) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-02 14:07:25 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
laser.set_ld_drive_current_limit(ElectricCurrent::new::<ampere>(val))
|
2024-02-02 14:07:25 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-02 14:07:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(LdCmdEnum::SetPdResponsitivity) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-22 16:44:45 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-02-22 16:44:45 +08:00
|
|
|
laser.set_pd_responsitivity(ResponsitivityUnit {dimension: PhantomData, units: PhantomData, value: val})
|
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-22 16:44:45 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-02 14:07:25 +08:00
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(LdCmdEnum::SetPdDarkCurrent) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-22 16:44:45 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
laser.set_pd_dark_current(ElectricCurrent::new::<ampere>(val))
|
2024-02-22 16:44:45 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-22 16:44:45 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-02 14:07:25 +08:00
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(LdCmdEnum::SetLdPwrLimit) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-22 16:44:45 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-02-22 16:44:45 +08:00
|
|
|
laser.set_ld_power_limit(Power::new::<milliwatt>(val))
|
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-22 16:44:45 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-02 14:07:25 +08:00
|
|
|
}
|
2024-02-23 11:38:26 +08:00
|
|
|
Some(LdCmdEnum::ClearAlarm) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-02-02 14:07:25 +08:00
|
|
|
laser.pd_mon_clear_alarm()
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
None => { /* Do Nothing*/ }
|
2024-02-02 14:07:25 +08:00
|
|
|
_ => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-02 14:07:25 +08:00
|
|
|
info!("Unimplemented Command")
|
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
|
|
|
|
match cmd.json.thermostat_cmd {
|
2024-03-04 16:07:39 +08:00
|
|
|
Some(ThermostatCmdEnum::SetDefaultPowerOn) => {
|
|
|
|
match cmd.json.data_bool {
|
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_default_pwr_on(val);
|
2024-03-04 16:07:39 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-03-04 16:07:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(ThermostatCmdEnum::PowerUp) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.power_up()
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::PowerDown) => {
|
2024-03-12 11:47:58 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.power_down()
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetTecMaxV) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_max_v(ElectricPotential::new::<volt>(val));
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetTecMaxIPos) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_max_i_pos(ElectricCurrent::new::<ampere>(val));
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetTecMaxINeg) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_max_i_pos(ElectricCurrent::new::<ampere>(val));
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetTecIOut) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_i(ElectricCurrent::new::<ampere>(val));
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-06 15:20:23 +08:00
|
|
|
Some(ThermostatCmdEnum::SetTemperatureSetpoint) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-06 15:20:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_temperature_setpoint(ThermodynamicTemperature::new::<degree_celsius>(val));
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
2024-02-15 10:34:02 +08:00
|
|
|
Some(ThermostatCmdEnum::SetPidEngage) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_pid_engaged(true);
|
2024-02-15 10:34:02 +08:00
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetPidDisEngage) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_pid_engaged(false);
|
2024-02-15 10:34:02 +08:00
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(ThermostatCmdEnum::SetPidKp) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-06 15:20:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_pid(Kp, val);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetPidKi) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-06 15:20:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_pid(Ki, val);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetPidKd) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-06 15:20:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_pid(Kd, val);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetPidOutMin) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-06 15:20:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_pid(Min, val);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetPidOutMax) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-06 15:20:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_pid(Max, val);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetPidUpdateInterval) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidCmd, None, socket);
|
|
|
|
debug!("Not supported Yet")
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
2024-02-27 11:00:32 +08:00
|
|
|
Some(ThermostatCmdEnum::ConfigTempAdcFilter) => {
|
|
|
|
match cmd.json.temp_adc_filter {
|
|
|
|
Some(val) => {
|
|
|
|
match val.filter_type {
|
|
|
|
FilterType::Sinc5Sinc1With50hz60HzRejection => {
|
|
|
|
match val.sinc5sinc1postfilter {
|
|
|
|
Some(val2) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_temp_adc_sinc5_sinc1_with_postfilter(0, val2);
|
2024-02-27 11:00:32 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_POSTFILTER), socket);
|
2024-02-27 11:00:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FilterType::Sinc5Sinc1 => {
|
|
|
|
match val.sinc5sinc1odr {
|
|
|
|
Some(val2) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_temp_adc_sinc5_sinc1_filter(0, val2);
|
2024-02-27 11:00:32 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_SINC5SINC1ODR), socket);
|
2024-02-27 11:00:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FilterType::Sinc3WithFineODR => {
|
|
|
|
match val.sinc3fineodr {
|
|
|
|
Some(val2) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_temp_adc_sinc3_fine_filter(0, val2);
|
2024-02-27 11:00:32 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_SINC3FINEODR), socket);
|
2024-02-27 11:00:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FilterType::Sinc3 => {
|
|
|
|
match val.sinc3odr {
|
|
|
|
Some(val2) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_temp_adc_sinc3_filter(0, val2);
|
2024-02-27 11:00:32 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_SINC3ODR), socket);
|
2024-02-27 11:00:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_TEMP_ADC_FILTER), socket);
|
2024-02-27 11:00:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-21 15:49:08 +08:00
|
|
|
Some(ThermostatCmdEnum::SetTempMonUpperLimit) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-21 15:49:08 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_temp_mon_upper_limit(ThermodynamicTemperature::new::<degree_celsius>(val));
|
2024-02-21 15:49:08 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-21 15:49:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetTempMonLowerLimit) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-21 15:49:08 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_temp_mon_lower_limit(ThermodynamicTemperature::new::<degree_celsius>(val));
|
2024-02-21 15:49:08 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-21 15:49:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::ClearAlarm) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.clear_temp_mon_alarm();
|
2024-02-21 15:49:08 +08:00
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
Some(ThermostatCmdEnum::SetShT0) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-06 15:20:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_sh_t0(ThermodynamicTemperature::new::<degree_celsius>(val));
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetShR0) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-06 15:20:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_sh_r0(ElectricalResistance::new::<ohm>(val));
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
Some(ThermostatCmdEnum::SetShBeta) => {
|
2024-02-27 16:26:05 +08:00
|
|
|
match cmd.json.data_f32 {
|
2024-02-06 15:20:23 +08:00
|
|
|
Some(val) => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
|
2024-03-18 15:41:31 +08:00
|
|
|
thermostat.set_sh_beta(val);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
None => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
|
2024-02-06 15:20:23 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
None => { /* Do Nothing*/ }
|
|
|
|
_ => {
|
2024-03-08 16:30:15 +08:00
|
|
|
send_response(buffer, ResponseEnum::InvalidCmd, None, socket);
|
2024-02-05 15:14:23 +08:00
|
|
|
}
|
|
|
|
}
|
2024-02-02 14:07:25 +08:00
|
|
|
}
|
2024-03-08 16:30:15 +08:00
|
|
|
Err(_) => {
|
|
|
|
send_response(buffer, ResponseEnum::InvalidCmd, None, socket);
|
2024-02-02 14:07:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|