cmd: add cmds to poll tec temp, dis/enable pid

This commit is contained in:
linuswck 2024-02-15 10:34:02 +08:00
parent e29898f8f8
commit 412f5ec58b

View File

@ -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")