2020-12-03 18:24:51 +01:00
|
|
|
#ifndef FSFW_MONITORING_ABSLIMITMONITOR_H_
|
|
|
|
#define FSFW_MONITORING_ABSLIMITMONITOR_H_
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "MonitorBase.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class AbsLimitMonitor: public MonitorBase<T> {
|
|
|
|
public:
|
2020-12-03 18:24:51 +01:00
|
|
|
AbsLimitMonitor(object_id_t reporterId, uint8_t monitorId,
|
|
|
|
gp_id_t globalPoolId, uint16_t confirmationLimit, T limit,
|
|
|
|
Event violationEvent = MonitoringIF::VALUE_OUT_OF_RANGE,
|
|
|
|
bool aboveIsViolation = true) :
|
|
|
|
MonitorBase<T>(reporterId, monitorId, globalPoolId,
|
|
|
|
confirmationLimit),
|
|
|
|
limit(limit), violationEvent(violationEvent),
|
|
|
|
aboveIsViolation(aboveIsViolation) {
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
virtual ~AbsLimitMonitor() {
|
|
|
|
}
|
|
|
|
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) {
|
2018-07-12 16:29:32 +02:00
|
|
|
*crossedLimit = limit;
|
2016-06-15 23:48:41 +02:00
|
|
|
if (aboveIsViolation) {
|
|
|
|
if ((std::abs(sample) > limit)) {
|
|
|
|
return MonitoringIF::OUT_OF_RANGE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((std::abs(sample) < limit)) {
|
|
|
|
return MonitoringIF::OUT_OF_RANGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK; //We're not out of range.
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
|
|
|
ParameterWrapper *parameterWrapper,
|
|
|
|
const ParameterWrapper *newValues, uint16_t startAtIndex) {
|
|
|
|
ReturnValue_t result = this->MonitorBase<T>::getParameter(domainId,
|
|
|
|
parameterId, parameterWrapper, newValues, startAtIndex);
|
2020-12-03 18:24:51 +01:00
|
|
|
// We'll reuse the DOMAIN_ID of MonitorReporter,
|
|
|
|
// as we know the parameterIds used there.
|
|
|
|
if (result != this->INVALID_IDENTIFIER_ID) {
|
2016-06-15 23:48:41 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
switch (parameterId) {
|
|
|
|
case 10:
|
|
|
|
parameterWrapper->set(this->limit);
|
|
|
|
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() {
|
|
|
|
if (this->oldState == MonitoringIF::OUT_OF_RANGE) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void setLimit(T value) {
|
|
|
|
limit = value;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
void sendTransitionEvent(T currentValue, ReturnValue_t state) {
|
|
|
|
switch (state) {
|
|
|
|
case MonitoringIF::OUT_OF_RANGE:
|
2020-12-03 18:24:51 +01:00
|
|
|
EventManagerIF::triggerEvent(this->reportingId,
|
|
|
|
violationEvent, this->globalPoolId.objectId,
|
|
|
|
this->globalPoolId.localPoolId);
|
2016-06-15 23:48:41 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
T limit;
|
|
|
|
const Event violationEvent;
|
|
|
|
const bool aboveIsViolation;
|
|
|
|
};
|
|
|
|
|
2020-12-03 18:24:51 +01:00
|
|
|
#endif /* FSFW_MONITORING_ABSLIMITMONITOR_H_ */
|