1
0
forked from M-Labs/kirdy

cmd: Add cmds to config pd_mon params

This commit is contained in:
linuswck 2024-02-22 16:44:45 +08:00
parent 6ee45b4814
commit c4135f6ac3
3 changed files with 44 additions and 13 deletions

View File

@ -168,11 +168,11 @@ impl LdDrive{
} }
pub fn set_pd_responsitivity(&mut self, responsitivity: pd_responsitivity::ResponsitivityUnit){ pub fn set_pd_responsitivity(&mut self, responsitivity: pd_responsitivity::ResponsitivityUnit){
self.settings.pd_responsitivity.responsitivity = responsitivity; self.settings.pd_responsitivity.set(responsitivity);
} }
pub fn set_pd_dark_current(&mut self, i_dark: ElectricCurrent){ pub fn set_pd_dark_current(&mut self, i_dark: ElectricCurrent){
self.settings.pd_responsitivity.i_dark = i_dark; self.settings.pd_responsitivity.set_i_dark(i_dark);
} }
pub fn set_ld_power_limit(&mut self, pwr_limit: Power){ pub fn set_ld_power_limit(&mut self, pwr_limit: Power){

View File

@ -14,8 +14,8 @@ pub type ResponsitivityUnit = Quantity<ISQ<N2, N1, P3, P1, Z0, Z0, Z0>, SI<f64>,
#[derive(Clone, Debug, PartialEq, Tree)] #[derive(Clone, Debug, PartialEq, Tree)]
pub struct Parameters { pub struct Parameters {
pub responsitivity: ResponsitivityUnit, responsitivity: ResponsitivityUnit,
pub i_dark: ElectricCurrent, i_dark: ElectricCurrent,
} }
impl Parameters { impl Parameters {
@ -28,6 +28,14 @@ impl Parameters {
let ld_i = pwr * self.responsitivity + self.i_dark; let ld_i = pwr * self.responsitivity + self.i_dark;
ld_i ld_i
} }
pub fn set(&mut self, responsitivity: ResponsitivityUnit) {
self.responsitivity = responsitivity;
}
pub fn set_i_dark(&mut self, i_dark: ElectricCurrent) {
self.i_dark = i_dark;
}
} }
impl Default for Parameters { impl Default for Parameters {

View File

@ -1,14 +1,16 @@
use core::{default, fmt::Debug}; use core::{fmt::Debug, marker::PhantomData};
use miniconf::{JsonCoreSlash, Tree}; use miniconf::{JsonCoreSlash, Tree};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uom::si::{ use uom::si::{
electric_current::{ampere, milliampere, ElectricCurrent}, electric_current::{ampere, microampere, milliampere, ElectricCurrent},
electric_potential::{volt, ElectricPotential}, electric_potential::{volt, ElectricPotential},
electrical_resistance::{ElectricalResistance, ohm}, electrical_resistance::{ohm, ElectricalResistance},
f64::ThermodynamicTemperature, thermodynamic_temperature::degree_celsius power::{milliwatt, Power},
thermodynamic_temperature::{degree_celsius, ThermodynamicTemperature}
}; };
use crate::{laser_diode::laser_diode::{ use crate::{laser_diode::{laser_diode::{
LdDrive, StatusReport as LdStatusReport LdDrive, StatusReport as LdStatusReport},
pd_responsitivity::ResponsitivityUnit
}, },
net::net, net::net,
thermostat::thermostat::StatusReport as TecStatusReport thermostat::thermostat::StatusReport as TecStatusReport
@ -194,10 +196,24 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mu
} }
} }
Some(LdCmdEnum::SetPdResponsitivity) => { Some(LdCmdEnum::SetPdResponsitivity) => {
info!("Not supported Yet") match cmd.json.data_f64 {
Some(val) => {
laser.set_pd_responsitivity(ResponsitivityUnit {dimension: PhantomData, units: PhantomData, value: val})
}
None => {
info!("Wrong Data type is received")
}
}
} }
Some(LdCmdEnum::SetPdDarkCurrent) => { Some(LdCmdEnum::SetPdDarkCurrent) => {
info!("Not supported Yet") match cmd.json.data_f64 {
Some(val) => {
laser.set_pd_dark_current(ElectricCurrent::new::<microampere>(val))
}
None => {
info!("Wrong Data type is received")
}
}
} }
Some(LdCmdEnum::SetPdILimit) => { Some(LdCmdEnum::SetPdILimit) => {
match cmd.json.data_f64 { match cmd.json.data_f64 {
@ -210,7 +226,14 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mu
} }
} }
Some(LdCmdEnum::SetLdPwrLimit) => { Some(LdCmdEnum::SetLdPwrLimit) => {
info!("Not supported Yet") match cmd.json.data_f64 {
Some(val) => {
laser.set_ld_power_limit(Power::new::<milliwatt>(val))
}
None => {
info!("Wrong Data type is received")
}
}
} }
Some(LdCmdEnum::ClearAlarmStatus) => { Some(LdCmdEnum::ClearAlarmStatus) => {
laser.pd_mon_clear_alarm() laser.pd_mon_clear_alarm()