Merge remote-tracking branch 'upstream/development' into mueller/enhanced-controller

This commit is contained in:
Robin Müller 2020-12-10 16:52:44 +01:00
commit cbdf56e62b
28 changed files with 349 additions and 279 deletions

View File

@ -19,6 +19,11 @@ a C file without issues
- New base class for a controller which also implements HasActionsIF and HasLocalDataPoolIF - New base class for a controller which also implements HasActionsIF and HasLocalDataPoolIF
### Device Handler Base
- There is an additional `PERFORM_OPERATION` step for the device handler base. It is important
that DHB users adapt their polling sequence tables to perform this step. This steps allows for aclear distinction between operation and communication steps
### Events ### Events
- makeEvent function: Now takes three input parameters instead of two and - makeEvent function: Now takes three input parameters instead of two and

View File

@ -1,23 +1,19 @@
/** #ifndef FSFW_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_
* @file AcceptsDeviceResponsesIF.h #define FSFW_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_
* @brief This file defines the AcceptsDeviceResponsesIF class.
* @date 15.05.2013
* @author baetz
*/
#ifndef ACCEPTSDEVICERESPONSESIF_H_
#define ACCEPTSDEVICERESPONSESIF_H_
#include "../ipc/MessageQueueSenderIF.h" #include "../ipc/MessageQueueSenderIF.h"
/**
* This interface is used by the device handler to send a device response
* to the queue ID, which is returned in the implemented abstract method.
*/
class AcceptsDeviceResponsesIF { class AcceptsDeviceResponsesIF {
public: public:
/** /**
* Default empty virtual destructor. * Default empty virtual destructor.
*/ */
virtual ~AcceptsDeviceResponsesIF() { virtual ~AcceptsDeviceResponsesIF() {}
} virtual MessageQueueId_t getDeviceQueue() = 0;
virtual MessageQueueId_t getDeviceQueue() = 0;
}; };
#endif /* ACCEPTSDEVICERESPONSESIF_H_ */ #endif /* FSFW_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_ */

View File

@ -2,10 +2,10 @@
AssemblyBase::AssemblyBase(object_id_t objectId, object_id_t parentId, AssemblyBase::AssemblyBase(object_id_t objectId, object_id_t parentId,
uint16_t commandQueueDepth) : uint16_t commandQueueDepth) :
SubsystemBase(objectId, parentId, MODE_OFF, commandQueueDepth), internalState( SubsystemBase(objectId, parentId, MODE_OFF, commandQueueDepth),
STATE_NONE), recoveryState(RECOVERY_IDLE), recoveringDevice( internalState(STATE_NONE), recoveryState(RECOVERY_IDLE),
childrenMap.end()), targetMode(MODE_OFF), targetSubmode( recoveringDevice(childrenMap.end()), targetMode(MODE_OFF),
SUBMODE_NONE) { targetSubmode(SUBMODE_NONE) {
recoveryOffTimer.setTimeout(POWER_OFF_TIME_MS); recoveryOffTimer.setTimeout(POWER_OFF_TIME_MS);
} }
@ -165,9 +165,8 @@ ReturnValue_t AssemblyBase::checkChildrenState() {
} }
ReturnValue_t AssemblyBase::checkChildrenStateOff() { ReturnValue_t AssemblyBase::checkChildrenStateOff() {
for (std::map<object_id_t, ChildInfo>::iterator iter = childrenMap.begin(); for (const auto& childIter: childrenMap) {
iter != childrenMap.end(); iter++) { if (checkChildOff(childIter.first) != RETURN_OK) {
if (checkChildOff(iter->first) != RETURN_OK) {
return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE; return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE;
} }
} }

View File

@ -1,10 +1,30 @@
#ifndef ASSEMBLYBASE_H_ #ifndef FSFW_DEVICEHANDLERS_ASSEMBLYBASE_H_
#define ASSEMBLYBASE_H_ #define FSFW_DEVICEHANDLERS_ASSEMBLYBASE_H_
#include "../container/FixedArrayList.h"
#include "DeviceHandlerBase.h" #include "DeviceHandlerBase.h"
#include "../container/FixedArrayList.h"
#include "../subsystem/SubsystemBase.h" #include "../subsystem/SubsystemBase.h"
/**
* @brief Base class to implement reconfiguration and failure handling for
* redundant devices by monitoring their modes health states.
* @details
* Documentation: Dissertation Baetz p.156, 157.
*
* This class reduces the complexity of controller components which would
* otherwise be needed for the handling of redundant devices.
*
* The template class monitors mode and health state of its children
* and checks availability of devices on every detected change.
* AssemblyBase does not implement any redundancy logic by itself, but provides
* adaptation points for implementations to do so. Since most monitoring
* activities rely on mode and health state only and are therefore
* generic, it is sufficient for subclasses to provide:
*
* 1. check logic when active-> checkChildrenStateOn
* 2. transition logic to change the mode -> commandChildren
*
*/
class AssemblyBase: public SubsystemBase { class AssemblyBase: public SubsystemBase {
public: public:
static const uint8_t INTERFACE_ID = CLASS_ID::ASSEMBLY_BASE; static const uint8_t INTERFACE_ID = CLASS_ID::ASSEMBLY_BASE;
@ -16,10 +36,41 @@ public:
static const ReturnValue_t NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE = static const ReturnValue_t NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE =
MAKE_RETURN_CODE(0xa1); MAKE_RETURN_CODE(0xa1);
AssemblyBase(object_id_t objectId, object_id_t parentId, uint16_t commandQueueDepth = 8); AssemblyBase(object_id_t objectId, object_id_t parentId,
uint16_t commandQueueDepth = 8);
virtual ~AssemblyBase(); virtual ~AssemblyBase();
protected: protected:
// SHOULDDO: Change that OVERWRITE_HEALTH may be returned
// (or return internalState directly?)
/**
* Command children to reach [mode,submode] combination
* Can be done by setting #commandsOutstanding correctly,
* or using executeTable()
* @param mode
* @param submode
* @return
* - @c RETURN_OK if ok
* - @c NEED_SECOND_STEP if children need to be commanded again
*/
virtual ReturnValue_t commandChildren(Mode_t mode, Submode_t submode) = 0;
/**
* Check whether desired assembly mode was achieved by checking the modes
* or/and health states of child device handlers.
* The assembly template class will also call this function if a health
* or mode change of a child device handler was detected.
* @param wantedMode
* @param wantedSubmode
* @return
*/
virtual ReturnValue_t checkChildrenStateOn(Mode_t wantedMode,
Submode_t wantedSubmode) = 0;
virtual ReturnValue_t isModeCombinationValid(Mode_t mode,
Submode_t submode) = 0;
enum InternalState { enum InternalState {
STATE_NONE, STATE_NONE,
STATE_OVERWRITE_HEALTH, STATE_OVERWRITE_HEALTH,
@ -36,6 +87,7 @@ protected:
RECOVERY_WAIT RECOVERY_WAIT
} recoveryState; //!< Indicates if one of the children requested a recovery. } recoveryState; //!< Indicates if one of the children requested a recovery.
ChildrenMap::iterator recoveringDevice; ChildrenMap::iterator recoveringDevice;
/** /**
* the mode the current transition is trying to achieve. * the mode the current transition is trying to achieve.
* Can be different from the modehelper.commandedMode! * Can be different from the modehelper.commandedMode!
@ -61,8 +113,8 @@ protected:
bool handleChildrenChanged(); bool handleChildrenChanged();
/** /**
* This method is called if the children changed its mode in a way that the current * This method is called if the children changed its mode in a way that
* mode can't be kept. * the current mode can't be kept.
* Default behavior is to go to MODE_OFF. * Default behavior is to go to MODE_OFF.
* @param result The failure code which was returned by checkChildrenState. * @param result The failure code which was returned by checkChildrenState.
*/ */
@ -75,9 +127,6 @@ protected:
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t *msToReachTheMode); uint32_t *msToReachTheMode);
virtual ReturnValue_t isModeCombinationValid(Mode_t mode,
Submode_t submode) = 0;
virtual void startTransition(Mode_t mode, Submode_t submode); virtual void startTransition(Mode_t mode, Submode_t submode);
virtual void doStartTransition(Mode_t mode, Submode_t submode); virtual void doStartTransition(Mode_t mode, Submode_t submode);
@ -90,24 +139,6 @@ protected:
void sendHealthCommand(MessageQueueId_t sendTo, HealthState health); void sendHealthCommand(MessageQueueId_t sendTo, HealthState health);
//SHOULDDO: Change that OVERWRITE_HEALTH may be returned (or return internalState directly?)
/**
* command children to reach mode,submode
*
* set #commandsOutstanding correctly, or use executeTable()
*
* @param mode
* @param submode
* @return
* - @c RETURN_OK if ok
* - @c NEED_SECOND_STEP if children need to be commanded again
*/
virtual ReturnValue_t commandChildren(Mode_t mode, Submode_t submode) = 0;
//SHOULDDO: Remove wantedMode, wantedSubmode, as targetMode/submode is available?
virtual ReturnValue_t checkChildrenStateOn(Mode_t wantedMode,
Submode_t wantedSubmode) = 0;
virtual ReturnValue_t checkChildrenStateOff(); virtual ReturnValue_t checkChildrenStateOff();
ReturnValue_t checkChildrenState(); ReturnValue_t checkChildrenState();
@ -125,8 +156,9 @@ protected:
* Also sets state to STATE_OVERWRITE_HEATH. * Also sets state to STATE_OVERWRITE_HEATH.
* @param objectId Must be a registered child. * @param objectId Must be a registered child.
*/ */
void overwriteDeviceHealth(object_id_t objectId, HasHealthIF::HealthState oldHealth); void overwriteDeviceHealth(object_id_t objectId,
HasHealthIF::HealthState oldHealth);
}; };
#endif /* ASSEMBLYBASE_H_ */ #endif /* FSFW_DEVICEHANDLERS_ASSEMBLYBASE_H_ */

View File

@ -1,16 +1,18 @@
#include "ChildHandlerBase.h"
#include "../subsystem/SubsystemBase.h" #include "../subsystem/SubsystemBase.h"
#include "../devicehandlers/ChildHandlerBase.h"
#include "../subsystem/SubsystemBase.h" #include "../subsystem/SubsystemBase.h"
ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId, ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId,
object_id_t deviceCommunication, CookieIF * cookie, object_id_t deviceCommunication, CookieIF * cookie,
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, object_id_t hkDestination, uint32_t thermalStatePoolId,
object_id_t parent, FailureIsolationBase* customFdir, uint32_t thermalRequestPoolId,
size_t cmdQueueSize) : object_id_t parent,
FailureIsolationBase* customFdir, size_t cmdQueueSize) :
DeviceHandlerBase(setObjectId, deviceCommunication, cookie, DeviceHandlerBase(setObjectId, deviceCommunication, cookie,
(customFdir == nullptr? &childHandlerFdir : customFdir), (customFdir == nullptr? &childHandlerFdir : customFdir),
cmdQueueSize), cmdQueueSize),
parentId(parent), childHandlerFdir(setObjectId) { parentId(parent), childHandlerFdir(setObjectId) {
this->setHkDestination(hkDestination);
this->setThermalStateRequestPoolIds(thermalStatePoolId, this->setThermalStateRequestPoolIds(thermalStatePoolId,
thermalRequestPoolId); thermalRequestPoolId);

View File

@ -1,17 +1,18 @@
#ifndef FSFW_DEVICES_CHILDHANDLERBASE_H_ #ifndef FSFW_DEVICEHANDLER_CHILDHANDLERBASE_H_
#define FSFW_DEVICES_CHILDHANDLERBASE_H_ #define FSFW_DEVICEHANDLER_CHILDHANDLERBASE_H_
#include "ChildHandlerFDIR.h"
#include "DeviceHandlerBase.h" #include "DeviceHandlerBase.h"
#include "ChildHandlerFDIR.h"
class ChildHandlerBase: public DeviceHandlerBase { class ChildHandlerBase: public DeviceHandlerBase {
public: public:
ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
CookieIF * cookie, uint32_t thermalStatePoolId, CookieIF * cookie, object_id_t hkDestination,
uint32_t thermalRequestPoolId, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
object_id_t parent = objects::NO_OBJECT, object_id_t parent = objects::NO_OBJECT,
FailureIsolationBase* customFdir = nullptr, FailureIsolationBase* customFdir = nullptr,
size_t cmdQueueSize = 20); size_t cmdQueueSize = 20);
virtual ~ChildHandlerBase(); virtual ~ChildHandlerBase();
virtual ReturnValue_t initialize(); virtual ReturnValue_t initialize();
@ -22,5 +23,4 @@ protected:
}; };
#endif /* FSFW_DEVICES_CHILDHANDLERBASE_H_ */ #endif /* FSFW_DEVICEHANDLER_CHILDHANDLERBASE_H_ */

View File

@ -1,6 +1,7 @@
#include "ChildHandlerFDIR.h" #include "ChildHandlerFDIR.h"
ChildHandlerFDIR::ChildHandlerFDIR(object_id_t owner, object_id_t faultTreeParent, uint32_t recoveryCount) : ChildHandlerFDIR::ChildHandlerFDIR(object_id_t owner,
object_id_t faultTreeParent, uint32_t recoveryCount) :
DeviceHandlerFailureIsolation(owner, faultTreeParent) { DeviceHandlerFailureIsolation(owner, faultTreeParent) {
recoveryCounter.setFailureThreshold(recoveryCount); recoveryCounter.setFailureThreshold(recoveryCount);
} }

View File

@ -1,5 +1,5 @@
#ifndef FRAMEWORK_DEVICEHANDLERS_CHILDHANDLERFDIR_H_ #ifndef FSFW_DEVICEHANDLERS_CHILDHANDLERFDIR_H_
#define FRAMEWORK_DEVICEHANDLERS_CHILDHANDLERFDIR_H_ #define FSFW_DEVICEHANDLERS_CHILDHANDLERFDIR_H_
#include "DeviceHandlerFailureIsolation.h" #include "DeviceHandlerFailureIsolation.h"

View File

@ -1,11 +1,12 @@
#ifndef COOKIE_H_ #ifndef FSFW_DEVICEHANDLER_COOKIE_H_
#define COOKIE_H_ #define FSFW_DEVICEHANDLER_COOKIE_H_
#include <cstdint> #include <cstdint>
/** /**
* @brief Physical address type * @brief Physical address type
*/ */
typedef std::uint32_t address_t; using address_t = uint32_t;
/** /**
* @brief This datatype is used to identify different connection over a * @brief This datatype is used to identify different connection over a
@ -16,7 +17,6 @@ typedef std::uint32_t address_t;
* calling @code{.cpp} CookieIF* childCookie = new ChildCookie(...) * calling @code{.cpp} CookieIF* childCookie = new ChildCookie(...)
* @endcode . * @endcode .
* *
* [not implemented yet]
* This cookie is then passed to the child device handlers, which stores the * This cookie is then passed to the child device handlers, which stores the
* pointer and passes it to the communication interface functions. * pointer and passes it to the communication interface functions.
* *
@ -31,4 +31,4 @@ public:
virtual ~CookieIF() {}; virtual ~CookieIF() {};
}; };
#endif /* COOKIE_H_ */ #endif /* FSFW_DEVICEHANDLER_COOKIE_H_ */

View File

@ -1,9 +1,10 @@
#ifndef DEVICECOMMUNICATIONIF_H_ #ifndef FSFW_DEVICES_DEVICECOMMUNICATIONIF_H_
#define DEVICECOMMUNICATIONIF_H_ #define FSFW_DEVICES_DEVICECOMMUNICATIONIF_H_
#include "CookieIF.h" #include "CookieIF.h"
#include "DeviceHandlerIF.h"
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
#include <cstddef>
/** /**
* @defgroup interfaces Interfaces * @defgroup interfaces Interfaces
* @brief Interfaces for flight software objects * @brief Interfaces for flight software objects
@ -19,8 +20,8 @@
* the device handler to allow reuse of these components. * the device handler to allow reuse of these components.
* @details * @details
* Documentation: Dissertation Baetz p.138. * Documentation: Dissertation Baetz p.138.
* It works with the assumption that received data * It works with the assumption that received data is polled by a component.
* is polled by a component. There are four generic steps of device communication: * There are four generic steps of device communication:
* *
* 1. Send data to a device * 1. Send data to a device
* 2. Get acknowledgement for sending * 2. Get acknowledgement for sending
@ -38,24 +39,20 @@ class DeviceCommunicationIF: public HasReturnvaluesIF {
public: public:
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF; static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF;
//! Standard Error Codes //! This is returned in readReceivedMessage() if no reply was reived.
static const ReturnValue_t NO_REPLY_RECEIVED = MAKE_RETURN_CODE(0x01);
//! General protocol error. Define more concrete errors in child handler //! General protocol error. Define more concrete errors in child handler
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x01); static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x02);
//! If cookie is a null pointer //! If cookie is a null pointer
static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x02); static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x03);
static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x03); static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x04);
// is this needed if there is no open/close call? // is this needed if there is no open/close call?
static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x05); static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x05);
static const ReturnValue_t INVALID_ADDRESS = MAKE_RETURN_CODE(0x06); static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x06);
static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x07);
static const ReturnValue_t CANT_CHANGE_REPLY_LEN = MAKE_RETURN_CODE(0x08);
//! Can be used in readReceivedMessage() if no reply was received.
static const ReturnValue_t NO_REPLY_RECEIVED = MAKE_RETURN_CODE(0xA1);
virtual ~DeviceCommunicationIF() {} virtual ~DeviceCommunicationIF() {}
/** /**
* @brief Device specific initialization, using the cookie. * @brief Device specific initialization, using the cookie.
* @details * @details
@ -76,13 +73,13 @@ public:
* by implementing and calling related drivers or wrapper functions. * by implementing and calling related drivers or wrapper functions.
* @param cookie * @param cookie
* @param data * @param data
* @param len * @param len If this is 0, nothing shall be sent.
* @return * @return
* - @c RETURN_OK for successfull send * - @c RETURN_OK for successfull send
* - Everything else triggers failure event with returnvalue as parameter 1 * - Everything else triggers failure event with returnvalue as parameter 1
*/ */
virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData, virtual ReturnValue_t sendMessage(CookieIF *cookie,
size_t sendLen) = 0; const uint8_t * sendData, size_t sendLen) = 0;
/** /**
* Called by DHB in the GET_WRITE doGetWrite(). * Called by DHB in the GET_WRITE doGetWrite().
@ -124,8 +121,8 @@ public:
* - Everything else triggers failure event with * - Everything else triggers failure event with
* returnvalue as parameter 1 * returnvalue as parameter 1
*/ */
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
size_t *size) = 0; uint8_t **buffer, size_t *size) = 0;
}; };
#endif /* DEVICECOMMUNICATIONIF_H_ */ #endif /* FSFW_DEVICES_DEVICECOMMUNICATIONIF_H_ */

View File

@ -72,8 +72,13 @@ DeviceHandlerBase::~DeviceHandlerBase() {
ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) { ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) {
this->pstStep = counter; this->pstStep = counter;
this->lastStep = this->pstStep;
if (getComAction() == SEND_WRITE) { if (getComAction() == CommunicationAction::NOTHING) {
return HasReturnvaluesIF::RETURN_OK;
}
if (getComAction() == CommunicationAction::PERFORM_OPERATION) {
cookieInfo.state = COOKIE_UNUSED; cookieInfo.state = COOKIE_UNUSED;
readCommandQueue(); readCommandQueue();
doStateMachine(); doStateMachine();
@ -83,26 +88,29 @@ ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) {
hkSwitcher.performOperation(); hkSwitcher.performOperation();
hkManager.performHkOperation(); hkManager.performHkOperation();
performOperationHook(); performOperationHook();
return RETURN_OK;
} }
if (mode == MODE_OFF) { if (mode == MODE_OFF) {
return RETURN_OK; return RETURN_OK;
} }
switch (getComAction()) { switch (getComAction()) {
case SEND_WRITE: case CommunicationAction::SEND_WRITE:
if ((cookieInfo.state == COOKIE_UNUSED)) { if (cookieInfo.state == COOKIE_UNUSED) {
// if no external command was specified, build internal command.
buildInternalCommand(); buildInternalCommand();
} }
doSendWrite(); doSendWrite();
break; break;
case GET_WRITE: case CommunicationAction::GET_WRITE:
doGetWrite(); doGetWrite();
break; break;
case SEND_READ: case CommunicationAction::SEND_READ:
doSendRead(); doSendRead();
break; break;
case GET_READ: case CommunicationAction::GET_READ:
doGetRead(); doGetRead();
cookieInfo.state = COOKIE_UNUSED;
break; break;
default: default:
break; break;
@ -821,24 +829,27 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
} }
//Default child implementations //Default child implementations
DeviceHandlerIF::CommunicationAction_t DeviceHandlerBase::getComAction() { DeviceHandlerIF::CommunicationAction DeviceHandlerBase::getComAction() {
switch (pstStep) { switch (pstStep) {
case 0: case 0:
return SEND_WRITE; return CommunicationAction::PERFORM_OPERATION;
break; break;
case 1: case 1:
return GET_WRITE; return CommunicationAction::SEND_WRITE;
break; break;
case 2: case 2:
return SEND_READ; return CommunicationAction::GET_WRITE;
break; break;
case 3: case 3:
return GET_READ; return CommunicationAction::SEND_READ;
break;
case 4:
return CommunicationAction::GET_READ;
break; break;
default: default:
break; break;
} }
return NOTHING; return CommunicationAction::NOTHING;
} }
MessageQueueId_t DeviceHandlerBase::getCommandQueue() const { MessageQueueId_t DeviceHandlerBase::getCommandQueue() const {

View File

@ -577,6 +577,7 @@ protected:
/** This is the counter value from performOperation(). */ /** This is the counter value from performOperation(). */
uint8_t pstStep = 0; uint8_t pstStep = 0;
uint8_t lastStep = 0;
uint32_t pstIntervalMs = 0; uint32_t pstIntervalMs = 0;
/** /**
@ -841,7 +842,7 @@ protected:
* @return The Rmap action to execute in this step * @return The Rmap action to execute in this step
*/ */
virtual CommunicationAction_t getComAction(); virtual CommunicationAction getComAction();
/** /**
* Build the device command to send for raw mode. * Build the device command to send for raw mode.

View File

@ -247,6 +247,14 @@ bool DeviceHandlerFailureIsolation::isFdirInActionOrAreWeFaulty(
} }
return true; return true;
} }
if (owner == nullptr) {
// Configuration error.
sif::error << "DeviceHandlerFailureIsolation::"
<< "isFdirInActionOrAreWeFaulty: Owner not set!" << std::endl;
return false;
}
if (owner->getHealth() == HasHealthIF::FAULTY if (owner->getHealth() == HasHealthIF::FAULTY
|| owner->getHealth() == HasHealthIF::PERMANENT_FAULTY) { || owner->getHealth() == HasHealthIF::PERMANENT_FAULTY) {
//Ignore all events in case device is already faulty. //Ignore all events in case device is already faulty.

View File

@ -1,12 +1,19 @@
#ifndef DEVICEHANDLERIF_H_ #ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_
#define DEVICEHANDLERIF_H_ #define FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_
#include "DeviceHandlerMessage.h"
#include "../action/HasActionsIF.h" #include "../action/HasActionsIF.h"
#include "DeviceHandlerMessage.h"
#include "../events/Event.h" #include "../events/Event.h"
#include "../modes/HasModesIF.h" #include "../modes/HasModesIF.h"
#include "../ipc/MessageQueueSenderIF.h" #include "../ipc/MessageQueueSenderIF.h"
/**
* This is used to uniquely identify commands that are sent to a device
* The values are defined in the device-specific implementations
*/
using DeviceCommandId_t = uint32_t;
/** /**
* @brief This is the Interface used to communicate with a device handler. * @brief This is the Interface used to communicate with a device handler.
* @details Includes all expected return values, events and modes. * @details Includes all expected return values, events and modes.
@ -15,6 +22,7 @@
class DeviceHandlerIF { class DeviceHandlerIF {
public: public:
static const uint8_t TRANSITION_MODE_CHILD_ACTION_MASK = 0x20; static const uint8_t TRANSITION_MODE_CHILD_ACTION_MASK = 0x20;
static const uint8_t TRANSITION_MODE_BASE_ACTION_MASK = 0x10; static const uint8_t TRANSITION_MODE_BASE_ACTION_MASK = 0x10;
@ -49,6 +57,8 @@ public:
//! This is a transitional state which can not be commanded. //! This is a transitional state which can not be commanded.
//! The device handler performs all actions and commands to get the device //! The device handler performs all actions and commands to get the device
//! shut down. When the device is off, the mode changes to @c MODE_OFF. //! shut down. When the device is off, the mode changes to @c MODE_OFF.
//! It is possible to set the mode to _MODE_SHUT_DOWN to use the to off
//! transition if available.
static const Mode_t _MODE_SHUT_DOWN = TRANSITION_MODE_CHILD_ACTION_MASK | 6; static const Mode_t _MODE_SHUT_DOWN = TRANSITION_MODE_CHILD_ACTION_MASK | 6;
//! It is possible to set the mode to _MODE_TO_ON to use the to on //! It is possible to set the mode to _MODE_TO_ON to use the to on
//! transition if available. //! transition if available.
@ -98,7 +108,7 @@ public:
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF; static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF;
// Standard codes used when building commands. // Standard codes used when building commands.
static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA0); //!< If the command size is 0. Checked in DHB static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA0); //!< If no command data was given when expected.
static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); //!< Command ID not in commandMap. Checked in DHB static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); //!< Command ID not in commandMap. Checked in DHB
static const ReturnValue_t COMMAND_ALREADY_SENT = MAKE_RETURN_CODE(0xA2); //!< Command was already executed. Checked in DHB static const ReturnValue_t COMMAND_ALREADY_SENT = MAKE_RETURN_CODE(0xA2); //!< Command was already executed. Checked in DHB
static const ReturnValue_t COMMAND_WAS_NOT_SENT = MAKE_RETURN_CODE(0xA3); static const ReturnValue_t COMMAND_WAS_NOT_SENT = MAKE_RETURN_CODE(0xA3);
@ -131,7 +141,8 @@ public:
* *
* This is used by the child class to tell the base class what to do. * This is used by the child class to tell the base class what to do.
*/ */
enum CommunicationAction_t: uint8_t { enum CommunicationAction: uint8_t {
PERFORM_OPERATION,
SEND_WRITE,//!< Send write SEND_WRITE,//!< Send write
GET_WRITE, //!< Get write GET_WRITE, //!< Get write
SEND_READ, //!< Send read SEND_READ, //!< Send read
@ -152,4 +163,4 @@ public:
}; };
#endif /* DEVICEHANDLERIF_H_ */ #endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_ */

View File

@ -1,10 +1,6 @@
#include "../objectmanager/ObjectManagerIF.h"
#include "DeviceHandlerMessage.h" #include "DeviceHandlerMessage.h"
#include "../objectmanager/ObjectManagerIF.h" #include "../objectmanager/ObjectManagerIF.h"
DeviceHandlerMessage::DeviceHandlerMessage() {
}
store_address_t DeviceHandlerMessage::getStoreAddress( store_address_t DeviceHandlerMessage::getStoreAddress(
const CommandMessage* message) { const CommandMessage* message) {
return store_address_t(message->getParameter2()); return store_address_t(message->getParameter2());
@ -25,14 +21,6 @@ uint8_t DeviceHandlerMessage::getWiretappingMode(
return message->getParameter(); return message->getParameter();
} }
//void DeviceHandlerMessage::setDeviceHandlerDirectCommandMessage(
// CommandMessage* message, DeviceCommandId_t deviceCommand,
// store_address_t commandParametersStoreId) {
// message->setCommand(CMD_DIRECT);
// message->setParameter(deviceCommand);
// message->setParameter2(commandParametersStoreId.raw);
//}
void DeviceHandlerMessage::setDeviceHandlerRawCommandMessage( void DeviceHandlerMessage::setDeviceHandlerRawCommandMessage(
CommandMessage* message, store_address_t rawPacketStoreId) { CommandMessage* message, store_address_t rawPacketStoreId) {
message->setCommand(CMD_RAW); message->setCommand(CMD_RAW);
@ -47,7 +35,7 @@ void DeviceHandlerMessage::setDeviceHandlerWiretappingMessage(
void DeviceHandlerMessage::setDeviceHandlerSwitchIoBoardMessage( void DeviceHandlerMessage::setDeviceHandlerSwitchIoBoardMessage(
CommandMessage* message, uint32_t ioBoardIdentifier) { CommandMessage* message, uint32_t ioBoardIdentifier) {
message->setCommand(CMD_SWITCH_IOBOARD); message->setCommand(CMD_SWITCH_ADDRESS);
message->setParameter(ioBoardIdentifier); message->setParameter(ioBoardIdentifier);
} }
@ -79,18 +67,17 @@ void DeviceHandlerMessage::setDeviceHandlerDirectCommandReply(
void DeviceHandlerMessage::clear(CommandMessage* message) { void DeviceHandlerMessage::clear(CommandMessage* message) {
switch (message->getCommand()) { switch (message->getCommand()) {
case CMD_RAW: case CMD_RAW:
// case CMD_DIRECT:
case REPLY_RAW_COMMAND: case REPLY_RAW_COMMAND:
case REPLY_RAW_REPLY: case REPLY_RAW_REPLY:
case REPLY_DIRECT_COMMAND_DATA: { case REPLY_DIRECT_COMMAND_DATA: {
StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>( StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>(
objects::IPC_STORE); objects::IPC_STORE);
if (ipcStore != NULL) { if (ipcStore != nullptr) {
ipcStore->deleteData(getStoreAddress(message)); ipcStore->deleteData(getStoreAddress(message));
} }
} }
/* NO BREAK falls through*/ /* NO BREAK falls through*/
case CMD_SWITCH_IOBOARD: case CMD_SWITCH_ADDRESS:
case CMD_WIRETAPPING: case CMD_WIRETAPPING:
message->setCommand(CommandMessage::CMD_NONE); message->setCommand(CommandMessage::CMD_NONE);
message->setParameter(0); message->setParameter(0);

View File

@ -1,69 +1,56 @@
#ifndef DEVICEHANDLERMESSAGE_H_ #ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERMESSAGE_H_
#define DEVICEHANDLERMESSAGE_H_ #define FSFW_DEVICEHANDLERS_DEVICEHANDLERMESSAGE_H_
#include "../action/ActionMessage.h" #include "../action/ActionMessage.h"
#include "../ipc/CommandMessage.h" #include "../ipc/CommandMessage.h"
#include "../objectmanager/SystemObjectIF.h" #include "../objectmanager/SystemObjectIF.h"
#include "../storagemanager/StorageManagerIF.h" #include "../storagemanager/StorageManagerIF.h"
//SHOULDDO: rework the static constructors to name the type of command they are building, maybe even hide setting the commandID. // SHOULDDO: rework the static constructors to name the type of command
// they are building, maybe even hide setting the commandID.
/** /**
* This is used to uniquely identify commands that are sent to a device * @brief The DeviceHandlerMessage is used to send commands to classes
* * implementing DeviceHandlerIF
* The values are defined in the device-specific implementations
*/
typedef uint32_t DeviceCommandId_t;
/**
* The DeviceHandlerMessage is used to send Commands to a DeviceHandlerIF
*/ */
class DeviceHandlerMessage { class DeviceHandlerMessage {
private:
DeviceHandlerMessage();
public: public:
/**
* Instantiation forbidden. Instead, use static functions to operate
* on messages.
*/
DeviceHandlerMessage() = delete;
virtual ~DeviceHandlerMessage() {}
/** /**
* These are the commands that can be sent to a DeviceHandlerBase * These are the commands that can be sent to a DeviceHandlerBase
*/ */
static const uint8_t MESSAGE_ID = messagetypes::DEVICE_HANDLER_COMMAND; static const uint8_t MESSAGE_ID = messagetypes::DEVICE_HANDLER_COMMAND;
static const Command_t CMD_RAW = MAKE_COMMAND_ID( 1 ); //!< Sends a raw command, setParameter is a ::store_id_t containing the raw packet to send //! Sends a raw command, setParameter is a storeId containing the
// static const Command_t CMD_DIRECT = MAKE_COMMAND_ID( 2 ); //!< Sends a direct command, setParameter is a ::DeviceCommandId_t, setParameter2 is a ::store_id_t containing the data needed for the command //! raw packet to send
static const Command_t CMD_SWITCH_IOBOARD = MAKE_COMMAND_ID( 3 ); //!< Requests a IO-Board switch, setParameter() is the IO-Board identifier static const Command_t CMD_RAW = MAKE_COMMAND_ID(1);
static const Command_t CMD_WIRETAPPING = MAKE_COMMAND_ID( 4 ); //!< (De)Activates the monitoring of all raw traffic in DeviceHandlers, setParameter is 0 to deactivate, 1 to activate //! Requests a IO-Board switch, setParameter() is the IO-Board identifier
static const Command_t CMD_SWITCH_ADDRESS = MAKE_COMMAND_ID(3);
//! (De)Activates the monitoring of all raw traffic in DeviceHandlers,
//! setParameter is 0 to deactivate, 1 to activate
static const Command_t CMD_WIRETAPPING = MAKE_COMMAND_ID(4);
/*static const Command_t REPLY_SWITCHED_IOBOARD = MAKE_COMMAND_ID(1 );//!< Reply to a @c CMD_SWITCH_IOBOARD, indicates switch was successful, getParameter() contains the board switched to (0: nominal, 1: redundant) //! Signals that a direct command was sent
static const Command_t REPLY_CANT_SWITCH_IOBOARD = MAKE_COMMAND_ID( 2); //!< Reply to a @c CMD_SWITCH_IOBOARD, indicating the switch could not be performed, getParameter() contains the error message static const Command_t REPLY_DIRECT_COMMAND_SENT = ActionMessage::STEP_SUCCESS;
static const Command_t REPLY_WIRETAPPING = MAKE_COMMAND_ID( 3); //!< Reply to a @c CMD_WIRETAPPING, getParameter() is the current state, 1 enabled, 0 disabled //! Contains a raw command sent to the Device
static const Command_t REPLY_RAW_COMMAND = MAKE_COMMAND_ID(0x11);
static const Command_t REPLY_COMMAND_WAS_SENT = MAKE_COMMAND_ID(4 );//!< Reply to a @c CMD_RAW or @c CMD_DIRECT, indicates the command was successfully sent to the device, getParameter() contains the ::DeviceCommandId_t //! Contains a raw reply from the Device, getParameter() is the ObjcetId
static const Command_t REPLY_COMMAND_NOT_SUPPORTED = MAKE_COMMAND_ID(5 );//!< Reply to a @c CMD_DIRECT, the requested ::DeviceCommand_t is not supported, getParameter() contains the requested ::DeviceCommand_t, getParameter2() contains the ::DeviceCommandId_t //! of the sender, getParameter2() is a ::store_id_t containing the
static const Command_t REPLY_COMMAND_WAS_NOT_SENT = MAKE_COMMAND_ID(6 );//!< Reply to a @c CMD_RAW or @c CMD_DIRECT, indicates the command was not sent, getParameter contains the RMAP Return code (@see rmap.h), getParameter2() contains the ::DeviceCommandId_t //! raw packet received
static const Command_t REPLY_RAW_REPLY = MAKE_COMMAND_ID(0x12);
static const Command_t REPLY_COMMAND_ALREADY_SENT = MAKE_COMMAND_ID(7 );//!< Reply to a @c CMD_DIRECT, the requested ::DeviceCommand_t has already been sent to the device and not ye been answered
static const Command_t REPLY_WRONG_MODE_FOR_CMD = MAKE_COMMAND_ID(8 );//!< Reply to a @c CMD_RAW or @c CMD_DIRECT, indicates that the requested command can not be sent in the curent mode, getParameter() contains the DeviceHandlerCommand_t
static const Command_t REPLY_NO_DATA = MAKE_COMMAND_ID(9 ); //!< Reply to a CMD_RAW or @c CMD_DIRECT, indicates that the ::store_id_t was invalid, getParameter() contains the ::DeviceCommandId_t, getPrameter2() contains the error code
*/
static const Command_t REPLY_DIRECT_COMMAND_SENT = ActionMessage::STEP_SUCCESS; //!< Signals that a direct command was sent
static const Command_t REPLY_RAW_COMMAND = MAKE_COMMAND_ID(0x11 ); //!< Contains a raw command sent to the Device
static const Command_t REPLY_RAW_REPLY = MAKE_COMMAND_ID( 0x12); //!< Contains a raw reply from the Device, getParameter() is the ObjcetId of the sender, getParameter2() is a ::store_id_t containing the raw packet received
static const Command_t REPLY_DIRECT_COMMAND_DATA = ActionMessage::DATA_REPLY; static const Command_t REPLY_DIRECT_COMMAND_DATA = ActionMessage::DATA_REPLY;
/**
* Default Destructor
*/
virtual ~DeviceHandlerMessage() {
}
static store_address_t getStoreAddress(const CommandMessage* message); static store_address_t getStoreAddress(const CommandMessage* message);
static uint32_t getDeviceCommandId(const CommandMessage* message); static uint32_t getDeviceCommandId(const CommandMessage* message);
static object_id_t getDeviceObjectId(const CommandMessage *message); static object_id_t getDeviceObjectId(const CommandMessage *message);
static object_id_t getIoBoardObjectId(const CommandMessage* message); static object_id_t getIoBoardObjectId(const CommandMessage* message);
static uint8_t getWiretappingMode(const CommandMessage* message); static uint8_t getWiretappingMode(const CommandMessage* message);
// static void setDeviceHandlerDirectCommandMessage(CommandMessage* message,
// DeviceCommandId_t deviceCommand,
// store_address_t commandParametersStoreId);
static void setDeviceHandlerDirectCommandReply(CommandMessage* message, static void setDeviceHandlerDirectCommandReply(CommandMessage* message,
object_id_t deviceObjectid, object_id_t deviceObjectid,
store_address_t commandParametersStoreId); store_address_t commandParametersStoreId);
@ -75,11 +62,6 @@ public:
object_id_t deviceObjectid, store_address_t rawPacketStoreId, object_id_t deviceObjectid, store_address_t rawPacketStoreId,
bool isCommand); bool isCommand);
// static void setDeviceHandlerMessage(CommandMessage* message,
// Command_t command, DeviceCommandId_t deviceCommand,
// store_address_t commandParametersStoreId);
// static void setDeviceHandlerMessage(CommandMessage* message,
// Command_t command, store_address_t rawPacketStoreId);
static void setDeviceHandlerWiretappingMessage(CommandMessage* message, static void setDeviceHandlerWiretappingMessage(CommandMessage* message,
uint8_t wiretappingMode); uint8_t wiretappingMode);
static void setDeviceHandlerSwitchIoBoardMessage(CommandMessage* message, static void setDeviceHandlerSwitchIoBoardMessage(CommandMessage* message,
@ -88,4 +70,4 @@ public:
static void clear(CommandMessage* message); static void clear(CommandMessage* message);
}; };
#endif /* DEVICEHANDLERMESSAGE_H_ */ #endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERMESSAGE_H_ */

View File

@ -1,4 +1,3 @@
#include "../serialize/SerializeAdapter.h"
#include "DeviceTmReportingWrapper.h" #include "DeviceTmReportingWrapper.h"
#include "../serialize/SerializeAdapter.h" #include "../serialize/SerializeAdapter.h"

View File

@ -1,5 +1,5 @@
#ifndef DEVICETMREPORTINGWRAPPER_H_ #ifndef FSFW_DEVICEHANDLERS_DEVICETMREPORTINGWRAPPER_H_
#define DEVICETMREPORTINGWRAPPER_H_ #define FSFW_DEVICEHANDLERS_DEVICETMREPORTINGWRAPPER_H_
#include "../action/HasActionsIF.h" #include "../action/HasActionsIF.h"
#include "../objectmanager/SystemObjectIF.h" #include "../objectmanager/SystemObjectIF.h"
@ -24,4 +24,4 @@ private:
SerializeIF *data; SerializeIF *data;
}; };
#endif /* DEVICETMREPORTINGWRAPPER_H_ */ #endif /* FSFW_DEVICEHANDLERS_DEVICETMREPORTINGWRAPPER_H_ */

View File

@ -13,10 +13,10 @@ HealthDevice::~HealthDevice() {
} }
ReturnValue_t HealthDevice::performOperation(uint8_t opCode) { ReturnValue_t HealthDevice::performOperation(uint8_t opCode) {
CommandMessage message; CommandMessage command;
ReturnValue_t result = commandQueue->receiveMessage(&message); ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
healthHelper.handleHealthCommand(&message); healthHelper.handleHealthCommand(&command);
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -1,5 +1,5 @@
#ifndef HEALTHDEVICE_H_ #ifndef FSFW_DEVICEHANDLERS_HEALTHDEVICE_H_
#define HEALTHDEVICE_H_ #define FSFW_DEVICEHANDLERS_HEALTHDEVICE_H_
#include "../health/HasHealthIF.h" #include "../health/HasHealthIF.h"
#include "../health/HealthHelper.h" #include "../health/HealthHelper.h"
@ -37,4 +37,4 @@ public:
HealthHelper healthHelper; HealthHelper healthHelper;
}; };
#endif /* HEALTHDEVICE_H_ */ #endif /* FSFW_DEVICEHANDLERS_HEALTHDEVICE_H_ */

View File

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

View File

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

View File

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

View File

@ -1,39 +1,50 @@
#ifndef MONITORBASE_H_ #ifndef FSFW_MONITORING_MONITORBASE_H_
#define MONITORBASE_H_ #define FSFW_MONITORING_MONITORBASE_H_
#include "LimitViolationReporter.h"
#include "MonitoringIF.h"
#include "MonitoringMessageContent.h"
#include "MonitorReporter.h"
#include "../datapoollocal/LocalPoolVariable.h"
#include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/PIDReader.h"
#include "../monitoring/LimitViolationReporter.h"
#include "../monitoring/MonitoringIF.h"
#include "../monitoring/MonitoringMessageContent.h"
#include "../monitoring/MonitorReporter.h"
/** /**
* Base class for monitoring of parameters. * @brief Base class for monitoring of parameters.
* Can be used anywhere, specializations need to implement checkSample and should override sendTransitionEvent. * @details
* Manages state handling, enabling and disabling of events/reports and forwarding of transition * Can be used anywhere, specializations need to implement checkSample and
* reports via MonitorReporter. In addition, it provides default implementations for fetching the parameter sample from * should override sendTransitionEvent.
* the data pool and a simple confirmation counter. * Manages state handling, enabling and disabling of events/reports and
* forwarding of transition reports via MonitorReporter.
*
* In addition, it provides default implementations for fetching the
* parameter sample from the data pool and a simple confirmation counter.
*/ */
template<typename T> template<typename T>
class MonitorBase: public MonitorReporter<T> { class MonitorBase: public MonitorReporter<T> {
public: public:
MonitorBase(object_id_t reporterId, uint8_t monitorId, MonitorBase(object_id_t reporterId, uint8_t monitorId,
uint32_t parameterId, uint16_t confirmationLimit) : gp_id_t globalPoolId, uint16_t confirmationLimit):
MonitorReporter<T>(reporterId, monitorId, parameterId, confirmationLimit) { MonitorReporter<T>(reporterId, monitorId, globalPoolId,
confirmationLimit),
poolVariable(globalPoolId) {
} }
virtual ~MonitorBase() { virtual ~MonitorBase() {
} }
virtual ReturnValue_t check() { virtual ReturnValue_t check() {
//1. Fetch sample of type T, return validity. // 1. Fetch sample of type T, return validity.
T sample = 0; T sample = 0;
ReturnValue_t validity = fetchSample(&sample); ReturnValue_t validity = fetchSample(&sample);
//2. If returning from fetch != OK, parameter is invalid. Report (if oldState is != invalidity). // 2. If returning from fetch != OK, parameter is invalid.
// Report (if oldState is != invalidity).
if (validity != HasReturnvaluesIF::RETURN_OK) { if (validity != HasReturnvaluesIF::RETURN_OK) {
this->monitorStateIs(validity, sample, 0); this->monitorStateIs(validity, sample, 0);
//3. Otherwise, check sample.
} else { } else {
//3. Otherwise, check sample.
this->oldState = doCheck(sample); this->oldState = doCheck(sample);
} }
return this->oldState; return this->oldState;
@ -43,20 +54,25 @@ public:
ReturnValue_t currentState = checkSample(sample, &crossedLimit); ReturnValue_t currentState = checkSample(sample, &crossedLimit);
return this->monitorStateIs(currentState,sample, crossedLimit); return this->monitorStateIs(currentState,sample, crossedLimit);
} }
//Abstract or default.
// Abstract or default.
virtual ReturnValue_t checkSample(T sample, T* crossedLimit) = 0; virtual ReturnValue_t checkSample(T sample, T* crossedLimit) = 0;
protected: protected:
virtual ReturnValue_t fetchSample(T* sample) { virtual ReturnValue_t fetchSample(T* sample) {
GlobDataSet mySet; ReturnValue_t result = poolVariable.read();
PIDReader<T> parameter(this->parameterId, &mySet); if(result != HasReturnvaluesIF::RETURN_OK) {
mySet.read(); return result;
if (!parameter.isValid()) { }
if (not poolVariable.isValid()) {
return MonitoringIF::INVALID; return MonitoringIF::INVALID;
} }
*sample = parameter.value; *sample = poolVariable.value;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
LocalPoolVar<T> poolVariable;
}; };
#endif /* MONITORBASE_H_ */ #endif /* FSFW_MONITORING_MONITORBASE_H_ */

View File

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

View File

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

View File

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

View File

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