Merge branch 'development' into mueller/parameter-convergence

This commit is contained in:
Steffen Gaisser 2020-12-10 16:24:19 +01:00
commit 14ecce084e
8 changed files with 131 additions and 92 deletions

View File

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

View File

@ -1,11 +1,5 @@
/**
* @file HasMonitorsIF.h
* @brief This file defines the HasMonitorsIF class.
* @date 28.07.2014
* @author baetz
*/
#ifndef HASMONITORSIF_H_
#define HASMONITORSIF_H_
#ifndef FSFW_MONITORING_HASMONITORSIF_H_
#define FSFW_MONITORING_HASMONITORSIF_H_
#include "../events/EventReportingProxyIF.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>
class LimitMonitor: public MonitorBase<T> {
public:
LimitMonitor(object_id_t reporterId, uint8_t monitorId, uint32_t parameterId,
uint16_t confirmationLimit, T lowerLimit, T upperLimit,
Event belowLowEvent = MonitoringIF::VALUE_BELOW_LOW_LIMIT,
LimitMonitor(object_id_t reporterId, uint8_t monitorId,
gp_id_t globalPoolId, uint16_t confirmationLimit, T lowerLimit,
T upperLimit, Event belowLowEvent =
MonitoringIF::VALUE_BELOW_LOW_LIMIT,
Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) :
MonitorBase<T>(reporterId, monitorId, parameterId, confirmationLimit), lowerLimit(
lowerLimit), upperLimit(upperLimit), belowLowEvent(
belowLowEvent), aboveHighEvent(aboveHighEvent) {
MonitorBase<T>(reporterId, monitorId, globalPoolId,
confirmationLimit),
lowerLimit(lowerLimit), upperLimit(upperLimit),
belowLowEvent(belowLowEvent), aboveHighEvent(aboveHighEvent) {
}
virtual ~LimitMonitor() {
}
@ -41,7 +43,7 @@ public:
ReturnValue_t result = this->MonitorBase<T>::getParameter(domainId,
parameterId, parameterWrapper, newValues, startAtIndex);
//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;
}
switch (parameterId) {
@ -52,12 +54,13 @@ public:
parameterWrapper->set(this->upperLimit);
break;
default:
return this->INVALID_MATRIX_ID;
return this->INVALID_IDENTIFIER_ID;
}
return HasReturnvaluesIF::RETURN_OK;
}
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;
} else {
return false;
@ -76,10 +79,12 @@ protected:
void sendTransitionEvent(T currentValue, ReturnValue_t state) {
switch (state) {
case MonitoringIF::BELOW_LOW_LIMIT:
EventManagerIF::triggerEvent(this->reportingId, belowLowEvent, this->parameterId);
EventManagerIF::triggerEvent(this->reportingId, belowLowEvent,
this->globalPoolId.objectId, this->globalPoolId.localPoolId);
break;
case MonitoringIF::ABOVE_HIGH_LIMIT:
EventManagerIF::triggerEvent(this->reportingId, aboveHighEvent, this->parameterId);
EventManagerIF::triggerEvent(this->reportingId, aboveHighEvent,
this->globalPoolId.objectId, this->globalPoolId.localPoolId);
break;
default:
break;

View File

@ -1,39 +1,50 @@
#ifndef MONITORBASE_H_
#define MONITORBASE_H_
#ifndef FSFW_MONITORING_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.
* 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) {
gp_id_t globalPoolId, uint16_t confirmationLimit):
MonitorReporter<T>(reporterId, monitorId, globalPoolId,
confirmationLimit),
poolVariable(globalPoolId) {
}
virtual ~MonitorBase() {
}
virtual ReturnValue_t check() {
//1. Fetch sample of type T, return validity.
// 1. Fetch sample of type T, return validity.
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.
} else {
//3. Otherwise, check sample.
this->oldState = doCheck(sample);
}
return this->oldState;
@ -43,20 +54,25 @@ public:
ReturnValue_t currentState = checkSample(sample, &crossedLimit);
return this->monitorStateIs(currentState,sample, crossedLimit);
}
//Abstract or default.
// Abstract or default.
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()) {
ReturnValue_t result = poolVariable.read();
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (not poolVariable.isValid()) {
return MonitoringIF::INVALID;
}
*sample = parameter.value;
*sample = poolVariable.value;
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_
#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 "../datapoollocal/locPoolDefinitions.h"
#include "../events/EventManagerIF.h"
#include "../parameters/HasParametersIF.h"
template<typename T>
@ -14,11 +16,14 @@ 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) {
// TODO: Adapt to use SID instead of parameter ID.
MonitorReporter(object_id_t reportingId, uint8_t monitorId,
gp_id_t globalPoolId, uint16_t confirmationLimit) :
monitorId(monitorId), globalPoolId(globalPoolId),
reportingId(reportingId), oldState(MonitoringIF::UNCHECKED),
reportingEnabled(ENABLED), eventEnabled(ENABLED), currentCounter(0),
confirmationLimit(confirmationLimit) {
}
virtual ~MonitorReporter() {
@ -63,7 +68,7 @@ public:
parameterWrapper->set(this->eventEnabled);
break;
default:
return INVALID_MATRIX_ID;
return INVALID_IDENTIFIER_ID;
}
return HasReturnvaluesIF::RETURN_OK;
}
@ -91,7 +96,7 @@ public:
protected:
const uint8_t monitorId;
const uint32_t parameterId;
const gp_id_t globalPoolId;
object_id_t reportingId;
ReturnValue_t oldState;
@ -148,7 +153,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,14 +165,15 @@ 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) {
MonitoringReportContent<T> report(parameterId,
virtual void sendTransitionReport(T parameterValue, T crossedLimit,
ReturnValue_t state) {
MonitoringReportContent<T> report(globalPoolId,
parameterValue, crossedLimit, oldState, state);
LimitViolationReporter::sendLimitViolationReport(&report);
}
ReturnValue_t setToState(ReturnValue_t state) {
if (oldState != state && reportingEnabled) {
MonitoringReportContent<T> report(parameterId, 0, 0, oldState,
MonitoringReportContent<T> report(globalPoolId, 0, 0, oldState,
state);
LimitViolationReporter::sendLimitViolationReport(&report);
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_
#define MONITORINGIF_H_
#ifndef FSFW_MONITORING_MONITORINGIF_H_
#define FSFW_MONITORING_MONITORINGIF_H_
#include "../memory/HasMemoryIF.h"
#include "MonitoringMessage.h"
#include "../memory/HasMemoryIF.h"
#include "../serialize/SerializeIF.h"
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 "MonitoringIF.h"
#include "../datapoollocal/locPoolDefinitions.h"
#include "../objectmanager/ObjectManagerIF.h"
#include "../serialize/SerialBufferAdapter.h"
#include "../serialize/SerialFixedArrayListAdapter.h"
@ -16,12 +17,17 @@ void setStaticFrameworkObjectIds();
}
//PID(uint32_t), TYPE, LIMIT_ID, value,limitValue, previous, later, timestamp
/**
* @brief Does magic.
* @tparam T
*/
template<typename T>
class MonitoringReportContent: public SerialLinkedListAdapter<SerializeIF> {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
SerializeElement<uint8_t> monitorId;
SerializeElement<uint32_t> parameterId;
SerializeElement<uint32_t> parameterObjectId;
SerializeElement<lp_id_t> localPoolId;
SerializeElement<T> parameterValue;
SerializeElement<T> limitValue;
SerializeElement<ReturnValue_t> oldState;
@ -30,20 +36,23 @@ public:
SerializeElement<SerialBufferAdapter<uint8_t>> timestampSerializer;
TimeStamperIF* timeStamper;
MonitoringReportContent() :
SerialLinkedListAdapter<SerializeIF>(
LinkedElement<SerializeIF>::Iterator(&parameterId)), monitorId(0), parameterId(
0), parameterValue(0), limitValue(0), oldState(0), newState(
0), rawTimestamp( { 0 }), timestampSerializer(rawTimestamp,
SerialLinkedListAdapter<SerializeIF>(&parameterObjectId),
monitorId(0), parameterObjectId(0),
localPoolId(0), parameterValue(0),
limitValue(0), oldState(0), newState(0),
rawTimestamp( { 0 }), timestampSerializer(rawTimestamp,
sizeof(rawTimestamp)), timeStamper(NULL) {
setAllNext();
}
MonitoringReportContent(uint32_t setPID, T value, T limitValue,
MonitoringReportContent(gp_id_t globalPoolId, T value, T limitValue,
ReturnValue_t oldState, ReturnValue_t newState) :
SerialLinkedListAdapter<SerializeIF>(
LinkedElement<SerializeIF>::Iterator(&parameterId)), monitorId(0), parameterId(
setPID), parameterValue(value), limitValue(limitValue), oldState(
oldState), newState(newState), timestampSerializer(rawTimestamp,
sizeof(rawTimestamp)), timeStamper(NULL) {
SerialLinkedListAdapter<SerializeIF>(&parameterObjectId),
monitorId(0), parameterObjectId(globalPoolId.objectId),
localPoolId(globalPoolId.localPoolId),
parameterValue(value), limitValue(limitValue),
oldState(oldState), newState(newState),
timestampSerializer(rawTimestamp, sizeof(rawTimestamp)),
timeStamper(NULL) {
setAllNext();
if (checkAndSetStamper()) {
timeStamper->addTimeStamp(rawTimestamp, sizeof(rawTimestamp));
@ -53,16 +62,16 @@ private:
static object_id_t timeStamperId;
void setAllNext() {
parameterId.setNext(&parameterValue);
parameterObjectId.setNext(&parameterValue);
parameterValue.setNext(&limitValue);
limitValue.setNext(&oldState);
oldState.setNext(&newState);
newState.setNext(&timestampSerializer);
}
bool checkAndSetStamper() {
if (timeStamper == NULL) {
if (timeStamper == nullptr) {
timeStamper = objectManager->get<TimeStamperIF>( timeStamperId );
if ( timeStamper == NULL ) {
if ( timeStamper == nullptr ) {
sif::error << "MonitoringReportContent::checkAndSetStamper: "
"Stamper not found!" << std::endl;
return false;

View File

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