cmd: Add temp adc filter config cmd

This commit is contained in:
linuswck 2024-02-27 11:00:32 +08:00
parent 19341672a9
commit 9f82fa58f4

View File

@ -9,11 +9,11 @@ use uom::si::{
thermodynamic_temperature::{degree_celsius, ThermodynamicTemperature}
};
use crate::{laser_diode::{laser_diode::{
LdDrive, StatusReport as LdStatusReport, LdSettingsSummary},
LdDrive, LdSettingsSummary, StatusReport as LdStatusReport},
pd_responsitivity::ResponsitivityUnit
},
net::net,
thermostat::thermostat::StatusReport as TecStatusReport
thermostat::{ad7172::{FilterType, PostFilter, SingleChODR}, thermostat::StatusReport as TecStatusReport}
};
use crate::thermostat::thermostat::{Thermostat, ThermostatSettingsSummary};
use crate::thermostat::pid_state::PidSettings::*;
@ -70,6 +70,8 @@ enum ThermostatCmdEnum {
SetPidOutMin,
SetPidOutMax,
SetPidUpdateInterval, // Update Interval is set based on the sampling rate of ADC
// Temperature ADC
ConfigTempAdcFilter,
// TempMon
SetTempMonUpperLimit,
SetTempMonLowerLimit,
@ -88,12 +90,22 @@ pub struct CmdJsonObj{
data_bool: Option<bool>,
data_f32: Option<f32>,
data_f64: Option<f64>,
temp_adc_filter: Option<TempAdcFilter>,
}
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
pub struct Cmd {
json: CmdJsonObj
}
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
pub struct TempAdcFilter{
filter_type: FilterType,
sinc5sinc1odr: Option<SingleChODR>,
sinc3odr: Option<SingleChODR>,
sinc5sinc1postfilter: Option<PostFilter>,
sinc3fineodr: Option<f64>
}
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
pub struct StatusReport {
ts: u32,
@ -370,6 +382,57 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mu
Some(ThermostatCmdEnum::SetPidUpdateInterval) => {
info!("Not supported Yet")
}
Some(ThermostatCmdEnum::ConfigTempAdcFilter) => {
match cmd.json.temp_adc_filter {
Some(val) => {
match val.filter_type {
FilterType::Sinc5Sinc1With50hz60HzRejection => {
match val.sinc5sinc1postfilter {
Some(val2) => {
tec.set_temp_adc_sinc5_sinc1_with_postfilter(0, val2);
}
None => {
info!("sinc5sinc1postfilter field needs to be set for configuration");
}
}
}
FilterType::Sinc5Sinc1 => {
match val.sinc5sinc1odr {
Some(val2) => {
tec.set_temp_adc_sinc5_sinc1_filter(0, val2);
}
None => {
info!("sinc5sinc1odr field needs to be set for configuration");
}
}
}
FilterType::Sinc3WithFineODR => {
match val.sinc3fineodr {
Some(val2) => {
tec.set_temp_adc_sinc3_fine_filter(0, val2);
}
None => {
info!("data_f64 field needs to be set for configuration");
}
}
}
FilterType::Sinc3 => {
match val.sinc3odr {
Some(val2) => {
tec.set_temp_adc_sinc3_filter(0, val2);
}
None => {
info!("sinc3_filter field needs to be set for configuration");
}
}
}
}
}
None => {
info!("temp_adc_filter needs to be set for configuration")
}
}
}
Some(ThermostatCmdEnum::SetTempMonUpperLimit) => {
match cmd.json.data_f64 {
Some(val) => {