Merge pull request 'monitoring update' (#294) from KSat/fsfw:mueller/monitoring-update into development

Reviewed-on: fsfw/fsfw#294
This commit is contained in:
Steffen Gaisser 2020-12-10 16:24:00 +01:00
commit 4fbebcb019
8 changed files with 131 additions and 92 deletions

View File

@ -1,5 +1,5 @@
#ifndef FRAMEWORK_MONITORING_ABSLIMITMONITOR_H_ #ifndef FSFW_MONITORING_ABSLIMITMONITOR_H_
#define FRAMEWORK_MONITORING_ABSLIMITMONITOR_H_ #define FSFW_MONITORING_ABSLIMITMONITOR_H_
#include "MonitorBase.h" #include "MonitorBase.h"
#include <cmath> #include <cmath>
@ -7,9 +7,14 @@
template<typename T> template<typename T>
class AbsLimitMonitor: public MonitorBase<T> { class AbsLimitMonitor: public MonitorBase<T> {
public: public:
AbsLimitMonitor(object_id_t reporterId, uint8_t monitorId, uint32_t parameterId, AbsLimitMonitor(object_id_t reporterId, uint8_t monitorId,
uint16_t confirmationLimit, T limit, Event violationEvent = MonitoringIF::VALUE_OUT_OF_RANGE, bool aboveIsViolation = true) : gp_id_t globalPoolId, uint16_t confirmationLimit, T limit,
MonitorBase<T>(reporterId, monitorId, parameterId, confirmationLimit), limit(limit), violationEvent(violationEvent), aboveIsViolation(aboveIsViolation) { Event violationEvent = MonitoringIF::VALUE_OUT_OF_RANGE,
bool aboveIsViolation = true) :
MonitorBase<T>(reporterId, monitorId, globalPoolId,
confirmationLimit),
limit(limit), violationEvent(violationEvent),
aboveIsViolation(aboveIsViolation) {
} }
virtual ~AbsLimitMonitor() { virtual ~AbsLimitMonitor() {
} }
@ -32,8 +37,9 @@ public:
const ParameterWrapper *newValues, uint16_t startAtIndex) { const ParameterWrapper *newValues, uint16_t startAtIndex) {
ReturnValue_t result = this->MonitorBase<T>::getParameter(domainId, ReturnValue_t result = this->MonitorBase<T>::getParameter(domainId,
parameterId, parameterWrapper, newValues, startAtIndex); parameterId, parameterWrapper, newValues, startAtIndex);
//We'll reuse the DOMAIN_ID of MonitorReporter, as we know the parameterIds used there. // We'll reuse the DOMAIN_ID of MonitorReporter,
if (result != this->INVALID_MATRIX_ID) { // as we know the parameterIds used there.
if (result != this->INVALID_IDENTIFIER_ID) {
return result; return result;
} }
switch (parameterId) { switch (parameterId) {
@ -41,7 +47,7 @@ public:
parameterWrapper->set(this->limit); parameterWrapper->set(this->limit);
break; break;
default: default:
return this->INVALID_MATRIX_ID; return this->INVALID_IDENTIFIER_ID;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -59,7 +65,9 @@ protected:
void sendTransitionEvent(T currentValue, ReturnValue_t state) { void sendTransitionEvent(T currentValue, ReturnValue_t state) {
switch (state) { switch (state) {
case MonitoringIF::OUT_OF_RANGE: case MonitoringIF::OUT_OF_RANGE:
EventManagerIF::triggerEvent(this->reportingId, violationEvent, this->parameterId); EventManagerIF::triggerEvent(this->reportingId,
violationEvent, this->globalPoolId.objectId,
this->globalPoolId.localPoolId);
break; break;
default: default:
break; break;
@ -70,4 +78,4 @@ protected:
const bool aboveIsViolation; const bool aboveIsViolation;
}; };
#endif /* FRAMEWORK_MONITORING_ABSLIMITMONITOR_H_ */ #endif /* FSFW_MONITORING_ABSLIMITMONITOR_H_ */

View File

@ -1,11 +1,5 @@
/** #ifndef FSFW_MONITORING_HASMONITORSIF_H_
* @file HasMonitorsIF.h #define FSFW_MONITORING_HASMONITORSIF_H_
* @brief This file defines the HasMonitorsIF class.
* @date 28.07.2014
* @author baetz
*/
#ifndef HASMONITORSIF_H_
#define HASMONITORSIF_H_
#include "../events/EventReportingProxyIF.h" #include "../events/EventReportingProxyIF.h"
#include "../objectmanager/ObjectManagerIF.h" #include "../objectmanager/ObjectManagerIF.h"
@ -27,4 +21,4 @@ public:
} }
}; };
#endif /* HASMONITORSIF_H_ */ #endif /* FSFW_MONITORING_HASMONITORSIF_H_ */

View File

@ -12,13 +12,15 @@
template<typename T> template<typename T>
class LimitMonitor: public MonitorBase<T> { class LimitMonitor: public MonitorBase<T> {
public: public:
LimitMonitor(object_id_t reporterId, uint8_t monitorId, uint32_t parameterId, LimitMonitor(object_id_t reporterId, uint8_t monitorId,
uint16_t confirmationLimit, T lowerLimit, T upperLimit, gp_id_t globalPoolId, uint16_t confirmationLimit, T lowerLimit,
Event belowLowEvent = MonitoringIF::VALUE_BELOW_LOW_LIMIT, T upperLimit, Event belowLowEvent =
MonitoringIF::VALUE_BELOW_LOW_LIMIT,
Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) : Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) :
MonitorBase<T>(reporterId, monitorId, parameterId, confirmationLimit), lowerLimit( MonitorBase<T>(reporterId, monitorId, globalPoolId,
lowerLimit), upperLimit(upperLimit), belowLowEvent( confirmationLimit),
belowLowEvent), aboveHighEvent(aboveHighEvent) { lowerLimit(lowerLimit), upperLimit(upperLimit),
belowLowEvent(belowLowEvent), aboveHighEvent(aboveHighEvent) {
} }
virtual ~LimitMonitor() { virtual ~LimitMonitor() {
} }
@ -41,7 +43,7 @@ public:
ReturnValue_t result = this->MonitorBase<T>::getParameter(domainId, ReturnValue_t result = this->MonitorBase<T>::getParameter(domainId,
parameterId, parameterWrapper, newValues, startAtIndex); parameterId, parameterWrapper, newValues, startAtIndex);
//We'll reuse the DOMAIN_ID of MonitorReporter, as we know the parameterIds used there. //We'll reuse the DOMAIN_ID of MonitorReporter, as we know the parameterIds used there.
if (result != this->INVALID_MATRIX_ID) { if (result != this->INVALID_IDENTIFIER_ID) {
return result; return result;
} }
switch (parameterId) { switch (parameterId) {
@ -52,12 +54,13 @@ public:
parameterWrapper->set(this->upperLimit); parameterWrapper->set(this->upperLimit);
break; break;
default: default:
return this->INVALID_MATRIX_ID; return this->INVALID_IDENTIFIER_ID;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
bool isOutOfLimits() { bool isOutOfLimits() {
if (this->oldState == MonitoringIF::ABOVE_HIGH_LIMIT || this->oldState == MonitoringIF::BELOW_LOW_LIMIT) { if (this->oldState == MonitoringIF::ABOVE_HIGH_LIMIT or
this->oldState == MonitoringIF::BELOW_LOW_LIMIT) {
return true; return true;
} else { } else {
return false; return false;
@ -76,10 +79,12 @@ protected:
void sendTransitionEvent(T currentValue, ReturnValue_t state) { void sendTransitionEvent(T currentValue, ReturnValue_t state) {
switch (state) { switch (state) {
case MonitoringIF::BELOW_LOW_LIMIT: case MonitoringIF::BELOW_LOW_LIMIT:
EventManagerIF::triggerEvent(this->reportingId, belowLowEvent, this->parameterId); EventManagerIF::triggerEvent(this->reportingId, belowLowEvent,
this->globalPoolId.objectId, this->globalPoolId.localPoolId);
break; break;
case MonitoringIF::ABOVE_HIGH_LIMIT: case MonitoringIF::ABOVE_HIGH_LIMIT:
EventManagerIF::triggerEvent(this->reportingId, aboveHighEvent, this->parameterId); EventManagerIF::triggerEvent(this->reportingId, aboveHighEvent,
this->globalPoolId.objectId, this->globalPoolId.localPoolId);
break; break;
default: default:
break; break;

View File

@ -1,39 +1,50 @@
#ifndef MONITORBASE_H_ #ifndef FSFW_MONITORING_MONITORBASE_H_
#define MONITORBASE_H_ #define FSFW_MONITORING_MONITORBASE_H_
#include "LimitViolationReporter.h"
#include "MonitoringIF.h"
#include "MonitoringMessageContent.h"
#include "MonitorReporter.h"
#include "../datapoollocal/LocalPoolVariable.h"
#include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/PIDReader.h"
#include "../monitoring/LimitViolationReporter.h"
#include "../monitoring/MonitoringIF.h"
#include "../monitoring/MonitoringMessageContent.h"
#include "../monitoring/MonitorReporter.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) : gp_id_t globalPoolId, uint16_t confirmationLimit):
MonitorReporter<T>(reporterId, monitorId, parameterId, confirmationLimit) { MonitorReporter<T>(reporterId, monitorId, globalPoolId,
confirmationLimit),
poolVariable(globalPoolId) {
} }
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.
} else { } else {
//3. Otherwise, check sample.
this->oldState = doCheck(sample); this->oldState = doCheck(sample);
} }
return this->oldState; return this->oldState;
@ -43,20 +54,25 @@ 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:
virtual ReturnValue_t fetchSample(T* sample) { virtual ReturnValue_t fetchSample(T* sample) {
GlobDataSet mySet; ReturnValue_t result = poolVariable.read();
PIDReader<T> parameter(this->parameterId, &mySet); if(result != HasReturnvaluesIF::RETURN_OK) {
mySet.read(); return result;
if (!parameter.isValid()) { }
if (not poolVariable.isValid()) {
return MonitoringIF::INVALID; return MonitoringIF::INVALID;
} }
*sample = parameter.value; *sample = poolVariable.value;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
LocalPoolVar<T> poolVariable;
}; };
#endif /* MONITORBASE_H_ */ #endif /* FSFW_MONITORING_MONITORBASE_H_ */

View File

@ -1,10 +1,12 @@
#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 "../datapoollocal/locPoolDefinitions.h"
#include "../events/EventManagerIF.h"
#include "../parameters/HasParametersIF.h" #include "../parameters/HasParametersIF.h"
template<typename T> template<typename T>
@ -14,11 +16,14 @@ 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) : // TODO: Adapt to use SID instead of parameter ID.
monitorId(monitorId), parameterId(parameterId), reportingId(
reportingId), oldState(MonitoringIF::UNCHECKED), reportingEnabled( MonitorReporter(object_id_t reportingId, uint8_t monitorId,
ENABLED), eventEnabled(ENABLED), currentCounter(0), confirmationLimit( gp_id_t globalPoolId, uint16_t confirmationLimit) :
confirmationLimit) { monitorId(monitorId), globalPoolId(globalPoolId),
reportingId(reportingId), oldState(MonitoringIF::UNCHECKED),
reportingEnabled(ENABLED), eventEnabled(ENABLED), currentCounter(0),
confirmationLimit(confirmationLimit) {
} }
virtual ~MonitorReporter() { virtual ~MonitorReporter() {
@ -63,7 +68,7 @@ public:
parameterWrapper->set(this->eventEnabled); parameterWrapper->set(this->eventEnabled);
break; break;
default: default:
return INVALID_MATRIX_ID; return INVALID_IDENTIFIER_ID;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -91,7 +96,7 @@ public:
protected: protected:
const uint8_t monitorId; const uint8_t monitorId;
const uint32_t parameterId; const gp_id_t globalPoolId;
object_id_t reportingId; object_id_t reportingId;
ReturnValue_t oldState; ReturnValue_t oldState;
@ -148,7 +153,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,14 +165,15 @@ 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,
MonitoringReportContent<T> report(parameterId, ReturnValue_t state) {
MonitoringReportContent<T> report(globalPoolId,
parameterValue, crossedLimit, oldState, state); parameterValue, crossedLimit, oldState, state);
LimitViolationReporter::sendLimitViolationReport(&report); LimitViolationReporter::sendLimitViolationReport(&report);
} }
ReturnValue_t setToState(ReturnValue_t state) { ReturnValue_t setToState(ReturnValue_t state) {
if (oldState != state && reportingEnabled) { if (oldState != state && reportingEnabled) {
MonitoringReportContent<T> report(parameterId, 0, 0, oldState, MonitoringReportContent<T> report(globalPoolId, 0, 0, oldState,
state); state);
LimitViolationReporter::sendLimitViolationReport(&report); LimitViolationReporter::sendLimitViolationReport(&report);
oldState = state; oldState = state;
@ -175,4 +182,4 @@ protected:
} }
}; };
#endif /* FRAMEWORK_MONITORING_MONITORREPORTER_H_ */ #endif /* FSFW_MONITORING_MONITORREPORTER_H_ */

View File

@ -1,8 +1,8 @@
#ifndef MONITORINGIF_H_ #ifndef FSFW_MONITORING_MONITORINGIF_H_
#define MONITORINGIF_H_ #define FSFW_MONITORING_MONITORINGIF_H_
#include "../memory/HasMemoryIF.h"
#include "MonitoringMessage.h" #include "MonitoringMessage.h"
#include "../memory/HasMemoryIF.h"
#include "../serialize/SerializeIF.h" #include "../serialize/SerializeIF.h"
class MonitoringIF : public SerializeIF { class MonitoringIF : public SerializeIF {
@ -64,4 +64,4 @@ public:
#endif /* MONITORINGIF_H_ */ #endif /* FSFW_MONITORING_MONITORINGIF_H_ */

View File

@ -3,6 +3,7 @@
#include "HasMonitorsIF.h" #include "HasMonitorsIF.h"
#include "MonitoringIF.h" #include "MonitoringIF.h"
#include "../datapoollocal/locPoolDefinitions.h"
#include "../objectmanager/ObjectManagerIF.h" #include "../objectmanager/ObjectManagerIF.h"
#include "../serialize/SerialBufferAdapter.h" #include "../serialize/SerialBufferAdapter.h"
#include "../serialize/SerialFixedArrayListAdapter.h" #include "../serialize/SerialFixedArrayListAdapter.h"
@ -16,12 +17,17 @@ void setStaticFrameworkObjectIds();
} }
//PID(uint32_t), TYPE, LIMIT_ID, value,limitValue, previous, later, timestamp //PID(uint32_t), TYPE, LIMIT_ID, value,limitValue, previous, later, timestamp
/**
* @brief Does magic.
* @tparam T
*/
template<typename T> template<typename T>
class MonitoringReportContent: public SerialLinkedListAdapter<SerializeIF> { class MonitoringReportContent: public SerialLinkedListAdapter<SerializeIF> {
friend void (Factory::setStaticFrameworkObjectIds)(); friend void (Factory::setStaticFrameworkObjectIds)();
public: public:
SerializeElement<uint8_t> monitorId; SerializeElement<uint8_t> monitorId;
SerializeElement<uint32_t> parameterId; SerializeElement<uint32_t> parameterObjectId;
SerializeElement<lp_id_t> localPoolId;
SerializeElement<T> parameterValue; SerializeElement<T> parameterValue;
SerializeElement<T> limitValue; SerializeElement<T> limitValue;
SerializeElement<ReturnValue_t> oldState; SerializeElement<ReturnValue_t> oldState;
@ -30,20 +36,23 @@ public:
SerializeElement<SerialBufferAdapter<uint8_t>> timestampSerializer; SerializeElement<SerialBufferAdapter<uint8_t>> timestampSerializer;
TimeStamperIF* timeStamper; TimeStamperIF* timeStamper;
MonitoringReportContent() : MonitoringReportContent() :
SerialLinkedListAdapter<SerializeIF>( SerialLinkedListAdapter<SerializeIF>(&parameterObjectId),
LinkedElement<SerializeIF>::Iterator(&parameterId)), monitorId(0), parameterId( monitorId(0), parameterObjectId(0),
0), parameterValue(0), limitValue(0), oldState(0), newState( localPoolId(0), parameterValue(0),
0), rawTimestamp( { 0 }), timestampSerializer(rawTimestamp, limitValue(0), oldState(0), newState(0),
rawTimestamp( { 0 }), timestampSerializer(rawTimestamp,
sizeof(rawTimestamp)), timeStamper(NULL) { sizeof(rawTimestamp)), timeStamper(NULL) {
setAllNext(); setAllNext();
} }
MonitoringReportContent(uint32_t setPID, T value, T limitValue, MonitoringReportContent(gp_id_t globalPoolId, T value, T limitValue,
ReturnValue_t oldState, ReturnValue_t newState) : ReturnValue_t oldState, ReturnValue_t newState) :
SerialLinkedListAdapter<SerializeIF>( SerialLinkedListAdapter<SerializeIF>(&parameterObjectId),
LinkedElement<SerializeIF>::Iterator(&parameterId)), monitorId(0), parameterId( monitorId(0), parameterObjectId(globalPoolId.objectId),
setPID), parameterValue(value), limitValue(limitValue), oldState( localPoolId(globalPoolId.localPoolId),
oldState), newState(newState), timestampSerializer(rawTimestamp, parameterValue(value), limitValue(limitValue),
sizeof(rawTimestamp)), timeStamper(NULL) { oldState(oldState), newState(newState),
timestampSerializer(rawTimestamp, sizeof(rawTimestamp)),
timeStamper(NULL) {
setAllNext(); setAllNext();
if (checkAndSetStamper()) { if (checkAndSetStamper()) {
timeStamper->addTimeStamp(rawTimestamp, sizeof(rawTimestamp)); timeStamper->addTimeStamp(rawTimestamp, sizeof(rawTimestamp));
@ -53,16 +62,16 @@ private:
static object_id_t timeStamperId; static object_id_t timeStamperId;
void setAllNext() { void setAllNext() {
parameterId.setNext(&parameterValue); parameterObjectId.setNext(&parameterValue);
parameterValue.setNext(&limitValue); parameterValue.setNext(&limitValue);
limitValue.setNext(&oldState); limitValue.setNext(&oldState);
oldState.setNext(&newState); oldState.setNext(&newState);
newState.setNext(&timestampSerializer); newState.setNext(&timestampSerializer);
} }
bool checkAndSetStamper() { bool checkAndSetStamper() {
if (timeStamper == NULL) { if (timeStamper == nullptr) {
timeStamper = objectManager->get<TimeStamperIF>( timeStamperId ); timeStamper = objectManager->get<TimeStamperIF>( timeStamperId );
if ( timeStamper == NULL ) { if ( timeStamper == nullptr ) {
sif::error << "MonitoringReportContent::checkAndSetStamper: " sif::error << "MonitoringReportContent::checkAndSetStamper: "
"Stamper not found!" << std::endl; "Stamper not found!" << std::endl;
return false; return false;

View File

@ -82,7 +82,7 @@ public:
parameterWrapper->set(limit); parameterWrapper->set(limit);
break; break;
default: default:
return INVALID_MATRIX_ID; return INVALID_IDENTIFIER_ID;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }