2016-06-15 23:48:41 +02:00
|
|
|
#ifndef FRAMEWORK_MONITORING_LIMITMONITOR_H_
|
|
|
|
#define FRAMEWORK_MONITORING_LIMITMONITOR_H_
|
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "MonitorBase.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "monitoringConf.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Variant of a limit checking class.
|
|
|
|
* Newer version as compared to LimitCheckMonitor.
|
|
|
|
* Functionality is more or less the same, but does not use
|
|
|
|
* heavy weight MonitoringIF.
|
|
|
|
*/
|
2022-02-02 10:29:30 +01:00
|
|
|
template <typename T>
|
|
|
|
class LimitMonitor : public MonitorBase<T> {
|
|
|
|
public:
|
|
|
|
LimitMonitor(object_id_t reporterId, uint8_t monitorId, gp_id_t globalPoolId,
|
|
|
|
uint16_t confirmationLimit, T lowerLimit, T upperLimit,
|
|
|
|
Event belowLowEvent = MonitoringIF::VALUE_BELOW_LOW_LIMIT,
|
|
|
|
Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT)
|
|
|
|
: MonitorBase<T>(reporterId, monitorId, globalPoolId, confirmationLimit),
|
|
|
|
lowerLimit(lowerLimit),
|
|
|
|
upperLimit(upperLimit),
|
|
|
|
belowLowEvent(belowLowEvent),
|
|
|
|
aboveHighEvent(aboveHighEvent) {}
|
|
|
|
virtual ~LimitMonitor() {}
|
|
|
|
virtual ReturnValue_t checkSample(T sample, T *crossedLimit) {
|
|
|
|
*crossedLimit = 0.0;
|
|
|
|
if (sample > upperLimit) {
|
|
|
|
*crossedLimit = upperLimit;
|
|
|
|
return MonitoringIF::ABOVE_HIGH_LIMIT;
|
|
|
|
} else if (sample < lowerLimit) {
|
|
|
|
*crossedLimit = lowerLimit;
|
|
|
|
return MonitoringIF::BELOW_LOW_LIMIT;
|
|
|
|
} else {
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::OK; // Within limits.
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
|
|
|
|
ParameterWrapper *parameterWrapper,
|
|
|
|
const ParameterWrapper *newValues, uint16_t startAtIndex) {
|
|
|
|
ReturnValue_t result = this->MonitorBase<T>::getParameter(domainId, uniqueId, parameterWrapper,
|
|
|
|
newValues, startAtIndex);
|
|
|
|
// We'll reuse the DOMAIN_ID of MonitorReporter, as we know the parameterIds used there.
|
|
|
|
if (result != this->INVALID_IDENTIFIER_ID) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
switch (uniqueId) {
|
|
|
|
case 10:
|
|
|
|
parameterWrapper->set(this->lowerLimit);
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
parameterWrapper->set(this->upperLimit);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return this->INVALID_IDENTIFIER_ID;
|
|
|
|
}
|
2022-08-16 01:08:26 +02:00
|
|
|
return returnvalue::OK;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
bool isOutOfLimits() {
|
|
|
|
if (this->oldState == MonitoringIF::ABOVE_HIGH_LIMIT or
|
|
|
|
this->oldState == MonitoringIF::BELOW_LOW_LIMIT) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
T getLowerLimit() const { return lowerLimit; }
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
T getUpperLimit() const { return upperLimit; }
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
protected:
|
|
|
|
void sendTransitionEvent(T currentValue, ReturnValue_t state) {
|
|
|
|
switch (state) {
|
|
|
|
case MonitoringIF::BELOW_LOW_LIMIT:
|
|
|
|
EventManagerIF::triggerEvent(this->reportingId, belowLowEvent, this->globalPoolId.objectId,
|
|
|
|
this->globalPoolId.localPoolId);
|
|
|
|
break;
|
|
|
|
case MonitoringIF::ABOVE_HIGH_LIMIT:
|
|
|
|
EventManagerIF::triggerEvent(this->reportingId, aboveHighEvent, this->globalPoolId.objectId,
|
|
|
|
this->globalPoolId.localPoolId);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
T lowerLimit;
|
|
|
|
T upperLimit;
|
|
|
|
const Event belowLowEvent;
|
|
|
|
const Event aboveHighEvent;
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FRAMEWORK_MONITORING_LIMITMONITOR_H_ */
|