Today's the day. Renamed platform to framework.
This commit is contained in:
75
monitoring/AbsLimitMonitor.h
Normal file
75
monitoring/AbsLimitMonitor.h
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
#ifndef FRAMEWORK_MONITORING_ABSLIMITMONITOR_H_
|
||||
#define FRAMEWORK_MONITORING_ABSLIMITMONITOR_H_
|
||||
|
||||
#include <framework/monitoring/MonitorBase.h>
|
||||
#include <cmath>
|
||||
|
||||
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) {
|
||||
}
|
||||
virtual ~AbsLimitMonitor() {
|
||||
}
|
||||
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK; //We're not out of range.
|
||||
}
|
||||
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
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) {
|
||||
return result;
|
||||
}
|
||||
switch (parameterId) {
|
||||
case 10:
|
||||
parameterWrapper->set(this->limit);
|
||||
break;
|
||||
default:
|
||||
return this->INVALID_MATRIX_ID;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
bool isOutOfLimits() {
|
||||
if (this->oldState == MonitoringIF::OUT_OF_RANGE) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void setLimit(T value) {
|
||||
limit = value;
|
||||
}
|
||||
protected:
|
||||
void sendTransitionEvent(T currentValue, ReturnValue_t state) {
|
||||
switch (state) {
|
||||
case MonitoringIF::OUT_OF_RANGE:
|
||||
EventManagerIF::triggerEvent(this->reportingId, violationEvent, this->parameterId);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
T limit;
|
||||
const Event violationEvent;
|
||||
const bool aboveIsViolation;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_MONITORING_ABSLIMITMONITOR_H_ */
|
129
monitoring/DeltaCheckMonitor.h
Normal file
129
monitoring/DeltaCheckMonitor.h
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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_ */
|
30
monitoring/HasMonitorsIF.h
Normal file
30
monitoring/HasMonitorsIF.h
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @file HasMonitorsIF.h
|
||||
* @brief This file defines the HasMonitorsIF class.
|
||||
* @date 28.07.2014
|
||||
* @author baetz
|
||||
*/
|
||||
#ifndef HASMONITORSIF_H_
|
||||
#define HASMONITORSIF_H_
|
||||
|
||||
#include <framework/events/EventReportingProxyIF.h>
|
||||
#include <framework/ipc/MessageQueue.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
|
||||
class HasMonitorsIF {
|
||||
public:
|
||||
static const uint8_t MAX_N_PARAMETER = 10;
|
||||
// static const uint8_t MAX_N_LIMIT_ID = 10;
|
||||
virtual ReturnValue_t setCheckingOfParameters(uint8_t checkingStrategy,
|
||||
bool forOnePid = false, uint32_t parameterId = 0) = 0;
|
||||
virtual ReturnValue_t modifyParameterMonitor(uint8_t limitType,
|
||||
uint32_t parameterId, const uint8_t* data, uint32_t size) = 0;
|
||||
virtual ReturnValue_t modifyObjectMonitor(uint32_t objectId,
|
||||
const uint8_t* data, const uint32_t size) = 0;
|
||||
virtual void setAllMonitorsToUnchecked() = 0;
|
||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||
virtual ~HasMonitorsIF() {
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* HASMONITORSIF_H_ */
|
271
monitoring/LimitCheckMonitor.h
Normal file
271
monitoring/LimitCheckMonitor.h
Normal file
@ -0,0 +1,271 @@
|
||||
/*
|
||||
* 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_ */
|
85
monitoring/LimitMonitor.h
Normal file
85
monitoring/LimitMonitor.h
Normal file
@ -0,0 +1,85 @@
|
||||
|
||||
#ifndef FRAMEWORK_MONITORING_LIMITMONITOR_H_
|
||||
#define FRAMEWORK_MONITORING_LIMITMONITOR_H_
|
||||
|
||||
#include <framework/monitoring/MonitorBase.h>
|
||||
|
||||
/**
|
||||
* Variant of a limit checking class.
|
||||
* Newer version as compared to LimitCheckMonitor.
|
||||
* Functionality is more or less the same, but does not use
|
||||
* heavy weight MonitoringIF.
|
||||
*/
|
||||
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,
|
||||
Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) :
|
||||
MonitorBase<T>(reporterId, monitorId, parameterId, confirmationLimit), lowerLimit(
|
||||
lowerLimit), upperLimit(upperLimit), belowLowEvent(
|
||||
belowLowEvent), aboveHighEvent(aboveHighEvent) {
|
||||
}
|
||||
virtual ~LimitMonitor() {
|
||||
}
|
||||
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) {
|
||||
if (sample > upperLimit) {
|
||||
*crossedLimit = upperLimit;
|
||||
return MonitoringIF::ABOVE_HIGH_LIMIT;
|
||||
} else if (sample < lowerLimit) {
|
||||
*crossedLimit = lowerLimit;
|
||||
return MonitoringIF::BELOW_LOW_LIMIT;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_OK; //Within limits.
|
||||
}
|
||||
}
|
||||
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
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) {
|
||||
return result;
|
||||
}
|
||||
switch (parameterId) {
|
||||
case 10:
|
||||
parameterWrapper->set(this->lowerLimit);
|
||||
break;
|
||||
case 11:
|
||||
parameterWrapper->set(this->lowerLimit);
|
||||
break;
|
||||
default:
|
||||
return this->INVALID_MATRIX_ID;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
bool isOutOfLimits() {
|
||||
if (this->oldState == MonitoringIF::ABOVE_HIGH_LIMIT || this->oldState == MonitoringIF::BELOW_LOW_LIMIT) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
protected:
|
||||
void sendTransitionEvent(T currentValue, ReturnValue_t state) {
|
||||
switch (state) {
|
||||
case MonitoringIF::BELOW_LOW_LIMIT:
|
||||
EventManagerIF::triggerEvent(this->reportingId, belowLowEvent, this->parameterId);
|
||||
break;
|
||||
case MonitoringIF::ABOVE_HIGH_LIMIT:
|
||||
EventManagerIF::triggerEvent(this->reportingId, aboveHighEvent, this->parameterId);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
T lowerLimit;
|
||||
T upperLimit;
|
||||
const Event belowLowEvent;
|
||||
const Event aboveHighEvent;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_MONITORING_LIMITMONITOR_H_ */
|
59
monitoring/LimitViolationReporter.cpp
Normal file
59
monitoring/LimitViolationReporter.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @file LimitViolationReporter.cpp
|
||||
* @brief This file defines the LimitViolationReporter class.
|
||||
* @date 17.07.2014
|
||||
* @author baetz
|
||||
*/
|
||||
#include <framework/monitoring/LimitViolationReporter.h>
|
||||
#include <framework/monitoring/MonitoringIF.h>
|
||||
#include <framework/monitoring/ReceivesMonitoringReportsIF.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
|
||||
ReturnValue_t LimitViolationReporter::sendLimitViolationReport(const SerializeIF* data) {
|
||||
ReturnValue_t result = checkClassLoaded();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
store_address_t storeId;
|
||||
uint8_t* dataTarget = NULL;
|
||||
uint32_t maxSize = data->getSerializedSize();
|
||||
if (maxSize > MonitoringIF::VIOLATION_REPORT_MAX_SIZE) {
|
||||
return MonitoringIF::INVALID_SIZE;
|
||||
}
|
||||
result = ipcStore->getFreeElement(&storeId, maxSize,
|
||||
&dataTarget);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
uint32_t size = 0;
|
||||
result = data->serialize(&dataTarget, &size, maxSize, true);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
CommandMessage report;
|
||||
MonitoringMessage::setLimitViolationReport(&report, storeId);
|
||||
return reportQueue.sendToDefault(&report);
|
||||
}
|
||||
|
||||
ReturnValue_t LimitViolationReporter::checkClassLoaded() {
|
||||
if (reportQueue.getDefaultDestination() == 0) {
|
||||
ReceivesMonitoringReportsIF* receiver = objectManager->get<
|
||||
ReceivesMonitoringReportsIF>(objects::PUS_MONITORING_SERVICE);
|
||||
if (receiver == NULL) {
|
||||
return ObjectManagerIF::NOT_FOUND;
|
||||
}
|
||||
reportQueue.setDefaultDestination(receiver->getCommandQueue());
|
||||
}
|
||||
if (ipcStore == NULL) {
|
||||
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if (ipcStore == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
//Lazy initialization.
|
||||
MessageQueueSender LimitViolationReporter::reportQueue;
|
||||
StorageManagerIF* LimitViolationReporter::ipcStore = NULL;
|
25
monitoring/LimitViolationReporter.h
Normal file
25
monitoring/LimitViolationReporter.h
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @file LimitViolationReporter.h
|
||||
* @brief This file defines the LimitViolationReporter class.
|
||||
* @date 17.07.2014
|
||||
* @author baetz
|
||||
*/
|
||||
#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>
|
||||
|
||||
class LimitViolationReporter {
|
||||
public:
|
||||
static ReturnValue_t sendLimitViolationReport(const SerializeIF* data);
|
||||
private:
|
||||
static MessageQueueSender reportQueue;
|
||||
static StorageManagerIF* ipcStore;
|
||||
static ReturnValue_t checkClassLoaded();
|
||||
LimitViolationReporter();
|
||||
};
|
||||
|
||||
#endif /* LIMITVIOLATIONREPORTER_H_ */
|
69
monitoring/MonitorBase.h
Normal file
69
monitoring/MonitorBase.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* MonitorBase.h
|
||||
*
|
||||
* Created on: 25.07.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef MONITORBASE_H_
|
||||
#define MONITORBASE_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PIDReader.h>
|
||||
#include <framework/monitoring/LimitViolationReporter.h>
|
||||
#include <framework/monitoring/MonitoringIF.h>
|
||||
#include <framework/monitoring/MonitoringMessageContent.h>
|
||||
#include <framework/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.
|
||||
*/
|
||||
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) {
|
||||
}
|
||||
virtual ~MonitorBase() {
|
||||
}
|
||||
virtual ReturnValue_t check() {
|
||||
//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).
|
||||
if (validity != HasReturnvaluesIF::RETURN_OK) {
|
||||
monitorStateIs(validity, sample, 0);
|
||||
//3. Otherwise, check sample.
|
||||
} else {
|
||||
this->oldState = doCheck(sample);
|
||||
}
|
||||
return this->oldState;
|
||||
}
|
||||
virtual ReturnValue_t doCheck(T sample) {
|
||||
T crossedLimit;
|
||||
ReturnValue_t currentState = checkSample(sample, &crossedLimit);
|
||||
return this->monitorStateIs(currentState,sample, crossedLimit);
|
||||
}
|
||||
//Abstract or default.
|
||||
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) = 0;
|
||||
|
||||
protected:
|
||||
virtual ReturnValue_t fetchSample(T* sample) {
|
||||
DataSet mySet;
|
||||
PIDReader<T> parameter(this->parameterId, &mySet);
|
||||
mySet.read();
|
||||
if (!parameter.isValid()) {
|
||||
return MonitoringIF::INVALID;
|
||||
}
|
||||
*sample = parameter.value;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* MONITORBASE_H_ */
|
162
monitoring/MonitorReporter.h
Normal file
162
monitoring/MonitorReporter.h
Normal file
@ -0,0 +1,162 @@
|
||||
|
||||
#ifndef FRAMEWORK_MONITORING_MONITORREPORTER_H_
|
||||
#define FRAMEWORK_MONITORING_MONITORREPORTER_H_
|
||||
|
||||
#include <framework/events/EventManagerIF.h>
|
||||
#include <framework/monitoring/LimitViolationReporter.h>
|
||||
#include <framework/monitoring/MonitoringIF.h>
|
||||
#include <framework/monitoring/MonitoringMessageContent.h>
|
||||
#include <framework/parameters/HasParametersIF.h>
|
||||
|
||||
template<typename T>
|
||||
class MonitorReporter: public HasParametersIF {
|
||||
public:
|
||||
|
||||
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(
|
||||
confirmationLimit) {
|
||||
}
|
||||
|
||||
virtual ~MonitorReporter() {
|
||||
}
|
||||
|
||||
ReturnValue_t monitorStateIs(ReturnValue_t state, T parameterValue = 0,
|
||||
T crossedLimit = 0) {
|
||||
if (state != oldState) {
|
||||
if (isConfirmed(state)) {
|
||||
if (this->eventEnabled) {
|
||||
sendTransitionEvent(parameterValue, state);
|
||||
}
|
||||
if (this->reportingEnabled) {
|
||||
sendTransitionReport(parameterValue, crossedLimit, state);
|
||||
}
|
||||
} else {
|
||||
//This is to ensure confirmation works.
|
||||
//Needs to be reset to be able to confirm against oldState again next time.
|
||||
return oldState;
|
||||
}
|
||||
} else {
|
||||
resetConfirmation();
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex) {
|
||||
if (domainId != monitorId) {
|
||||
return INVALID_DOMAIN_ID;
|
||||
}
|
||||
switch (parameterId) {
|
||||
case 1:
|
||||
parameterWrapper->set(this->confirmationLimit);
|
||||
break;
|
||||
case 2:
|
||||
parameterWrapper->set(this->reportingEnabled);
|
||||
break;
|
||||
case 3:
|
||||
parameterWrapper->set(this->eventEnabled);
|
||||
break;
|
||||
default:
|
||||
return INVALID_MATRIX_ID;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
virtual ReturnValue_t setToUnchecked() {
|
||||
return setToState(MonitoringIF::UNCHECKED);
|
||||
}
|
||||
virtual ReturnValue_t setToInvalid() {
|
||||
return setToState(MonitoringIF::INVALID);
|
||||
}
|
||||
object_id_t getReporterId() const {
|
||||
return reportingId;
|
||||
}
|
||||
protected:
|
||||
const uint8_t monitorId;
|
||||
const uint32_t parameterId;
|
||||
object_id_t reportingId;
|
||||
ReturnValue_t oldState;
|
||||
|
||||
bool reportingEnabled;
|
||||
|
||||
bool eventEnabled;
|
||||
|
||||
uint16_t currentCounter;
|
||||
uint16_t confirmationLimit;
|
||||
|
||||
bool isConfirmed(ReturnValue_t state) {
|
||||
//Confirm INVALID and UNCHECKED immediately.
|
||||
if (state == MonitoringIF::INVALID
|
||||
|| state == MonitoringIF::UNCHECKED) {
|
||||
currentCounter = 0;
|
||||
return true;
|
||||
}
|
||||
return doesChildConfirm(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the most simple form of confirmation.
|
||||
* A counter counts any violation and compares the number to maxCounter.
|
||||
* @param state The state, indicating the type of violation. Not used here.
|
||||
* @return true if counter > maxCounter, else false.
|
||||
*/
|
||||
virtual bool doesChildConfirm(ReturnValue_t state) {
|
||||
currentCounter += 1;
|
||||
if (currentCounter > confirmationLimit) {
|
||||
currentCounter = 0;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This method needs to reset the confirmation in case a valid sample was found.
|
||||
* Here, simply resets the current counter.
|
||||
*/
|
||||
virtual void resetConfirmation() {
|
||||
currentCounter = 0;
|
||||
}
|
||||
/**
|
||||
* Default version of sending transitional events.
|
||||
* Should be overridden from specialized monitors.
|
||||
* @param currentValue The current value which was monitored.
|
||||
* @param state The state the monitor changed to.
|
||||
*/
|
||||
virtual void sendTransitionEvent(T currentValue, ReturnValue_t state) {
|
||||
switch(state) {
|
||||
case MonitoringIF::UNCHECKED:
|
||||
case MonitoringIF::UNSELECTED:
|
||||
case MonitoringIF::INVALID:
|
||||
case HasReturnvaluesIF::RETURN_OK:
|
||||
break;
|
||||
default:
|
||||
EventManagerIF::triggerEvent(reportingId, MonitoringIF::MONITOR_CHANGED_STATE, state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Default implementation for sending transition report.
|
||||
* May be overridden, but is seldom necessary.
|
||||
* @param parameterValue Current value of the parameter
|
||||
* @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,
|
||||
parameterValue, crossedLimit, oldState, state);
|
||||
LimitViolationReporter::sendLimitViolationReport(&report);
|
||||
}
|
||||
ReturnValue_t setToState(ReturnValue_t state) {
|
||||
if (oldState != state) {
|
||||
MonitoringReportContent<float> report(parameterId, 0, 0, oldState,
|
||||
state);
|
||||
LimitViolationReporter::sendLimitViolationReport(&report);
|
||||
oldState = state;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_MONITORING_MONITORREPORTER_H_ */
|
133
monitoring/MonitoringHelper.cpp
Normal file
133
monitoring/MonitoringHelper.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
30
monitoring/MonitoringHelper.h
Normal file
30
monitoring/MonitoringHelper.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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_ */
|
67
monitoring/MonitoringIF.h
Normal file
67
monitoring/MonitoringIF.h
Normal file
@ -0,0 +1,67 @@
|
||||
#ifndef MONITORINGIF_H_
|
||||
#define MONITORINGIF_H_
|
||||
|
||||
#include <framework/memory/HasMemoryIF.h>
|
||||
#include <framework/monitoring/MonitoringMessage.h>
|
||||
#include <framework/serialize/SerializeIF.h>
|
||||
|
||||
class MonitoringIF : public SerializeIF {
|
||||
public:
|
||||
static const uint8_t VIOLATION_REPORT_MAX_SIZE = 30;
|
||||
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;
|
||||
static const uint8_t LIMIT_TYPE_ABSOLUTE_CHECK = 2;
|
||||
static const uint8_t LIMIT_TYPE_OBJECT = 128;
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::FDIR_2;
|
||||
static const Event MONITOR_CHANGED_STATE = MAKE_EVENT(1, SEVERITY::LOW);
|
||||
static const Event VALUE_BELOW_LOW_LIMIT = MAKE_EVENT(2, SEVERITY::LOW);
|
||||
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 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);
|
||||
static const ReturnValue_t BELOW_LOW_LIMIT = MAKE_RETURN_CODE(4);
|
||||
// static const ReturnValue_t CHECKING_STATUS_BELOW_LOW_THRESHOLD = MAKE_RETURN_CODE(4);
|
||||
// static const ReturnValue_t CHECKING_STATUS_ABOVE_HIGH_THRESHOLD = MAKE_RETURN_CODE(5);
|
||||
static const ReturnValue_t ABOVE_HIGH_LIMIT = MAKE_RETURN_CODE(5);
|
||||
static const ReturnValue_t UNEXPECTED_VALUE = MAKE_RETURN_CODE(6);
|
||||
static const ReturnValue_t OUT_OF_RANGE = MAKE_RETURN_CODE(7);
|
||||
|
||||
|
||||
static const ReturnValue_t FIRST_SAMPLE = MAKE_RETURN_CODE(0xA0);
|
||||
static const ReturnValue_t INVALID_SIZE = MAKE_RETURN_CODE(0xE0);
|
||||
static const ReturnValue_t WRONG_TYPE = MAKE_RETURN_CODE(0xE1);
|
||||
static const ReturnValue_t WRONG_PID = MAKE_RETURN_CODE(0xE2);
|
||||
static const ReturnValue_t WRONG_LIMIT_ID = MAKE_RETURN_CODE(0xE3);
|
||||
static const ReturnValue_t MONITOR_NOT_FOUND = MAKE_RETURN_CODE(0xEE);
|
||||
|
||||
static const uint8_t REPORT_NONE = 0;
|
||||
static const uint8_t REPORT_EVENTS_ONLY = 1;
|
||||
static const uint8_t REPORT_REPORTS_ONLY = 2;
|
||||
static const uint8_t REPORT_ALL = 3;
|
||||
|
||||
// static const ReturnValue_t STILL_IN_LOW_WARNING = MAKE_RETURN_CODE(0x11);
|
||||
// static const ReturnValue_t STILL_IN_LOW_LIMIT = MAKE_RETURN_CODE(0x12);
|
||||
// static const ReturnValue_t STILL_IN_HIGH_WARNING = MAKE_RETURN_CODE(0x13);
|
||||
// static const ReturnValue_t STILL_IN_HIGH_LIMIT = MAKE_RETURN_CODE(0x14);
|
||||
// static const ReturnValue_t VARIABLE_IS_INVALID = MAKE_RETURN_CODE(0xE0);
|
||||
// static const ReturnValue_t INVALID_SIZE = MAKE_RETURN_CODE(0xE1);
|
||||
// static const ReturnValue_t INVALID_ID = MAKE_RETURN_CODE(0xE2);
|
||||
virtual ReturnValue_t check() = 0;
|
||||
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 ReturnValue_t setEventReporting(bool active) = 0;
|
||||
virtual ~MonitoringIF() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* MONITORINGIF_H_ */
|
79
monitoring/MonitoringListAdapter.cpp
Normal file
79
monitoring/MonitoringListAdapter.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
59
monitoring/MonitoringListAdapter.h
Normal file
59
monitoring/MonitoringListAdapter.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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_ */
|
56
monitoring/MonitoringMessage.cpp
Normal file
56
monitoring/MonitoringMessage.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include <framework/monitoring/MonitoringMessage.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void MonitoringMessage::setTypicalMessage(CommandMessage* message,
|
||||
Command_t type, store_address_t storeId) {
|
||||
message->setCommand(type);
|
||||
message->setParameter2(storeId.raw);
|
||||
}
|
||||
|
||||
store_address_t MonitoringMessage::getStoreId(const CommandMessage* message) {
|
||||
store_address_t temp;
|
||||
temp.raw = message->getParameter2();
|
||||
return temp;
|
||||
}
|
||||
|
||||
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);
|
||||
if (ipcStore != NULL) {
|
||||
ipcStore->deleteData(getStoreId(message));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
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);
|
||||
}
|
31
monitoring/MonitoringMessage.h
Normal file
31
monitoring/MonitoringMessage.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef MONITORINGMESSAGE_H_
|
||||
#define MONITORINGMESSAGE_H_
|
||||
|
||||
#include <framework/ipc/CommandMessage.h>
|
||||
#include <framework/storagemanager/StorageManagerIF.h>
|
||||
|
||||
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.
|
||||
//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);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* MONITORINGMESSAGE_H_ */
|
108
monitoring/MonitoringMessageContent.h
Normal file
108
monitoring/MonitoringMessageContent.h
Normal file
@ -0,0 +1,108 @@
|
||||
#ifndef MONITORINGMESSAGECONTENT_H_
|
||||
#define MONITORINGMESSAGECONTENT_H_
|
||||
|
||||
#include <framework/monitoring/HasMonitorsIF.h>
|
||||
#include <framework/monitoring/MonitoringIF.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/serialize/SerialBufferAdapter.h>
|
||||
#include <framework/serialize/SerialFixedArrayListAdapter.h>
|
||||
#include <framework/serialize/SerializeElement.h>
|
||||
#include <framework/serialize/SerialLinkedListAdapter.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/timemanager/TimeStamperIF.h>
|
||||
|
||||
//PID(uint32_t), TYPE, LIMIT_ID, value,limitValue, previous, later, timestamp
|
||||
template<typename T>
|
||||
class MonitoringReportContent: public SerialLinkedListAdapter<SerializeIF> {
|
||||
public:
|
||||
SerializeElement<uint8_t> monitorId;
|
||||
SerializeElement<uint32_t> parameterId;
|
||||
SerializeElement<T> parameterValue;
|
||||
SerializeElement<T> limitValue;
|
||||
SerializeElement<ReturnValue_t> oldState;
|
||||
SerializeElement<ReturnValue_t> newState;
|
||||
uint8_t rawTimestamp[TimeStamperIF::MISSION_TIMESTAMP_SIZE];
|
||||
SerializeElement<SerialBufferAdapter> timestampSerializer;
|
||||
TimeStamperIF* timeStamper;
|
||||
MonitoringReportContent() :
|
||||
SerialLinkedListAdapter<SerializeIF>(
|
||||
LinkedElement<SerializeIF>::Iterator(¶meterId)), monitorId(0), parameterId(
|
||||
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,
|
||||
ReturnValue_t oldState, ReturnValue_t newState) :
|
||||
SerialLinkedListAdapter<SerializeIF>(
|
||||
LinkedElement<SerializeIF>::Iterator(¶meterId)), parameterId(
|
||||
setPID), parameterValue(value), limitValue(limitValue), oldState(
|
||||
oldState), newState(newState), rawTimestamp( { 0 }), timestampSerializer(rawTimestamp,
|
||||
sizeof(rawTimestamp)), timeStamper(NULL) {
|
||||
setAllNext();
|
||||
if (checkAndSetStamper()) {
|
||||
timeStamper->addTimeStamp(rawTimestamp, sizeof(rawTimestamp));
|
||||
}
|
||||
}
|
||||
private:
|
||||
void setAllNext() {
|
||||
parameterId.setNext(¶meterValue);
|
||||
parameterValue.setNext(&limitValue);
|
||||
limitValue.setNext(&oldState);
|
||||
oldState.setNext(&newState);
|
||||
newState.setNext(×tampSerializer);
|
||||
}
|
||||
bool checkAndSetStamper() {
|
||||
if (timeStamper == NULL) {
|
||||
//TODO: Adjust name?
|
||||
timeStamper = objectManager->get<TimeStamperIF>( objects::TIME_MANAGER );
|
||||
if ( timeStamper == NULL ) {
|
||||
error << "MonitoringReportContent::checkAndSetStamper: Stamper not found!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* MONITORINGMESSAGECONTENT_H_ */
|
119
monitoring/OneParameterMonitorList.h
Normal file
119
monitoring/OneParameterMonitorList.h
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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_ */
|
22
monitoring/ReceivesMonitoringReportsIF.h
Normal file
22
monitoring/ReceivesMonitoringReportsIF.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* ReceivesMonitoringReportsIF.h
|
||||
*
|
||||
* Created on: 07.07.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef RECEIVESMONITORINGREPORTSIF_H_
|
||||
#define RECEIVESMONITORINGREPORTSIF_H_
|
||||
|
||||
#include <framework/ipc/MessageQueue.h>
|
||||
|
||||
class ReceivesMonitoringReportsIF {
|
||||
public:
|
||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||
virtual ~ReceivesMonitoringReportsIF() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* RECEIVESMONITORINGREPORTSIF_H_ */
|
45
monitoring/TwoValueLimitMonitor.h
Normal file
45
monitoring/TwoValueLimitMonitor.h
Normal file
@ -0,0 +1,45 @@
|
||||
|
||||
#ifndef FRAMEWORK_MONITORING_TWOVALUELIMITMONITOR_H_
|
||||
#define FRAMEWORK_MONITORING_TWOVALUELIMITMONITOR_H_
|
||||
|
||||
#include <framework/monitoring/LimitMonitor.h>
|
||||
|
||||
template<typename T>
|
||||
class TwoValueLimitMonitor: public LimitMonitor<T> {
|
||||
public:
|
||||
TwoValueLimitMonitor(object_id_t reporterId, uint8_t monitorId,
|
||||
uint32_t lowParameterId, uint32_t highParameterId,
|
||||
uint16_t confirmationLimit, T lowerLimit, T upperLimit,
|
||||
Event belowLowEvent = MonitoringIF::VALUE_BELOW_LOW_LIMIT,
|
||||
Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) :
|
||||
LimitMonitor<T>(reporterId, monitorId, lowParameterId,
|
||||
confirmationLimit, lowerLimit, upperLimit, belowLowEvent,
|
||||
aboveHighEvent), highValueParameterId(highParameterId) {
|
||||
}
|
||||
virtual ~TwoValueLimitMonitor() {
|
||||
}
|
||||
ReturnValue_t doCheck(T lowSample, T highSample) {
|
||||
T crossedLimit;
|
||||
ReturnValue_t currentState = checkSample(lowSample, &crossedLimit);
|
||||
if (currentState != HasReturnvaluesIF::RETURN_OK) {
|
||||
return this->monitorStateIs(currentState, lowSample, crossedLimit);
|
||||
}
|
||||
currentState = checkSample(highSample, &crossedLimit);
|
||||
return this->monitorStateIs(currentState, highSample, crossedLimit);
|
||||
}
|
||||
protected:
|
||||
virtual void sendTransitionReport(T parameterValue, T crossedLimit,
|
||||
ReturnValue_t state) {
|
||||
uint32_t usedParameterId = this->parameterId;
|
||||
if (state == MonitoringIF::ABOVE_HIGH_LIMIT) {
|
||||
usedParameterId = this->highValueParameterId;
|
||||
}
|
||||
MonitoringReportContent<T> report(usedParameterId, parameterValue,
|
||||
crossedLimit, this->oldState, state);
|
||||
LimitViolationReporter::sendLimitViolationReport(&report);
|
||||
}
|
||||
private:
|
||||
const uint32_t highValueParameterId;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_MONITORING_TWOVALUELIMITMONITOR_H_ */
|
Reference in New Issue
Block a user