WIP: somethings wrong.. #19
@ -16,12 +16,13 @@ public:
|
|||||||
uint16_t confirmationLimit, T lowerLimit, T upperLimit,
|
uint16_t confirmationLimit, T lowerLimit, T upperLimit,
|
||||||
Event belowLowEvent = MonitoringIF::VALUE_BELOW_LOW_LIMIT,
|
Event belowLowEvent = MonitoringIF::VALUE_BELOW_LOW_LIMIT,
|
||||||
Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) :
|
Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) :
|
||||||
MonitorBase<T>(reporterId, monitorId, parameterId, confirmationLimit), lowerLimit(
|
MonitorBase<T>(reporterId, monitorId, parameterId, confirmationLimit),
|
||||||
lowerLimit), upperLimit(upperLimit), belowLowEvent(
|
lowerLimit(lowerLimit), upperLimit(upperLimit), belowLowEvent(belowLowEvent),
|
||||||
belowLowEvent), aboveHighEvent(aboveHighEvent) {
|
aboveHighEvent(aboveHighEvent) {
|
||||||
}
|
|
||||||
virtual ~LimitMonitor() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~LimitMonitor() {}
|
||||||
|
|
||||||
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) {
|
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) {
|
||||||
*crossedLimit = 0.0;
|
*crossedLimit = 0.0;
|
||||||
if (sample > upperLimit) {
|
if (sample > upperLimit) {
|
||||||
|
@ -1,105 +1,142 @@
|
|||||||
#ifndef TEMPERATURESENSOR_H_
|
#ifndef TEMPERATURESENSOR_H_
|
||||||
#define TEMPERATURESENSOR_H_
|
#define TEMPERATURESENSOR_H_
|
||||||
|
|
||||||
|
#include <framework/thermal/AbstractTemperatureSensor.h>
|
||||||
#include <framework/datapool/DataSet.h>
|
#include <framework/datapool/DataSet.h>
|
||||||
#include "AbstractTemperatureSensor.h"
|
|
||||||
#include <framework/monitoring/LimitMonitor.h>
|
#include <framework/monitoring/LimitMonitor.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This building block handles non-linear value conversion and
|
* @brief This building block handles non-linear value conversion and
|
||||||
* range checks for analog temperature sensors.
|
* range checks for analog temperature sensors.
|
||||||
* @details HOW TO USE
|
* @details This class can be used to perform all necessary tasks for temperature sensors.
|
||||||
|
* A sensor can be instantiated by calling the constructor.
|
||||||
|
* The temperature is calculated from an input value with
|
||||||
|
* the calculateOutputTemperature() function. Range checking and
|
||||||
|
* limit monitoring is performed automatically.
|
||||||
*
|
*
|
||||||
|
* @ingroup thermal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class TemperatureSensor: public AbstractTemperatureSensor {
|
class TemperatureSensor: public AbstractTemperatureSensor {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What are a,b and c?
|
* This structure contains parameters required for range checking
|
||||||
|
* and the conversion from the input value to the output temperature.
|
||||||
|
* a, b and c can be any parameters required to calculate the output
|
||||||
|
* temperature from the input value, for example parameters for the
|
||||||
|
* Callendar-Van-Dusen equation(see datasheet of used sensor / ADC)
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* format
|
||||||
*/
|
*/
|
||||||
struct Parameters {
|
struct Parameters {
|
||||||
float a;
|
float a;
|
||||||
float b;
|
float b;
|
||||||
float c;
|
float c;
|
||||||
T lowerLimit;
|
float maxGradient;
|
||||||
T upperLimit;
|
|
||||||
float gradient;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How to use me.
|
* Forward declaration for explicit instantiation of used parameters.
|
||||||
* @param setObjectid
|
|
||||||
* @param inputTemperature
|
|
||||||
* @param poolVariable
|
|
||||||
* @param vectorIndex
|
|
||||||
* @param parameters
|
|
||||||
* @param datapoolId
|
|
||||||
* @param outputSet
|
|
||||||
* @param thermalModule
|
|
||||||
*/
|
*/
|
||||||
TemperatureSensor(object_id_t setObjectid,
|
|
||||||
T *inputTemperature, PoolVariableIF *poolVariable,
|
|
||||||
uint8_t vectorIndex, Parameters parameters, uint32_t datapoolId,
|
|
||||||
DataSet *outputSet, ThermalModuleIF *thermalModule) :
|
|
||||||
|
|
||||||
AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters),
|
|
||||||
inputTemperature(inputTemperature), poolVariable(poolVariable),
|
|
||||||
outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE),
|
|
||||||
sensorMonitor(setObjectid, DOMAIN_ID_SENSOR,
|
|
||||||
DataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex),
|
|
||||||
DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit,parameters.upperLimit,
|
|
||||||
TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH),
|
|
||||||
oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) {
|
|
||||||
}
|
|
||||||
|
|
||||||
struct UsedParameters {
|
struct UsedParameters {
|
||||||
UsedParameters(Parameters parameters) :
|
UsedParameters(Parameters parameters) :
|
||||||
a(parameters.a), b(parameters.b), c(parameters.c),
|
a(parameters.a), b(parameters.b), c(parameters.c),
|
||||||
gradient(parameters.gradient) {}
|
gradient(parameters.maxGradient) {}
|
||||||
float a;
|
float a;
|
||||||
float b;
|
float b;
|
||||||
float c;
|
float c;
|
||||||
float gradient;
|
float gradient;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t ADDRESS_A = 0;
|
/**
|
||||||
static const uint16_t ADDRESS_B = 1;
|
* Constructor to check against raw input values
|
||||||
static const uint16_t ADDRESS_C = 2;
|
* @param setObjectid objectId of the sensor object
|
||||||
static const uint16_t ADDRESS_GRADIENT = 3;
|
* @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
|
||||||
|
*/
|
||||||
|
TemperatureSensor(object_id_t setObjectid,
|
||||||
|
T *inputValue, T lowerLimit, T 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 })
|
||||||
|
{
|
||||||
|
sensorMonitorRaw = new LimitMonitor<T>(setObjectid, DOMAIN_ID_SENSOR,
|
||||||
|
DataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex),
|
||||||
|
DEFAULT_CONFIRMATION_COUNT, lowerLimit, upperLimit,
|
||||||
|
TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH);
|
||||||
|
delete sensorMonitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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:
|
||||||
|
/**
|
||||||
|
* This formula is used to calculate the temperature from an input value
|
||||||
|
* with an arbitrary type.
|
||||||
|
* A default implementation is provided but can be replaced depending
|
||||||
|
* on the required calculation.
|
||||||
|
* @param inputTemperature
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual float calculateOutputTemperature(T inputValue) {
|
||||||
|
return parameters.a * inputValue * inputValue
|
||||||
|
+ parameters.b * inputValue + parameters.c;
|
||||||
|
}
|
||||||
|
|
||||||
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.)
|
|
||||||
|
|
||||||
static const uint8_t DOMAIN_ID_SENSOR = 1;
|
|
||||||
private:
|
private:
|
||||||
void setInvalid() {
|
void setInvalid() {
|
||||||
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 *inputTemperature;
|
T * inputValue;
|
||||||
|
|
||||||
PoolVariableIF *poolVariable;
|
PoolVariableIF *poolVariable;
|
||||||
|
|
||||||
PoolVariable<float> outputTemperature;
|
PoolVariable<float> outputTemperature;
|
||||||
|
|
||||||
LimitMonitor<T> sensorMonitor;
|
LimitMonitor<T> * sensorMonitorRaw;
|
||||||
|
LimitMonitor<float> * sensorMonitor;
|
||||||
|
|
||||||
float oldTemperature;
|
float oldTemperature;
|
||||||
timeval uptimeOfOldTemperature;
|
timeval uptimeOfOldTemperature;
|
||||||
|
|
||||||
virtual float calculateOutputTemperature(T inputTemperature) {
|
|
||||||
return parameters.a * inputTemperature * inputTemperature
|
|
||||||
+ parameters.b * inputTemperature + parameters.c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void doChildOperation() {
|
void doChildOperation() {
|
||||||
if (!poolVariable->isValid()
|
if (!poolVariable->isValid()
|
||||||
|| !healthHelper.healthTable->isHealthy(getObjectId())) {
|
|| !healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||||
@ -107,7 +144,7 @@ protected:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
outputTemperature = calculateOutputTemperature(*inputTemperature);
|
outputTemperature = calculateOutputTemperature(*inputValue);
|
||||||
outputTemperature.setValid(PoolVariableIF::VALID);
|
outputTemperature.setValid(PoolVariableIF::VALID);
|
||||||
|
|
||||||
timeval uptime;
|
timeval uptime;
|
||||||
@ -115,7 +152,7 @@ protected:
|
|||||||
|
|
||||||
if (uptimeOfOldTemperature.tv_sec != INVALID_UPTIME) {
|
if (uptimeOfOldTemperature.tv_sec != INVALID_UPTIME) {
|
||||||
//In theory, we could use an AbsValueMonitor to monitor the gradient.
|
//In theory, we could use an AbsValueMonitor to monitor the gradient.
|
||||||
//But this would require storing the gradient in DP and quite some overhead.
|
//But this would require storing the maxGradient in DP and quite some overhead.
|
||||||
//The concept of delta limits is a bit strange anyway.
|
//The concept of delta limits is a bit strange anyway.
|
||||||
float deltaTime;
|
float deltaTime;
|
||||||
float deltaTemp;
|
float deltaTemp;
|
||||||
@ -133,10 +170,10 @@ 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(*inputTemperature);
|
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;
|
||||||
@ -155,10 +192,19 @@ public:
|
|||||||
return outputTemperature.isValid();
|
return outputTemperature.isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const uint16_t ADDRESS_A = 0;
|
||||||
|
static const uint16_t ADDRESS_B = 1;
|
||||||
|
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.)
|
||||||
|
|
||||||
|
static const uint8_t DOMAIN_ID_SENSOR = 1;
|
||||||
|
|
||||||
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;
|
||||||
@ -186,7 +232,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void resetOldState() {
|
virtual void resetOldState() {
|
||||||
sensorMonitor.setToUnchecked();
|
sensorMonitor->setToUnchecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user