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,26 +1,32 @@
#ifndef MONITORBASE_H_
#define MONITORBASE_H_
#ifndef FSFW_MONITORING_MONITORBASE_H_
#define FSFW_MONITORING_MONITORBASE_H_
#include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/PIDReader.h"
#include "LimitViolationReporter.h"
#include "MonitoringIF.h"
#include "MonitoringMessageContent.h"
#include "MonitorReporter.h"
#include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/PIDReader.h"
/**
* Base class for monitoring of parameters.
* 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.
* @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.
*/
template<typename T>
class MonitorBase: public MonitorReporter<T> {
public:
MonitorBase(object_id_t reporterId, uint8_t monitorId,
uint32_t parameterId, uint16_t confirmationLimit) :
MonitorReporter<T>(reporterId, monitorId, parameterId, confirmationLimit) {
MonitorReporter<T>(reporterId, monitorId, parameterId,
confirmationLimit) {
}
virtual ~MonitorBase() {
}
@ -29,7 +35,8 @@ public:
T sample = 0;
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) {
this->monitorStateIs(validity, sample, 0);
//3. Otherwise, check sample.
@ -43,6 +50,7 @@ public:
ReturnValue_t currentState = checkSample(sample, &crossedLimit);
return this->monitorStateIs(currentState,sample, crossedLimit);
}
// Abstract or default.
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) = 0;
@ -59,4 +67,4 @@ protected:
}
};
#endif /* MONITORBASE_H_ */
#endif /* FSFW_MONITORING_MONITORBASE_H_ */

View File

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