some more form improvements

This commit is contained in:
Robin Müller 2020-10-12 17:42:30 +02:00
parent 06c7919daa
commit 736ce2d5fd
2 changed files with 37 additions and 25 deletions

View File

@ -1,35 +1,42 @@
#ifndef MONITORBASE_H_ #ifndef FSFW_MONITORING_MONITORBASE_H_
#define MONITORBASE_H_ #define FSFW_MONITORING_MONITORBASE_H_
#include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/PIDReader.h"
#include "LimitViolationReporter.h" #include "LimitViolationReporter.h"
#include "MonitoringIF.h" #include "MonitoringIF.h"
#include "MonitoringMessageContent.h" #include "MonitoringMessageContent.h"
#include "MonitorReporter.h" #include "MonitorReporter.h"
#include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/PIDReader.h"
/** /**
* Base class for monitoring of parameters. * @brief Base class for monitoring of parameters.
* Can be used anywhere, specializations need to implement checkSample and should override sendTransitionEvent. * @details
* Manages state handling, enabling and disabling of events/reports and forwarding of transition * Can be used anywhere, specializations need to implement checkSample and
* reports via MonitorReporter. In addition, it provides default implementations for fetching the parameter sample from * should override sendTransitionEvent.
* the data pool and a simple confirmation counter. * 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.
*/ */
template<typename T> template<typename T>
class MonitorBase: public MonitorReporter<T> { class MonitorBase: public MonitorReporter<T> {
public: public:
MonitorBase(object_id_t reporterId, uint8_t monitorId, MonitorBase(object_id_t reporterId, uint8_t monitorId,
uint32_t parameterId, uint16_t confirmationLimit) : uint32_t parameterId, uint16_t confirmationLimit) :
MonitorReporter<T>(reporterId, monitorId, parameterId, confirmationLimit) { MonitorReporter<T>(reporterId, monitorId, parameterId,
confirmationLimit) {
} }
virtual ~MonitorBase() { virtual ~MonitorBase() {
} }
virtual ReturnValue_t check() { virtual ReturnValue_t check() {
//1. Fetch sample of type T, return validity. // 1. Fetch sample of type T, return validity.
T sample = 0; T sample = 0;
ReturnValue_t validity = fetchSample(&sample); ReturnValue_t validity = fetchSample(&sample);
//2. If returning from fetch != OK, parameter is invalid. Report (if oldState is != invalidity). // 2. If returning from fetch != OK, parameter is invalid.
// Report (if oldState is != invalidity).
if (validity != HasReturnvaluesIF::RETURN_OK) { if (validity != HasReturnvaluesIF::RETURN_OK) {
this->monitorStateIs(validity, sample, 0); this->monitorStateIs(validity, sample, 0);
//3. Otherwise, check sample. //3. Otherwise, check sample.
@ -43,7 +50,8 @@ public:
ReturnValue_t currentState = checkSample(sample, &crossedLimit); ReturnValue_t currentState = checkSample(sample, &crossedLimit);
return this->monitorStateIs(currentState,sample, crossedLimit); return this->monitorStateIs(currentState,sample, crossedLimit);
} }
//Abstract or default.
// Abstract or default.
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) = 0; virtual ReturnValue_t checkSample(T sample, T* crossedLimit) = 0;
protected: protected:
@ -59,4 +67,4 @@ protected:
} }
}; };
#endif /* MONITORBASE_H_ */ #endif /* FSFW_MONITORING_MONITORBASE_H_ */

View File

@ -1,10 +1,11 @@
#ifndef FRAMEWORK_MONITORING_MONITORREPORTER_H_ #ifndef FSFW_MONITORING_MONITORREPORTER_H_
#define FRAMEWORK_MONITORING_MONITORREPORTER_H_ #define FSFW_MONITORING_MONITORREPORTER_H_
#include "../events/EventManagerIF.h"
#include "LimitViolationReporter.h" #include "LimitViolationReporter.h"
#include "MonitoringIF.h" #include "MonitoringIF.h"
#include "MonitoringMessageContent.h" #include "MonitoringMessageContent.h"
#include "../events/EventManagerIF.h"
#include "../parameters/HasParametersIF.h" #include "../parameters/HasParametersIF.h"
template<typename T> template<typename T>
@ -14,11 +15,12 @@ public:
static const uint8_t ENABLED = 1; static const uint8_t ENABLED = 1;
static const uint8_t DISABLED = 0; static const uint8_t DISABLED = 0;
MonitorReporter(object_id_t reportingId, uint8_t monitorId, uint32_t parameterId, uint16_t confirmationLimit) : MonitorReporter(object_id_t reportingId, uint8_t monitorId,
monitorId(monitorId), parameterId(parameterId), reportingId( uint32_t parameterId, uint16_t confirmationLimit) :
reportingId), oldState(MonitoringIF::UNCHECKED), reportingEnabled( monitorId(monitorId), parameterId(parameterId),
ENABLED), eventEnabled(ENABLED), currentCounter(0), confirmationLimit( reportingId(reportingId), oldState(MonitoringIF::UNCHECKED),
confirmationLimit) { reportingEnabled(ENABLED), eventEnabled(ENABLED), currentCounter(0),
confirmationLimit(confirmationLimit) {
} }
virtual ~MonitorReporter() { virtual ~MonitorReporter() {
@ -148,7 +150,8 @@ protected:
case HasReturnvaluesIF::RETURN_OK: case HasReturnvaluesIF::RETURN_OK:
break; break;
default: default:
EventManagerIF::triggerEvent(reportingId, MonitoringIF::MONITOR_CHANGED_STATE, state); EventManagerIF::triggerEvent(reportingId,
MonitoringIF::MONITOR_CHANGED_STATE, state);
break; break;
} }
} }
@ -159,7 +162,8 @@ protected:
* @param crossedLimit The limit crossed (if applicable). * @param crossedLimit The limit crossed (if applicable).
* @param state Current state the monitor is in. * @param state Current state the monitor is in.
*/ */
virtual void sendTransitionReport(T parameterValue, T crossedLimit, ReturnValue_t state) { virtual void sendTransitionReport(T parameterValue, T crossedLimit,
ReturnValue_t state) {
MonitoringReportContent<T> report(parameterId, MonitoringReportContent<T> report(parameterId,
parameterValue, crossedLimit, oldState, state); parameterValue, crossedLimit, oldState, state);
LimitViolationReporter::sendLimitViolationReport(&report); LimitViolationReporter::sendLimitViolationReport(&report);
@ -175,4 +179,4 @@ protected:
} }
}; };
#endif /* FRAMEWORK_MONITORING_MONITORREPORTER_H_ */ #endif /* FSFW_MONITORING_MONITORREPORTER_H_ */