updating code from Flying Laptop
This is the framework of Flying Laptop OBSW version A.13.0.
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
|
||||
#ifndef FRAMEWORK_MONITORING_ABSLIMITMONITOR_H_
|
||||
#define FRAMEWORK_MONITORING_ABSLIMITMONITOR_H_
|
||||
|
||||
@ -15,14 +14,13 @@ public:
|
||||
virtual ~AbsLimitMonitor() {
|
||||
}
|
||||
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) {
|
||||
*crossedLimit = limit;
|
||||
if (aboveIsViolation) {
|
||||
if ((std::abs(sample) > limit)) {
|
||||
*crossedLimit = limit;
|
||||
return MonitoringIF::OUT_OF_RANGE;
|
||||
}
|
||||
} else {
|
||||
if ((std::abs(sample) < limit)) {
|
||||
*crossedLimit = limit;
|
||||
return MonitoringIF::OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
@ -1,129 +0,0 @@
|
||||
/*
|
||||
* DeltaCheckMonitor.h
|
||||
*
|
||||
* Created on: 21.07.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef DELTACHECKMONITOR_H_
|
||||
#define DELTACHECKMONITOR_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PIDReader.h>
|
||||
#include <framework/monitoring/HasMonitorsIF.h>
|
||||
#include <framework/monitoring/LimitViolationReporter.h>
|
||||
#include <framework/monitoring/MonitoringIF.h>
|
||||
#include <framework/monitoring/MonitoringMessageContent.h>
|
||||
#include <framework/serialize/SerializeElement.h>
|
||||
|
||||
|
||||
|
||||
//TODO: Lots of old, unfixed stuff. Do not use!
|
||||
template<typename T>
|
||||
class DeltaCheckMonitor: public MonitoringIF {
|
||||
public:
|
||||
DeltaCheckMonitor(HasMonitorsIF* owner, uint32_t poolId,
|
||||
T initialMinDelta, T initialMaxDelta, uint8_t arrayPos = 0,
|
||||
uint8_t initialStrategy = REPORT_ALL, Event eventToTrigger = 0) :
|
||||
owner(owner), parameter(poolId, NULL, arrayPos), oldValue(
|
||||
0), comparisonValueValid(false), minDelta(initialMinDelta), maxDelta(
|
||||
initialMaxDelta), reportingStrategy(initialStrategy), checkingState(
|
||||
CHECKING_STATUS_OK), event(eventToTrigger) {
|
||||
initialMinDelta.setNext(&initialMaxDelta);
|
||||
}
|
||||
virtual ~DeltaCheckMonitor() {
|
||||
|
||||
}
|
||||
ReturnValue_t check() {
|
||||
DataSet mySet;
|
||||
mySet.registerVariable(¶meter);
|
||||
mySet.read();
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
uint8_t oldState = 0;
|
||||
if (!parameter.isValid()) {
|
||||
checkingState = CHECKING_STATUS_INVALID;
|
||||
comparisonValueValid = false;
|
||||
result = PARAMETER_INVALID;
|
||||
} else {
|
||||
if (!comparisonValueValid) {
|
||||
oldValue = parameter;
|
||||
comparisonValueValid = true;
|
||||
return FIRST_SAMPLE;
|
||||
}
|
||||
oldState = checkingState;
|
||||
if ((parameter.value - oldValue) > maxDelta.entry) {
|
||||
checkingState = CHECKING_STATUS_ABOVE_HIGH_THRESHOLD;
|
||||
result = HIGH_LIMIT;
|
||||
} else if ((parameter.value - oldValue) < minDelta.entry) {
|
||||
checkingState = CHECKING_STATUS_BELOW_LOW_THRESHOLD;
|
||||
result = LOW_LIMIT;
|
||||
} else {
|
||||
checkingState = CHECKING_STATUS_OK;
|
||||
}
|
||||
if (oldState != checkingState) {
|
||||
reportViolation(oldState);
|
||||
}
|
||||
}
|
||||
if (reportingStrategy == REPORT_NONE) {
|
||||
checkingState = CHECKING_STATUS_UNSELECTED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
ReturnValue_t setLimits(uint8_t type, const uint8_t* data, uint32_t size) {
|
||||
if (type != getLimitType()) {
|
||||
return WRONG_TYPE;
|
||||
}
|
||||
UpdateLimitMonitorContent<T> content;
|
||||
int32_t tempSize = size;
|
||||
const uint8_t* pBuffer = data;
|
||||
ReturnValue_t result = content.deSerialize(&pBuffer, &tempSize, true);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
minDelta = content.lowValue.entry;
|
||||
maxDelta = content.highValue.entry;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
ReturnValue_t setChecking(uint8_t strategy) {
|
||||
reportingStrategy = strategy;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
uint32_t getPID() {
|
||||
return parameter.getParameterId();
|
||||
}
|
||||
const uint8_t getLimitType() const {
|
||||
return LIMIT_TYPE_DELTA_CHECK;
|
||||
}
|
||||
private:
|
||||
HasMonitorsIF* owner;
|
||||
PIDReader<T> parameter;
|
||||
T oldValue;
|
||||
bool comparisonValueValid;
|
||||
SerializeElement<T> minDelta;
|
||||
SerializeElement<T> maxDelta;
|
||||
uint8_t reportingStrategy;
|
||||
uint8_t checkingState;
|
||||
EventId_t event;
|
||||
void reportViolation(uint8_t oldState) {
|
||||
if ((reportingStrategy & REPORT_REPORTS_ONLY) != 0) {
|
||||
if (checkingState == CHECKING_STATUS_ABOVE_HIGH_THRESHOLD) {
|
||||
MonitoringReportContent<T> report(parameter.getParameterId(),
|
||||
parameter.value, maxDelta.entry, oldState,
|
||||
checkingState);
|
||||
LimitViolationReporter::sendLimitViolationReport(&report);
|
||||
} else {
|
||||
MonitoringReportContent<T> report(parameter.getParameterId(),
|
||||
parameter.value, minDelta.entry, oldState,
|
||||
checkingState);
|
||||
LimitViolationReporter::sendLimitViolationReport(&report);
|
||||
};
|
||||
}
|
||||
if ((this->reportingStrategy & REPORT_EVENTS_ONLY) != 0) {
|
||||
if (checkingState == CHECKING_STATUS_ABOVE_HIGH_THRESHOLD || checkingState == CHECKING_STATUS_BELOW_LOW_THRESHOLD) {
|
||||
owner->forwardEvent(event, (oldState << 8) + checkingState);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* DELTACHECKMONITOR_H_ */
|
@ -8,8 +8,8 @@
|
||||
#define HASMONITORSIF_H_
|
||||
|
||||
#include <framework/events/EventReportingProxyIF.h>
|
||||
#include <framework/ipc/MessageQueue.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/ipc/MessageQueueSenderIF.h>
|
||||
|
||||
class HasMonitorsIF {
|
||||
public:
|
||||
|
@ -1,271 +0,0 @@
|
||||
/*
|
||||
* LimitCheckMonitor.h
|
||||
*
|
||||
* Created on: 21.07.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef LIMITCHECKMONITOR_H_
|
||||
#define LIMITCHECKMONITOR_H_
|
||||
|
||||
#include <framework/container/LinkedElementDecorator.h>
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PIDReader.h>
|
||||
#include <framework/monitoring/LimitViolationReporter.h>
|
||||
#include <framework/monitoring/MonitoringMessageContent.h>
|
||||
#include <framework/serialize/SerializeElement.h>
|
||||
#include <framework/serialize/SerialLinkedListAdapter.h>
|
||||
#include <framework/events/EventManagerIF.h>
|
||||
|
||||
template<typename T>
|
||||
class LimitCheckMonitor: public MonitoringIF {
|
||||
public:
|
||||
struct CheckParameters {
|
||||
|
||||
CheckParameters() :
|
||||
oldState(HasReturnvaluesIF::RETURN_OK), parameterId(
|
||||
PoolVariableIF::NO_PARAMETER), sendTransitionreport(
|
||||
false), sendTransitionEvent(false), lowerTransitionEvent(
|
||||
0), upperTransitionEvent(0), reportingObject(0), currentCounter(
|
||||
0), maxCounter(0) {
|
||||
}
|
||||
|
||||
CheckParameters(ReturnValue_t oldState, const uint32_t parameterId,
|
||||
bool sendTransitionreport, bool sendTransitionEvent,
|
||||
Event lowerTransitionEvent, Event upperTransitionEvent,
|
||||
const object_id_t reportingObject, uint16_t maxCounter = 0) :
|
||||
oldState(oldState), parameterId(parameterId), sendTransitionreport(
|
||||
sendTransitionreport), sendTransitionEvent(
|
||||
sendTransitionEvent), lowerTransitionEvent(
|
||||
lowerTransitionEvent), upperTransitionEvent(
|
||||
upperTransitionEvent), reportingObject(reportingObject), currentCounter(
|
||||
0), maxCounter(maxCounter) {
|
||||
}
|
||||
|
||||
ReturnValue_t oldState;
|
||||
const uint32_t parameterId;
|
||||
bool sendTransitionreport;
|
||||
bool sendTransitionEvent;
|
||||
Event lowerTransitionEvent;
|
||||
Event upperTransitionEvent;
|
||||
const object_id_t reportingObject;
|
||||
uint16_t currentCounter;
|
||||
uint16_t maxCounter;
|
||||
};
|
||||
|
||||
LimitCheckMonitor(object_id_t reportAs, uint32_t parameterId,
|
||||
T initialLower, T initialUpper, bool generateReports = true,
|
||||
bool throwEvents = false, Event lowerTransitionEvent = 0,
|
||||
Event upperTransitionEvent = 0, uint16_t confirmationNumber = 0) :
|
||||
lowerLimit(initialLower), upperLimit(initialUpper), parameters(
|
||||
UNCHECKED, parameterId, generateReports, throwEvents,
|
||||
lowerTransitionEvent, upperTransitionEvent, reportAs,
|
||||
confirmationNumber) {
|
||||
lowerLimit.setNext(&upperLimit);
|
||||
}
|
||||
|
||||
virtual ~LimitCheckMonitor() {
|
||||
}
|
||||
|
||||
virtual ReturnValue_t check() {
|
||||
DataSet mySet;
|
||||
PIDReader<T> parameter(parameters.parameterId, &mySet);
|
||||
mySet.read();
|
||||
if (!parameter.isValid()) {
|
||||
if (parameters.oldState != INVALID) {
|
||||
MonitoringReportContent<T> report(parameter.getParameterId(), 0,
|
||||
0, parameters.oldState, INVALID);
|
||||
LimitViolationReporter::sendLimitViolationReport(&report);
|
||||
parameters.oldState = INVALID;
|
||||
}
|
||||
} else {
|
||||
parameters.oldState = doCheck(parameter.value, lowerLimit,
|
||||
upperLimit, ¶meters);
|
||||
}
|
||||
return parameters.oldState;
|
||||
}
|
||||
|
||||
static ReturnValue_t doCheck(T value, T lowerLimit, T upperLimit,
|
||||
CheckParameters* checkParameters, ReturnValue_t lowerReturnCode =
|
||||
BELOW_LOW_LIMIT, ReturnValue_t upperReturnCode =
|
||||
ABOVE_HIGH_LIMIT) {
|
||||
return doCheck(value, lowerLimit, upperLimit, checkParameters->oldState,
|
||||
checkParameters->parameterId,
|
||||
checkParameters->sendTransitionreport,
|
||||
checkParameters->sendTransitionEvent,
|
||||
checkParameters->lowerTransitionEvent,
|
||||
checkParameters->upperTransitionEvent,
|
||||
checkParameters->reportingObject,
|
||||
&checkParameters->currentCounter, checkParameters->maxCounter,
|
||||
lowerReturnCode, upperReturnCode);
|
||||
}
|
||||
|
||||
static ReturnValue_t doCheck(T value, T lowerLimit, T upperLimit,
|
||||
ReturnValue_t oldState, uint32_t parameterId,
|
||||
bool sendTransitionreport, bool sendTransitionEvent,
|
||||
Event lowerTransitionEvent, Event upperTransitionEvent,
|
||||
object_id_t reportingObject, uint16_t *currentCounter = NULL,
|
||||
uint16_t maxCounter = 0, ReturnValue_t lowerReturnCode =
|
||||
BELOW_LOW_LIMIT, ReturnValue_t upperReturnCode =
|
||||
ABOVE_HIGH_LIMIT) {
|
||||
uint16_t tempCounter = 0;
|
||||
if (currentCounter == NULL) {
|
||||
currentCounter = &tempCounter;
|
||||
maxCounter = 0;
|
||||
}
|
||||
|
||||
ReturnValue_t currentState = HasReturnvaluesIF::RETURN_OK;
|
||||
T crossedLimit = 0;
|
||||
if (value > upperLimit) {
|
||||
currentState = upperReturnCode;
|
||||
crossedLimit = upperLimit;
|
||||
} else if (value < lowerLimit) {
|
||||
currentState = lowerReturnCode;
|
||||
crossedLimit = lowerLimit;
|
||||
}
|
||||
|
||||
if (oldState != currentState) {
|
||||
//confirmation
|
||||
*currentCounter += 1;
|
||||
if (*currentCounter > maxCounter || oldState == UNCHECKED) {
|
||||
*currentCounter = 0;
|
||||
// Distinction of 3 cases: up/down/(ok or default)
|
||||
if (currentState == upperReturnCode) {
|
||||
if (sendTransitionEvent) {
|
||||
EventManagerIF::triggerEvent(reportingObject,
|
||||
upperTransitionEvent, 0,
|
||||
0);
|
||||
}
|
||||
} else if (currentState == lowerReturnCode) {
|
||||
if (sendTransitionEvent) {
|
||||
EventManagerIF::triggerEvent(reportingObject,
|
||||
lowerTransitionEvent, 0,
|
||||
0);
|
||||
}
|
||||
} else {
|
||||
// RETURN_OK or all other cases
|
||||
if (oldState == lowerReturnCode) {
|
||||
crossedLimit = lowerLimit;
|
||||
} else {
|
||||
crossedLimit = upperLimit;
|
||||
}
|
||||
}
|
||||
|
||||
if (sendTransitionreport) {
|
||||
MonitoringReportContent<T> report(parameterId, value,
|
||||
crossedLimit, oldState, currentState);
|
||||
LimitViolationReporter::sendLimitViolationReport(&report);
|
||||
} else {
|
||||
currentState = UNSELECTED;
|
||||
}
|
||||
} else {
|
||||
currentState = oldState;
|
||||
}
|
||||
} else {
|
||||
*currentCounter = 0;
|
||||
}
|
||||
return currentState;
|
||||
}
|
||||
|
||||
ReturnValue_t setLimits(uint8_t type, const uint8_t* data, uint32_t size) {
|
||||
if (type != getLimitType()) {
|
||||
return WRONG_TYPE;
|
||||
}
|
||||
|
||||
UpdateLimitMonitorContent<T> content;
|
||||
|
||||
if (size != content.getSerializedSize()) {
|
||||
return INVALID_SIZE;
|
||||
}
|
||||
|
||||
int32_t tempSize = size;
|
||||
const uint8_t* pBuffer = data;
|
||||
ReturnValue_t result = content.deSerialize(&pBuffer, &tempSize, true);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
setLimits(content.lowValue, content.highValue);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void setLimits(T lower, T upper) {
|
||||
lowerLimit = lower;
|
||||
upperLimit = upper;
|
||||
}
|
||||
|
||||
ReturnValue_t setChecking(uint8_t strategy) {
|
||||
if ((strategy & REPORT_EVENTS_ONLY) != 0) {
|
||||
parameters.sendTransitionEvent = true;
|
||||
} else {
|
||||
parameters.sendTransitionEvent = false;
|
||||
}
|
||||
if ((strategy & REPORT_REPORTS_ONLY) != 0) {
|
||||
parameters.sendTransitionreport = true;
|
||||
} else {
|
||||
parameters.sendTransitionreport = false;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t setToUnchecked() {
|
||||
return setToState(UNCHECKED, ¶meters);
|
||||
}
|
||||
|
||||
static ReturnValue_t setToUnchecked(CheckParameters* parameters) {
|
||||
if (parameters->oldState != UNCHECKED) {
|
||||
MonitoringReportContent<float> report(parameters->parameterId, 0, 0,
|
||||
parameters->oldState, UNCHECKED);
|
||||
LimitViolationReporter::sendLimitViolationReport(&report);
|
||||
parameters->oldState = UNCHECKED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
static ReturnValue_t setToState(ReturnValue_t newState, CheckParameters* parameters) {
|
||||
if (parameters->oldState != newState) {
|
||||
MonitoringReportContent<float> report(parameters->parameterId, 0, 0,
|
||||
parameters->oldState, newState);
|
||||
LimitViolationReporter::sendLimitViolationReport(&report);
|
||||
parameters->oldState = newState;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
|
||||
const uint32_t max_size, bool bigEndian) const {
|
||||
return SerialLinkedListAdapter<SerializeIF>::serialize(&lowerLimit,
|
||||
buffer, size, max_size, bigEndian);
|
||||
}
|
||||
|
||||
uint32_t getSerializedSize() const {
|
||||
return SerialLinkedListAdapter<SerializeIF>::getSerializedSize(
|
||||
&lowerLimit);
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian) {
|
||||
return SerialLinkedListAdapter<SerializeIF>::deSerialize(&lowerLimit,
|
||||
buffer, size, bigEndian);
|
||||
}
|
||||
const uint8_t getLimitType() const {
|
||||
return LIMIT_TYPE_LIMIT_CHECK;
|
||||
}
|
||||
const uint32_t getLimitId() const {
|
||||
return parameters.parameterId;
|
||||
}
|
||||
T getLowerLimit() {
|
||||
return lowerLimit;
|
||||
}
|
||||
T getUpperLimit() {
|
||||
return upperLimit;
|
||||
}
|
||||
private:
|
||||
SerializeElement<T> lowerLimit;
|
||||
SerializeElement<T> upperLimit;
|
||||
CheckParameters parameters;
|
||||
};
|
||||
|
||||
//TODO: This is for float only, as this is currently the only need.
|
||||
typedef LinkedElementDecorator<LimitCheckMonitor<float>, MonitoringIF> LinkedLimitMonitor;
|
||||
|
||||
#endif /* LIMITCHECKMONITOR_H_ */
|
@ -1,4 +1,3 @@
|
||||
|
||||
#ifndef FRAMEWORK_MONITORING_LIMITMONITOR_H_
|
||||
#define FRAMEWORK_MONITORING_LIMITMONITOR_H_
|
||||
|
||||
@ -24,6 +23,7 @@ public:
|
||||
virtual ~LimitMonitor() {
|
||||
}
|
||||
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) {
|
||||
*crossedLimit = 0.0;
|
||||
if (sample > upperLimit) {
|
||||
*crossedLimit = upperLimit;
|
||||
return MonitoringIF::ABOVE_HIGH_LIMIT;
|
||||
@ -49,7 +49,7 @@ public:
|
||||
parameterWrapper->set(this->lowerLimit);
|
||||
break;
|
||||
case 11:
|
||||
parameterWrapper->set(this->lowerLimit);
|
||||
parameterWrapper->set(this->upperLimit);
|
||||
break;
|
||||
default:
|
||||
return this->INVALID_MATRIX_ID;
|
||||
@ -63,6 +63,15 @@ public:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
T getLowerLimit() const {
|
||||
return lowerLimit;
|
||||
}
|
||||
|
||||
T getUpperLimit() const {
|
||||
return upperLimit;
|
||||
}
|
||||
|
||||
protected:
|
||||
void sendTransitionEvent(T currentValue, ReturnValue_t state) {
|
||||
switch (state) {
|
||||
|
@ -33,17 +33,17 @@ ReturnValue_t LimitViolationReporter::sendLimitViolationReport(const SerializeIF
|
||||
}
|
||||
CommandMessage report;
|
||||
MonitoringMessage::setLimitViolationReport(&report, storeId);
|
||||
return reportQueue.sendToDefault(&report);
|
||||
return MessageQueueSenderIF::sendMessage(reportQueue, &report);
|
||||
}
|
||||
|
||||
ReturnValue_t LimitViolationReporter::checkClassLoaded() {
|
||||
if (reportQueue.getDefaultDestination() == 0) {
|
||||
if (reportQueue == 0) {
|
||||
ReceivesMonitoringReportsIF* receiver = objectManager->get<
|
||||
ReceivesMonitoringReportsIF>(objects::PUS_MONITORING_SERVICE);
|
||||
ReceivesMonitoringReportsIF>(reportingTarget);
|
||||
if (receiver == NULL) {
|
||||
return ObjectManagerIF::NOT_FOUND;
|
||||
}
|
||||
reportQueue.setDefaultDestination(receiver->getCommandQueue());
|
||||
reportQueue = receiver->getCommandQueue();
|
||||
}
|
||||
if (ipcStore == NULL) {
|
||||
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
@ -55,5 +55,6 @@ ReturnValue_t LimitViolationReporter::checkClassLoaded() {
|
||||
}
|
||||
|
||||
//Lazy initialization.
|
||||
MessageQueueSender LimitViolationReporter::reportQueue;
|
||||
MessageQueueId_t LimitViolationReporter::reportQueue = 0;
|
||||
StorageManagerIF* LimitViolationReporter::ipcStore = NULL;
|
||||
object_id_t LimitViolationReporter::reportingTarget = 0;
|
||||
|
@ -7,16 +7,22 @@
|
||||
#ifndef LIMITVIOLATIONREPORTER_H_
|
||||
#define LIMITVIOLATIONREPORTER_H_
|
||||
|
||||
#include <framework/ipc/MessageQueueSender.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/serialize/SerializeIF.h>
|
||||
#include <framework/storagemanager/StorageManagerIF.h>
|
||||
#include <framework/ipc/MessageQueueSenderIF.h>
|
||||
|
||||
namespace Factory{
|
||||
void setStaticFrameworkObjectIds();
|
||||
}
|
||||
|
||||
class LimitViolationReporter {
|
||||
friend void (Factory::setStaticFrameworkObjectIds)();
|
||||
public:
|
||||
static ReturnValue_t sendLimitViolationReport(const SerializeIF* data);
|
||||
private:
|
||||
static MessageQueueSender reportQueue;
|
||||
static object_id_t reportingTarget;
|
||||
static MessageQueueId_t reportQueue;
|
||||
static StorageManagerIF* ipcStore;
|
||||
static ReturnValue_t checkClassLoaded();
|
||||
LimitViolationReporter();
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* MonitorBase.h
|
||||
*
|
||||
* Created on: 25.07.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef MONITORBASE_H_
|
||||
#define MONITORBASE_H_
|
||||
|
||||
@ -38,7 +31,7 @@ public:
|
||||
|
||||
//2. If returning from fetch != OK, parameter is invalid. Report (if oldState is != invalidity).
|
||||
if (validity != HasReturnvaluesIF::RETURN_OK) {
|
||||
monitorStateIs(validity, sample, 0);
|
||||
this->monitorStateIs(validity, sample, 0);
|
||||
//3. Otherwise, check sample.
|
||||
} else {
|
||||
this->oldState = doCheck(sample);
|
||||
@ -46,7 +39,7 @@ public:
|
||||
return this->oldState;
|
||||
}
|
||||
virtual ReturnValue_t doCheck(T sample) {
|
||||
T crossedLimit;
|
||||
T crossedLimit = 0.0;
|
||||
ReturnValue_t currentState = checkSample(sample, &crossedLimit);
|
||||
return this->monitorStateIs(currentState,sample, crossedLimit);
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
#ifndef FRAMEWORK_MONITORING_MONITORREPORTER_H_
|
||||
#define FRAMEWORK_MONITORING_MONITORREPORTER_H_
|
||||
|
||||
@ -12,10 +11,13 @@ template<typename T>
|
||||
class MonitorReporter: public HasParametersIF {
|
||||
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(
|
||||
true), eventEnabled(true), currentCounter(0), confirmationLimit(
|
||||
ENABLED), eventEnabled(ENABLED), currentCounter(0), confirmationLimit(
|
||||
confirmationLimit) {
|
||||
}
|
||||
|
||||
@ -26,12 +28,13 @@ public:
|
||||
T crossedLimit = 0) {
|
||||
if (state != oldState) {
|
||||
if (isConfirmed(state)) {
|
||||
if (this->eventEnabled) {
|
||||
if (eventEnabled == ENABLED) {
|
||||
sendTransitionEvent(parameterValue, state);
|
||||
}
|
||||
if (this->reportingEnabled) {
|
||||
if (reportingEnabled == ENABLED) {
|
||||
sendTransitionReport(parameterValue, crossedLimit, state);
|
||||
}
|
||||
oldState = state;
|
||||
} else {
|
||||
//This is to ensure confirmation works.
|
||||
//Needs to be reset to be able to confirm against oldState again next time.
|
||||
@ -50,13 +53,13 @@ public:
|
||||
return INVALID_DOMAIN_ID;
|
||||
}
|
||||
switch (parameterId) {
|
||||
case 1:
|
||||
case 0:
|
||||
parameterWrapper->set(this->confirmationLimit);
|
||||
break;
|
||||
case 2:
|
||||
case 1:
|
||||
parameterWrapper->set(this->reportingEnabled);
|
||||
break;
|
||||
case 3:
|
||||
case 2:
|
||||
parameterWrapper->set(this->eventEnabled);
|
||||
break;
|
||||
default:
|
||||
@ -73,15 +76,28 @@ public:
|
||||
object_id_t getReporterId() const {
|
||||
return reportingId;
|
||||
}
|
||||
|
||||
void setEventEnabled(uint8_t eventEnabled) {
|
||||
this->eventEnabled = eventEnabled;
|
||||
}
|
||||
|
||||
void setReportingEnabled(uint8_t reportingEnabled) {
|
||||
this->reportingEnabled = reportingEnabled;
|
||||
}
|
||||
|
||||
bool isEventEnabled() const {
|
||||
return (eventEnabled == ENABLED);
|
||||
}
|
||||
|
||||
protected:
|
||||
const uint8_t monitorId;
|
||||
const uint32_t parameterId;
|
||||
object_id_t reportingId;
|
||||
ReturnValue_t oldState;
|
||||
|
||||
bool reportingEnabled;
|
||||
uint8_t reportingEnabled;
|
||||
|
||||
bool eventEnabled;
|
||||
uint8_t eventEnabled;
|
||||
|
||||
uint16_t currentCounter;
|
||||
uint16_t confirmationLimit;
|
||||
@ -149,8 +165,8 @@ protected:
|
||||
LimitViolationReporter::sendLimitViolationReport(&report);
|
||||
}
|
||||
ReturnValue_t setToState(ReturnValue_t state) {
|
||||
if (oldState != state) {
|
||||
MonitoringReportContent<float> report(parameterId, 0, 0, oldState,
|
||||
if (oldState != state && reportingEnabled) {
|
||||
MonitoringReportContent<T> report(parameterId, 0, 0, oldState,
|
||||
state);
|
||||
LimitViolationReporter::sendLimitViolationReport(&report);
|
||||
oldState = state;
|
||||
|
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* MonitoringHelper.cpp
|
||||
*
|
||||
* Created on: 07.07.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/monitoring/MonitoringHelper.h>
|
||||
#include <framework/monitoring/MonitoringIF.h>
|
||||
#include <framework/monitoring/MonitoringMessage.h>
|
||||
#include <framework/monitoring/MonitoringMessageContent.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
|
||||
MonitoringHelper::MonitoringHelper(HasMonitorsIF* limitOwner) :
|
||||
owner(limitOwner), ipcStore(NULL) {
|
||||
}
|
||||
|
||||
MonitoringHelper::~MonitoringHelper() {
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t MonitoringHelper::handleMessage(CommandMessage* message) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
switch (message->getCommand()) {
|
||||
case MonitoringMessage::CHANGE_REPORTING_STRATEGY:
|
||||
result = handleReportingStrategyMessage(MonitoringMessage::getReportingStategy(message),
|
||||
MonitoringMessage::getStoreId(message));
|
||||
break;
|
||||
case MonitoringMessage::UPDATE_PARAMETER_MONITOR:
|
||||
result = handleUpdateParameterMonitor(MonitoringMessage::getStoreId(message));
|
||||
break;
|
||||
case MonitoringMessage::UPDATE_OBJECT_MONITOR:
|
||||
result = handleUpdateObjectMonitor(MonitoringMessage::getStoreId(message));
|
||||
break;
|
||||
default:
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
replyReturnValue(message, result);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MonitoringHelper::handleReportingStrategyMessage(uint8_t strategy,
|
||||
store_address_t storeId) {
|
||||
const uint8_t* data = NULL;
|
||||
uint32_t size = 0;
|
||||
ReturnValue_t result = ipcStore->getData(storeId, &data, &size);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
EnableDisableContent content;
|
||||
int32_t tSize = size;
|
||||
result = content.deSerialize(&data, &tSize, true);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
ipcStore->deleteData(storeId);
|
||||
return result;
|
||||
}
|
||||
if (content.funkyList.size == 0) {
|
||||
result = owner->setCheckingOfParameters(strategy);
|
||||
} else {
|
||||
for (EnableDisableContent::EnableDisableList::Iterator iter = content.funkyList.begin();
|
||||
iter != content.funkyList.end(); iter++) {
|
||||
result = owner->setCheckingOfParameters(strategy, true, *iter);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
//TODO: SW event (as stated in pus)
|
||||
}
|
||||
break;
|
||||
}
|
||||
result = HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
ipcStore->deleteData(storeId);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t MonitoringHelper::handleUpdateParameterMonitor(store_address_t storeId) {
|
||||
const uint8_t* data = NULL;
|
||||
uint32_t size = 0;
|
||||
ReturnValue_t result = ipcStore->getData(storeId, &data, &size);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
uint8_t limitType = *data;
|
||||
data++;
|
||||
size -= 1;
|
||||
const uint8_t* pData = data;
|
||||
int32_t pSize = size;
|
||||
uint32_t parameterId = 0;
|
||||
result = SerializeAdapter<uint32_t>::deSerialize(¶meterId, &pData, &pSize,
|
||||
true);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
result = owner->modifyParameterMonitor(limitType, parameterId, pData, pSize);
|
||||
}
|
||||
ipcStore->deleteData(storeId);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t MonitoringHelper::handleUpdateObjectMonitor(store_address_t storeId) {
|
||||
const uint8_t* data = NULL;
|
||||
uint32_t size = 0;
|
||||
ReturnValue_t result = ipcStore->getData(storeId, &data, &size);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
object_id_t objectId = 0;
|
||||
const uint8_t* pData = data;
|
||||
int32_t tSize = size;
|
||||
result = SerializeAdapter<object_id_t>::deSerialize(&objectId, &pData, &tSize, true);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
result = owner->modifyObjectMonitor(objectId, pData, tSize);
|
||||
}
|
||||
ipcStore->deleteData(storeId);
|
||||
return result;
|
||||
}
|
||||
|
||||
void MonitoringHelper::replyReturnValue(CommandMessage* message, ReturnValue_t result) {
|
||||
CommandMessage reply;
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
reply.setCommand(CommandMessage::REPLY_COMMAND_OK);
|
||||
} else {
|
||||
reply.setReplyRejected(result, message->getCommand());
|
||||
}
|
||||
MessageQueueSender sender(message->getSender());
|
||||
sender.sendToDefault(&reply, owner->getCommandQueue());
|
||||
}
|
||||
|
||||
ReturnValue_t MonitoringHelper::initialize() {
|
||||
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if (ipcStore != NULL) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
/*
|
||||
* MonitoringHelper.h
|
||||
*
|
||||
* Created on: 07.07.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef MONITORINGHELPER_H_
|
||||
#define MONITORINGHELPER_H_
|
||||
|
||||
#include <framework/ipc/CommandMessage.h>
|
||||
#include <framework/monitoring/HasMonitorsIF.h>
|
||||
#include <framework/storagemanager/StorageManagerIF.h>
|
||||
|
||||
class MonitoringHelper {
|
||||
public:
|
||||
MonitoringHelper(HasMonitorsIF* limitOwner);
|
||||
virtual ~MonitoringHelper();
|
||||
ReturnValue_t handleMessage(CommandMessage* message);
|
||||
ReturnValue_t initialize();
|
||||
private:
|
||||
HasMonitorsIF* owner;
|
||||
StorageManagerIF* ipcStore; //might be static
|
||||
ReturnValue_t handleReportingStrategyMessage(uint8_t strategy, store_address_t storeId);
|
||||
ReturnValue_t handleUpdateParameterMonitor(store_address_t storeId);
|
||||
ReturnValue_t handleUpdateObjectMonitor(store_address_t storeId);
|
||||
void replyReturnValue(CommandMessage* message, ReturnValue_t result);
|
||||
};
|
||||
|
||||
#endif /* MONITORINGHELPER_H_ */
|
@ -7,7 +7,7 @@
|
||||
|
||||
class MonitoringIF : public SerializeIF {
|
||||
public:
|
||||
static const uint8_t VIOLATION_REPORT_MAX_SIZE = 30;
|
||||
static const uint8_t VIOLATION_REPORT_MAX_SIZE = 32;
|
||||
static const uint8_t LIMIT_TYPE_NO_TYPE = 0xFF;
|
||||
static const uint8_t LIMIT_TYPE_LIMIT_CHECK = 0;
|
||||
static const uint8_t LIMIT_TYPE_DELTA_CHECK = 1;
|
||||
@ -20,7 +20,7 @@ public:
|
||||
static const Event VALUE_ABOVE_HIGH_LIMIT = MAKE_EVENT(3, SEVERITY::LOW);
|
||||
static const Event VALUE_OUT_OF_RANGE = MAKE_EVENT(4, SEVERITY::LOW);
|
||||
|
||||
static const uint8_t INTERFACE_ID = LIMITS_IF;
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::LIMITS_IF;
|
||||
static const ReturnValue_t UNCHECKED = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t INVALID = MAKE_RETURN_CODE(2);
|
||||
static const ReturnValue_t UNSELECTED = MAKE_RETURN_CODE(3);
|
||||
@ -55,8 +55,8 @@ public:
|
||||
virtual ReturnValue_t setLimits( uint8_t type, const uint8_t* data, uint32_t size) = 0;
|
||||
virtual ReturnValue_t setChecking(uint8_t strategy) = 0;
|
||||
virtual ReturnValue_t setToUnchecked() = 0;
|
||||
virtual const uint8_t getLimitType() const = 0;
|
||||
virtual const uint32_t getLimitId() const = 0;
|
||||
virtual uint8_t getLimitType() const = 0;
|
||||
virtual uint32_t getLimitId() const = 0;
|
||||
// virtual ReturnValue_t setEventReporting(bool active) = 0;
|
||||
virtual ~MonitoringIF() {
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* MonitoringListAdapter.cpp
|
||||
*
|
||||
* Created on: 09.07.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/monitoring/MonitoringListAdapter.h>
|
||||
|
||||
ReturnValue_t MonitoringListAdapter::check() {
|
||||
LinkedElement<MonitoringIF>* element = start;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
bool atLeastOneFailed = false;
|
||||
while ((element != NULL)) {
|
||||
result = element->value->check();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
atLeastOneFailed = true;
|
||||
}
|
||||
element = element->getNext();
|
||||
}
|
||||
return (atLeastOneFailed) ?
|
||||
(ReturnValue_t) HasReturnvaluesIF::RETURN_FAILED :
|
||||
(ReturnValue_t) HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
//ReturnValue_t MonitoringListAdapter::serialize(uint8_t** buffer, uint32_t* size,
|
||||
// const uint32_t max_size, bool bigEndian) const {
|
||||
// return SerialListAdapter<MonitoringIF>::serialize(start, buffer, size, max_size, bigEndian);
|
||||
//}
|
||||
//
|
||||
//uint32_t MonitoringListAdapter::getSerializedSize() const {
|
||||
// return SerialListAdapter<MonitoringIF>::getSerializedSize(start);
|
||||
//}
|
||||
//
|
||||
//ReturnValue_t MonitoringListAdapter::deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
// bool bigEndian) {
|
||||
// return SerialListAdapter<MonitoringIF>::deSerialize(start, buffer, size, bigEndian);
|
||||
//}
|
||||
|
||||
ReturnValue_t MonitoringListAdapter::updateMonitor(uint32_t parameterId,
|
||||
uint8_t limitType, const uint8_t* data, uint32_t size) {
|
||||
LinkedElement<MonitoringIF>* element = start;
|
||||
while ((element != NULL)) {
|
||||
if ((element->value->getLimitId() == parameterId)) {
|
||||
return element->value->setLimits(limitType, data, size);
|
||||
}
|
||||
element = element->getNext();
|
||||
}
|
||||
return MonitoringIF::MONITOR_NOT_FOUND;
|
||||
}
|
||||
|
||||
ReturnValue_t MonitoringListAdapter::setChecking(uint8_t strategy, uint32_t parameterId) {
|
||||
LinkedElement<MonitoringIF>* element = start;
|
||||
while ((element != NULL)) {
|
||||
if ((element->value->getLimitId() == parameterId)) {
|
||||
return element->value->setChecking(strategy);
|
||||
}
|
||||
element = element->getNext();
|
||||
}
|
||||
return MonitoringIF::MONITOR_NOT_FOUND;
|
||||
}
|
||||
|
||||
ReturnValue_t MonitoringListAdapter::setChecking(uint8_t strategy) {
|
||||
LinkedElement<MonitoringIF>* element = start;
|
||||
ReturnValue_t result = MonitoringIF::MONITOR_NOT_FOUND;
|
||||
bool atLeastOneUpdated = false;
|
||||
while ((element != NULL)) {
|
||||
result = element->value->setChecking(strategy);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
atLeastOneUpdated = true;
|
||||
}
|
||||
element = element->getNext();
|
||||
}
|
||||
result =
|
||||
(atLeastOneUpdated) ?
|
||||
(ReturnValue_t) HasReturnvaluesIF::RETURN_OK :
|
||||
(ReturnValue_t) MonitoringIF::MONITOR_NOT_FOUND;
|
||||
return result;
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* MonitoringListAdapter.h
|
||||
*
|
||||
* Created on: 09.07.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef MONITORINGLISTADAPTER_H_
|
||||
#define MONITORINGLISTADAPTER_H_
|
||||
|
||||
#include <framework/monitoring/MonitoringIF.h>
|
||||
#include <framework/serialize/SerialLinkedListAdapter.h>
|
||||
|
||||
class MonitoringListAdapter : public SerialLinkedListAdapter<MonitoringIF> {
|
||||
public:
|
||||
MonitoringListAdapter(LinkedElement<MonitoringIF>* start) : SerialLinkedListAdapter<MonitoringIF>(start) {
|
||||
}
|
||||
MonitoringListAdapter() : SerialLinkedListAdapter<MonitoringIF>() {
|
||||
}
|
||||
/**
|
||||
* Checks all elements.
|
||||
* @return Returns RETURN_FAILED if at least one check failed.
|
||||
*/
|
||||
ReturnValue_t check();
|
||||
/**
|
||||
* Iterates the list to update the requested monitor.
|
||||
* @param parameterId The parameter id to monitor.
|
||||
* @param limitId The limit id for the given PID.
|
||||
* @param data contains the new values
|
||||
* @param size size of the new values
|
||||
* @return The return code of the monitor if it was found and an update attempt, MONITOR_NOT_FOUND else.
|
||||
*/
|
||||
ReturnValue_t updateMonitor( uint32_t parameterId, uint8_t limitType, const uint8_t* data, uint32_t size);
|
||||
/**
|
||||
* Iterates the list to set the checking strategies for one monitor.
|
||||
* @param strategy the reporting strategy.
|
||||
* @param parameterId The PID.
|
||||
* @param limitId The limit id for the given PID.
|
||||
* @return The return code of the monitor if it was found and an update attempt, MONITOR_NOT_FOUND else.
|
||||
*/
|
||||
// ReturnValue_t setChecking(uint8_t strategy, uint32_t parameterId, uint32_t limitId);
|
||||
/**
|
||||
* Iterates the list to set the checking strategies for all monitors of a given parameter.
|
||||
* @param strategy the reporting strategy.
|
||||
* @param parameterId The PID.
|
||||
* @return RETURN_OK if at least one monitor was updated, MONITOR_NOT_FOUND else.
|
||||
*/
|
||||
ReturnValue_t setChecking(uint8_t strategy, uint32_t parameterId);
|
||||
/**
|
||||
* Iterates the list to set the checking strategies for all monitors-
|
||||
* @param strategy the reporting strategy.
|
||||
* @return RETURN_OK if at least one monitor was updated, MONITOR_NOT_FOUND else.
|
||||
*/
|
||||
ReturnValue_t setChecking(uint8_t strategy);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* MONITORINGLISTADAPTER_H_ */
|
@ -4,11 +4,6 @@
|
||||
MonitoringMessage::~MonitoringMessage() {
|
||||
}
|
||||
|
||||
void MonitoringMessage::setAddLimitCommand(CommandMessage* message,
|
||||
store_address_t storeId) {
|
||||
setTypicalMessage(message, ADD_MONITOR, storeId);
|
||||
}
|
||||
|
||||
void MonitoringMessage::setLimitViolationReport(CommandMessage* message,
|
||||
store_address_t storeId) {
|
||||
setTypicalMessage(message, LIMIT_VIOLATION_REPORT, storeId);
|
||||
@ -29,8 +24,6 @@ store_address_t MonitoringMessage::getStoreId(const CommandMessage* message) {
|
||||
void MonitoringMessage::clear(CommandMessage* message) {
|
||||
message->setCommand(CommandMessage::CMD_NONE);
|
||||
switch (message->getCommand()) {
|
||||
case MonitoringMessage::ADD_MONITOR:
|
||||
case MonitoringMessage::UPDATE_PARAMETER_MONITOR:
|
||||
case MonitoringMessage::LIMIT_VIOLATION_REPORT: {
|
||||
StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>(
|
||||
objects::IPC_STORE);
|
||||
@ -43,14 +36,3 @@ void MonitoringMessage::clear(CommandMessage* message) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MonitoringMessage::setChangeReportingStrategy(CommandMessage* message,
|
||||
uint8_t strategy, store_address_t storeId) {
|
||||
message->setCommand(CHANGE_REPORTING_STRATEGY);
|
||||
message->setParameter(strategy);
|
||||
message->setParameter2(storeId.raw);
|
||||
}
|
||||
|
||||
uint8_t MonitoringMessage::getReportingStategy(CommandMessage* message) {
|
||||
return (message->getParameter() & 0xFF);
|
||||
}
|
||||
|
@ -6,23 +6,13 @@
|
||||
|
||||
class MonitoringMessage: public CommandMessage {
|
||||
public:
|
||||
static const uint8_t MESSAGE_ID = LIMIT_MESSAGE_ID;
|
||||
static const Command_t ADD_MONITOR = MAKE_COMMAND_ID(1); //PID(uint32_t), Data(type, {LIMIT_ID(uint8_t), initialLimits(data, depends)})
|
||||
static const Command_t UPDATE_PARAMETER_MONITOR = MAKE_COMMAND_ID(2); //PID(uint32_t), Data{type, n_entries {LIMIT_ID(uint8_t), TYPE(uint8_t) newLimits(data, depends)
|
||||
static const Command_t UPDATE_OBJECT_MONITOR = MAKE_COMMAND_ID(3);
|
||||
static const Command_t CHANGE_REPORTING_STRATEGY = MAKE_COMMAND_ID(4); //PID(uint32_t), Data{type, n_entries {LIMIT_ID(uint8_t), TYPE(uint8_t) newLimits(data, depends)
|
||||
//Optional
|
||||
// static const Command_t REPORT_LIMIT_DEFINITIONS = MAKE_COMMAND_ID(3); //N_PIDS, PID(uint32_t)
|
||||
// static const Command_t LIMIT_DEFINITION_REPORT = MAKE_COMMAND_ID(3); //Eventually multiple reports per type or even per definition.
|
||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::MONITORING;
|
||||
//Object id could be useful, but we better manage that on service level (register potential reporters).
|
||||
static const Command_t LIMIT_VIOLATION_REPORT = MAKE_COMMAND_ID(10);
|
||||
virtual ~MonitoringMessage();
|
||||
static void setAddLimitCommand(CommandMessage* message, store_address_t storeId);
|
||||
static void setChangeReportingStrategy(CommandMessage* message, uint8_t strategy, store_address_t storeId);
|
||||
static void setLimitViolationReport(CommandMessage* message, store_address_t storeId);
|
||||
static void clear(CommandMessage* message);
|
||||
static store_address_t getStoreId(const CommandMessage* message);
|
||||
static uint8_t getReportingStategy(CommandMessage* message);
|
||||
static void setTypicalMessage(CommandMessage* message, Command_t type, store_address_t storeId);
|
||||
|
||||
};
|
||||
|
@ -11,9 +11,14 @@
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/timemanager/TimeStamperIF.h>
|
||||
|
||||
namespace Factory{
|
||||
void setStaticFrameworkObjectIds();
|
||||
}
|
||||
|
||||
//PID(uint32_t), TYPE, LIMIT_ID, value,limitValue, previous, later, timestamp
|
||||
template<typename T>
|
||||
class MonitoringReportContent: public SerialLinkedListAdapter<SerializeIF> {
|
||||
friend void (Factory::setStaticFrameworkObjectIds)();
|
||||
public:
|
||||
SerializeElement<uint8_t> monitorId;
|
||||
SerializeElement<uint32_t> parameterId;
|
||||
@ -22,7 +27,7 @@ public:
|
||||
SerializeElement<ReturnValue_t> oldState;
|
||||
SerializeElement<ReturnValue_t> newState;
|
||||
uint8_t rawTimestamp[TimeStamperIF::MISSION_TIMESTAMP_SIZE];
|
||||
SerializeElement<SerialBufferAdapter> timestampSerializer;
|
||||
SerializeElement<SerialBufferAdapter<uint8_t>> timestampSerializer;
|
||||
TimeStamperIF* timeStamper;
|
||||
MonitoringReportContent() :
|
||||
SerialLinkedListAdapter<SerializeIF>(
|
||||
@ -35,9 +40,9 @@ public:
|
||||
MonitoringReportContent(uint32_t setPID, T value, T limitValue,
|
||||
ReturnValue_t oldState, ReturnValue_t newState) :
|
||||
SerialLinkedListAdapter<SerializeIF>(
|
||||
LinkedElement<SerializeIF>::Iterator(¶meterId)), parameterId(
|
||||
LinkedElement<SerializeIF>::Iterator(¶meterId)), monitorId(0), parameterId(
|
||||
setPID), parameterValue(value), limitValue(limitValue), oldState(
|
||||
oldState), newState(newState), rawTimestamp( { 0 }), timestampSerializer(rawTimestamp,
|
||||
oldState), newState(newState), timestampSerializer(rawTimestamp,
|
||||
sizeof(rawTimestamp)), timeStamper(NULL) {
|
||||
setAllNext();
|
||||
if (checkAndSetStamper()) {
|
||||
@ -45,6 +50,8 @@ public:
|
||||
}
|
||||
}
|
||||
private:
|
||||
|
||||
static object_id_t timeStamperId;
|
||||
void setAllNext() {
|
||||
parameterId.setNext(¶meterValue);
|
||||
parameterValue.setNext(&limitValue);
|
||||
@ -54,8 +61,7 @@ private:
|
||||
}
|
||||
bool checkAndSetStamper() {
|
||||
if (timeStamper == NULL) {
|
||||
//TODO: Adjust name?
|
||||
timeStamper = objectManager->get<TimeStamperIF>( objects::TIME_MANAGER );
|
||||
timeStamper = objectManager->get<TimeStamperIF>( timeStamperId );
|
||||
if ( timeStamper == NULL ) {
|
||||
error << "MonitoringReportContent::checkAndSetStamper: Stamper not found!" << std::endl;
|
||||
return false;
|
||||
@ -64,45 +70,7 @@ private:
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//TODO: Next message would be update_limit message.
|
||||
//PID(uint32_t), Data{type, n_entries {LIMIT_ID(uint8_t), TYPE(uint8_t) newLimits(data, depends)
|
||||
|
||||
template<typename T>
|
||||
class UpdateLimitMonitorContent: public SerialLinkedListAdapter<SerializeIF> {
|
||||
public:
|
||||
SerializeElement<T> lowValue;
|
||||
SerializeElement<T> highValue;
|
||||
UpdateLimitMonitorContent() :
|
||||
SerialLinkedListAdapter<SerializeIF>(&lowValue), lowValue(0), highValue(
|
||||
0) {
|
||||
lowValue.setNext(&highValue);
|
||||
}
|
||||
private:
|
||||
};
|
||||
|
||||
//Not used at the moment.
|
||||
//class EnableDisableInner: public SerialLinkedListAdapter<SerializeIF> {
|
||||
//public:
|
||||
// SerializeElement<uint32_t> parameterId;
|
||||
// typedef FixedArrayList<uint32_t, HasMonitorsIF::MAX_N_LIMIT_ID> LimitIdList;
|
||||
// SerializeElement<LimitIdList> limitList;
|
||||
// EnableDisableInner() :
|
||||
// SerialLinkedListAdapter<SerializeIF>(¶meterId) {
|
||||
// parameterId.setNext(&limitList);
|
||||
// }
|
||||
//};
|
||||
|
||||
class EnableDisableContent {
|
||||
public:
|
||||
typedef SerialFixedArrayListAdapter<uint32_t, HasMonitorsIF::MAX_N_PARAMETER> EnableDisableList;
|
||||
EnableDisableList funkyList;
|
||||
EnableDisableContent() {
|
||||
}
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian) {
|
||||
return funkyList.deSerialize(buffer, size, bigEndian);
|
||||
}
|
||||
};
|
||||
object_id_t MonitoringReportContent<T>::timeStamperId = 0;
|
||||
|
||||
#endif /* MONITORINGMESSAGECONTENT_H_ */
|
||||
|
@ -1,119 +0,0 @@
|
||||
/*
|
||||
* OneParameterMonitorList.h
|
||||
*
|
||||
* Created on: 25.07.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef ONEPARAMETERMONITORLIST_H_
|
||||
#define ONEPARAMETERMONITORLIST_H_
|
||||
|
||||
#include <framework/monitoring/MonitoringIF.h>
|
||||
#include <framework/serialize/SerialLinkedListAdapter.h>
|
||||
|
||||
class OneParameterMonitorList: public SinglyLinkedList<MonitoringIF>,
|
||||
public MonitoringIF {
|
||||
public:
|
||||
OneParameterMonitorList(uint32_t setParameterId,
|
||||
LinkedElement<MonitoringIF>* start) :
|
||||
SinglyLinkedList<MonitoringIF>(start), parameterId(
|
||||
setParameterId) {
|
||||
}
|
||||
|
||||
OneParameterMonitorList() :
|
||||
SinglyLinkedList<MonitoringIF>(), parameterId(0) {
|
||||
}
|
||||
|
||||
ReturnValue_t check() {
|
||||
LinkedElement<MonitoringIF>* element = start;
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
bool atLeastOneFailed = false;
|
||||
while ((element != NULL)) {
|
||||
result = element->value->check();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
atLeastOneFailed = true;
|
||||
}
|
||||
element = element->getNext();
|
||||
}
|
||||
return (atLeastOneFailed) ?
|
||||
(ReturnValue_t) HasReturnvaluesIF::RETURN_FAILED :
|
||||
(ReturnValue_t) HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t setLimits(uint8_t type, const uint8_t* data, uint32_t size) {
|
||||
uint8_t position = *data;
|
||||
data++;
|
||||
size--;
|
||||
uint8_t currentPosition = 1;
|
||||
LinkedElement<MonitoringIF>* element = start;
|
||||
while ((element != NULL)) {
|
||||
if ((element->value->getLimitType() == type)) {
|
||||
if (position == currentPosition++) {
|
||||
return element->value->setLimits(type, data, size);
|
||||
}
|
||||
}
|
||||
element = element->getNext();
|
||||
}
|
||||
return MonitoringIF::MONITOR_NOT_FOUND;
|
||||
}
|
||||
|
||||
ReturnValue_t setChecking(uint8_t strategy) {
|
||||
LinkedElement<MonitoringIF>* element = start;
|
||||
ReturnValue_t result = MonitoringIF::MONITOR_NOT_FOUND;
|
||||
bool atLeastOneUpdated = false;
|
||||
while ((element != NULL)) {
|
||||
result = element->value->setChecking(strategy);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
atLeastOneUpdated = true;
|
||||
}
|
||||
element = element->getNext();
|
||||
}
|
||||
result =
|
||||
(atLeastOneUpdated) ?
|
||||
(ReturnValue_t) HasReturnvaluesIF::RETURN_OK :
|
||||
(ReturnValue_t) MonitoringIF::MONITOR_NOT_FOUND;
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t setToUnchecked() {
|
||||
LinkedElement<MonitoringIF>* element = start;
|
||||
ReturnValue_t result = MonitoringIF::MONITOR_NOT_FOUND;
|
||||
bool atLeastOneUpdated = false;
|
||||
while ((element != NULL)) {
|
||||
result = element->value->setToUnchecked();
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
atLeastOneUpdated = true;
|
||||
}
|
||||
element = element->getNext();
|
||||
}
|
||||
result =
|
||||
(atLeastOneUpdated) ?
|
||||
(ReturnValue_t) HasReturnvaluesIF::RETURN_OK :
|
||||
(ReturnValue_t) MonitoringIF::MONITOR_NOT_FOUND;
|
||||
return result;
|
||||
}
|
||||
|
||||
const uint8_t getLimitType() const {
|
||||
return LIMIT_TYPE_NO_TYPE;
|
||||
}
|
||||
const uint32_t getLimitId() const {
|
||||
return parameterId;
|
||||
}
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
|
||||
const uint32_t max_size, bool bigEndian) const {
|
||||
return SerialLinkedListAdapter<MonitoringIF>::serialize(this->start,buffer,size, max_size,bigEndian);
|
||||
}
|
||||
|
||||
uint32_t getSerializedSize() const {
|
||||
return SerialLinkedListAdapter<MonitoringIF>::getSerializedSize(this->start);
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian) {
|
||||
return SerialLinkedListAdapter<MonitoringIF>::deSerialize(this->start, buffer, size, bigEndian);
|
||||
}
|
||||
private:
|
||||
uint32_t parameterId;
|
||||
};
|
||||
#endif /* ONEPARAMETERMONITORLIST_H_ */
|
@ -1,14 +1,7 @@
|
||||
/*
|
||||
* ReceivesMonitoringReportsIF.h
|
||||
*
|
||||
* Created on: 07.07.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef RECEIVESMONITORINGREPORTSIF_H_
|
||||
#define RECEIVESMONITORINGREPORTSIF_H_
|
||||
|
||||
#include <framework/ipc/MessageQueue.h>
|
||||
#include <framework/ipc/MessageQueueSenderIF.h>
|
||||
|
||||
class ReceivesMonitoringReportsIF {
|
||||
public:
|
||||
|
155
monitoring/TriplexMonitor.h
Normal file
155
monitoring/TriplexMonitor.h
Normal file
@ -0,0 +1,155 @@
|
||||
#ifndef FRAMEWORK_MONITORING_TRIPLEXMONITOR_H_
|
||||
#define FRAMEWORK_MONITORING_TRIPLEXMONITOR_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PIDReaderList.h>
|
||||
#include <framework/health/HealthTableIF.h>
|
||||
#include <framework/parameters/HasParametersIF.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
|
||||
|
||||
//SHOULDDO: This is by far not perfect. Could be merged with new Monitor classes. But still, it's over-engineering.
|
||||
template<typename T>
|
||||
class TriplexMonitor : public HasParametersIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::TRIPLE_REDUNDACY_CHECK;
|
||||
static const ReturnValue_t NOT_ENOUGH_SENSORS = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t LOWEST_VALUE_OOL = MAKE_RETURN_CODE(2);
|
||||
static const ReturnValue_t HIGHEST_VALUE_OOL = MAKE_RETURN_CODE(3);
|
||||
static const ReturnValue_t BOTH_VALUES_OOL = MAKE_RETURN_CODE(4);
|
||||
static const ReturnValue_t DUPLEX_OOL = MAKE_RETURN_CODE(5);
|
||||
|
||||
static const uint8_t THREE = 3;
|
||||
|
||||
TriplexMonitor(const uint32_t parameterIds[3], uint8_t domainId, const T initialLimit,
|
||||
Event eventTripleCheck, Event eventDualCheck) :
|
||||
values(parameterIds, &dataSet), limit(initialLimit), eventTripleCheck(
|
||||
eventTripleCheck), eventDualCheck(eventDualCheck), healthTable(
|
||||
NULL), domainId(domainId) {
|
||||
|
||||
}
|
||||
virtual ~TriplexMonitor() {
|
||||
}
|
||||
ReturnValue_t check() {
|
||||
dataSet.read();
|
||||
//check health and validity
|
||||
uint8_t availableIndex[2] = { 0, 0 };
|
||||
bool first = true;
|
||||
uint8_t nAvailable = 0;
|
||||
for (uint8_t count = 0; count < THREE; count++) {
|
||||
if (values[count].isValid() && checkObjectHealthState(count)) {
|
||||
if (first) {
|
||||
availableIndex[0] = count;
|
||||
first = false;
|
||||
} else {
|
||||
//Might be filled twice, but then it's not needed anyway.
|
||||
availableIndex[1] = count;
|
||||
}
|
||||
nAvailable++;
|
||||
}
|
||||
}
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||
switch (nAvailable) {
|
||||
case 3:
|
||||
result = doTriplexMonitoring();
|
||||
break;
|
||||
case 2:
|
||||
result = doDuplexMonitoring(availableIndex);
|
||||
break;
|
||||
default:
|
||||
result = NOT_ENOUGH_SENSORS;
|
||||
break;
|
||||
}
|
||||
dataSet.commit();
|
||||
return result;
|
||||
}
|
||||
ReturnValue_t initialize() {
|
||||
healthTable = objectManager->get<HealthTableIF>(objects::HEALTH_TABLE);
|
||||
if (healthTable == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex) {
|
||||
if (domainId != this->domainId) {
|
||||
return INVALID_DOMAIN_ID;
|
||||
}
|
||||
switch (parameterId) {
|
||||
case 0:
|
||||
parameterWrapper->set(limit);
|
||||
break;
|
||||
default:
|
||||
return INVALID_MATRIX_ID;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
DataSet dataSet;
|
||||
PIDReaderList<T, THREE> values;
|
||||
T limit;
|
||||
Event eventTripleCheck;
|
||||
Event eventDualCheck;
|
||||
HealthTableIF* healthTable;
|
||||
uint8_t domainId;
|
||||
ReturnValue_t doTriplexMonitoring() {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
//Find middle value, by ordering indices
|
||||
uint8_t index[3] = { 0, 1, 2 };
|
||||
if (values[index[0]].value > values[index[1]].value) {
|
||||
std::swap(index[0], index[1]);
|
||||
}
|
||||
if (values[index[0]].value > values[index[2]].value) {
|
||||
std::swap(index[0], index[2]);
|
||||
}
|
||||
if (values[index[1]].value > values[index[2]].value) {
|
||||
std::swap(index[1], index[2]);
|
||||
}
|
||||
//Test if smallest value is out-of-limit.
|
||||
if (values[index[0]] < (values[index[1]] - limit)) {
|
||||
EventManagerIF::triggerEvent(getRefereneceObject(index[0]),
|
||||
eventTripleCheck, LOWEST_VALUE_OOL, 0);
|
||||
result = LOWEST_VALUE_OOL;
|
||||
}
|
||||
//Test if largest value is out-of-limit.
|
||||
if (values[index[2]] > (values[index[1]] + limit)) {
|
||||
EventManagerIF::triggerEvent(getRefereneceObject(index[2]),
|
||||
eventTripleCheck, HIGHEST_VALUE_OOL, 0);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
result = HIGHEST_VALUE_OOL;
|
||||
} else {
|
||||
result = BOTH_VALUES_OOL;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t doDuplexMonitoring(uint8_t index[2]) {
|
||||
T mean = (values[index[0]] + values[index[1]]) / 2;
|
||||
if (values[index[0]] > values[index[1]]) {
|
||||
if (values[index[0]] > (mean + limit)) {
|
||||
EventManagerIF::triggerEvent(getRefereneceObject(index[0]),
|
||||
eventDualCheck, 0, 0);
|
||||
EventManagerIF::triggerEvent(getRefereneceObject(index[1]),
|
||||
eventDualCheck, 0, 0);
|
||||
return DUPLEX_OOL;
|
||||
}
|
||||
} else {
|
||||
if (values[index[1]] > (mean + limit)) {
|
||||
EventManagerIF::triggerEvent(getRefereneceObject(index[0]),
|
||||
eventDualCheck, 0, 0);
|
||||
EventManagerIF::triggerEvent(getRefereneceObject(index[1]),
|
||||
eventDualCheck, 0, 0);
|
||||
return DUPLEX_OOL;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
virtual bool checkObjectHealthState(uint8_t valueIndex) = 0;
|
||||
virtual object_id_t getRefereneceObject(uint8_t valueIndex) = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_MONITORING_TRIPLEXMONITOR_H_ */
|
@ -1,4 +1,3 @@
|
||||
|
||||
#ifndef FRAMEWORK_MONITORING_TWOVALUELIMITMONITOR_H_
|
||||
#define FRAMEWORK_MONITORING_TWOVALUELIMITMONITOR_H_
|
||||
|
||||
|
Reference in New Issue
Block a user