refactored: limit type specified separately
This commit is contained in:
parent
ddae9ee80f
commit
99b90e625d
@ -13,11 +13,12 @@
|
|||||||
* The temperature is calculated from an input value with
|
* The temperature is calculated from an input value with
|
||||||
* the calculateOutputTemperature() function. Range checking and
|
* the calculateOutputTemperature() function. Range checking and
|
||||||
* limit monitoring is performed automatically.
|
* limit monitoring is performed automatically.
|
||||||
*
|
* The inputType specifies the type of the raw input while the
|
||||||
|
* limitType specifies the type of the upper and lower limit to check against.
|
||||||
* @ingroup thermal
|
* @ingroup thermal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
template<typename inputType, typename limitType = inputType>
|
||||||
class TemperatureSensor: public AbstractTemperatureSensor {
|
class TemperatureSensor: public AbstractTemperatureSensor {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -29,13 +30,15 @@ public:
|
|||||||
*
|
*
|
||||||
* The parameters a,b and c are used in the calculateOutputTemperature() call.
|
* The parameters a,b and c are used in the calculateOutputTemperature() call.
|
||||||
*
|
*
|
||||||
* The lower and upper limits can be specified in °C or in the input value
|
* The lower and upper limits can be specified in any type, for example float for C° values
|
||||||
* format
|
* or any other type for raw values.
|
||||||
*/
|
*/
|
||||||
struct Parameters {
|
struct Parameters {
|
||||||
float a;
|
float a;
|
||||||
float b;
|
float b;
|
||||||
float c;
|
float c;
|
||||||
|
limitType lowerLimit;
|
||||||
|
limitType upperLimit;
|
||||||
float maxGradient;
|
float maxGradient;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -64,39 +67,19 @@ public:
|
|||||||
* @param thermalModule respective thermal module, if it has one
|
* @param thermalModule respective thermal module, if it has one
|
||||||
*/
|
*/
|
||||||
TemperatureSensor(object_id_t setObjectid,
|
TemperatureSensor(object_id_t setObjectid,
|
||||||
T *inputValue, T lowerLimit, T upperLimit, PoolVariableIF *poolVariable,
|
inputType *inputValue, PoolVariableIF *poolVariable,
|
||||||
uint8_t vectorIndex, uint32_t datapoolId, Parameters parameters = {0, 0, 0, 0},
|
uint8_t vectorIndex, uint32_t datapoolId, Parameters parameters = {0, 0, 0, 0, 0, 0},
|
||||||
DataSet *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) :
|
DataSet *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) :
|
||||||
AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters),
|
AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters),
|
||||||
inputValue(inputValue), poolVariable(poolVariable),
|
inputValue(inputValue), poolVariable(poolVariable),
|
||||||
outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE),
|
outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE),
|
||||||
oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 })
|
sensorMonitor(setObjectid, DOMAIN_ID_SENSOR,
|
||||||
{
|
|
||||||
sensorMonitorRaw = new LimitMonitor<T>(setObjectid, DOMAIN_ID_SENSOR,
|
|
||||||
DataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex),
|
DataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex),
|
||||||
DEFAULT_CONFIRMATION_COUNT, lowerLimit, upperLimit,
|
DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit, parameters.upperLimit,
|
||||||
TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH);
|
TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH),
|
||||||
delete sensorMonitor;
|
oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor do check against °C values
|
|
||||||
*/
|
|
||||||
TemperatureSensor(object_id_t setObjectid,
|
|
||||||
T *inputValue, float lowerLimit, float upperLimit, PoolVariableIF *poolVariable,
|
|
||||||
uint8_t vectorIndex, uint32_t datapoolId, Parameters parameters = {0, 0, 0, 0},
|
|
||||||
DataSet *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) :
|
|
||||||
AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters),
|
|
||||||
inputValue(inputValue), poolVariable(poolVariable),
|
|
||||||
outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE),
|
|
||||||
oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 })
|
|
||||||
{
|
|
||||||
sensorMonitor = new LimitMonitor<float>(setObjectid, DOMAIN_ID_SENSOR,
|
|
||||||
DataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex),
|
|
||||||
DEFAULT_CONFIRMATION_COUNT, lowerLimit, upperLimit,
|
|
||||||
TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH);
|
|
||||||
delete sensorMonitorRaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@ -107,7 +90,7 @@ protected:
|
|||||||
* @param inputTemperature
|
* @param inputTemperature
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual float calculateOutputTemperature(T inputValue) {
|
virtual float calculateOutputTemperature(inputType inputValue) {
|
||||||
return parameters.a * inputValue * inputValue
|
return parameters.a * inputValue * inputValue
|
||||||
+ parameters.b * inputValue + parameters.c;
|
+ parameters.b * inputValue + parameters.c;
|
||||||
}
|
}
|
||||||
@ -118,21 +101,20 @@ private:
|
|||||||
outputTemperature = INVALID_TEMPERATURE;
|
outputTemperature = INVALID_TEMPERATURE;
|
||||||
outputTemperature.setValid(false);
|
outputTemperature.setValid(false);
|
||||||
uptimeOfOldTemperature.tv_sec = INVALID_UPTIME;
|
uptimeOfOldTemperature.tv_sec = INVALID_UPTIME;
|
||||||
sensorMonitor->setToInvalid();
|
sensorMonitor.setToInvalid();
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
static const int32_t INVALID_UPTIME = 0;
|
static const int32_t INVALID_UPTIME = 0;
|
||||||
|
|
||||||
UsedParameters parameters;
|
UsedParameters parameters;
|
||||||
|
|
||||||
T * inputValue;
|
inputType * inputValue;
|
||||||
|
|
||||||
PoolVariableIF *poolVariable;
|
PoolVariableIF *poolVariable;
|
||||||
|
|
||||||
PoolVariable<float> outputTemperature;
|
PoolVariable<float> outputTemperature;
|
||||||
|
|
||||||
LimitMonitor<T> * sensorMonitorRaw;
|
LimitMonitor<limitType> sensorMonitor;
|
||||||
LimitMonitor<float> * sensorMonitor;
|
|
||||||
|
|
||||||
float oldTemperature;
|
float oldTemperature;
|
||||||
timeval uptimeOfOldTemperature;
|
timeval uptimeOfOldTemperature;
|
||||||
@ -171,9 +153,9 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check is done against raw limits. SHOULDDO: Why? Using °C would be more easy to handle.
|
//Check is done against raw limits. SHOULDDO: Why? Using °C would be more easy to handle.
|
||||||
sensorMonitor->doCheck(outputTemperature.value);
|
sensorMonitor.doCheck(outputTemperature.value);
|
||||||
|
|
||||||
if (sensorMonitor->isOutOfLimits()) {
|
if (sensorMonitor.isOutOfLimits()) {
|
||||||
uptimeOfOldTemperature.tv_sec = INVALID_UPTIME;
|
uptimeOfOldTemperature.tv_sec = INVALID_UPTIME;
|
||||||
outputTemperature.setValid(PoolVariableIF::INVALID);
|
outputTemperature.setValid(PoolVariableIF::INVALID);
|
||||||
outputTemperature = INVALID_TEMPERATURE;
|
outputTemperature = INVALID_TEMPERATURE;
|
||||||
@ -204,7 +186,7 @@ public:
|
|||||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||||
ParameterWrapper *parameterWrapper,
|
ParameterWrapper *parameterWrapper,
|
||||||
const ParameterWrapper *newValues, uint16_t startAtIndex) {
|
const ParameterWrapper *newValues, uint16_t startAtIndex) {
|
||||||
ReturnValue_t result = sensorMonitor->getParameter(domainId, parameterId,
|
ReturnValue_t result = sensorMonitor.getParameter(domainId, parameterId,
|
||||||
parameterWrapper, newValues, startAtIndex);
|
parameterWrapper, newValues, startAtIndex);
|
||||||
if (result != INVALID_DOMAIN_ID) {
|
if (result != INVALID_DOMAIN_ID) {
|
||||||
return result;
|
return result;
|
||||||
@ -232,7 +214,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void resetOldState() {
|
virtual void resetOldState() {
|
||||||
sensorMonitor->setToUnchecked();
|
sensorMonitor.setToUnchecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user