heater tweaks + coverity fix #410
@ -1,11 +1,14 @@
|
||||
#ifndef TEMPERATURESENSOR_H_
|
||||
#define TEMPERATURESENSOR_H_
|
||||
#ifndef FSFW_THERMAL_TEMPERATURESENSOR_H_
|
||||
#define FSFW_THERMAL_TEMPERATURESENSOR_H_
|
||||
|
||||
#include "../thermal/AbstractTemperatureSensor.h"
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "tcsDefinitions.h"
|
||||
#include "AbstractTemperatureSensor.h"
|
||||
|
||||
#include "../datapoollocal/LocalPoolDataSetBase.h"
|
||||
#include "../datapoollocal/LocalPoolVariable.h"
|
||||
#include "../monitoring/LimitMonitor.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief This building block handles non-linear value conversion and
|
||||
* range checks for analog temperature sensors.
|
||||
@ -57,27 +60,25 @@ public:
|
||||
|
||||
/**
|
||||
* Instantiate Temperature Sensor Object.
|
||||
* @param setObjectid objectId of the sensor object
|
||||
* @param inputValue Input value which is converted to a temperature
|
||||
* @param poolVariable Pool Variable to store the temperature value
|
||||
* @param vectorIndex Vector Index for the sensor monitor
|
||||
* @param parameters Calculation parameters, temperature limits, gradient limit
|
||||
* @param datapoolId Datapool ID of the output temperature
|
||||
* @param outputSet Output dataset for the output temperature to fetch it with read()
|
||||
* @param thermalModule respective thermal module, if it has one
|
||||
* @param setObjectid objectId of the sensor object
|
||||
* @param inputTemperature Pointer to a raw input value which is converted to an floating
|
||||
* point C output temperature
|
||||
* @param outputGpid Global Pool ID of the output value
|
||||
* @param vectorIndex Vector Index for the sensor monitor
|
||||
* @param parameters Calculation parameters, temperature limits, gradient limit
|
||||
* @param outputSet Output dataset for the output temperature to fetch it with read()
|
||||
* @param thermalModule Respective thermal module, if it has one
|
||||
*/
|
||||
TemperatureSensor(object_id_t setObjectid,
|
||||
inputType *inputValue, PoolVariableIF *poolVariable,
|
||||
uint8_t vectorIndex, uint32_t datapoolId, Parameters parameters = {0, 0, 0, 0, 0, 0},
|
||||
GlobDataSet *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) :
|
||||
TemperatureSensor(object_id_t setObjectid,lp_var_t<limitType>* inputTemperature,
|
||||
gp_id_t outputGpid, uint8_t vectorIndex, Parameters parameters = {0, 0, 0, 0, 0, 0},
|
||||
LocalPoolDataSetBase *outputSet = nullptr, ThermalModuleIF *thermalModule = nullptr) :
|
||||
AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters),
|
||||
inputValue(inputValue), poolVariable(poolVariable),
|
||||
outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE),
|
||||
sensorMonitor(setObjectid, DOMAIN_ID_SENSOR,
|
||||
GlobalDataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex),
|
||||
inputTemperature(inputTemperature),
|
||||
outputTemperature(outputGpid, outputSet, PoolVariableIF::VAR_WRITE),
|
||||
sensorMonitor(setObjectid, DOMAIN_ID_SENSOR, outputGpid,
|
||||
DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit, parameters.upperLimit,
|
||||
TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH),
|
||||
oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) {
|
||||
oldTemperature(20), uptimeOfOldTemperature({ thermal::INVALID_TEMPERATURE, 0 }) {
|
||||
}
|
||||
|
||||
|
||||
@ -98,7 +99,7 @@ protected:
|
||||
|
||||
private:
|
||||
void setInvalid() {
|
||||
outputTemperature = INVALID_TEMPERATURE;
|
||||
outputTemperature = thermal::INVALID_TEMPERATURE;
|
||||
outputTemperature.setValid(false);
|
||||
uptimeOfOldTemperature.tv_sec = INVALID_UPTIME;
|
||||
sensorMonitor.setToInvalid();
|
||||
@ -108,11 +109,8 @@ protected:
|
||||
|
||||
UsedParameters parameters;
|
||||
|
||||
inputType * inputValue;
|
||||
|
||||
PoolVariableIF *poolVariable;
|
||||
|
||||
gp_float_t outputTemperature;
|
||||
lp_var_t<limitType>* inputTemperature;
|
||||
lp_var_t<float> outputTemperature;
|
||||
|
||||
LimitMonitor<limitType> sensorMonitor;
|
||||
|
||||
@ -120,22 +118,27 @@ protected:
|
||||
timeval uptimeOfOldTemperature;
|
||||
|
||||
void doChildOperation() {
|
||||
if (!poolVariable->isValid()
|
||||
|| !healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||
ReturnValue_t result = inputTemperature->read(MutexIF::TimeoutType::WAITING, 20);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((not inputTemperature->isValid()) or
|
||||
(not healthHelper.healthTable->isHealthy(getObjectId()))) {
|
||||
setInvalid();
|
||||
return;
|
||||
}
|
||||
|
||||
outputTemperature = calculateOutputTemperature(*inputValue);
|
||||
outputTemperature = calculateOutputTemperature(inputTemperature->value);
|
||||
outputTemperature.setValid(PoolVariableIF::VALID);
|
||||
|
||||
timeval uptime;
|
||||
Clock::getUptime(&uptime);
|
||||
|
||||
if (uptimeOfOldTemperature.tv_sec != INVALID_UPTIME) {
|
||||
//In theory, we could use an AbsValueMonitor to monitor the gradient.
|
||||
//But this would require storing the maxGradient in DP and quite some overhead.
|
||||
//The concept of delta limits is a bit strange anyway.
|
||||
// In theory, we could use an AbsValueMonitor to monitor the gradient.
|
||||
// But this would require storing the maxGradient in DP and quite some overhead.
|
||||
// The concept of delta limits is a bit strange anyway.
|
||||
float deltaTime;
|
||||
float deltaTemp;
|
||||
|
||||
@ -148,17 +151,17 @@ protected:
|
||||
}
|
||||
if (parameters.gradient < deltaTemp / deltaTime) {
|
||||
triggerEvent(TEMP_SENSOR_GRADIENT);
|
||||
//Don't set invalid, as we did not recognize it as invalid with full authority, let FDIR handle it
|
||||
// Don't set invalid, as we did not recognize it as invalid with full authority,
|
||||
// let FDIR handle it
|
||||
}
|
||||
}
|
||||
|
||||
//Check is done against raw limits. SHOULDDO: Why? Using <20>C would be more easy to handle.
|
||||
sensorMonitor.doCheck(outputTemperature.value);
|
||||
|
||||
if (sensorMonitor.isOutOfLimits()) {
|
||||
uptimeOfOldTemperature.tv_sec = INVALID_UPTIME;
|
||||
outputTemperature.setValid(PoolVariableIF::INVALID);
|
||||
outputTemperature = INVALID_TEMPERATURE;
|
||||
outputTemperature = thermal::INVALID_TEMPERATURE;
|
||||
} else {
|
||||
oldTemperature = outputTemperature;
|
||||
uptimeOfOldTemperature = uptime;
|
||||
@ -179,7 +182,10 @@ public:
|
||||
static const uint16_t ADDRESS_C = 2;
|
||||
static const uint16_t ADDRESS_GRADIENT = 3;
|
||||
|
||||
static const uint16_t DEFAULT_CONFIRMATION_COUNT = 1; //!< Changed due to issue with later temperature checking even tough the sensor monitor was confirming already (Was 10 before with comment = Correlates to a 10s confirmation time. Chosen rather large, should not be so bad for components and helps survive glitches.)
|
||||
//! Changed due to issue with later temperature checking even tough the sensor monitor was
|
||||
//! confirming already (Was 10 before with comment = Correlates to a 10s confirmation time.
|
||||
//! Chosen rather large, should not be so bad for components and helps survive glitches.)
|
||||
static const uint16_t DEFAULT_CONFIRMATION_COUNT = 1;
|
||||
|
||||
static const uint8_t DOMAIN_ID_SENSOR = 1;
|
||||
|
||||
@ -219,4 +225,4 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#endif /* TEMPERATURESENSOR_H_ */
|
||||
#endif /* FSFW_THERMAL_TEMPERATURESENSOR_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user