pub fn decide_calibration_value_workflow(
        &self,
        channel: usize,
        calib_data: CalibData,
    ) -> Result<CalibData> {
        if calib_data.temp < self.temp_lower_limit || calib_data.temp > self.temp_upper_limit {
            info!("invalid temperature: {}.", calib_data.temp);
            return self
                .get_previous_calibration_value(channel)
                .map_err(|_| Error::InvalidTemperature(calib_data.temp));
        }
        let (datastore_exist, previous_calib) = match self.get_previous_calibration_value(channel) {
            Ok(previous_calib) => (true, previous_calib),
            Err(e) => {
                info!("{}, use vpd as previous calibration value", e);
                (false, self.get_vpd_calibration_value(channel)?)
            }
        };

        let diff = {
            let calib_rdc_ohm = (self.rdc_to_ohm)(calib_data.rdc);
            let previous_rdc_ohm = (self.rdc_to_ohm)(previous_calib.rdc);
            (calib_rdc_ohm - previous_rdc_ohm) / previous_rdc_ohm
        };
        if diff > Self::CALI_ERROR_UPPER_LIMIT {
            Err(Error::LargeCalibrationDiff(calib_data))
        } else if diff < Self::CALI_ERROR_LOWER_LIMIT {
            if !datastore_exist {
                Datastore::UseVPD.save(&self.snd_card, channel)?;
            }
            Ok(previous_calib)
        } else {
            Datastore::DSM {
                rdc: calib_data.rdc,
                temp: (self.temp_converter.celsius_to_vpd)(calib_data.temp),
            }
            .save(&self.snd_card, channel)?;
            Ok(calib_data)
        }
    }
/// Decides a good calibration value and updates the stored value according to the following
/// logic:
/// * Returns the previous value if the ambient temperature is not within a valid range.
/// * Returns Error::LargeCalibrationDiff if rdc difference is larger than
///   `CALI_ERROR_UPPER_LIMIT`.
/// * Returns the previous value if the rdc difference is smaller than `CALI_ERROR_LOWER_LIMIT`.
/// * Returns the boot time calibration value and updates the datastore value if the rdc.
///   difference is between `CALI_ERROR_UPPER_LIMIT` and `CALI_ERROR_LOWER_LIMIT`.
///
/// # Arguments
///
/// * `card` - `&Card`.
/// * `channel` - `channel number`.
/// * `calib_data` - `boot time calibrated data`.
///
/// # Results
///
/// * `CalibData` - the calibration data to be applied according to the deciding logic.
///
/// # Errors
///
/// * VPD does not exist.
/// * rdc difference is larger than `CALI_ERROR_UPPER_LIMIT`.
/// * Failed to update Datastore.
Decides a good calibration value and updates the stored value according to the following
logic:
Returns the previous value if the ambient temperature is not within a valid range.
Returns Error::LargeCalibrationDiff if rdc difference is larger than
`CALI_ERROR_UPPER_LIMIT`.
Returns the previous value if the rdc difference is smaller than `CALI_ERROR_LOWER_LIMIT`.
Returns the boot time calibration value and updates the datastore value if the rdc.
Decides a good calibration value and updates the stored value according to the following logic : Returns the previous value if the ambient temperature is not within a valid range . Returns Error :: LargeCalibrationDiff if rdc difference is larger than ` CALI_ERROR_UPPER_LIMIT ` . Returns the previous value if the rdc difference is smaller than ` CALI_ERROR_LOWER_LIMIT ` . Returns the boot time calibration value and updates the datastore value if the rdc .
pub fn decide_calibration_value_workflow(
        &self,
        channel: usize,
        calib_data: CalibData,
    ) -> Result<CalibData> {
        if calib_data.temp < self.temp_lower_limit || calib_data.temp > self.temp_upper_limit {
            info!("invalid temperature: {}.", calib_data.temp);
            return self
                .get_previous_calibration_value(channel)
                .map_err(|_| Error::InvalidTemperature(calib_data.temp));
        }
        let (datastore_exist, previous_calib) = match self.get_previous_calibration_value(channel) {
            Ok(previous_calib) => (true, previous_calib),
            Err(e) => {
                info!("{}, use vpd as previous calibration value", e);
                (false, self.get_vpd_calibration_value(channel)?)
            }
        };
        let diff = {
            let calib_rdc_ohm = (self.rdc_to_ohm)(calib_data.rdc);
            let previous_rdc_ohm = (self.rdc_to_ohm)(previous_calib.rdc);
            (calib_rdc_ohm - previous_rdc_ohm) / previous_rdc_ohm
        };
        if diff > Self::CALI_ERROR_UPPER_LIMIT {
            Err(Error::LargeCalibrationDiff(calib_data))
        } else if diff < Self::CALI_ERROR_LOWER_LIMIT {
            if !datastore_exist {
                Datastore::UseVPD.save(&self.snd_card, channel)?;
            }
            Ok(previous_calib)
        } else {
            Datastore::DSM {
                rdc: calib_data.rdc,
                temp: (self.temp_converter.celsius_to_vpd)(calib_data.temp),
            }
            .save(&self.snd_card, channel)?;
            Ok(calib_data)
        }
    }
pub fn decide_calibration_value_workflow ( & self , channel : usize , calib_data : CalibData , ) -> Result < CalibData > { if calib_data . temp < self . temp_lower_limit || calib_data . temp > self . temp_upper_limit { info ! ( " " calib_data temp ) ; return self . get_previous_calibration_value ( channel ) . map_err ( | _ | Error :: InvalidTemperature ( calib_data . temp ) ) ; } let ( datastore_exist , previous_calib ) = match self . get_previous_calibration_value ( channel ) { Ok ( previous_calib ) => ( true , previous_calib ) , Err ( e ) => { info ! ( " " e ) ; ( false , self . get_vpd_calibration_value ( channel ) ? ) } } ; let diff = { let calib_rdc_ohm = ( self . rdc_to_ohm ) ( calib_data . rdc ) ; let previous_rdc_ohm = ( self . rdc_to_ohm ) ( previous_calib . rdc ) ; ( calib_rdc_ohm - previous_rdc_ohm ) / previous_rdc_ohm } ; if diff > Self :: CALI_ERROR_UPPER_LIMIT { Err ( Error :: LargeCalibrationDiff ( calib_data ) ) } else if diff < Self :: CALI_ERROR_LOWER_LIMIT { if ! datastore_exist { Datastore :: UseVPD . save ( & self . snd_card , channel ) ? ; } Ok ( previous_calib ) } else { Datastore :: DSM { rdc : calib_data . rdc , temp : ( self . temp_converter . celsius_to_vpd ) ( calib_data . temp ) , } . save ( & self . snd_card , channel ) ? ; Ok ( calib_data ) } }
Decides a good calibration value and updates the stored value according to the following
logic:
 Returns the previous value if the ambient temperature is not within a valid range.
Decides a good calibration value and updates the stored value according to the following logic : Returns the previous value if the ambient temperature is not within a valid range .
&self
channel
usize
calib_data
CalibData
&self
channel
usize
calib_data
CalibData
results
`CalibData` - the calibration data to be applied according to the deciding logic.
` CalibData ` - the calibration data to be applied according to the deciding logic .
errors
VPD does not exist.
rdc difference is larger than `CALI_ERROR_UPPER_LIMIT`.
Failed to update Datastore.
VPD does not exist . rdc difference is larger than ` CALI_ERROR_UPPER_LIMIT ` . Failed to update Datastore .