1
0
Fork 0

Unify naming and unit in firmware and driver

- mA, uA -> A
- K -> Degree Celsius
- tec -> thermostat
This commit is contained in:
linuswck 2024-03-18 15:41:31 +08:00
parent ed5cda6364
commit 0380c8d30b
4 changed files with 57 additions and 46 deletions

View File

@ -9,7 +9,7 @@ async def main():
await kirdy.laser.set_power_on(False)
await kirdy.laser.clear_alarm()
await kirdy.laser.set_i(0)
await kirdy.laser.set_i_soft_limit(250)
await kirdy.laser.set_i_soft_limit(0.25)
await kirdy.laser.set_power_on(True)
await kirdy.thermostat.set_power_on(False)

View File

@ -89,7 +89,7 @@ class Device:
self._send_raw_cmd = send_raw_cmd_handler
self._read_response = read_response
async def set_ip_settings(self, addr=[192, 168, 1, 132], port=1337, prefix_len=24, gateway=[192, 168, 1, 1]):
async def set_ip_settings(self, addr=[192, 168, 1, 128], port=1337, prefix_len=24, gateway=[192, 168, 1, 1]):
"""
After calling this fn, the user needs to issue the SaveFlashSettings cmd and then issue a
Hard Reset/Power Cycle Kirdy for the new network settings to be effective.
@ -181,7 +181,7 @@ class Device:
'thermostat': {
'default_pwr_on': True, # Power on Thermostat at Startup
'pid_engaged': True, # True: PID Control Mode | False Constant Current Mode
'temperature_setpoint': 298.15, # Temperature Setpoint (K)
'temperature_setpoint': 298.15, # Temperature Setpoint (Degree Celsius)
'tec_settings': {
'i_set': { # Current TEC Current Set by PID Controller/User
'value': 0.04330516, # Value Set
@ -293,14 +293,14 @@ class Laser:
async def set_i(self, i):
"""
Set laser diode output current: Max(0, Min(i_set, i_soft_limit))
- i: mA
- i: A
"""
return await self._send_cmd(TARGET_LD, "SetI", i)
async def set_i_soft_limit(self, i_limit):
"""
Set laser diode software output current limit
- i_limit: mA
- i_limit: A
"""
return await self._send_cmd(TARGET_LD, "SetISoftLimit", i_limit)
@ -308,7 +308,7 @@ class Laser:
"""
Configure the photodiode monitor parameters
- responsitivity: A/W
- dark current: uA
- dark current: A
"""
response = await self._send_cmd(TARGET_LD, "SetPdResponsitivity", responsitivity)
if response["msg_type"] != "Acknowledge":

View File

@ -2,7 +2,7 @@ use core::{fmt::Debug, marker::PhantomData};
use miniconf::{JsonCoreSlash, Tree};
use serde::{Deserialize, Serialize};
use uom::si::{
electric_current::{ampere, microampere, milliampere, ElectricCurrent},
electric_current::{ampere, ElectricCurrent},
electric_potential::{volt, ElectricPotential},
electrical_resistance::{ohm, ElectricalResistance},
power::{milliwatt, Power},
@ -151,7 +151,7 @@ pub struct Cmd {
pub struct StatusReport {
ts: u32,
laser: LdStatusReport,
tec: TecStatusReport,
thermostat: TecStatusReport,
}
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
@ -183,11 +183,11 @@ pub fn send_response(buffer: &mut [u8], msg_type: ResponseEnum, msg: MsgType, so
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, thermostat: &mut Thermostat, socket: &mut SocketHandle){
let settings_summary = SettingsSummaryObj {
json: SettingsSummary {
laser: laser.get_settings_summary(),
thermostat: tec.get_settings_summary(),
thermostat: thermostat.get_settings_summary(),
}
};
let num_bytes = settings_summary.get_json("/json", buffer).unwrap();
@ -195,12 +195,12 @@ pub fn send_settings_summary(buffer: &mut [u8], laser: &mut LdDrive, tec: &mut T
}
pub fn send_status_report(buffer: &mut [u8], laser: &mut LdDrive, tec: &mut Thermostat, socket: &mut SocketHandle){
pub fn send_status_report(buffer: &mut [u8], laser: &mut LdDrive, thermostat: &mut Thermostat, socket: &mut SocketHandle){
let status_report = StatusReportObj {
json: StatusReport {
ts: sys_timer::now(),
laser: laser.get_status_report(),
tec: tec.get_status_report(),
thermostat: thermostat.get_status_report(),
}
};
let num_bytes = status_report.get_json("/json", buffer).unwrap();
@ -221,13 +221,13 @@ pub struct TecSetICmd {
/// 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.
pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHandle, laser: &mut LdDrive, tec: &mut Thermostat, state: &mut State, device_settings: &mut DeviceSettings){
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){
let mut cmd = TecSetICmd {
json: TecSetICmdJson::default()
};
match cmd.set_json("/json", &buffer[0..buffer_size]){
Ok(_) => {
tec.set_i(ElectricCurrent::new::<milliampere>(cmd.json.tec_set_i));
thermostat.set_i(ElectricCurrent::new::<ampere>(cmd.json.tec_set_i));
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
return;
}
@ -275,11 +275,11 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
}
Some(DeviceCmd::GetStatusReport) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
send_status_report(buffer, laser, tec, socket);
send_status_report(buffer, laser, thermostat, socket);
}
Some(DeviceCmd::GetSettingsSummary) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
send_settings_summary(buffer, laser, tec, socket);
send_settings_summary(buffer, laser, thermostat, socket);
}
Some(DeviceCmd::SaveFlashSettings) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
@ -333,7 +333,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
laser.ld_set_i(ElectricCurrent::new::<milliampere>(val));
laser.ld_set_i(ElectricCurrent::new::<ampere>(val));
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -344,7 +344,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
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::<ampere>(val))
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -366,7 +366,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
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::<ampere>(val))
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -400,7 +400,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_bool {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_default_pwr_on(val);
thermostat.set_default_pwr_on(val);
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -409,17 +409,17 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
}
Some(ThermostatCmdEnum::PowerUp) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.power_up()
thermostat.power_up()
}
Some(ThermostatCmdEnum::PowerDown) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.power_down()
thermostat.power_down()
}
Some(ThermostatCmdEnum::SetTecMaxV) => {
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_max_v(ElectricPotential::new::<volt>(val));
thermostat.set_max_v(ElectricPotential::new::<volt>(val));
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -430,7 +430,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_max_i_pos(ElectricCurrent::new::<ampere>(val));
thermostat.set_max_i_pos(ElectricCurrent::new::<ampere>(val));
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -441,7 +441,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_max_i_pos(ElectricCurrent::new::<milliampere>(val));
thermostat.set_max_i_pos(ElectricCurrent::new::<ampere>(val));
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -452,7 +452,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_i(ElectricCurrent::new::<milliampere>(val));
thermostat.set_i(ElectricCurrent::new::<ampere>(val));
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -463,7 +463,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temperature_setpoint(ThermodynamicTemperature::new::<degree_celsius>(val));
thermostat.set_temperature_setpoint(ThermodynamicTemperature::new::<degree_celsius>(val));
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -472,17 +472,17 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
}
Some(ThermostatCmdEnum::SetPidEngage) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid_engaged(true);
thermostat.set_pid_engaged(true);
}
Some(ThermostatCmdEnum::SetPidDisEngage) => {
send_response(buffer, ResponseEnum::Acknowledge, Some(ERR_MSG_MISSING_DATA_F32), socket);
tec.set_pid_engaged(false);
thermostat.set_pid_engaged(false);
}
Some(ThermostatCmdEnum::SetPidKp) => {
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid(Kp, val);
thermostat.set_pid(Kp, val);
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -493,7 +493,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid(Ki, val);
thermostat.set_pid(Ki, val);
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -504,7 +504,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid(Kd, val);
thermostat.set_pid(Kd, val);
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -515,7 +515,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid(Min, val);
thermostat.set_pid(Min, val);
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -526,7 +526,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_pid(Max, val);
thermostat.set_pid(Max, val);
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -545,7 +545,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match val.sinc5sinc1postfilter {
Some(val2) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_adc_sinc5_sinc1_with_postfilter(0, val2);
thermostat.set_temp_adc_sinc5_sinc1_with_postfilter(0, val2);
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_POSTFILTER), socket);
@ -556,7 +556,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match val.sinc5sinc1odr {
Some(val2) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_adc_sinc5_sinc1_filter(0, val2);
thermostat.set_temp_adc_sinc5_sinc1_filter(0, val2);
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_SINC5SINC1ODR), socket);
@ -567,7 +567,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match val.sinc3fineodr {
Some(val2) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_adc_sinc3_fine_filter(0, val2);
thermostat.set_temp_adc_sinc3_fine_filter(0, val2);
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_SINC3FINEODR), socket);
@ -578,7 +578,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match val.sinc3odr {
Some(val2) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_adc_sinc3_filter(0, val2);
thermostat.set_temp_adc_sinc3_filter(0, val2);
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_SINC3ODR), socket);
@ -596,7 +596,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_mon_upper_limit(ThermodynamicTemperature::new::<degree_celsius>(val));
thermostat.set_temp_mon_upper_limit(ThermodynamicTemperature::new::<degree_celsius>(val));
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -607,7 +607,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_temp_mon_lower_limit(ThermodynamicTemperature::new::<degree_celsius>(val));
thermostat.set_temp_mon_lower_limit(ThermodynamicTemperature::new::<degree_celsius>(val));
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -616,13 +616,13 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
}
Some(ThermostatCmdEnum::ClearAlarm) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.clear_temp_mon_alarm();
thermostat.clear_temp_mon_alarm();
}
Some(ThermostatCmdEnum::SetShT0) => {
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_sh_t0(ThermodynamicTemperature::new::<degree_celsius>(val));
thermostat.set_sh_t0(ThermodynamicTemperature::new::<degree_celsius>(val));
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -633,7 +633,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_sh_r0(ElectricalResistance::new::<ohm>(val));
thermostat.set_sh_r0(ElectricalResistance::new::<ohm>(val));
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);
@ -644,7 +644,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, socket: &mut SocketHan
match cmd.json.data_f32 {
Some(val) => {
send_response(buffer, ResponseEnum::Acknowledge, None, socket);
tec.set_sh_beta(val);
thermostat.set_sh_beta(val);
}
None => {
send_response(buffer, ResponseEnum::InvalidDatatype, Some(ERR_MSG_MISSING_DATA_F32), socket);

View File

@ -340,11 +340,22 @@ impl Thermostat{
pub fn get_status_report(&mut self) -> StatusReport {
let (tec_v, tec_i) = self.get_tec_readings();
let temperature: Option<f32>;
match self.pid_ctrl_ch0.get_temperature() {
Some(val) => {
temperature = Some(val.get::<degree_celsius>())
}
None => {
temperature = None;
}
}
StatusReport {
pwr_on: self.max1968.is_powered_on(),
pid_engaged: self.get_pid_engaged(),
temp_mon_status: self.temp_mon.get_status(),
temperature: self.pid_ctrl_ch0.get_temperature(),
temperature: temperature,
i_set: self.tec_settings.i_set,
tec_i: tec_i,
tec_v: tec_v,
@ -540,7 +551,7 @@ pub struct StatusReport {
pwr_on: bool,
pid_engaged: bool,
temp_mon_status: TempStatus,
temperature: Option<ThermodynamicTemperature>,
temperature: Option<f32>,
i_set: ElectricCurrent,
tec_i: ElectricCurrent,
tec_v: ElectricPotential,