1
0
Fork 0

Send Response Back to The Client after Recv Cmd

This commit is contained in:
linuswck 2024-03-08 16:30:15 +08:00
parent 8cd3f70721
commit a9dbff8250
2 changed files with 154 additions and 37 deletions

View File

@ -43,6 +43,7 @@ pub enum State {
LoadFlashSettings, LoadFlashSettings,
MainLoop, MainLoop,
SaveFlashSettings, SaveFlashSettings,
PrepareForHardReset,
HardReset, HardReset,
} }
@ -218,6 +219,21 @@ fn main() -> ! {
} }
} }
} }
State::PrepareForHardReset => {
// State Transition
state = State::HardReset;
wd.feed();
laser.power_down();
thermostat.power_down();
net::net::for_each(|mut socket| {
if net::net::eth_is_socket_active(socket) {
unsafe {
net::cmd_handler::send_response(&mut ETH_DATA_BUFFER, net::cmd_handler::ResponseEnum::HardReset, None, &mut socket);
}
}
});
}
State::HardReset => { State::HardReset => {
wd.feed(); wd.feed();
laser.power_down(); laser.power_down();

View File

@ -18,10 +18,43 @@ use crate::{laser_diode::{laser_diode::{
use crate::thermostat::thermostat::{Thermostat, ThermostatSettingsSummary}; use crate::thermostat::thermostat::{Thermostat, ThermostatSettingsSummary};
use crate::thermostat::pid_state::PidSettings::*; use crate::thermostat::pid_state::PidSettings::*;
use crate::device::{dfu, sys_timer}; use crate::device::{dfu, sys_timer};
use log::info; use log::{info, debug};
use crate::{DeviceSettings, State, IpSettings}; use crate::{DeviceSettings, State, IpSettings};
use smoltcp::iface::SocketHandle; use smoltcp::iface::SocketHandle;
#[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>
}
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)] #[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
enum DeviceCmd { enum DeviceCmd {
#[default] #[default]
@ -89,6 +122,15 @@ enum ThermostatCmdEnum {
SetShBeta, SetShBeta,
} }
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";
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)] #[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
pub struct CmdJsonObj{ pub struct CmdJsonObj{
laser_diode_cmd: Option<LdCmdEnum>, laser_diode_cmd: Option<LdCmdEnum>,
@ -128,6 +170,19 @@ pub struct SettingsSummaryObj {
json: SettingsSummary json: SettingsSummary
} }
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);
let num_bytes = response.get_json("/json", buffer).unwrap();
net::eth_send(buffer, num_bytes, *socket);
}
pub fn send_settings_summary(buffer: &mut [u8], laser: &mut LdDrive, tec: &mut Thermostat, socket: &mut SocketHandle){ pub fn send_settings_summary(buffer: &mut [u8], laser: &mut LdDrive, tec: &mut Thermostat, socket: &mut SocketHandle){
let settings_summary = SettingsSummaryObj { let settings_summary = SettingsSummaryObj {
json: SettingsSummary { json: SettingsSummary {
@ -191,14 +246,16 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
Some(DeviceCmd::SetIPSettings) => { Some(DeviceCmd::SetIPSettings) => {
match cmd.json.ip_settings { match cmd.json.ip_settings {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
device_settings.ip_settings = val; device_settings.ip_settings = val;
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_IP_SETTINGS), socket);
} }
} }
} }
Some(DeviceCmd::Dfu) => { Some(DeviceCmd::Dfu) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
unsafe { unsafe {
dfu::set_dfu_trigger(); dfu::set_dfu_trigger();
} }
@ -207,31 +264,38 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
Some(DeviceCmd::SetActiveReportMode) => { Some(DeviceCmd::SetActiveReportMode) => {
match cmd.json.data_bool{ match cmd.json.data_bool{
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
device_settings.report_readings = val; device_settings.report_readings = val;
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_BOOL), socket);
} }
} }
} }
Some(DeviceCmd::GetStatusReport) => { Some(DeviceCmd::GetStatusReport) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
send_status_report(buffer, laser, tec, socket); send_status_report(buffer, laser, tec, socket);
} }
Some(DeviceCmd::GetSettingsSummary) => { Some(DeviceCmd::GetSettingsSummary) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
send_settings_summary(buffer, laser, tec, socket); send_settings_summary(buffer, laser, tec, socket);
} }
Some(DeviceCmd::SaveFlashSettings) => { Some(DeviceCmd::SaveFlashSettings) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
*state = State::SaveFlashSettings; *state = State::SaveFlashSettings;
} }
Some(DeviceCmd::LoadFlashSettings) => { Some(DeviceCmd::LoadFlashSettings) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
*state = State::LoadFlashSettings; *state = State::LoadFlashSettings;
} }
Some(DeviceCmd::HardReset) => { Some(DeviceCmd::HardReset) => {
*state = State::HardReset; send_response(buffer, ResponseEnum::Acknowledge, None, socket);
*state = State::PrepareForHardReset;
} }
None => { /* Do Nothing */} None => { /* Do Nothing */}
_ => { _ => {
info!("Unimplemented Command") send_response(buffer, ResponseEnum::InvalidCmd, None, socket);
debug!("Unimplemented Command")
} }
} }
@ -239,81 +303,93 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
Some(LdCmdEnum::SetDefaultPowerOn) => { Some(LdCmdEnum::SetDefaultPowerOn) => {
match cmd.json.data_bool { match cmd.json.data_bool {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.set_default_pwr_on(val); laser.set_default_pwr_on(val);
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_BOOL), socket);
} }
} }
} }
Some(LdCmdEnum::PowerUp) => { Some(LdCmdEnum::PowerUp) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.power_up() laser.power_up()
} }
Some(LdCmdEnum::PowerDown) => { Some(LdCmdEnum::PowerDown) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.power_down() laser.power_down()
} }
Some(LdCmdEnum::LdTermsShort) => { Some(LdCmdEnum::LdTermsShort) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.ld_short(); laser.ld_short();
} }
Some(LdCmdEnum::LdTermsOpen) => { Some(LdCmdEnum::LdTermsOpen) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.ld_open(); laser.ld_open();
} }
Some(LdCmdEnum::SetI) => { Some(LdCmdEnum::SetI) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.ld_set_i(ElectricCurrent::new::<milliampere>(val)); laser.ld_set_i(ElectricCurrent::new::<milliampere>(val));
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(LdCmdEnum::SetISoftLimit) => { Some(LdCmdEnum::SetISoftLimit) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.set_ld_drive_current_limit(ElectricCurrent::new::<milliampere>(val)) laser.set_ld_drive_current_limit(ElectricCurrent::new::<milliampere>(val))
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(LdCmdEnum::SetPdResponsitivity) => { Some(LdCmdEnum::SetPdResponsitivity) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.set_pd_responsitivity(ResponsitivityUnit {dimension: PhantomData, units: PhantomData, value: val}) laser.set_pd_responsitivity(ResponsitivityUnit {dimension: PhantomData, units: PhantomData, value: val})
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(LdCmdEnum::SetPdDarkCurrent) => { Some(LdCmdEnum::SetPdDarkCurrent) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.set_pd_dark_current(ElectricCurrent::new::<microampere>(val)) laser.set_pd_dark_current(ElectricCurrent::new::<microampere>(val))
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(LdCmdEnum::SetLdPwrLimit) => { Some(LdCmdEnum::SetLdPwrLimit) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.set_ld_power_limit(Power::new::<milliwatt>(val)) laser.set_ld_power_limit(Power::new::<milliwatt>(val))
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(LdCmdEnum::ClearAlarm) => { Some(LdCmdEnum::ClearAlarm) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.pd_mon_clear_alarm() laser.pd_mon_clear_alarm()
} }
None => { /* Do Nothing*/ } None => { /* Do Nothing*/ }
_ => { _ => {
send_response(buffer, ResponseEnum::InvalidCmd, Some(ERR_MSG_MISSING_DATA_F32), socket);
info!("Unimplemented Command") info!("Unimplemented Command")
} }
} }
@ -322,128 +398,143 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
Some(ThermostatCmdEnum::SetDefaultPowerOn) => { Some(ThermostatCmdEnum::SetDefaultPowerOn) => {
match cmd.json.data_bool { match cmd.json.data_bool {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_default_pwr_on(val); tec.set_default_pwr_on(val);
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::PowerUp) => { Some(ThermostatCmdEnum::PowerUp) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.power_up() tec.power_up()
} }
Some(ThermostatCmdEnum::PowerDown) => { Some(ThermostatCmdEnum::PowerDown) => {
send_response(buffer, ResponseEnum::Acknowledge, Some(ERR_MSG_MISSING_DATA_F32), socket);
tec.power_down() tec.power_down()
} }
Some(ThermostatCmdEnum::SetTecMaxV) => { Some(ThermostatCmdEnum::SetTecMaxV) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_max_v(ElectricPotential::new::<volt>(val)); tec.set_max_v(ElectricPotential::new::<volt>(val));
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetTecMaxIPos) => { Some(ThermostatCmdEnum::SetTecMaxIPos) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_max_i_pos(ElectricCurrent::new::<ampere>(val)); tec.set_max_i_pos(ElectricCurrent::new::<ampere>(val));
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetTecMaxINeg) => { Some(ThermostatCmdEnum::SetTecMaxINeg) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_max_i_pos(ElectricCurrent::new::<milliampere>(val)); tec.set_max_i_pos(ElectricCurrent::new::<milliampere>(val));
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetTecIOut) => { Some(ThermostatCmdEnum::SetTecIOut) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_i(ElectricCurrent::new::<milliampere>(val)); tec.set_i(ElectricCurrent::new::<milliampere>(val));
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetTemperatureSetpoint) => { Some(ThermostatCmdEnum::SetTemperatureSetpoint) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temperature_setpoint(ThermodynamicTemperature::new::<degree_celsius>(val)); tec.set_temperature_setpoint(ThermodynamicTemperature::new::<degree_celsius>(val));
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetPidEngage) => { Some(ThermostatCmdEnum::SetPidEngage) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid_engaged(true); tec.set_pid_engaged(true);
} }
Some(ThermostatCmdEnum::SetPidDisEngage) => { Some(ThermostatCmdEnum::SetPidDisEngage) => {
send_response(buffer, ResponseEnum::Acknowledge, Some(ERR_MSG_MISSING_DATA_F32), socket);
tec.set_pid_engaged(false); tec.set_pid_engaged(false);
} }
Some(ThermostatCmdEnum::SetPidKp) => { Some(ThermostatCmdEnum::SetPidKp) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid(Kp, val); tec.set_pid(Kp, val);
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetPidKi) => { Some(ThermostatCmdEnum::SetPidKi) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid(Ki, val); tec.set_pid(Ki, val);
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetPidKd) => { Some(ThermostatCmdEnum::SetPidKd) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid(Kd, val); tec.set_pid(Kd, val);
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetPidOutMin) => { Some(ThermostatCmdEnum::SetPidOutMin) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid(Min, val); tec.set_pid(Min, val);
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetPidOutMax) => { Some(ThermostatCmdEnum::SetPidOutMax) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid(Max, val); tec.set_pid(Max, val);
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetPidUpdateInterval) => { Some(ThermostatCmdEnum::SetPidUpdateInterval) => {
info!("Not supported Yet") send_response(buffer, ResponseEnum::InvalidCmd, None, socket);
debug!("Not supported Yet")
} }
Some(ThermostatCmdEnum::ConfigTempAdcFilter) => { Some(ThermostatCmdEnum::ConfigTempAdcFilter) => {
match cmd.json.temp_adc_filter { match cmd.json.temp_adc_filter {
@ -452,111 +543,121 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
FilterType::Sinc5Sinc1With50hz60HzRejection => { FilterType::Sinc5Sinc1With50hz60HzRejection => {
match val.sinc5sinc1postfilter { match val.sinc5sinc1postfilter {
Some(val2) => { Some(val2) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_adc_sinc5_sinc1_with_postfilter(0, val2); tec.set_temp_adc_sinc5_sinc1_with_postfilter(0, val2);
} }
None => { None => {
info!("sinc5sinc1postfilter field needs to be set for configuration"); send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_POSTFILTER), socket);
} }
} }
} }
FilterType::Sinc5Sinc1 => { FilterType::Sinc5Sinc1 => {
match val.sinc5sinc1odr { match val.sinc5sinc1odr {
Some(val2) => { Some(val2) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_adc_sinc5_sinc1_filter(0, val2); tec.set_temp_adc_sinc5_sinc1_filter(0, val2);
} }
None => { None => {
info!("sinc5sinc1odr field needs to be set for configuration"); send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_SINC5SINC1ODR), socket);
} }
} }
} }
FilterType::Sinc3WithFineODR => { FilterType::Sinc3WithFineODR => {
match val.sinc3fineodr { match val.sinc3fineodr {
Some(val2) => { Some(val2) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_adc_sinc3_fine_filter(0, val2); tec.set_temp_adc_sinc3_fine_filter(0, val2);
} }
None => { None => {
info!("data_f32 field needs to be set for configuration"); send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_SINC3FINEODR), socket);
} }
} }
} }
FilterType::Sinc3 => { FilterType::Sinc3 => {
match val.sinc3odr { match val.sinc3odr {
Some(val2) => { Some(val2) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_adc_sinc3_filter(0, val2); tec.set_temp_adc_sinc3_filter(0, val2);
} }
None => { None => {
info!("sinc3_filter field needs to be set for configuration"); send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_SINC3ODR), socket);
} }
} }
} }
} }
} }
None => { None => {
info!("temp_adc_filter needs to be set for configuration") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_TEMP_ADC_FILTER), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetTempMonUpperLimit) => { Some(ThermostatCmdEnum::SetTempMonUpperLimit) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_mon_upper_limit(ThermodynamicTemperature::new::<degree_celsius>(val)); tec.set_temp_mon_upper_limit(ThermodynamicTemperature::new::<degree_celsius>(val));
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetTempMonLowerLimit) => { Some(ThermostatCmdEnum::SetTempMonLowerLimit) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_mon_lower_limit(ThermodynamicTemperature::new::<degree_celsius>(val)); tec.set_temp_mon_lower_limit(ThermodynamicTemperature::new::<degree_celsius>(val));
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::ClearAlarm) => { Some(ThermostatCmdEnum::ClearAlarm) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.clear_temp_mon_alarm(); tec.clear_temp_mon_alarm();
} }
Some(ThermostatCmdEnum::SetShT0) => { Some(ThermostatCmdEnum::SetShT0) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_sh_t0(ThermodynamicTemperature::new::<degree_celsius>(val)); tec.set_sh_t0(ThermodynamicTemperature::new::<degree_celsius>(val));
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetShR0) => { Some(ThermostatCmdEnum::SetShR0) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_sh_r0(ElectricalResistance::new::<ohm>(val)); tec.set_sh_r0(ElectricalResistance::new::<ohm>(val));
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
Some(ThermostatCmdEnum::SetShBeta) => { Some(ThermostatCmdEnum::SetShBeta) => {
match cmd.json.data_f32 { match cmd.json.data_f32 {
Some(val) => { Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_sh_beta(val); tec.set_sh_beta(val);
} }
None => { None => {
info!("Wrong Data type is received") send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
} }
} }
} }
None => { /* Do Nothing*/ } None => { /* Do Nothing*/ }
_ => { _ => {
info!("Unimplemented Command") send_response(buffer, ResponseEnum::InvalidCmd, None, socket);
} }
} }
} }
Err(err) => { Err(_) => {
info!("Invalid Command: {:?}", err); send_response(buffer, ResponseEnum::InvalidCmd, None, socket);
} }
} }
} }