fsfw/monitoring/AbsLimitMonitor.h

82 lines
2.2 KiB
C
Raw Normal View History

2020-10-12 17:39:13 +02:00
#ifndef FSFW_MONITORING_ABSLIMITMONITOR_H_
#define FSFW_MONITORING_ABSLIMITMONITOR_H_
2020-08-28 18:33:29 +02:00
2020-09-29 18:01:55 +02:00
#include "MonitorBase.h"
2020-08-28 18:33:29 +02:00
#include <cmath>
template<typename T>
class AbsLimitMonitor: public MonitorBase<T> {
public:
2020-10-12 17:39:13 +02:00
AbsLimitMonitor(object_id_t reporterId, uint8_t monitorId,
2020-11-18 21:15:14 +01:00
object_id_t dataCreatorId, lp_id_t localPoolId,
uint16_t confirmationLimit, T limit,
2020-10-12 17:39:13 +02:00
Event violationEvent = MonitoringIF::VALUE_OUT_OF_RANGE,
bool aboveIsViolation = true) :
2020-11-18 21:15:14 +01:00
MonitorBase<T>(reporterId, monitorId, dataCreatorId, localPoolId,
2020-10-12 17:39:13 +02:00
confirmationLimit),
limit(limit), violationEvent(violationEvent),
aboveIsViolation(aboveIsViolation) {
2020-08-28 18:33:29 +02:00
}
virtual ~AbsLimitMonitor() {
}
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) {
*crossedLimit = limit;
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-10-12 17:39:13 +02:00
// We'll reuse the DOMAIN_ID of MonitorReporter,
// as we know the parameterIds used there.
2020-10-18 23:50:02 +02:00
if (result != this->INVALID_IDENTIFIER_ID) {
2020-08-28 18:33:29 +02:00
return result;
}
switch (parameterId) {
case 10:
parameterWrapper->set(this->limit);
break;
default:
2020-10-18 23:50:02 +02:00
return this->INVALID_IDENTIFIER_ID;
2020-08-28 18:33:29 +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-10-12 17:39:13 +02:00
EventManagerIF::triggerEvent(this->reportingId,
violationEvent, this->parameterId);
2020-08-28 18:33:29 +02:00
break;
default:
break;
}
}
T limit;
const Event violationEvent;
const bool aboveIsViolation;
};
2020-10-12 17:39:13 +02:00
#endif /* FSFW_MONITORING_ABSLIMITMONITOR_H_ */