2020-12-03 18:24:51 +01:00
|
|
|
#ifndef FSFW_MONITORING_MONITORBASE_H_
|
|
|
|
#define FSFW_MONITORING_MONITORBASE_H_
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "LimitViolationReporter.h"
|
|
|
|
#include "MonitoringIF.h"
|
|
|
|
#include "MonitoringMessageContent.h"
|
|
|
|
#include "MonitorReporter.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-12-03 18:24:51 +01:00
|
|
|
#include "../datapoollocal/LocalPoolVariable.h"
|
|
|
|
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
/**
|
2020-12-03 18:24:51 +01: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.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class MonitorBase: public MonitorReporter<T> {
|
|
|
|
public:
|
2020-12-03 18:24:51 +01:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
MonitorBase(object_id_t reporterId, uint8_t monitorId,
|
2020-12-03 18:24:51 +01:00
|
|
|
gp_id_t globalPoolId, uint16_t confirmationLimit):
|
|
|
|
MonitorReporter<T>(reporterId, monitorId, globalPoolId,
|
|
|
|
confirmationLimit),
|
|
|
|
poolVariable(globalPoolId) {
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2020-12-03 18:24:51 +01:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
virtual ~MonitorBase() {
|
|
|
|
}
|
2020-12-03 18:24:51 +01:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
virtual ReturnValue_t check() {
|
2020-12-03 18:24:51 +01:00
|
|
|
// 1. Fetch sample of type T, return validity.
|
2016-06-15 23:48:41 +02:00
|
|
|
T sample = 0;
|
|
|
|
ReturnValue_t validity = fetchSample(&sample);
|
|
|
|
|
2020-12-03 18:24:51 +01:00
|
|
|
// 2. If returning from fetch != OK, parameter is invalid.
|
|
|
|
// Report (if oldState is != invalidity).
|
2016-06-15 23:48:41 +02:00
|
|
|
if (validity != HasReturnvaluesIF::RETURN_OK) {
|
2018-07-12 16:29:32 +02:00
|
|
|
this->monitorStateIs(validity, sample, 0);
|
2016-06-15 23:48:41 +02:00
|
|
|
} else {
|
2020-12-03 18:24:51 +01:00
|
|
|
//3. Otherwise, check sample.
|
2016-06-15 23:48:41 +02:00
|
|
|
this->oldState = doCheck(sample);
|
|
|
|
}
|
|
|
|
return this->oldState;
|
|
|
|
}
|
|
|
|
virtual ReturnValue_t doCheck(T sample) {
|
2018-07-12 16:29:32 +02:00
|
|
|
T crossedLimit = 0.0;
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t currentState = checkSample(sample, &crossedLimit);
|
|
|
|
return this->monitorStateIs(currentState,sample, crossedLimit);
|
|
|
|
}
|
2020-12-03 18:24:51 +01:00
|
|
|
|
|
|
|
// Abstract or default.
|
2016-06-15 23:48:41 +02:00
|
|
|
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) = 0;
|
|
|
|
|
|
|
|
protected:
|
2020-12-03 18:24:51 +01:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
virtual ReturnValue_t fetchSample(T* sample) {
|
2020-12-03 18:24:51 +01:00
|
|
|
ReturnValue_t result = poolVariable.read();
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (not poolVariable.isValid()) {
|
|
|
|
return MonitoringIF::INVALID;
|
|
|
|
}
|
|
|
|
*sample = poolVariable.value;
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2020-12-03 18:24:51 +01:00
|
|
|
|
|
|
|
LocalPoolVar<T> poolVariable;
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
2020-12-03 18:24:51 +01:00
|
|
|
#endif /* FSFW_MONITORING_MONITORBASE_H_ */
|