forked from M-Labs/kirdy
eth: Add Thermostat related json cmd
This commit is contained in:
parent
4132bfacd3
commit
de262b849d
|
@ -112,7 +112,7 @@ fn main() -> ! {
|
||||||
});
|
});
|
||||||
let bytes = net::net::eth_recv(&mut ETH_DATA_BUFFER);
|
let bytes = net::net::eth_recv(&mut ETH_DATA_BUFFER);
|
||||||
debug!("Number of bytes recv: {:?}", bytes);
|
debug!("Number of bytes recv: {:?}", bytes);
|
||||||
laser = net::cmd_handler::execute_cmd(&mut ETH_DATA_BUFFER, bytes, laser);
|
(laser, thermostat) = net::cmd_handler::execute_cmd(&mut ETH_DATA_BUFFER, bytes, laser, thermostat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
use miniconf::{Error, JsonCoreSlash, Tree, TreeKey};
|
use miniconf::{JsonCoreSlash, Tree};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uom::si::electric_current::{milliampere, ElectricCurrent};
|
use uom::si::{
|
||||||
|
electric_current::{ampere, milliampere, ElectricCurrent},
|
||||||
|
electric_potential::{volt, ElectricPotential}
|
||||||
|
};
|
||||||
use crate::laser_diode::laser_diode::LdDrive;
|
use crate::laser_diode::laser_diode::LdDrive;
|
||||||
|
use crate::thermostat::thermostat::Thermostat;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
|
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
|
||||||
|
@ -28,10 +32,42 @@ enum LdCmdEnum {
|
||||||
GetAlramStatus,
|
GetAlramStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
|
||||||
|
enum ThermostatCmdEnum {
|
||||||
|
#[default]
|
||||||
|
Reserved,
|
||||||
|
PowerUp,
|
||||||
|
PowerDown,
|
||||||
|
// TEC
|
||||||
|
SetTecMaxV,
|
||||||
|
SetTecMaxIPos,
|
||||||
|
SetTecMaxINeg,
|
||||||
|
SetTecIOut, // Constant Current Mode
|
||||||
|
// Control MOde
|
||||||
|
SetConstantCurrentMode,
|
||||||
|
SetPidControlMode,
|
||||||
|
// PID
|
||||||
|
SetPidKp,
|
||||||
|
SetPidKi,
|
||||||
|
SetPidKd,
|
||||||
|
SetPidOutMin,
|
||||||
|
SetPidOutMax,
|
||||||
|
SetPidUpdateInterval, // Update Interval is set based on the sampling rate of ADC
|
||||||
|
// Steinhart-Hart Equation
|
||||||
|
SetShT0,
|
||||||
|
SetShR0,
|
||||||
|
SetShBeta,
|
||||||
|
// Report Related
|
||||||
|
GetTecStatus,
|
||||||
|
GetPidStatus,
|
||||||
|
GetShParams,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
|
||||||
pub struct CmdJsonObj{
|
pub struct CmdJsonObj{
|
||||||
rev: u8,
|
rev: u8,
|
||||||
laser_diode_cmd: LdCmdEnum,
|
laser_diode_cmd: Option<LdCmdEnum>,
|
||||||
|
thermostat_cmd: Option<ThermostatCmdEnum>,
|
||||||
data_f32: Option<f32>,
|
data_f32: Option<f32>,
|
||||||
data_f64: Option<f64>,
|
data_f64: Option<f64>,
|
||||||
}
|
}
|
||||||
|
@ -40,7 +76,7 @@ pub struct Cmd {
|
||||||
json: CmdJsonObj
|
json: CmdJsonObj
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive)->(LdDrive){
|
pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mut tec: Thermostat)->(LdDrive, Thermostat){
|
||||||
let mut cmd = Cmd {
|
let mut cmd = Cmd {
|
||||||
json: CmdJsonObj::default()
|
json: CmdJsonObj::default()
|
||||||
};
|
};
|
||||||
|
@ -49,19 +85,19 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive)->(
|
||||||
info!("############ Command Received {:?}", cmd.json.laser_diode_cmd);
|
info!("############ Command Received {:?}", cmd.json.laser_diode_cmd);
|
||||||
|
|
||||||
match cmd.json.laser_diode_cmd {
|
match cmd.json.laser_diode_cmd {
|
||||||
LdCmdEnum::PowerUp => {
|
Some(LdCmdEnum::PowerUp) => {
|
||||||
laser.power_up()
|
laser.power_up()
|
||||||
}
|
}
|
||||||
LdCmdEnum::PowerDown => {
|
Some(LdCmdEnum::PowerDown) => {
|
||||||
laser.power_down()
|
laser.power_down()
|
||||||
}
|
}
|
||||||
LdCmdEnum::LdTermsShort => {
|
Some(LdCmdEnum::LdTermsShort) => {
|
||||||
laser.ld_short();
|
laser.ld_short();
|
||||||
}
|
}
|
||||||
LdCmdEnum::LdTermsOpen => {
|
Some(LdCmdEnum::LdTermsOpen) => {
|
||||||
laser.ld_open();
|
laser.ld_open();
|
||||||
}
|
}
|
||||||
LdCmdEnum::SetI => {
|
Some(LdCmdEnum::SetI) => {
|
||||||
match cmd.json.data_f64 {
|
match cmd.json.data_f64 {
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
laser.ld_set_i(ElectricCurrent::new::<milliampere>(val));
|
laser.ld_set_i(ElectricCurrent::new::<milliampere>(val));
|
||||||
|
@ -71,7 +107,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive)->(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LdCmdEnum::SetISoftLimit => {
|
Some(LdCmdEnum::SetISoftLimit) => {
|
||||||
match cmd.json.data_f64 {
|
match cmd.json.data_f64 {
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
laser.set_ld_drive_current_limit(ElectricCurrent::new::<milliampere>(val))
|
laser.set_ld_drive_current_limit(ElectricCurrent::new::<milliampere>(val))
|
||||||
|
@ -81,13 +117,13 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive)->(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LdCmdEnum::SetPdResponsitivity => {
|
Some(LdCmdEnum::SetPdResponsitivity) => {
|
||||||
info!("Not supported Yet")
|
info!("Not supported Yet")
|
||||||
}
|
}
|
||||||
LdCmdEnum::SetPdDarkCurrent => {
|
Some(LdCmdEnum::SetPdDarkCurrent) => {
|
||||||
info!("Not supported Yet")
|
info!("Not supported Yet")
|
||||||
}
|
}
|
||||||
LdCmdEnum::SetPdILimit => {
|
Some(LdCmdEnum::SetPdILimit) => {
|
||||||
match cmd.json.data_f64 {
|
match cmd.json.data_f64 {
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
laser.set_pd_i_limit(ElectricCurrent::new::<milliampere>(val))
|
laser.set_pd_i_limit(ElectricCurrent::new::<milliampere>(val))
|
||||||
|
@ -97,29 +133,126 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive)->(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LdCmdEnum::SetLdPwrLimit => {
|
Some(LdCmdEnum::SetLdPwrLimit) => {
|
||||||
info!("Not supported Yet")
|
info!("Not supported Yet")
|
||||||
}
|
}
|
||||||
LdCmdEnum::ClearAlarmStatus => {
|
Some(LdCmdEnum::ClearAlarmStatus) => {
|
||||||
laser.pd_mon_clear_alarm()
|
laser.pd_mon_clear_alarm()
|
||||||
}
|
}
|
||||||
LdCmdEnum::GetModInTermStatus => {
|
Some(LdCmdEnum::GetModInTermStatus) => {
|
||||||
info!("Not supported Yet")
|
info!("Not supported Yet")
|
||||||
}
|
}
|
||||||
LdCmdEnum::GetLdStatus => {
|
Some(LdCmdEnum::GetLdStatus) => {
|
||||||
info!("Not supported Yet")
|
info!("Not supported Yet")
|
||||||
}
|
}
|
||||||
LdCmdEnum::GetAlramStatus => {
|
Some(LdCmdEnum::GetAlramStatus) => {
|
||||||
info!("Not supported Yet")
|
info!("Not supported Yet")
|
||||||
}
|
}
|
||||||
|
None => { /* Do Nothing*/ }
|
||||||
_ => {
|
_ => {
|
||||||
info!("Unimplemented Command")
|
info!("Unimplemented Command")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match cmd.json.thermostat_cmd {
|
||||||
|
Some(ThermostatCmdEnum::PowerUp) => {
|
||||||
|
tec.power_up()
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::PowerDown) => {
|
||||||
|
tec.power_down()
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetTecMaxV) => {
|
||||||
|
match cmd.json.data_f64 {
|
||||||
|
Some(val) => {
|
||||||
|
tec.set_max_v(ElectricPotential::new::<volt>(val));
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
info!("Wrong Data type is received")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetTecMaxIPos) => {
|
||||||
|
match cmd.json.data_f64 {
|
||||||
|
Some(val) => {
|
||||||
|
tec.set_max_i_pos(ElectricCurrent::new::<ampere>(val));
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
info!("Wrong Data type is received")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetTecMaxINeg) => {
|
||||||
|
match cmd.json.data_f64 {
|
||||||
|
Some(val) => {
|
||||||
|
tec.set_max_i_pos(ElectricCurrent::new::<milliampere>(val));
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
info!("Wrong Data type is received")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetTecIOut) => {
|
||||||
|
match cmd.json.data_f64 {
|
||||||
|
Some(val) => {
|
||||||
|
tec.set_i(ElectricCurrent::new::<milliampere>(val));
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
info!("Wrong Data type is received")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetConstantCurrentMode) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetPidControlMode) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetPidKp) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetPidKi) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetPidKd) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetPidOutMin) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetPidOutMax) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetPidUpdateInterval) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetShT0) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetShR0) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::SetShBeta) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::GetTecStatus) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::GetPidStatus) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
Some(ThermostatCmdEnum::GetShParams) => {
|
||||||
|
info!("Not supported Yet")
|
||||||
|
}
|
||||||
|
None => { /* Do Nothing*/ }
|
||||||
|
_ => {
|
||||||
|
info!("Unimplemented Command")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
info!("Invalid Command: {:?}", err);
|
info!("Invalid Command: {:?}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
laser
|
(laser, tec)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue