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"
|
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.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class LimitMonitor: public MonitorBase<T> {
|
|
|
|
public:
|
2020-12-03 18:24:51 +01:00
|
|
|
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,
|
2016-06-15 23:48:41 +02:00
|
|
|
Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) :
|
2020-12-03 18:24:51 +01:00
|
|
|
MonitorBase<T>(reporterId, monitorId, globalPoolId,
|
|
|
|
confirmationLimit),
|
|
|
|
lowerLimit(lowerLimit), upperLimit(upperLimit),
|
|
|
|
belowLowEvent(belowLowEvent), aboveHighEvent(aboveHighEvent) {
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
virtual ~LimitMonitor() {
|
|
|
|
}
|
|
|
|
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) {
|
2018-07-12 16:29:32 +02:00
|
|
|
*crossedLimit = 0.0;
|
2016-06-15 23:48:41 +02:00
|
|
|
if (sample > upperLimit) {
|
|
|
|
*crossedLimit = upperLimit;
|
|
|
|
return MonitoringIF::ABOVE_HIGH_LIMIT;
|
|
|
|
} else if (sample < lowerLimit) {
|
|
|
|
*crossedLimit = lowerLimit;
|
|
|
|
return MonitoringIF::BELOW_LOW_LIMIT;
|
|
|
|
} else {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK; //Within limits.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-29 22:45:53 +01:00
|
|
|
virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
|
|
|
|
ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues,
|
|
|
|
uint16_t startAtIndex) {
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t result = this->MonitorBase<T>::getParameter(domainId,
|
2021-01-29 22:45:53 +01:00
|
|
|
uniqueId, parameterWrapper, newValues, startAtIndex);
|
2016-06-15 23:48:41 +02:00
|
|
|
//We'll reuse the DOMAIN_ID of MonitorReporter, as we know the parameterIds used there.
|
2020-12-03 18:24:51 +01:00
|
|
|
if (result != this->INVALID_IDENTIFIER_ID) {
|
2016-06-15 23:48:41 +02:00
|
|
|
return result;
|
|
|
|
}
|
2021-01-29 22:45:53 +01:00
|
|
|
switch (uniqueId) {
|
2016-06-15 23:48:41 +02:00
|
|
|
case 10:
|
|
|
|
parameterWrapper->set(this->lowerLimit);
|
|
|
|
break;
|
|
|
|
case 11:
|
2018-07-12 16:29:32 +02:00
|
|
|
parameterWrapper->set(this->upperLimit);
|
2016-06-15 23:48:41 +02:00
|
|
|
break;
|
|
|
|
default:
|
2020-12-03 18:24:51 +01:00
|
|
|
return this->INVALID_IDENTIFIER_ID;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
bool isOutOfLimits() {
|
2020-12-03 18:24:51 +01:00
|
|
|
if (this->oldState == MonitoringIF::ABOVE_HIGH_LIMIT or
|
|
|
|
this->oldState == MonitoringIF::BELOW_LOW_LIMIT) {
|
2016-06-15 23:48:41 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
T getLowerLimit() const {
|
|
|
|
return lowerLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
T getUpperLimit() const {
|
|
|
|
return upperLimit;
|
|
|
|
}
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
protected:
|
|
|
|
void sendTransitionEvent(T currentValue, ReturnValue_t state) {
|
|
|
|
switch (state) {
|
|
|
|
case MonitoringIF::BELOW_LOW_LIMIT:
|
2020-12-03 18:24:51 +01:00
|
|
|
EventManagerIF::triggerEvent(this->reportingId, belowLowEvent,
|
|
|
|
this->globalPoolId.objectId, this->globalPoolId.localPoolId);
|
2016-06-15 23:48:41 +02:00
|
|
|
break;
|
|
|
|
case MonitoringIF::ABOVE_HIGH_LIMIT:
|
2020-12-03 18:24:51 +01:00
|
|
|
EventManagerIF::triggerEvent(this->reportingId, aboveHighEvent,
|
|
|
|
this->globalPoolId.objectId, this->globalPoolId.localPoolId);
|
2016-06-15 23:48:41 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
T lowerLimit;
|
|
|
|
T upperLimit;
|
|
|
|
const Event belowLowEvent;
|
|
|
|
const Event aboveHighEvent;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FRAMEWORK_MONITORING_LIMITMONITOR_H_ */
|