fsfw/monitoring/MonitorBase.h

71 lines
2.1 KiB
C
Raw Normal View History

2020-10-12 17:42:30 +02:00
#ifndef FSFW_MONITORING_MONITORBASE_H_
#define FSFW_MONITORING_MONITORBASE_H_
2020-08-28 18:33:29 +02:00
2020-09-29 18:01:55 +02:00
#include "LimitViolationReporter.h"
#include "MonitoringIF.h"
#include "MonitoringMessageContent.h"
#include "MonitorReporter.h"
2020-08-28 18:33:29 +02:00
2020-10-12 17:42:30 +02:00
#include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/PIDReader.h"
2020-08-28 18:33:29 +02:00
/**
2020-10-12 17:42:30 +02:00
* @brief Base class for monitoring of parameters.
* @details
* Can be used anywhere, specializations need to implement checkSample and
* should override sendTransitionEvent.
* Manages state handling, enabling and disabling of events/reports and
* forwarding of transition reports via MonitorReporter.
*
* In addition, it provides default implementations for fetching the
* parameter sample from the data pool and a simple confirmation counter.
2020-08-28 18:33:29 +02:00
*/
template<typename T>
class MonitorBase: public MonitorReporter<T> {
public:
MonitorBase(object_id_t reporterId, uint8_t monitorId,
uint32_t parameterId, uint16_t confirmationLimit) :
2020-10-12 17:42:30 +02:00
MonitorReporter<T>(reporterId, monitorId, parameterId,
confirmationLimit) {
2020-08-28 18:33:29 +02:00
}
virtual ~MonitorBase() {
}
virtual ReturnValue_t check() {
2020-10-12 17:42:30 +02:00
// 1. Fetch sample of type T, return validity.
2020-08-28 18:33:29 +02:00
T sample = 0;
ReturnValue_t validity = fetchSample(&sample);
2020-10-12 17:42:30 +02:00
// 2. If returning from fetch != OK, parameter is invalid.
// Report (if oldState is != invalidity).
2020-08-28 18:33:29 +02:00
if (validity != HasReturnvaluesIF::RETURN_OK) {
this->monitorStateIs(validity, sample, 0);
//3. Otherwise, check sample.
} else {
this->oldState = doCheck(sample);
}
return this->oldState;
}
virtual ReturnValue_t doCheck(T sample) {
T crossedLimit = 0.0;
ReturnValue_t currentState = checkSample(sample, &crossedLimit);
return this->monitorStateIs(currentState,sample, crossedLimit);
}
2020-10-12 17:42:30 +02:00
// Abstract or default.
2020-08-28 18:33:29 +02:00
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) = 0;
protected:
virtual ReturnValue_t fetchSample(T* sample) {
GlobDataSet mySet;
PIDReader<T> parameter(this->parameterId, &mySet);
mySet.read();
if (!parameter.isValid()) {
return MonitoringIF::INVALID;
}
*sample = parameter.value;
return HasReturnvaluesIF::RETURN_OK;
}
};
2020-10-12 17:42:30 +02:00
#endif /* FSFW_MONITORING_MONITORBASE_H_ */