From 412f5ec58b289507a554d2201366afacb2077e24 Mon Sep 17 00:00:00 2001 From: linuswck Date: Thu, 15 Feb 2024 10:34:02 +0800 Subject: [PATCH] cmd: add cmds to poll tec temp, dis/enable pid --- src/net/cmd_handler.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/net/cmd_handler.rs b/src/net/cmd_handler.rs index cde48d1..4b78963 100644 --- a/src/net/cmd_handler.rs +++ b/src/net/cmd_handler.rs @@ -7,7 +7,7 @@ use uom::si::{ electrical_resistance::{ElectricalResistance, ohm}, f64::ThermodynamicTemperature, thermodynamic_temperature::degree_celsius }; -use crate::laser_diode::laser_diode::LdDrive; +use crate::{laser_diode::laser_diode::LdDrive, net::net, thermostat::thermostat::StatusReport}; use crate::thermostat::thermostat::Thermostat; use crate::thermostat::pid_state::PidSettings::*; use log::info; @@ -48,6 +48,8 @@ enum ThermostatCmdEnum { SetTecIOut, // Constant Current Mode SetTemperatureSetpoint, // PID + SetPidEngage, + SetPidDisEngage, SetPidKp, SetPidKi, SetPidKd, @@ -77,6 +79,11 @@ pub struct Cmd { json: CmdJsonObj } +#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)] +pub struct StatusReportStruct { + json: StatusReport +} + pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mut tec: Thermostat)->(LdDrive, Thermostat){ let mut cmd = Cmd { json: CmdJsonObj::default() @@ -158,10 +165,10 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mu match cmd.json.thermostat_cmd { Some(ThermostatCmdEnum::PowerUp) => { - tec.set_pid_engaged(true); + tec.power_up() } Some(ThermostatCmdEnum::PowerDown) => { - tec.set_pid_engaged(false); + tec.power_down() } Some(ThermostatCmdEnum::SetTecMaxV) => { match cmd.json.data_f64 { @@ -213,7 +220,12 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mu } } } - + Some(ThermostatCmdEnum::SetPidEngage) => { + tec.set_pid_engaged(true); + } + Some(ThermostatCmdEnum::SetPidDisEngage) => { + tec.set_pid_engaged(false); + } Some(ThermostatCmdEnum::SetPidKp) => { match cmd.json.data_f64 { Some(val) => { @@ -298,7 +310,11 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mu } } Some(ThermostatCmdEnum::GetTecStatus) => { - info!("Not supported Yet") + let status_report = StatusReportStruct { + json: tec.get_status_report() + }; + let num_bytes = status_report.get_json("/json", buffer).unwrap(); + net::eth_send(buffer, num_bytes); } Some(ThermostatCmdEnum::GetPidStatus) => { info!("Not supported Yet")