renormalized line endings

This commit is contained in:
2020-08-28 18:33:29 +02:00
parent 9abd796e6f
commit 1b9c8446b7
381 changed files with 38723 additions and 38723 deletions

View File

@ -1,19 +1,19 @@
#ifndef FRAMEWORK_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_
#define FRAMEWORK_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_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 {
public:
/**
* Default empty virtual destructor.
*/
virtual ~AcceptsDeviceResponsesIF() {}
virtual MessageQueueId_t getDeviceQueue() = 0;
};
#endif /* FRAMEWORK_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_ */
#ifndef FRAMEWORK_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_
#define FRAMEWORK_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_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 {
public:
/**
* Default empty virtual destructor.
*/
virtual ~AcceptsDeviceResponsesIF() {}
virtual MessageQueueId_t getDeviceQueue() = 0;
};
#endif /* FRAMEWORK_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_ */

View File

@ -1,273 +1,273 @@
#include "../devicehandlers/AssemblyBase.h"
AssemblyBase::AssemblyBase(object_id_t objectId, object_id_t parentId,
uint16_t commandQueueDepth) :
SubsystemBase(objectId, parentId, MODE_OFF, commandQueueDepth),
internalState(STATE_NONE), recoveryState(RECOVERY_IDLE),
recoveringDevice(childrenMap.end()), targetMode(MODE_OFF),
targetSubmode(SUBMODE_NONE) {
recoveryOffTimer.setTimeout(POWER_OFF_TIME_MS);
}
AssemblyBase::~AssemblyBase() {
}
ReturnValue_t AssemblyBase::handleCommandMessage(CommandMessage* message) {
return handleHealthReply(message);
}
void AssemblyBase::performChildOperation() {
if (isInTransition()) {
handleChildrenTransition();
} else {
handleChildrenChanged();
}
}
void AssemblyBase::startTransition(Mode_t mode, Submode_t submode) {
doStartTransition(mode, submode);
if (modeHelper.isForced()) {
triggerEvent(FORCING_MODE, mode, submode);
} else {
triggerEvent(CHANGING_MODE, mode, submode);
}
}
void AssemblyBase::doStartTransition(Mode_t mode, Submode_t submode) {
targetMode = mode;
targetSubmode = submode;
internalState = STATE_SINGLE_STEP;
ReturnValue_t result = commandChildren(mode, submode);
if (result == NEED_SECOND_STEP) {
internalState = STATE_NEED_SECOND_STEP;
}
}
bool AssemblyBase::isInTransition() {
return (internalState != STATE_NONE) || (recoveryState != RECOVERY_IDLE);
}
bool AssemblyBase::handleChildrenChanged() {
if (childrenChangedMode) {
ReturnValue_t result = checkChildrenState();
if (result != RETURN_OK) {
handleChildrenLostMode(result);
}
return true;
} else {
return handleChildrenChangedHealth();
}
}
void AssemblyBase::handleChildrenLostMode(ReturnValue_t result) {
triggerEvent(CANT_KEEP_MODE, mode, submode);
startTransition(MODE_OFF, SUBMODE_NONE);
}
bool AssemblyBase::handleChildrenChangedHealth() {
auto iter = childrenMap.begin();
for (; iter != childrenMap.end(); iter++) {
if (iter->second.healthChanged) {
iter->second.healthChanged = false;
break;
}
}
if (iter == childrenMap.end()) {
return false;
}
HealthState healthState = healthHelper.healthTable->getHealth(iter->first);
if (healthState == HasHealthIF::NEEDS_RECOVERY) {
triggerEvent(TRYING_RECOVERY);
recoveryState = RECOVERY_STARTED;
recoveringDevice = iter;
doStartTransition(targetMode, targetSubmode);
} else {
triggerEvent(CHILD_CHANGED_HEALTH);
doStartTransition(mode, submode);
}
if (modeHelper.isForced()) {
triggerEvent(FORCING_MODE, targetMode, targetSubmode);
}
return true;
}
void AssemblyBase::handleChildrenTransition() {
if (commandsOutstanding <= 0) {
switch (internalState) {
case STATE_NEED_SECOND_STEP:
internalState = STATE_SECOND_STEP;
commandChildren(targetMode, targetSubmode);
return;
case STATE_OVERWRITE_HEALTH: {
internalState = STATE_SINGLE_STEP;
ReturnValue_t result = commandChildren(mode, submode);
if (result == NEED_SECOND_STEP) {
internalState = STATE_NEED_SECOND_STEP;
}
return;
}
case STATE_NONE:
//Valid state, used in recovery.
case STATE_SINGLE_STEP:
case STATE_SECOND_STEP:
if (checkAndHandleRecovery()) {
return;
}
break;
}
ReturnValue_t result = checkChildrenState();
if (result == RETURN_OK) {
handleModeReached();
} else {
handleModeTransitionFailed(result);
}
}
}
void AssemblyBase::handleModeReached() {
internalState = STATE_NONE;
setMode(targetMode, targetSubmode);
}
void AssemblyBase::handleModeTransitionFailed(ReturnValue_t result) {
//always accept transition to OFF, there is nothing we can do except sending an info event
//In theory this should never happen, but we would risk an infinite loop otherwise
if (targetMode == MODE_OFF) {
triggerEvent(CHILD_PROBLEMS, result);
internalState = STATE_NONE;
setMode(targetMode, targetSubmode);
} else {
if (handleChildrenChangedHealth()) {
//If any health change is pending, handle that first.
return;
}
triggerEvent(MODE_TRANSITION_FAILED, result);
startTransition(MODE_OFF, SUBMODE_NONE);
}
}
void AssemblyBase::sendHealthCommand(MessageQueueId_t sendTo,
HealthState health) {
CommandMessage command;
HealthMessage::setHealthMessage(&command, HealthMessage::HEALTH_SET,
health);
if (commandQueue->sendMessage(sendTo, &command) == RETURN_OK) {
commandsOutstanding++;
}
}
ReturnValue_t AssemblyBase::checkChildrenState() {
if (targetMode == MODE_OFF) {
return checkChildrenStateOff();
} else {
return checkChildrenStateOn(targetMode, targetSubmode);
}
}
ReturnValue_t AssemblyBase::checkChildrenStateOff() {
for (const auto& childIter: childrenMap) {
if (checkChildOff(childIter.first) != RETURN_OK) {
return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE;
}
}
return RETURN_OK;
}
ReturnValue_t AssemblyBase::checkChildOff(uint32_t objectId) {
ChildInfo childInfo = childrenMap.find(objectId)->second;
if (healthHelper.healthTable->isCommandable(objectId)) {
if (childInfo.submode != SUBMODE_NONE) {
return RETURN_FAILED;
} else {
if ((childInfo.mode != MODE_OFF)
&& (childInfo.mode != DeviceHandlerIF::MODE_ERROR_ON)) {
return RETURN_FAILED;
}
}
}
return RETURN_OK;
}
ReturnValue_t AssemblyBase::checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t* msToReachTheMode) {
//always accept transition to OFF
if (mode == MODE_OFF) {
if (submode != SUBMODE_NONE) {
return INVALID_SUBMODE;
}
return RETURN_OK;
}
if ((mode != MODE_ON) && (mode != DeviceHandlerIF::MODE_NORMAL)) {
return INVALID_MODE;
}
if (internalState != STATE_NONE) {
return IN_TRANSITION;
}
return isModeCombinationValid(mode, submode);
}
ReturnValue_t AssemblyBase::handleHealthReply(CommandMessage* message) {
if (message->getCommand() == HealthMessage::HEALTH_INFO) {
HealthState health = HealthMessage::getHealth(message);
if (health != EXTERNAL_CONTROL) {
updateChildChangedHealth(message->getSender(), true);
}
return RETURN_OK;
}
if (message->getCommand() == HealthMessage::REPLY_HEALTH_SET
|| (message->getCommand() == CommandMessage::REPLY_REJECTED
&& message->getParameter2() == HealthMessage::HEALTH_SET)) {
if (isInTransition()) {
commandsOutstanding--;
}
return RETURN_OK;
}
return RETURN_FAILED;
}
bool AssemblyBase::checkAndHandleRecovery() {
switch (recoveryState) {
case RECOVERY_STARTED:
recoveryState = RECOVERY_WAIT;
recoveryOffTimer.resetTimer();
return true;
case RECOVERY_WAIT:
if (recoveryOffTimer.isBusy()) {
return true;
}
triggerEvent(RECOVERY_STEP, 0);
sendHealthCommand(recoveringDevice->second.commandQueue, HEALTHY);
internalState = STATE_NONE;
recoveryState = RECOVERY_ONGOING;
//Don't check state!
return true;
case RECOVERY_ONGOING:
triggerEvent(RECOVERY_STEP, 1);
recoveryState = RECOVERY_ONGOING_2;
recoveringDevice->second.healthChanged = false;
//Device should be healthy again, so restart a transition.
//Might be including second step, but that's already handled.
doStartTransition(targetMode, targetSubmode);
return true;
case RECOVERY_ONGOING_2:
triggerEvent(RECOVERY_DONE);
//Now we're through, but not sure if it was successful.
recoveryState = RECOVERY_IDLE;
return false;
case RECOVERY_IDLE:
default:
return false;
}
}
void AssemblyBase::overwriteDeviceHealth(object_id_t objectId,
HasHealthIF::HealthState oldHealth) {
triggerEvent(OVERWRITING_HEALTH, objectId, oldHealth);
internalState = STATE_OVERWRITE_HEALTH;
modeHelper.setForced(true);
sendHealthCommand(childrenMap[objectId].commandQueue, EXTERNAL_CONTROL);
}
#include "../devicehandlers/AssemblyBase.h"
AssemblyBase::AssemblyBase(object_id_t objectId, object_id_t parentId,
uint16_t commandQueueDepth) :
SubsystemBase(objectId, parentId, MODE_OFF, commandQueueDepth),
internalState(STATE_NONE), recoveryState(RECOVERY_IDLE),
recoveringDevice(childrenMap.end()), targetMode(MODE_OFF),
targetSubmode(SUBMODE_NONE) {
recoveryOffTimer.setTimeout(POWER_OFF_TIME_MS);
}
AssemblyBase::~AssemblyBase() {
}
ReturnValue_t AssemblyBase::handleCommandMessage(CommandMessage* message) {
return handleHealthReply(message);
}
void AssemblyBase::performChildOperation() {
if (isInTransition()) {
handleChildrenTransition();
} else {
handleChildrenChanged();
}
}
void AssemblyBase::startTransition(Mode_t mode, Submode_t submode) {
doStartTransition(mode, submode);
if (modeHelper.isForced()) {
triggerEvent(FORCING_MODE, mode, submode);
} else {
triggerEvent(CHANGING_MODE, mode, submode);
}
}
void AssemblyBase::doStartTransition(Mode_t mode, Submode_t submode) {
targetMode = mode;
targetSubmode = submode;
internalState = STATE_SINGLE_STEP;
ReturnValue_t result = commandChildren(mode, submode);
if (result == NEED_SECOND_STEP) {
internalState = STATE_NEED_SECOND_STEP;
}
}
bool AssemblyBase::isInTransition() {
return (internalState != STATE_NONE) || (recoveryState != RECOVERY_IDLE);
}
bool AssemblyBase::handleChildrenChanged() {
if (childrenChangedMode) {
ReturnValue_t result = checkChildrenState();
if (result != RETURN_OK) {
handleChildrenLostMode(result);
}
return true;
} else {
return handleChildrenChangedHealth();
}
}
void AssemblyBase::handleChildrenLostMode(ReturnValue_t result) {
triggerEvent(CANT_KEEP_MODE, mode, submode);
startTransition(MODE_OFF, SUBMODE_NONE);
}
bool AssemblyBase::handleChildrenChangedHealth() {
auto iter = childrenMap.begin();
for (; iter != childrenMap.end(); iter++) {
if (iter->second.healthChanged) {
iter->second.healthChanged = false;
break;
}
}
if (iter == childrenMap.end()) {
return false;
}
HealthState healthState = healthHelper.healthTable->getHealth(iter->first);
if (healthState == HasHealthIF::NEEDS_RECOVERY) {
triggerEvent(TRYING_RECOVERY);
recoveryState = RECOVERY_STARTED;
recoveringDevice = iter;
doStartTransition(targetMode, targetSubmode);
} else {
triggerEvent(CHILD_CHANGED_HEALTH);
doStartTransition(mode, submode);
}
if (modeHelper.isForced()) {
triggerEvent(FORCING_MODE, targetMode, targetSubmode);
}
return true;
}
void AssemblyBase::handleChildrenTransition() {
if (commandsOutstanding <= 0) {
switch (internalState) {
case STATE_NEED_SECOND_STEP:
internalState = STATE_SECOND_STEP;
commandChildren(targetMode, targetSubmode);
return;
case STATE_OVERWRITE_HEALTH: {
internalState = STATE_SINGLE_STEP;
ReturnValue_t result = commandChildren(mode, submode);
if (result == NEED_SECOND_STEP) {
internalState = STATE_NEED_SECOND_STEP;
}
return;
}
case STATE_NONE:
//Valid state, used in recovery.
case STATE_SINGLE_STEP:
case STATE_SECOND_STEP:
if (checkAndHandleRecovery()) {
return;
}
break;
}
ReturnValue_t result = checkChildrenState();
if (result == RETURN_OK) {
handleModeReached();
} else {
handleModeTransitionFailed(result);
}
}
}
void AssemblyBase::handleModeReached() {
internalState = STATE_NONE;
setMode(targetMode, targetSubmode);
}
void AssemblyBase::handleModeTransitionFailed(ReturnValue_t result) {
//always accept transition to OFF, there is nothing we can do except sending an info event
//In theory this should never happen, but we would risk an infinite loop otherwise
if (targetMode == MODE_OFF) {
triggerEvent(CHILD_PROBLEMS, result);
internalState = STATE_NONE;
setMode(targetMode, targetSubmode);
} else {
if (handleChildrenChangedHealth()) {
//If any health change is pending, handle that first.
return;
}
triggerEvent(MODE_TRANSITION_FAILED, result);
startTransition(MODE_OFF, SUBMODE_NONE);
}
}
void AssemblyBase::sendHealthCommand(MessageQueueId_t sendTo,
HealthState health) {
CommandMessage command;
HealthMessage::setHealthMessage(&command, HealthMessage::HEALTH_SET,
health);
if (commandQueue->sendMessage(sendTo, &command) == RETURN_OK) {
commandsOutstanding++;
}
}
ReturnValue_t AssemblyBase::checkChildrenState() {
if (targetMode == MODE_OFF) {
return checkChildrenStateOff();
} else {
return checkChildrenStateOn(targetMode, targetSubmode);
}
}
ReturnValue_t AssemblyBase::checkChildrenStateOff() {
for (const auto& childIter: childrenMap) {
if (checkChildOff(childIter.first) != RETURN_OK) {
return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE;
}
}
return RETURN_OK;
}
ReturnValue_t AssemblyBase::checkChildOff(uint32_t objectId) {
ChildInfo childInfo = childrenMap.find(objectId)->second;
if (healthHelper.healthTable->isCommandable(objectId)) {
if (childInfo.submode != SUBMODE_NONE) {
return RETURN_FAILED;
} else {
if ((childInfo.mode != MODE_OFF)
&& (childInfo.mode != DeviceHandlerIF::MODE_ERROR_ON)) {
return RETURN_FAILED;
}
}
}
return RETURN_OK;
}
ReturnValue_t AssemblyBase::checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t* msToReachTheMode) {
//always accept transition to OFF
if (mode == MODE_OFF) {
if (submode != SUBMODE_NONE) {
return INVALID_SUBMODE;
}
return RETURN_OK;
}
if ((mode != MODE_ON) && (mode != DeviceHandlerIF::MODE_NORMAL)) {
return INVALID_MODE;
}
if (internalState != STATE_NONE) {
return IN_TRANSITION;
}
return isModeCombinationValid(mode, submode);
}
ReturnValue_t AssemblyBase::handleHealthReply(CommandMessage* message) {
if (message->getCommand() == HealthMessage::HEALTH_INFO) {
HealthState health = HealthMessage::getHealth(message);
if (health != EXTERNAL_CONTROL) {
updateChildChangedHealth(message->getSender(), true);
}
return RETURN_OK;
}
if (message->getCommand() == HealthMessage::REPLY_HEALTH_SET
|| (message->getCommand() == CommandMessage::REPLY_REJECTED
&& message->getParameter2() == HealthMessage::HEALTH_SET)) {
if (isInTransition()) {
commandsOutstanding--;
}
return RETURN_OK;
}
return RETURN_FAILED;
}
bool AssemblyBase::checkAndHandleRecovery() {
switch (recoveryState) {
case RECOVERY_STARTED:
recoveryState = RECOVERY_WAIT;
recoveryOffTimer.resetTimer();
return true;
case RECOVERY_WAIT:
if (recoveryOffTimer.isBusy()) {
return true;
}
triggerEvent(RECOVERY_STEP, 0);
sendHealthCommand(recoveringDevice->second.commandQueue, HEALTHY);
internalState = STATE_NONE;
recoveryState = RECOVERY_ONGOING;
//Don't check state!
return true;
case RECOVERY_ONGOING:
triggerEvent(RECOVERY_STEP, 1);
recoveryState = RECOVERY_ONGOING_2;
recoveringDevice->second.healthChanged = false;
//Device should be healthy again, so restart a transition.
//Might be including second step, but that's already handled.
doStartTransition(targetMode, targetSubmode);
return true;
case RECOVERY_ONGOING_2:
triggerEvent(RECOVERY_DONE);
//Now we're through, but not sure if it was successful.
recoveryState = RECOVERY_IDLE;
return false;
case RECOVERY_IDLE:
default:
return false;
}
}
void AssemblyBase::overwriteDeviceHealth(object_id_t objectId,
HasHealthIF::HealthState oldHealth) {
triggerEvent(OVERWRITING_HEALTH, objectId, oldHealth);
internalState = STATE_OVERWRITE_HEALTH;
modeHelper.setForced(true);
sendHealthCommand(childrenMap[objectId].commandQueue, EXTERNAL_CONTROL);
}

View File

@ -1,163 +1,163 @@
#ifndef FRAMEWORK_DEVICEHANDLERS_ASSEMBLYBASE_H_
#define FRAMEWORK_DEVICEHANDLERS_ASSEMBLYBASE_H_
#include "../container/FixedArrayList.h"
#include "../devicehandlers/DeviceHandlerBase.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 {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::ASSEMBLY_BASE;
static const ReturnValue_t NEED_SECOND_STEP = MAKE_RETURN_CODE(0x01);
static const ReturnValue_t NEED_TO_RECONFIGURE = MAKE_RETURN_CODE(0x02);
static const ReturnValue_t MODE_FALLBACK = MAKE_RETURN_CODE(0x03);
static const ReturnValue_t CHILD_NOT_COMMANDABLE = MAKE_RETURN_CODE(0x04);
static const ReturnValue_t NEED_TO_CHANGE_HEALTH = MAKE_RETURN_CODE(0x05);
static const ReturnValue_t NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE =
MAKE_RETURN_CODE(0xa1);
AssemblyBase(object_id_t objectId, object_id_t parentId,
uint16_t commandQueueDepth = 8);
virtual ~AssemblyBase();
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 {
STATE_NONE,
STATE_OVERWRITE_HEALTH,
STATE_NEED_SECOND_STEP,
STATE_SINGLE_STEP,
STATE_SECOND_STEP,
} internalState;
enum RecoveryState {
RECOVERY_IDLE,
RECOVERY_STARTED,
RECOVERY_ONGOING,
RECOVERY_ONGOING_2,
RECOVERY_WAIT
} recoveryState; //!< Indicates if one of the children requested a recovery.
ChildrenMap::iterator recoveringDevice;
/**
* the mode the current transition is trying to achieve.
* Can be different from the modehelper.commandedMode!
*/
Mode_t targetMode;
/**
* the submode the current transition is trying to achieve.
* Can be different from the modehelper.commandedSubmode!
*/
Submode_t targetSubmode;
Countdown recoveryOffTimer;
static const uint32_t POWER_OFF_TIME_MS = 1000;
virtual ReturnValue_t handleCommandMessage(CommandMessage *message);
virtual ReturnValue_t handleHealthReply(CommandMessage *message);
virtual void performChildOperation();
bool handleChildrenChanged();
/**
* This method is called if the children changed its mode in a way that
* the current mode can't be kept.
* Default behavior is to go to MODE_OFF.
* @param result The failure code which was returned by checkChildrenState.
*/
virtual void handleChildrenLostMode(ReturnValue_t result);
bool handleChildrenChangedHealth();
virtual void handleChildrenTransition();
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t *msToReachTheMode);
virtual void startTransition(Mode_t mode, Submode_t submode);
virtual void doStartTransition(Mode_t mode, Submode_t submode);
virtual bool isInTransition();
virtual void handleModeReached();
virtual void handleModeTransitionFailed(ReturnValue_t result);
void sendHealthCommand(MessageQueueId_t sendTo, HealthState health);
virtual ReturnValue_t checkChildrenStateOff();
ReturnValue_t checkChildrenState();
virtual ReturnValue_t checkChildOff(uint32_t objectId);
/**
* Manages recovery of a device
* @return true if recovery is still ongoing, false else.
*/
bool checkAndHandleRecovery();
/**
* Helper method to overwrite health state of one of the children.
* Also sets state to STATE_OVERWRITE_HEATH.
* @param objectId Must be a registered child.
*/
void overwriteDeviceHealth(object_id_t objectId, HasHealthIF::HealthState oldHealth);
};
#endif /* FRAMEWORK_DEVICEHANDLERS_ASSEMBLYBASE_H_ */
#ifndef FRAMEWORK_DEVICEHANDLERS_ASSEMBLYBASE_H_
#define FRAMEWORK_DEVICEHANDLERS_ASSEMBLYBASE_H_
#include "../container/FixedArrayList.h"
#include "../devicehandlers/DeviceHandlerBase.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 {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::ASSEMBLY_BASE;
static const ReturnValue_t NEED_SECOND_STEP = MAKE_RETURN_CODE(0x01);
static const ReturnValue_t NEED_TO_RECONFIGURE = MAKE_RETURN_CODE(0x02);
static const ReturnValue_t MODE_FALLBACK = MAKE_RETURN_CODE(0x03);
static const ReturnValue_t CHILD_NOT_COMMANDABLE = MAKE_RETURN_CODE(0x04);
static const ReturnValue_t NEED_TO_CHANGE_HEALTH = MAKE_RETURN_CODE(0x05);
static const ReturnValue_t NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE =
MAKE_RETURN_CODE(0xa1);
AssemblyBase(object_id_t objectId, object_id_t parentId,
uint16_t commandQueueDepth = 8);
virtual ~AssemblyBase();
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 {
STATE_NONE,
STATE_OVERWRITE_HEALTH,
STATE_NEED_SECOND_STEP,
STATE_SINGLE_STEP,
STATE_SECOND_STEP,
} internalState;
enum RecoveryState {
RECOVERY_IDLE,
RECOVERY_STARTED,
RECOVERY_ONGOING,
RECOVERY_ONGOING_2,
RECOVERY_WAIT
} recoveryState; //!< Indicates if one of the children requested a recovery.
ChildrenMap::iterator recoveringDevice;
/**
* the mode the current transition is trying to achieve.
* Can be different from the modehelper.commandedMode!
*/
Mode_t targetMode;
/**
* the submode the current transition is trying to achieve.
* Can be different from the modehelper.commandedSubmode!
*/
Submode_t targetSubmode;
Countdown recoveryOffTimer;
static const uint32_t POWER_OFF_TIME_MS = 1000;
virtual ReturnValue_t handleCommandMessage(CommandMessage *message);
virtual ReturnValue_t handleHealthReply(CommandMessage *message);
virtual void performChildOperation();
bool handleChildrenChanged();
/**
* This method is called if the children changed its mode in a way that
* the current mode can't be kept.
* Default behavior is to go to MODE_OFF.
* @param result The failure code which was returned by checkChildrenState.
*/
virtual void handleChildrenLostMode(ReturnValue_t result);
bool handleChildrenChangedHealth();
virtual void handleChildrenTransition();
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t *msToReachTheMode);
virtual void startTransition(Mode_t mode, Submode_t submode);
virtual void doStartTransition(Mode_t mode, Submode_t submode);
virtual bool isInTransition();
virtual void handleModeReached();
virtual void handleModeTransitionFailed(ReturnValue_t result);
void sendHealthCommand(MessageQueueId_t sendTo, HealthState health);
virtual ReturnValue_t checkChildrenStateOff();
ReturnValue_t checkChildrenState();
virtual ReturnValue_t checkChildOff(uint32_t objectId);
/**
* Manages recovery of a device
* @return true if recovery is still ongoing, false else.
*/
bool checkAndHandleRecovery();
/**
* Helper method to overwrite health state of one of the children.
* Also sets state to STATE_OVERWRITE_HEATH.
* @param objectId Must be a registered child.
*/
void overwriteDeviceHealth(object_id_t objectId, HasHealthIF::HealthState oldHealth);
};
#endif /* FRAMEWORK_DEVICEHANDLERS_ASSEMBLYBASE_H_ */

View File

@ -1,47 +1,47 @@
#include "../subsystem/SubsystemBase.h"
#include "../devicehandlers/ChildHandlerBase.h"
#include "../subsystem/SubsystemBase.h"
ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId,
object_id_t deviceCommunication, CookieIF * cookie,
object_id_t hkDestination, uint32_t thermalStatePoolId,
uint32_t thermalRequestPoolId,
object_id_t parent,
FailureIsolationBase* customFdir, size_t cmdQueueSize) :
DeviceHandlerBase(setObjectId, deviceCommunication, cookie,
(customFdir == nullptr? &childHandlerFdir : customFdir),
cmdQueueSize),
parentId(parent), childHandlerFdir(setObjectId) {
this->setHkDestination(hkDestination);
this->setThermalStateRequestPoolIds(thermalStatePoolId,
thermalRequestPoolId);
}
ChildHandlerBase::~ChildHandlerBase() {
}
ReturnValue_t ChildHandlerBase::initialize() {
ReturnValue_t result = DeviceHandlerBase::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
MessageQueueId_t parentQueue = 0;
if (parentId != objects::NO_OBJECT) {
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
if (parent == NULL) {
return RETURN_FAILED;
}
parentQueue = parent->getCommandQueue();
parent->registerChild(getObjectId());
}
healthHelper.setParentQueue(parentQueue);
modeHelper.setParentQueue(parentQueue);
return RETURN_OK;
}
#include "../subsystem/SubsystemBase.h"
#include "../devicehandlers/ChildHandlerBase.h"
#include "../subsystem/SubsystemBase.h"
ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId,
object_id_t deviceCommunication, CookieIF * cookie,
object_id_t hkDestination, uint32_t thermalStatePoolId,
uint32_t thermalRequestPoolId,
object_id_t parent,
FailureIsolationBase* customFdir, size_t cmdQueueSize) :
DeviceHandlerBase(setObjectId, deviceCommunication, cookie,
(customFdir == nullptr? &childHandlerFdir : customFdir),
cmdQueueSize),
parentId(parent), childHandlerFdir(setObjectId) {
this->setHkDestination(hkDestination);
this->setThermalStateRequestPoolIds(thermalStatePoolId,
thermalRequestPoolId);
}
ChildHandlerBase::~ChildHandlerBase() {
}
ReturnValue_t ChildHandlerBase::initialize() {
ReturnValue_t result = DeviceHandlerBase::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
MessageQueueId_t parentQueue = 0;
if (parentId != objects::NO_OBJECT) {
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
if (parent == NULL) {
return RETURN_FAILED;
}
parentQueue = parent->getCommandQueue();
parent->registerChild(getObjectId());
}
healthHelper.setParentQueue(parentQueue);
modeHelper.setParentQueue(parentQueue);
return RETURN_OK;
}

View File

@ -1,24 +1,24 @@
#ifndef PAYLOADHANDLERBASE_H_
#define PAYLOADHANDLERBASE_H_
#include "../devicehandlers/ChildHandlerFDIR.h"
#include "../devicehandlers/DeviceHandlerBase.h"
class ChildHandlerBase: public DeviceHandlerBase {
public:
ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
CookieIF * cookie, object_id_t hkDestination,
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
object_id_t parent = objects::NO_OBJECT,
FailureIsolationBase* customFdir = nullptr, size_t cmdQueueSize = 20);
virtual ~ChildHandlerBase();
virtual ReturnValue_t initialize();
protected:
const uint32_t parentId;
ChildHandlerFDIR childHandlerFdir;
};
#endif /* PAYLOADHANDLERBASE_H_ */
#ifndef PAYLOADHANDLERBASE_H_
#define PAYLOADHANDLERBASE_H_
#include "../devicehandlers/ChildHandlerFDIR.h"
#include "../devicehandlers/DeviceHandlerBase.h"
class ChildHandlerBase: public DeviceHandlerBase {
public:
ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
CookieIF * cookie, object_id_t hkDestination,
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
object_id_t parent = objects::NO_OBJECT,
FailureIsolationBase* customFdir = nullptr, size_t cmdQueueSize = 20);
virtual ~ChildHandlerBase();
virtual ReturnValue_t initialize();
protected:
const uint32_t parentId;
ChildHandlerFDIR childHandlerFdir;
};
#endif /* PAYLOADHANDLERBASE_H_ */

View File

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

View File

@ -1,20 +1,20 @@
#ifndef FRAMEWORK_DEVICEHANDLERS_CHILDHANDLERFDIR_H_
#define FRAMEWORK_DEVICEHANDLERS_CHILDHANDLERFDIR_H_
#include "../devicehandlers/DeviceHandlerFailureIsolation.h"
/**
* Very simple extension to normal FDIR.
* Does not have a default fault tree parent and
* allows to make the recovery count settable to 0.
*/
class ChildHandlerFDIR: public DeviceHandlerFailureIsolation {
public:
ChildHandlerFDIR(object_id_t owner, object_id_t faultTreeParent =
NO_FAULT_TREE_PARENT, uint32_t recoveryCount = 0);
virtual ~ChildHandlerFDIR();
protected:
static const object_id_t NO_FAULT_TREE_PARENT = 0;
};
#endif /* FRAMEWORK_DEVICEHANDLERS_CHILDHANDLERFDIR_H_ */
#ifndef FRAMEWORK_DEVICEHANDLERS_CHILDHANDLERFDIR_H_
#define FRAMEWORK_DEVICEHANDLERS_CHILDHANDLERFDIR_H_
#include "../devicehandlers/DeviceHandlerFailureIsolation.h"
/**
* Very simple extension to normal FDIR.
* Does not have a default fault tree parent and
* allows to make the recovery count settable to 0.
*/
class ChildHandlerFDIR: public DeviceHandlerFailureIsolation {
public:
ChildHandlerFDIR(object_id_t owner, object_id_t faultTreeParent =
NO_FAULT_TREE_PARENT, uint32_t recoveryCount = 0);
virtual ~ChildHandlerFDIR();
protected:
static const object_id_t NO_FAULT_TREE_PARENT = 0;
};
#endif /* FRAMEWORK_DEVICEHANDLERS_CHILDHANDLERFDIR_H_ */

View File

@ -1,201 +1,201 @@
/**
* @file CommunicationMessage.cpp
*
* @date 28.02.2020
*/
#include "../devicehandlers/CommunicationMessage.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include <cstring>
CommunicationMessage::CommunicationMessage(): uninitialized(true) {
}
CommunicationMessage::~CommunicationMessage() {}
void CommunicationMessage::setSendRequestFromPointer(uint32_t address,
uint32_t dataLen, const uint8_t * data) {
setMessageType(SEND_DATA_FROM_POINTER);
setAddress(address);
setDataLen(dataLen);
setDataPointer(data);
}
void CommunicationMessage::setSendRequestFromIpcStore(uint32_t address, store_address_t storeId) {
setMessageType(SEND_DATA_FROM_IPC_STORE);
setAddress(address);
setStoreId(storeId.raw);
}
void CommunicationMessage::setSendRequestRaw(uint32_t address, uint32_t length,
uint16_t sendBufferPosition) {
setMessageType(SEND_DATA_RAW);
setAddress(address);
setDataLen(length);
if(sendBufferPosition != 0) {
setBufferPosition(sendBufferPosition);
}
}
void CommunicationMessage::setDataReplyFromIpcStore(uint32_t address, store_address_t storeId) {
setMessageType(REPLY_DATA_IPC_STORE);
setAddress(address);
setStoreId(storeId.raw);
}
void CommunicationMessage::setDataReplyFromPointer(uint32_t address,
uint32_t dataLen, uint8_t *data) {
setMessageType(REPLY_DATA_FROM_POINTER);
setAddress(address);
setDataLen(dataLen);
setDataPointer(data);
}
void CommunicationMessage::setDataReplyRaw(uint32_t address,
uint32_t length, uint16_t receiveBufferPosition) {
setMessageType(REPLY_DATA_RAW);
setAddress(address);
setDataLen(length);
if(receiveBufferPosition != 0) {
setBufferPosition(receiveBufferPosition);
}
}
void CommunicationMessage::setMessageType(messageType status) {
uint8_t status_uint8 = status;
memcpy(getData() + sizeof(uint32_t), &status_uint8, sizeof(status_uint8));
}
void CommunicationMessage::setAddress(address_t address) {
memcpy(getData(),&address,sizeof(address));
}
address_t CommunicationMessage::getAddress() const {
address_t address;
memcpy(&address,getData(),sizeof(address));
return address;
}
void CommunicationMessage::setBufferPosition(uint16_t bufferPosition) {
memcpy(getData() + sizeof(uint32_t) + sizeof(uint16_t),
&bufferPosition, sizeof(bufferPosition));
}
uint16_t CommunicationMessage::getBufferPosition() const {
uint16_t bufferPosition;
memcpy(&bufferPosition,
getData() + sizeof(uint32_t) + sizeof(uint16_t), sizeof(bufferPosition));
return bufferPosition;
}
void CommunicationMessage::setDataPointer(const void * data) {
memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(uint32_t));
}
void CommunicationMessage::setStoreId(store_address_t storeId) {
memcpy(getData() + 2 * sizeof(uint32_t), &storeId.raw, sizeof(uint32_t));
}
store_address_t CommunicationMessage::getStoreId() const{
store_address_t temp;
memcpy(&temp.raw,getData() + 2 * sizeof(uint32_t), sizeof(uint32_t));
return temp;
}
void CommunicationMessage::setDataLen(uint32_t length) {
memcpy(getData() + 2 * sizeof(uint32_t), &length, sizeof(length));
}
uint32_t CommunicationMessage::getDataLen() const {
uint32_t len;
memcpy(&len, getData() + 2 * sizeof(uint32_t), sizeof(len));
return len;
}
void CommunicationMessage::setUint32Data(uint32_t data) {
memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(data));
}
uint32_t CommunicationMessage::getUint32Data() const{
uint32_t data;
memcpy(&data,getData() + 3 * sizeof(uint32_t), sizeof(data));
return data;
}
void CommunicationMessage::setDataByte(uint8_t byte, uint8_t position) {
if(0 <= position && position <= 3) {
memcpy(getData() + 3 * sizeof(uint32_t) + position * sizeof(uint8_t), &byte, sizeof(byte));
}
else {
sif::error << "Comm Message: Invalid byte position" << std::endl;
}
}
uint8_t CommunicationMessage::getDataByte(uint8_t position) const {
if(0 <= position && position <= 3) {
uint8_t byte;
memcpy(&byte, getData() + 3 * sizeof(uint32_t) + position * sizeof(uint8_t), sizeof(byte));
return byte;
}
else {
return 0;
sif::error << "Comm Message: Invalid byte position" << std::endl;
}
}
void CommunicationMessage::setDataUint16(uint16_t data, uint8_t position) {
if(position == 0 || position == 1) {
memcpy(getData() + 3 * sizeof(uint32_t) + position * sizeof(uint16_t), &data, sizeof(data));
}
else {
sif::error << "Comm Message: Invalid byte position" << std::endl;
}
}
uint16_t CommunicationMessage::getDataUint16(uint8_t position) const{
if(position == 0 || position == 1) {
uint16_t data;
memcpy(&data, getData() + 3 * sizeof(uint32_t) + position * sizeof(uint16_t), sizeof(data));
return data;
}
else {
return 0;
sif::error << "Comm Message: Invalid byte position" << std::endl;
}
}
CommunicationMessage::messageType CommunicationMessage::getMessageType() const{
messageType messageType;
memcpy(&messageType, getData() + sizeof(uint32_t),sizeof(uint8_t));
return messageType;
}
void CommunicationMessage::setMessageId(uint8_t messageId) {
memcpy(getData() + sizeof(uint32_t) + sizeof(uint8_t), &messageId, sizeof(messageId));
}
uint8_t CommunicationMessage::getMessageId() const {
uint8_t messageId;
memcpy(&messageId, getData() + sizeof(uint32_t) + sizeof(uint8_t), sizeof(messageId));
return messageId;
}
void CommunicationMessage::clearCommunicationMessage() {
messageType messageType = getMessageType();
switch(messageType) {
case(messageType::REPLY_DATA_IPC_STORE):
case(messageType::SEND_DATA_FROM_IPC_STORE): {
store_address_t storeId = getStoreId();
StorageManagerIF *ipcStore = objectManager->
get<StorageManagerIF>(objects::IPC_STORE);
if (ipcStore != NULL) {
ipcStore->deleteData(storeId);
}
}
/* NO BREAK falls through*/
default:
memset(getData(),0,4*sizeof(uint32_t));
break;
}
}
/**
* @file CommunicationMessage.cpp
*
* @date 28.02.2020
*/
#include "../devicehandlers/CommunicationMessage.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include <cstring>
CommunicationMessage::CommunicationMessage(): uninitialized(true) {
}
CommunicationMessage::~CommunicationMessage() {}
void CommunicationMessage::setSendRequestFromPointer(uint32_t address,
uint32_t dataLen, const uint8_t * data) {
setMessageType(SEND_DATA_FROM_POINTER);
setAddress(address);
setDataLen(dataLen);
setDataPointer(data);
}
void CommunicationMessage::setSendRequestFromIpcStore(uint32_t address, store_address_t storeId) {
setMessageType(SEND_DATA_FROM_IPC_STORE);
setAddress(address);
setStoreId(storeId.raw);
}
void CommunicationMessage::setSendRequestRaw(uint32_t address, uint32_t length,
uint16_t sendBufferPosition) {
setMessageType(SEND_DATA_RAW);
setAddress(address);
setDataLen(length);
if(sendBufferPosition != 0) {
setBufferPosition(sendBufferPosition);
}
}
void CommunicationMessage::setDataReplyFromIpcStore(uint32_t address, store_address_t storeId) {
setMessageType(REPLY_DATA_IPC_STORE);
setAddress(address);
setStoreId(storeId.raw);
}
void CommunicationMessage::setDataReplyFromPointer(uint32_t address,
uint32_t dataLen, uint8_t *data) {
setMessageType(REPLY_DATA_FROM_POINTER);
setAddress(address);
setDataLen(dataLen);
setDataPointer(data);
}
void CommunicationMessage::setDataReplyRaw(uint32_t address,
uint32_t length, uint16_t receiveBufferPosition) {
setMessageType(REPLY_DATA_RAW);
setAddress(address);
setDataLen(length);
if(receiveBufferPosition != 0) {
setBufferPosition(receiveBufferPosition);
}
}
void CommunicationMessage::setMessageType(messageType status) {
uint8_t status_uint8 = status;
memcpy(getData() + sizeof(uint32_t), &status_uint8, sizeof(status_uint8));
}
void CommunicationMessage::setAddress(address_t address) {
memcpy(getData(),&address,sizeof(address));
}
address_t CommunicationMessage::getAddress() const {
address_t address;
memcpy(&address,getData(),sizeof(address));
return address;
}
void CommunicationMessage::setBufferPosition(uint16_t bufferPosition) {
memcpy(getData() + sizeof(uint32_t) + sizeof(uint16_t),
&bufferPosition, sizeof(bufferPosition));
}
uint16_t CommunicationMessage::getBufferPosition() const {
uint16_t bufferPosition;
memcpy(&bufferPosition,
getData() + sizeof(uint32_t) + sizeof(uint16_t), sizeof(bufferPosition));
return bufferPosition;
}
void CommunicationMessage::setDataPointer(const void * data) {
memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(uint32_t));
}
void CommunicationMessage::setStoreId(store_address_t storeId) {
memcpy(getData() + 2 * sizeof(uint32_t), &storeId.raw, sizeof(uint32_t));
}
store_address_t CommunicationMessage::getStoreId() const{
store_address_t temp;
memcpy(&temp.raw,getData() + 2 * sizeof(uint32_t), sizeof(uint32_t));
return temp;
}
void CommunicationMessage::setDataLen(uint32_t length) {
memcpy(getData() + 2 * sizeof(uint32_t), &length, sizeof(length));
}
uint32_t CommunicationMessage::getDataLen() const {
uint32_t len;
memcpy(&len, getData() + 2 * sizeof(uint32_t), sizeof(len));
return len;
}
void CommunicationMessage::setUint32Data(uint32_t data) {
memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(data));
}
uint32_t CommunicationMessage::getUint32Data() const{
uint32_t data;
memcpy(&data,getData() + 3 * sizeof(uint32_t), sizeof(data));
return data;
}
void CommunicationMessage::setDataByte(uint8_t byte, uint8_t position) {
if(0 <= position && position <= 3) {
memcpy(getData() + 3 * sizeof(uint32_t) + position * sizeof(uint8_t), &byte, sizeof(byte));
}
else {
sif::error << "Comm Message: Invalid byte position" << std::endl;
}
}
uint8_t CommunicationMessage::getDataByte(uint8_t position) const {
if(0 <= position && position <= 3) {
uint8_t byte;
memcpy(&byte, getData() + 3 * sizeof(uint32_t) + position * sizeof(uint8_t), sizeof(byte));
return byte;
}
else {
return 0;
sif::error << "Comm Message: Invalid byte position" << std::endl;
}
}
void CommunicationMessage::setDataUint16(uint16_t data, uint8_t position) {
if(position == 0 || position == 1) {
memcpy(getData() + 3 * sizeof(uint32_t) + position * sizeof(uint16_t), &data, sizeof(data));
}
else {
sif::error << "Comm Message: Invalid byte position" << std::endl;
}
}
uint16_t CommunicationMessage::getDataUint16(uint8_t position) const{
if(position == 0 || position == 1) {
uint16_t data;
memcpy(&data, getData() + 3 * sizeof(uint32_t) + position * sizeof(uint16_t), sizeof(data));
return data;
}
else {
return 0;
sif::error << "Comm Message: Invalid byte position" << std::endl;
}
}
CommunicationMessage::messageType CommunicationMessage::getMessageType() const{
messageType messageType;
memcpy(&messageType, getData() + sizeof(uint32_t),sizeof(uint8_t));
return messageType;
}
void CommunicationMessage::setMessageId(uint8_t messageId) {
memcpy(getData() + sizeof(uint32_t) + sizeof(uint8_t), &messageId, sizeof(messageId));
}
uint8_t CommunicationMessage::getMessageId() const {
uint8_t messageId;
memcpy(&messageId, getData() + sizeof(uint32_t) + sizeof(uint8_t), sizeof(messageId));
return messageId;
}
void CommunicationMessage::clearCommunicationMessage() {
messageType messageType = getMessageType();
switch(messageType) {
case(messageType::REPLY_DATA_IPC_STORE):
case(messageType::SEND_DATA_FROM_IPC_STORE): {
store_address_t storeId = getStoreId();
StorageManagerIF *ipcStore = objectManager->
get<StorageManagerIF>(objects::IPC_STORE);
if (ipcStore != NULL) {
ipcStore->deleteData(storeId);
}
}
/* NO BREAK falls through*/
default:
memset(getData(),0,4*sizeof(uint32_t));
break;
}
}

View File

@ -1,173 +1,173 @@
/**
* @file CommunicationMessage.h
*
* @date 28.02.2020
*/
#ifndef FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_
#define FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_
#include "../devicehandlers/CommunicationMessage.h"
#include "../ipc/MessageQueueMessage.h"
#include "../storagemanager/StorageManagerIF.h"
#include "../devicehandlers/DeviceHandlerBase.h"
/**
* @brief Message type to send larger messages
*
* @details
* Can be used to pass information like data pointers and
* data sizes between communication tasks.
*
*/
class CommunicationMessage: public MessageQueueMessage {
public:
enum messageType {
NONE,
SEND_DATA_FROM_POINTER,
SEND_DATA_FROM_IPC_STORE,
SEND_DATA_RAW,
REPLY_DATA_FROM_POINTER,
REPLY_DATA_IPC_STORE,
REPLY_DATA_RAW,
FAULTY,
};
//Add other messageIDs here if necessary.
static const uint8_t COMMUNICATION_MESSAGE_SIZE = HEADER_SIZE + 4 * sizeof(uint32_t);
CommunicationMessage();
virtual ~CommunicationMessage();
/**
* Message Type is stored as the fifth byte of the message data
* @param status
*/
void setMessageType(messageType status);
messageType getMessageType() const;
/**
* This is a unique ID which can be used to handle different kinds of messages.
* For example, the same interface (e.g. SPI) could be used to exchange raw data
* (e.g. sensor values) and data stored in the IPC store.
* The ID can be used to distinguish the messages in child implementations.
* The message ID is stored as the sixth byte of the message data.
* @param messageId
*/
void setMessageId(uint8_t messageId);
uint8_t getMessageId() const;
/**
* Send requests with pointer to the data to be sent and send data length
* @param address Target Address, first four bytes
* @param dataLen Length of data to send, next four bytes
* @param data Pointer to data to send
*
*/
void setSendRequestFromPointer(uint32_t address, uint32_t dataLen, const uint8_t * data);
/**
* Send requests with a store ID, using the IPC store
* @param address Target Address, first four bytes
* @param storeId Store ID in the IPC store
*
*/
void setSendRequestFromIpcStore(uint32_t address, store_address_t storeId);
/**
* Send requests with data length and data in message (max. 4 bytes)
* @param address Target Address, first four bytes
* @param dataLen Length of data to send, next four bytes
* @param data Pointer to data to send
*
*/
void setSendRequestRaw(uint32_t address, uint32_t length,
uint16_t sendBufferPosition = 0);
/**
* Data message with data stored in IPC store
* @param address Target Address, first four bytes
* @param length
* @param storeId
*/
void setDataReplyFromIpcStore(uint32_t address, store_address_t storeId);
/**
* Data reply with data stored in buffer, passing the pointer to
* the buffer and the data size
* @param address Target Address, first four bytes
* @param dataLen Length of data to send, next four bytes
* @param data Pointer to the data
*/
void setDataReplyFromPointer(uint32_t address, uint32_t dataLen, uint8_t * data);
/**
* Data message with data stored in actual message.
* 4 byte datafield is intialized with 0.
* Set data with specific setter functions below.
* Can also be used to supply information at which position the raw data should be stored
* in a receive buffer.
*/
void setDataReplyRaw(uint32_t address, uint32_t length, uint16_t receiveBufferPosition = 0);
/**
* First four bytes of message data
* @param address
*/
void setAddress(address_t address);
address_t getAddress() const;
/**
* Set byte as position of 4 byte data field
* @param byte
* @param position Position, 0 to 3 possible
*/
void setDataByte(uint8_t byte, uint8_t position);
uint8_t getDataByte(uint8_t position) const;
/**
* Set 2 byte value at position 1 or 2 of data field
* @param data
* @param position 0 or 1 possible
*/
void setDataUint16(uint16_t data, uint8_t position);
uint16_t getDataUint16(uint8_t position) const;
void setUint32Data(uint32_t data);
uint32_t getUint32Data() const;
/**
* Stored in Bytes 13-16 of message data
* @param length
*/
void setDataLen(uint32_t length);
uint32_t getDataLen() const;
/**
* Stored in last four bytes (Bytes 17-20) of message data
* @param sendData
*/
void setDataPointer(const void * data);
/**
* In case the send request data or reply data is to be stored in a buffer,
* a buffer Position can be stored here as the seventh and eigth byte of
* the message, so the receive buffer can't be larger than sizeof(uint16_t) for now.
* @param bufferPosition In case the data is stored in a buffer, the position can be supplied here
*/
void setBufferPosition(uint16_t bufferPosition);
uint16_t getBufferPosition() const;
void setStoreId(store_address_t storeId);
store_address_t getStoreId() const;
/**
* Clear the message. Deletes IPC Store data
* and sets all data to 0. Also sets message type to NONE
*/
void clearCommunicationMessage();
private:
bool uninitialized; //!< Could be used to warn if data has not been set.
};
#endif /* FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ */
/**
* @file CommunicationMessage.h
*
* @date 28.02.2020
*/
#ifndef FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_
#define FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_
#include "../devicehandlers/CommunicationMessage.h"
#include "../ipc/MessageQueueMessage.h"
#include "../storagemanager/StorageManagerIF.h"
#include "../devicehandlers/DeviceHandlerBase.h"
/**
* @brief Message type to send larger messages
*
* @details
* Can be used to pass information like data pointers and
* data sizes between communication tasks.
*
*/
class CommunicationMessage: public MessageQueueMessage {
public:
enum messageType {
NONE,
SEND_DATA_FROM_POINTER,
SEND_DATA_FROM_IPC_STORE,
SEND_DATA_RAW,
REPLY_DATA_FROM_POINTER,
REPLY_DATA_IPC_STORE,
REPLY_DATA_RAW,
FAULTY,
};
//Add other messageIDs here if necessary.
static const uint8_t COMMUNICATION_MESSAGE_SIZE = HEADER_SIZE + 4 * sizeof(uint32_t);
CommunicationMessage();
virtual ~CommunicationMessage();
/**
* Message Type is stored as the fifth byte of the message data
* @param status
*/
void setMessageType(messageType status);
messageType getMessageType() const;
/**
* This is a unique ID which can be used to handle different kinds of messages.
* For example, the same interface (e.g. SPI) could be used to exchange raw data
* (e.g. sensor values) and data stored in the IPC store.
* The ID can be used to distinguish the messages in child implementations.
* The message ID is stored as the sixth byte of the message data.
* @param messageId
*/
void setMessageId(uint8_t messageId);
uint8_t getMessageId() const;
/**
* Send requests with pointer to the data to be sent and send data length
* @param address Target Address, first four bytes
* @param dataLen Length of data to send, next four bytes
* @param data Pointer to data to send
*
*/
void setSendRequestFromPointer(uint32_t address, uint32_t dataLen, const uint8_t * data);
/**
* Send requests with a store ID, using the IPC store
* @param address Target Address, first four bytes
* @param storeId Store ID in the IPC store
*
*/
void setSendRequestFromIpcStore(uint32_t address, store_address_t storeId);
/**
* Send requests with data length and data in message (max. 4 bytes)
* @param address Target Address, first four bytes
* @param dataLen Length of data to send, next four bytes
* @param data Pointer to data to send
*
*/
void setSendRequestRaw(uint32_t address, uint32_t length,
uint16_t sendBufferPosition = 0);
/**
* Data message with data stored in IPC store
* @param address Target Address, first four bytes
* @param length
* @param storeId
*/
void setDataReplyFromIpcStore(uint32_t address, store_address_t storeId);
/**
* Data reply with data stored in buffer, passing the pointer to
* the buffer and the data size
* @param address Target Address, first four bytes
* @param dataLen Length of data to send, next four bytes
* @param data Pointer to the data
*/
void setDataReplyFromPointer(uint32_t address, uint32_t dataLen, uint8_t * data);
/**
* Data message with data stored in actual message.
* 4 byte datafield is intialized with 0.
* Set data with specific setter functions below.
* Can also be used to supply information at which position the raw data should be stored
* in a receive buffer.
*/
void setDataReplyRaw(uint32_t address, uint32_t length, uint16_t receiveBufferPosition = 0);
/**
* First four bytes of message data
* @param address
*/
void setAddress(address_t address);
address_t getAddress() const;
/**
* Set byte as position of 4 byte data field
* @param byte
* @param position Position, 0 to 3 possible
*/
void setDataByte(uint8_t byte, uint8_t position);
uint8_t getDataByte(uint8_t position) const;
/**
* Set 2 byte value at position 1 or 2 of data field
* @param data
* @param position 0 or 1 possible
*/
void setDataUint16(uint16_t data, uint8_t position);
uint16_t getDataUint16(uint8_t position) const;
void setUint32Data(uint32_t data);
uint32_t getUint32Data() const;
/**
* Stored in Bytes 13-16 of message data
* @param length
*/
void setDataLen(uint32_t length);
uint32_t getDataLen() const;
/**
* Stored in last four bytes (Bytes 17-20) of message data
* @param sendData
*/
void setDataPointer(const void * data);
/**
* In case the send request data or reply data is to be stored in a buffer,
* a buffer Position can be stored here as the seventh and eigth byte of
* the message, so the receive buffer can't be larger than sizeof(uint16_t) for now.
* @param bufferPosition In case the data is stored in a buffer, the position can be supplied here
*/
void setBufferPosition(uint16_t bufferPosition);
uint16_t getBufferPosition() const;
void setStoreId(store_address_t storeId);
store_address_t getStoreId() const;
/**
* Clear the message. Deletes IPC Store data
* and sets all data to 0. Also sets message type to NONE
*/
void clearCommunicationMessage();
private:
bool uninitialized; //!< Could be used to warn if data has not been set.
};
#endif /* FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ */

View File

@ -1,127 +1,127 @@
#ifndef FRAMEWORK_DEVICES_DEVICECOMMUNICATIONIF_H_
#define FRAMEWORK_DEVICES_DEVICECOMMUNICATIONIF_H_
#include "../devicehandlers/CookieIF.h"
#include "../devicehandlers/DeviceHandlerIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
/**
* @defgroup interfaces Interfaces
* @brief Interfaces for flight software objects
*/
/**
* @defgroup comm Communication
* @brief Communication software components.
*/
/**
* @brief This is an interface to decouple device communication from
* the device handler to allow reuse of these components.
* @details
* Documentation: Dissertation Baetz p.138.
* It works with the assumption that received data is polled by a component.
* There are four generic steps of device communication:
*
* 1. Send data to a device
* 2. Get acknowledgement for sending
* 3. Request reading data from a device
* 4. Read received data
*
* To identify different connection over a single interface can return
* so-called cookies to components.
* The CommunicationMessage message type can be used to extend the
* functionality of the ComIF if a separate polling task is required.
* @ingroup interfaces
* @ingroup comm
*/
class DeviceCommunicationIF: public HasReturnvaluesIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF;
//! 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
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x02);
//! If cookie is a null pointer
static const ReturnValue_t NULLPOINTER = 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?
static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x05);
static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x06);
virtual ~DeviceCommunicationIF() {}
/**
* @brief Device specific initialization, using the cookie.
* @details
* The cookie is already prepared in the factory. If the communication
* interface needs to be set up in some way and requires cookie information,
* this can be performed in this function, which is called on device handler
* initialization.
* @param cookie
* @return
* - @c RETURN_OK if initialization was successfull
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t initializeInterface(CookieIF * cookie) = 0;
/**
* Called by DHB in the SEND_WRITE doSendWrite().
* This function is used to send data to the physical device
* by implementing and calling related drivers or wrapper functions.
* @param cookie
* @param data
* @param len If this is 0, nothing shall be sent.
* @return
* - @c RETURN_OK for successfull send
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t sendMessage(CookieIF *cookie,
const uint8_t * sendData, size_t sendLen) = 0;
/**
* Called by DHB in the GET_WRITE doGetWrite().
* Get send confirmation that the data in sendMessage() was sent successfully.
* @param cookie
* @return - @c RETURN_OK if data was sent successfull
* - Everything else triggers falure event with
* returnvalue as parameter 1
*/
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0;
/**
* Called by DHB in the SEND_WRITE doSendRead().
* It is assumed that it is always possible to request a reply
* from a device. If a requestLen of 0 is supplied, no reply was enabled
* and communication specific action should be taken (e.g. read nothing
* or read everything).
*
* @param cookie
* @param requestLen Size of data to read
* @return - @c RETURN_OK to confirm the request for data has been sent.
* - Everything else triggers failure event with
* returnvalue as parameter 1
*/
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie,
size_t requestLen) = 0;
/**
* Called by DHB in the GET_WRITE doGetRead().
* This function is used to receive data from the physical device
* by implementing and calling related drivers or wrapper functions.
* @param cookie
* @param buffer [out] Set reply here (by using *buffer = ...)
* @param size [out] size pointer to set (by using *size = ...).
* Set to 0 if no reply was received
* @return - @c RETURN_OK for successfull receive
* - @c NO_REPLY_RECEIVED if not reply was received. Setting size to
* 0 has the same effect
* - Everything else triggers failure event with
* returnvalue as parameter 1
*/
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
uint8_t **buffer, size_t *size) = 0;
};
#endif /* DEVICECOMMUNICATIONIF_H_ */
#ifndef FRAMEWORK_DEVICES_DEVICECOMMUNICATIONIF_H_
#define FRAMEWORK_DEVICES_DEVICECOMMUNICATIONIF_H_
#include "../devicehandlers/CookieIF.h"
#include "../devicehandlers/DeviceHandlerIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
/**
* @defgroup interfaces Interfaces
* @brief Interfaces for flight software objects
*/
/**
* @defgroup comm Communication
* @brief Communication software components.
*/
/**
* @brief This is an interface to decouple device communication from
* the device handler to allow reuse of these components.
* @details
* Documentation: Dissertation Baetz p.138.
* It works with the assumption that received data is polled by a component.
* There are four generic steps of device communication:
*
* 1. Send data to a device
* 2. Get acknowledgement for sending
* 3. Request reading data from a device
* 4. Read received data
*
* To identify different connection over a single interface can return
* so-called cookies to components.
* The CommunicationMessage message type can be used to extend the
* functionality of the ComIF if a separate polling task is required.
* @ingroup interfaces
* @ingroup comm
*/
class DeviceCommunicationIF: public HasReturnvaluesIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF;
//! 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
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x02);
//! If cookie is a null pointer
static const ReturnValue_t NULLPOINTER = 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?
static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x05);
static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x06);
virtual ~DeviceCommunicationIF() {}
/**
* @brief Device specific initialization, using the cookie.
* @details
* The cookie is already prepared in the factory. If the communication
* interface needs to be set up in some way and requires cookie information,
* this can be performed in this function, which is called on device handler
* initialization.
* @param cookie
* @return
* - @c RETURN_OK if initialization was successfull
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t initializeInterface(CookieIF * cookie) = 0;
/**
* Called by DHB in the SEND_WRITE doSendWrite().
* This function is used to send data to the physical device
* by implementing and calling related drivers or wrapper functions.
* @param cookie
* @param data
* @param len If this is 0, nothing shall be sent.
* @return
* - @c RETURN_OK for successfull send
* - Everything else triggers failure event with returnvalue as parameter 1
*/
virtual ReturnValue_t sendMessage(CookieIF *cookie,
const uint8_t * sendData, size_t sendLen) = 0;
/**
* Called by DHB in the GET_WRITE doGetWrite().
* Get send confirmation that the data in sendMessage() was sent successfully.
* @param cookie
* @return - @c RETURN_OK if data was sent successfull
* - Everything else triggers falure event with
* returnvalue as parameter 1
*/
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0;
/**
* Called by DHB in the SEND_WRITE doSendRead().
* It is assumed that it is always possible to request a reply
* from a device. If a requestLen of 0 is supplied, no reply was enabled
* and communication specific action should be taken (e.g. read nothing
* or read everything).
*
* @param cookie
* @param requestLen Size of data to read
* @return - @c RETURN_OK to confirm the request for data has been sent.
* - Everything else triggers failure event with
* returnvalue as parameter 1
*/
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie,
size_t requestLen) = 0;
/**
* Called by DHB in the GET_WRITE doGetRead().
* This function is used to receive data from the physical device
* by implementing and calling related drivers or wrapper functions.
* @param cookie
* @param buffer [out] Set reply here (by using *buffer = ...)
* @param size [out] size pointer to set (by using *size = ...).
* Set to 0 if no reply was received
* @return - @c RETURN_OK for successfull receive
* - @c NO_REPLY_RECEIVED if not reply was received. Setting size to
* 0 has the same effect
* - Everything else triggers failure event with
* returnvalue as parameter 1
*/
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
uint8_t **buffer, size_t *size) = 0;
};
#endif /* DEVICECOMMUNICATIONIF_H_ */

View File

@ -1,155 +1,155 @@
#ifndef DEVICEHANDLERIF_H_
#define DEVICEHANDLERIF_H_
#include "../action/HasActionsIF.h"
#include "../devicehandlers/DeviceHandlerMessage.h"
#include "../events/Event.h"
#include "../modes/HasModesIF.h"
#include "../ipc/MessageQueueSenderIF.h"
/**
* @brief This is the Interface used to communicate with a device handler.
* @details Includes all expected return values, events and modes.
*
*/
class DeviceHandlerIF {
public:
static const uint8_t TRANSITION_MODE_CHILD_ACTION_MASK = 0x20;
static const uint8_t TRANSITION_MODE_BASE_ACTION_MASK = 0x10;
/**
* @brief This is the mode the <strong>device handler</strong> is in.
*
* @details The mode of the device handler must not be confused with the mode the device is in.
* The mode of the device itself is transparent to the user but related to the mode of the handler.
* MODE_ON and MODE_OFF are included in hasModesIF.h
*/
// MODE_ON = 0, //!< The device is powered and ready to perform operations. In this mode, no commands are sent by the device handler itself, but direct commands van be commanded and will be interpreted
// MODE_OFF = 1, //!< The device is powered off. The only command accepted in this mode is a mode change to on.
//! The device is powered on and the device handler periodically sends
//! commands. The commands to be sent are selected by the handler
//! according to the submode.
static const Mode_t MODE_NORMAL = 2;
//! The device is powered on and ready to perform operations. In this mode,
//! raw commands can be sent. The device handler will send all replies
//! received from the command back to the commanding object.
static const Mode_t MODE_RAW = 3;
//! The device is shut down but the switch could not be turned off, so the
//! device still is powered. In this mode, only a mode change to @c MODE_OFF
//! can be commanded, which tries to switch off the device again.
static const Mode_t MODE_ERROR_ON = 4;
//! This is a transitional state which can not be commanded. The device
//! handler performs all commands to get the device in a state ready to
//! perform commands. When this is completed, the mode changes to @c MODE_ON.
static const Mode_t _MODE_START_UP = TRANSITION_MODE_CHILD_ACTION_MASK | 5;
//! This is a transitional state which can not be commanded.
//! 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.
//! 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;
//! It is possible to set the mode to _MODE_TO_ON to use the to on
//! transition if available.
static const Mode_t _MODE_TO_ON = TRANSITION_MODE_CHILD_ACTION_MASK | HasModesIF::MODE_ON;
//! It is possible to set the mode to _MODE_TO_RAW to use the to raw
//! transition if available.
static const Mode_t _MODE_TO_RAW = TRANSITION_MODE_CHILD_ACTION_MASK | MODE_RAW;
//! It is possible to set the mode to _MODE_TO_NORMAL to use the to normal
//! transition if available.
static const Mode_t _MODE_TO_NORMAL = TRANSITION_MODE_CHILD_ACTION_MASK | MODE_NORMAL;
//! This is a transitional state which can not be commanded.
//! The device is shut down and ready to be switched off.
//! After the command to set the switch off has been sent,
//! the mode changes to @c MODE_WAIT_OFF
static const Mode_t _MODE_POWER_DOWN = TRANSITION_MODE_BASE_ACTION_MASK | 1;
//! This is a transitional state which can not be commanded. The device
//! will be switched on in this state. After the command to set the switch
//! on has been sent, the mode changes to @c MODE_WAIT_ON.
static const Mode_t _MODE_POWER_ON = TRANSITION_MODE_BASE_ACTION_MASK | 2;
//! This is a transitional state which can not be commanded. The switch has
//! been commanded off and the handler waits for it to be off.
//! When the switch is off, the mode changes to @c MODE_OFF.
static const Mode_t _MODE_WAIT_OFF = TRANSITION_MODE_BASE_ACTION_MASK | 3;
//! This is a transitional state which can not be commanded. The switch
//! has been commanded on and the handler waits for it to be on.
//! When the switch is on, the mode changes to @c MODE_TO_ON.
static const Mode_t _MODE_WAIT_ON = TRANSITION_MODE_BASE_ACTION_MASK | 4;
//! This is a transitional state which can not be commanded. The switch has
//! been commanded off and is off now. This state is only to do an RMAP
//! cycle once more where the doSendRead() function will set the mode to
//! MODE_OFF. The reason to do this is to get rid of stuck packets in the IO Board.
static const Mode_t _MODE_SWITCH_IS_OFF = TRANSITION_MODE_BASE_ACTION_MASK | 5;
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CDH;
static const Event DEVICE_BUILDING_COMMAND_FAILED = MAKE_EVENT(0, SEVERITY::LOW);
static const Event DEVICE_SENDING_COMMAND_FAILED = MAKE_EVENT(1, SEVERITY::LOW);
static const Event DEVICE_REQUESTING_REPLY_FAILED = MAKE_EVENT(2, SEVERITY::LOW);
static const Event DEVICE_READING_REPLY_FAILED = MAKE_EVENT(3, SEVERITY::LOW);
static const Event DEVICE_INTERPRETING_REPLY_FAILED = MAKE_EVENT(4, SEVERITY::LOW);
static const Event DEVICE_MISSED_REPLY = MAKE_EVENT(5, SEVERITY::LOW);
static const Event DEVICE_UNKNOWN_REPLY = MAKE_EVENT(6, SEVERITY::LOW);
static const Event DEVICE_UNREQUESTED_REPLY = MAKE_EVENT(7, SEVERITY::LOW);
static const Event INVALID_DEVICE_COMMAND = MAKE_EVENT(8, SEVERITY::LOW); //!< Indicates a SW bug in child class.
static const Event MONITORING_LIMIT_EXCEEDED = MAKE_EVENT(9, SEVERITY::LOW);
static const Event MONITORING_AMBIGUOUS = MAKE_EVENT(10, SEVERITY::HIGH);
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF;
// Standard codes used when building commands.
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_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 CANT_SWITCH_ADDRESS = MAKE_RETURN_CODE(0xA4);
static const ReturnValue_t WRONG_MODE_FOR_COMMAND = MAKE_RETURN_CODE(0xA5);
static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(0xA6);
static const ReturnValue_t BUSY = MAKE_RETURN_CODE(0xA7);
static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8); //!< Used to indicate that this is a command-only command.
static const ReturnValue_t NON_OP_TEMPERATURE = MAKE_RETURN_CODE(0xA9);
static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xAA);
// Standard codes used in scanForReply
static const ReturnValue_t CHECKSUM_ERROR = MAKE_RETURN_CODE(0xB0);
static const ReturnValue_t LENGTH_MISSMATCH = MAKE_RETURN_CODE(0xB1);
static const ReturnValue_t INVALID_DATA = MAKE_RETURN_CODE(0xB2);
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0xB3);
// Standard codes used in interpretDeviceReply
static const ReturnValue_t DEVICE_DID_NOT_EXECUTE = MAKE_RETURN_CODE(0xC0); //the device reported, that it did not execute the command
static const ReturnValue_t DEVICE_REPORTED_ERROR = MAKE_RETURN_CODE(0xC1);
static const ReturnValue_t UNKNOW_DEVICE_REPLY = MAKE_RETURN_CODE(0xC2); //the deviceCommandId reported by scanforReply is unknown
static const ReturnValue_t DEVICE_REPLY_INVALID = MAKE_RETURN_CODE(0xC3); //syntax etc is correct but still not ok, eg parameters where none are expected
// Standard codes used in buildCommandFromCommand
static const ReturnValue_t INVALID_COMMAND_PARAMETER = MAKE_RETURN_CODE(0xD0);
static const ReturnValue_t INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS = MAKE_RETURN_CODE(0xD1);
/**
* Communication action that will be executed.
*
* This is used by the child class to tell the base class what to do.
*/
enum CommunicationAction_t: uint8_t {
SEND_WRITE,//!< Send write
GET_WRITE, //!< Get write
SEND_READ, //!< Send read
GET_READ, //!< Get read
NOTHING //!< Do nothing.
};
/**
* Default Destructor
*/
virtual ~DeviceHandlerIF() {}
/**
* This MessageQueue is used to command the device handler.
* @return the id of the MessageQueue
*/
virtual MessageQueueId_t getCommandQueue() const = 0;
};
#endif /* DEVICEHANDLERIF_H_ */
#ifndef DEVICEHANDLERIF_H_
#define DEVICEHANDLERIF_H_
#include "../action/HasActionsIF.h"
#include "../devicehandlers/DeviceHandlerMessage.h"
#include "../events/Event.h"
#include "../modes/HasModesIF.h"
#include "../ipc/MessageQueueSenderIF.h"
/**
* @brief This is the Interface used to communicate with a device handler.
* @details Includes all expected return values, events and modes.
*
*/
class DeviceHandlerIF {
public:
static const uint8_t TRANSITION_MODE_CHILD_ACTION_MASK = 0x20;
static const uint8_t TRANSITION_MODE_BASE_ACTION_MASK = 0x10;
/**
* @brief This is the mode the <strong>device handler</strong> is in.
*
* @details The mode of the device handler must not be confused with the mode the device is in.
* The mode of the device itself is transparent to the user but related to the mode of the handler.
* MODE_ON and MODE_OFF are included in hasModesIF.h
*/
// MODE_ON = 0, //!< The device is powered and ready to perform operations. In this mode, no commands are sent by the device handler itself, but direct commands van be commanded and will be interpreted
// MODE_OFF = 1, //!< The device is powered off. The only command accepted in this mode is a mode change to on.
//! The device is powered on and the device handler periodically sends
//! commands. The commands to be sent are selected by the handler
//! according to the submode.
static const Mode_t MODE_NORMAL = 2;
//! The device is powered on and ready to perform operations. In this mode,
//! raw commands can be sent. The device handler will send all replies
//! received from the command back to the commanding object.
static const Mode_t MODE_RAW = 3;
//! The device is shut down but the switch could not be turned off, so the
//! device still is powered. In this mode, only a mode change to @c MODE_OFF
//! can be commanded, which tries to switch off the device again.
static const Mode_t MODE_ERROR_ON = 4;
//! This is a transitional state which can not be commanded. The device
//! handler performs all commands to get the device in a state ready to
//! perform commands. When this is completed, the mode changes to @c MODE_ON.
static const Mode_t _MODE_START_UP = TRANSITION_MODE_CHILD_ACTION_MASK | 5;
//! This is a transitional state which can not be commanded.
//! 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.
//! 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;
//! It is possible to set the mode to _MODE_TO_ON to use the to on
//! transition if available.
static const Mode_t _MODE_TO_ON = TRANSITION_MODE_CHILD_ACTION_MASK | HasModesIF::MODE_ON;
//! It is possible to set the mode to _MODE_TO_RAW to use the to raw
//! transition if available.
static const Mode_t _MODE_TO_RAW = TRANSITION_MODE_CHILD_ACTION_MASK | MODE_RAW;
//! It is possible to set the mode to _MODE_TO_NORMAL to use the to normal
//! transition if available.
static const Mode_t _MODE_TO_NORMAL = TRANSITION_MODE_CHILD_ACTION_MASK | MODE_NORMAL;
//! This is a transitional state which can not be commanded.
//! The device is shut down and ready to be switched off.
//! After the command to set the switch off has been sent,
//! the mode changes to @c MODE_WAIT_OFF
static const Mode_t _MODE_POWER_DOWN = TRANSITION_MODE_BASE_ACTION_MASK | 1;
//! This is a transitional state which can not be commanded. The device
//! will be switched on in this state. After the command to set the switch
//! on has been sent, the mode changes to @c MODE_WAIT_ON.
static const Mode_t _MODE_POWER_ON = TRANSITION_MODE_BASE_ACTION_MASK | 2;
//! This is a transitional state which can not be commanded. The switch has
//! been commanded off and the handler waits for it to be off.
//! When the switch is off, the mode changes to @c MODE_OFF.
static const Mode_t _MODE_WAIT_OFF = TRANSITION_MODE_BASE_ACTION_MASK | 3;
//! This is a transitional state which can not be commanded. The switch
//! has been commanded on and the handler waits for it to be on.
//! When the switch is on, the mode changes to @c MODE_TO_ON.
static const Mode_t _MODE_WAIT_ON = TRANSITION_MODE_BASE_ACTION_MASK | 4;
//! This is a transitional state which can not be commanded. The switch has
//! been commanded off and is off now. This state is only to do an RMAP
//! cycle once more where the doSendRead() function will set the mode to
//! MODE_OFF. The reason to do this is to get rid of stuck packets in the IO Board.
static const Mode_t _MODE_SWITCH_IS_OFF = TRANSITION_MODE_BASE_ACTION_MASK | 5;
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CDH;
static const Event DEVICE_BUILDING_COMMAND_FAILED = MAKE_EVENT(0, SEVERITY::LOW);
static const Event DEVICE_SENDING_COMMAND_FAILED = MAKE_EVENT(1, SEVERITY::LOW);
static const Event DEVICE_REQUESTING_REPLY_FAILED = MAKE_EVENT(2, SEVERITY::LOW);
static const Event DEVICE_READING_REPLY_FAILED = MAKE_EVENT(3, SEVERITY::LOW);
static const Event DEVICE_INTERPRETING_REPLY_FAILED = MAKE_EVENT(4, SEVERITY::LOW);
static const Event DEVICE_MISSED_REPLY = MAKE_EVENT(5, SEVERITY::LOW);
static const Event DEVICE_UNKNOWN_REPLY = MAKE_EVENT(6, SEVERITY::LOW);
static const Event DEVICE_UNREQUESTED_REPLY = MAKE_EVENT(7, SEVERITY::LOW);
static const Event INVALID_DEVICE_COMMAND = MAKE_EVENT(8, SEVERITY::LOW); //!< Indicates a SW bug in child class.
static const Event MONITORING_LIMIT_EXCEEDED = MAKE_EVENT(9, SEVERITY::LOW);
static const Event MONITORING_AMBIGUOUS = MAKE_EVENT(10, SEVERITY::HIGH);
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF;
// Standard codes used when building commands.
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_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 CANT_SWITCH_ADDRESS = MAKE_RETURN_CODE(0xA4);
static const ReturnValue_t WRONG_MODE_FOR_COMMAND = MAKE_RETURN_CODE(0xA5);
static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(0xA6);
static const ReturnValue_t BUSY = MAKE_RETURN_CODE(0xA7);
static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8); //!< Used to indicate that this is a command-only command.
static const ReturnValue_t NON_OP_TEMPERATURE = MAKE_RETURN_CODE(0xA9);
static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xAA);
// Standard codes used in scanForReply
static const ReturnValue_t CHECKSUM_ERROR = MAKE_RETURN_CODE(0xB0);
static const ReturnValue_t LENGTH_MISSMATCH = MAKE_RETURN_CODE(0xB1);
static const ReturnValue_t INVALID_DATA = MAKE_RETURN_CODE(0xB2);
static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0xB3);
// Standard codes used in interpretDeviceReply
static const ReturnValue_t DEVICE_DID_NOT_EXECUTE = MAKE_RETURN_CODE(0xC0); //the device reported, that it did not execute the command
static const ReturnValue_t DEVICE_REPORTED_ERROR = MAKE_RETURN_CODE(0xC1);
static const ReturnValue_t UNKNOW_DEVICE_REPLY = MAKE_RETURN_CODE(0xC2); //the deviceCommandId reported by scanforReply is unknown
static const ReturnValue_t DEVICE_REPLY_INVALID = MAKE_RETURN_CODE(0xC3); //syntax etc is correct but still not ok, eg parameters where none are expected
// Standard codes used in buildCommandFromCommand
static const ReturnValue_t INVALID_COMMAND_PARAMETER = MAKE_RETURN_CODE(0xD0);
static const ReturnValue_t INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS = MAKE_RETURN_CODE(0xD1);
/**
* Communication action that will be executed.
*
* This is used by the child class to tell the base class what to do.
*/
enum CommunicationAction_t: uint8_t {
SEND_WRITE,//!< Send write
GET_WRITE, //!< Get write
SEND_READ, //!< Send read
GET_READ, //!< Get read
NOTHING //!< Do nothing.
};
/**
* Default Destructor
*/
virtual ~DeviceHandlerIF() {}
/**
* This MessageQueue is used to command the device handler.
* @return the id of the MessageQueue
*/
virtual MessageQueueId_t getCommandQueue() const = 0;
};
#endif /* DEVICEHANDLERIF_H_ */

View File

@ -1,101 +1,101 @@
#include "../objectmanager/ObjectManagerIF.h"
#include "../devicehandlers/DeviceHandlerMessage.h"
#include "../objectmanager/ObjectManagerIF.h"
DeviceHandlerMessage::DeviceHandlerMessage() {
}
store_address_t DeviceHandlerMessage::getStoreAddress(
const CommandMessage* message) {
return store_address_t(message->getParameter2());
}
uint32_t DeviceHandlerMessage::getDeviceCommandId(
const CommandMessage* message) {
return message->getParameter();
}
object_id_t DeviceHandlerMessage::getIoBoardObjectId(
const CommandMessage* message) {
return message->getParameter();
}
uint8_t DeviceHandlerMessage::getWiretappingMode(
const CommandMessage* message) {
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(
CommandMessage* message, store_address_t rawPacketStoreId) {
message->setCommand(CMD_RAW);
message->setParameter2(rawPacketStoreId.raw);
}
void DeviceHandlerMessage::setDeviceHandlerWiretappingMessage(
CommandMessage* message, uint8_t wiretappingMode) {
message->setCommand(CMD_WIRETAPPING);
message->setParameter(wiretappingMode);
}
void DeviceHandlerMessage::setDeviceHandlerSwitchIoBoardMessage(
CommandMessage* message, uint32_t ioBoardIdentifier) {
message->setCommand(CMD_SWITCH_ADDRESS);
message->setParameter(ioBoardIdentifier);
}
object_id_t DeviceHandlerMessage::getDeviceObjectId(
const CommandMessage* message) {
return message->getParameter();
}
void DeviceHandlerMessage::setDeviceHandlerRawReplyMessage(
CommandMessage* message, object_id_t deviceObjectid,
store_address_t rawPacketStoreId, bool isCommand) {
if (isCommand) {
message->setCommand(REPLY_RAW_COMMAND);
} else {
message->setCommand(REPLY_RAW_REPLY);
}
message->setParameter(deviceObjectid);
message->setParameter2(rawPacketStoreId.raw);
}
void DeviceHandlerMessage::setDeviceHandlerDirectCommandReply(
CommandMessage* message, object_id_t deviceObjectid,
store_address_t commandParametersStoreId) {
message->setCommand(REPLY_DIRECT_COMMAND_DATA);
message->setParameter(deviceObjectid);
message->setParameter2(commandParametersStoreId.raw);
}
void DeviceHandlerMessage::clear(CommandMessage* message) {
switch (message->getCommand()) {
case CMD_RAW:
// case CMD_DIRECT:
case REPLY_RAW_COMMAND:
case REPLY_RAW_REPLY:
case REPLY_DIRECT_COMMAND_DATA: {
StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>(
objects::IPC_STORE);
if (ipcStore != NULL) {
ipcStore->deleteData(getStoreAddress(message));
}
}
/* NO BREAK falls through*/
case CMD_SWITCH_ADDRESS:
case CMD_WIRETAPPING:
message->setCommand(CommandMessage::CMD_NONE);
message->setParameter(0);
message->setParameter2(0);
break;
}
}
#include "../objectmanager/ObjectManagerIF.h"
#include "../devicehandlers/DeviceHandlerMessage.h"
#include "../objectmanager/ObjectManagerIF.h"
DeviceHandlerMessage::DeviceHandlerMessage() {
}
store_address_t DeviceHandlerMessage::getStoreAddress(
const CommandMessage* message) {
return store_address_t(message->getParameter2());
}
uint32_t DeviceHandlerMessage::getDeviceCommandId(
const CommandMessage* message) {
return message->getParameter();
}
object_id_t DeviceHandlerMessage::getIoBoardObjectId(
const CommandMessage* message) {
return message->getParameter();
}
uint8_t DeviceHandlerMessage::getWiretappingMode(
const CommandMessage* message) {
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(
CommandMessage* message, store_address_t rawPacketStoreId) {
message->setCommand(CMD_RAW);
message->setParameter2(rawPacketStoreId.raw);
}
void DeviceHandlerMessage::setDeviceHandlerWiretappingMessage(
CommandMessage* message, uint8_t wiretappingMode) {
message->setCommand(CMD_WIRETAPPING);
message->setParameter(wiretappingMode);
}
void DeviceHandlerMessage::setDeviceHandlerSwitchIoBoardMessage(
CommandMessage* message, uint32_t ioBoardIdentifier) {
message->setCommand(CMD_SWITCH_ADDRESS);
message->setParameter(ioBoardIdentifier);
}
object_id_t DeviceHandlerMessage::getDeviceObjectId(
const CommandMessage* message) {
return message->getParameter();
}
void DeviceHandlerMessage::setDeviceHandlerRawReplyMessage(
CommandMessage* message, object_id_t deviceObjectid,
store_address_t rawPacketStoreId, bool isCommand) {
if (isCommand) {
message->setCommand(REPLY_RAW_COMMAND);
} else {
message->setCommand(REPLY_RAW_REPLY);
}
message->setParameter(deviceObjectid);
message->setParameter2(rawPacketStoreId.raw);
}
void DeviceHandlerMessage::setDeviceHandlerDirectCommandReply(
CommandMessage* message, object_id_t deviceObjectid,
store_address_t commandParametersStoreId) {
message->setCommand(REPLY_DIRECT_COMMAND_DATA);
message->setParameter(deviceObjectid);
message->setParameter2(commandParametersStoreId.raw);
}
void DeviceHandlerMessage::clear(CommandMessage* message) {
switch (message->getCommand()) {
case CMD_RAW:
// case CMD_DIRECT:
case REPLY_RAW_COMMAND:
case REPLY_RAW_REPLY:
case REPLY_DIRECT_COMMAND_DATA: {
StorageManagerIF *ipcStore = objectManager->get<StorageManagerIF>(
objects::IPC_STORE);
if (ipcStore != NULL) {
ipcStore->deleteData(getStoreAddress(message));
}
}
/* NO BREAK falls through*/
case CMD_SWITCH_ADDRESS:
case CMD_WIRETAPPING:
message->setCommand(CommandMessage::CMD_NONE);
message->setParameter(0);
message->setParameter2(0);
break;
}
}

View File

@ -1,91 +1,91 @@
#ifndef DEVICEHANDLERMESSAGE_H_
#define DEVICEHANDLERMESSAGE_H_
#include "../action/ActionMessage.h"
#include "../ipc/CommandMessage.h"
#include "../objectmanager/SystemObjectIF.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.
/**
* This is used to uniquely identify commands that are sent to a device
*
* 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 {
private:
DeviceHandlerMessage();
public:
/**
* These are the commands that can be sent to a DeviceHandlerBase
*/
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
// 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
static const Command_t CMD_SWITCH_ADDRESS = MAKE_COMMAND_ID( 3 ); //!< Requests a IO-Board switch, setParameter() is the IO-Board identifier
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
/*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)
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_WIRETAPPING = MAKE_COMMAND_ID( 3); //!< Reply to a @c CMD_WIRETAPPING, getParameter() is the current state, 1 enabled, 0 disabled
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
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
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
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;
/**
* Default Destructor
*/
virtual ~DeviceHandlerMessage() {
}
static store_address_t getStoreAddress(const CommandMessage* message);
static uint32_t getDeviceCommandId(const CommandMessage* message);
static object_id_t getDeviceObjectId(const CommandMessage *message);
static object_id_t getIoBoardObjectId(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,
object_id_t deviceObjectid,
store_address_t commandParametersStoreId);
static void setDeviceHandlerRawCommandMessage(CommandMessage* message,
store_address_t rawPacketStoreId);
static void setDeviceHandlerRawReplyMessage(CommandMessage* message,
object_id_t deviceObjectid, store_address_t rawPacketStoreId,
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,
uint8_t wiretappingMode);
static void setDeviceHandlerSwitchIoBoardMessage(CommandMessage* message,
object_id_t ioBoardIdentifier);
static void clear(CommandMessage* message);
};
#endif /* DEVICEHANDLERMESSAGE_H_ */
#ifndef DEVICEHANDLERMESSAGE_H_
#define DEVICEHANDLERMESSAGE_H_
#include "../action/ActionMessage.h"
#include "../ipc/CommandMessage.h"
#include "../objectmanager/SystemObjectIF.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.
/**
* This is used to uniquely identify commands that are sent to a device
*
* 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 {
private:
DeviceHandlerMessage();
public:
/**
* These are the commands that can be sent to a DeviceHandlerBase
*/
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
// 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
static const Command_t CMD_SWITCH_ADDRESS = MAKE_COMMAND_ID( 3 ); //!< Requests a IO-Board switch, setParameter() is the IO-Board identifier
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
/*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)
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_WIRETAPPING = MAKE_COMMAND_ID( 3); //!< Reply to a @c CMD_WIRETAPPING, getParameter() is the current state, 1 enabled, 0 disabled
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
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
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
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;
/**
* Default Destructor
*/
virtual ~DeviceHandlerMessage() {
}
static store_address_t getStoreAddress(const CommandMessage* message);
static uint32_t getDeviceCommandId(const CommandMessage* message);
static object_id_t getDeviceObjectId(const CommandMessage *message);
static object_id_t getIoBoardObjectId(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,
object_id_t deviceObjectid,
store_address_t commandParametersStoreId);
static void setDeviceHandlerRawCommandMessage(CommandMessage* message,
store_address_t rawPacketStoreId);
static void setDeviceHandlerRawReplyMessage(CommandMessage* message,
object_id_t deviceObjectid, store_address_t rawPacketStoreId,
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,
uint8_t wiretappingMode);
static void setDeviceHandlerSwitchIoBoardMessage(CommandMessage* message,
object_id_t ioBoardIdentifier);
static void clear(CommandMessage* message);
};
#endif /* DEVICEHANDLERMESSAGE_H_ */

View File

@ -1,46 +1,46 @@
#include "../serialize/SerializeAdapter.h"
#include "../devicehandlers/DeviceTmReportingWrapper.h"
#include "../serialize/SerializeAdapter.h"
DeviceTmReportingWrapper::DeviceTmReportingWrapper(object_id_t objectId,
ActionId_t actionId, SerializeIF* data) :
objectId(objectId), actionId(actionId), data(data) {
}
DeviceTmReportingWrapper::~DeviceTmReportingWrapper() {
}
ReturnValue_t DeviceTmReportingWrapper::serialize(uint8_t** buffer,
size_t* size, size_t maxSize, Endianness streamEndianness) const {
ReturnValue_t result = SerializeAdapter::serialize(&objectId,
buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&actionId, buffer,
size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return data->serialize(buffer, size, maxSize, streamEndianness);
}
size_t DeviceTmReportingWrapper::getSerializedSize() const {
return sizeof(objectId) + sizeof(ActionId_t) + data->getSerializedSize();
}
ReturnValue_t DeviceTmReportingWrapper::deSerialize(const uint8_t** buffer,
size_t* size, Endianness streamEndianness) {
ReturnValue_t result = SerializeAdapter::deSerialize(&objectId,
buffer, size, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::deSerialize(&actionId, buffer,
size, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return data->deSerialize(buffer, size, streamEndianness);
}
#include "../serialize/SerializeAdapter.h"
#include "../devicehandlers/DeviceTmReportingWrapper.h"
#include "../serialize/SerializeAdapter.h"
DeviceTmReportingWrapper::DeviceTmReportingWrapper(object_id_t objectId,
ActionId_t actionId, SerializeIF* data) :
objectId(objectId), actionId(actionId), data(data) {
}
DeviceTmReportingWrapper::~DeviceTmReportingWrapper() {
}
ReturnValue_t DeviceTmReportingWrapper::serialize(uint8_t** buffer,
size_t* size, size_t maxSize, Endianness streamEndianness) const {
ReturnValue_t result = SerializeAdapter::serialize(&objectId,
buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&actionId, buffer,
size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return data->serialize(buffer, size, maxSize, streamEndianness);
}
size_t DeviceTmReportingWrapper::getSerializedSize() const {
return sizeof(objectId) + sizeof(ActionId_t) + data->getSerializedSize();
}
ReturnValue_t DeviceTmReportingWrapper::deSerialize(const uint8_t** buffer,
size_t* size, Endianness streamEndianness) {
ReturnValue_t result = SerializeAdapter::deSerialize(&objectId,
buffer, size, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::deSerialize(&actionId, buffer,
size, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return data->deSerialize(buffer, size, streamEndianness);
}

View File

@ -1,27 +1,27 @@
#ifndef DEVICETMREPORTINGWRAPPER_H_
#define DEVICETMREPORTINGWRAPPER_H_
#include "../action/HasActionsIF.h"
#include "../objectmanager/SystemObjectIF.h"
#include "../serialize/SerializeIF.h"
class DeviceTmReportingWrapper: public SerializeIF {
public:
DeviceTmReportingWrapper(object_id_t objectId, ActionId_t actionId,
SerializeIF *data);
virtual ~DeviceTmReportingWrapper();
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const override;
virtual size_t getSerializedSize() const override;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override;
private:
object_id_t objectId;
ActionId_t actionId;
SerializeIF *data;
};
#endif /* DEVICETMREPORTINGWRAPPER_H_ */
#ifndef DEVICETMREPORTINGWRAPPER_H_
#define DEVICETMREPORTINGWRAPPER_H_
#include "../action/HasActionsIF.h"
#include "../objectmanager/SystemObjectIF.h"
#include "../serialize/SerializeIF.h"
class DeviceTmReportingWrapper: public SerializeIF {
public:
DeviceTmReportingWrapper(object_id_t objectId, ActionId_t actionId,
SerializeIF *data);
virtual ~DeviceTmReportingWrapper();
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const override;
virtual size_t getSerializedSize() const override;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override;
private:
object_id_t objectId;
ActionId_t actionId;
SerializeIF *data;
};
#endif /* DEVICETMREPORTINGWRAPPER_H_ */

View File

@ -1,59 +1,59 @@
#include "../devicehandlers/HealthDevice.h"
#include "../ipc/QueueFactory.h"
HealthDevice::HealthDevice(object_id_t setObjectId,
MessageQueueId_t parentQueue) :
SystemObject(setObjectId), lastHealth(HEALTHY), parentQueue(
parentQueue), commandQueue(), healthHelper(this, setObjectId) {
commandQueue = QueueFactory::instance()->createMessageQueue(3, CommandMessage::MINIMUM_COMMAND_MESSAGE_SIZE);
}
HealthDevice::~HealthDevice() {
QueueFactory::instance()->deleteMessageQueue(commandQueue);
}
ReturnValue_t HealthDevice::performOperation(uint8_t opCode) {
CommandMessage command;
ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) {
healthHelper.handleHealthCommand(&command);
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t HealthDevice::initialize() {
ReturnValue_t result = SystemObject::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (parentQueue != 0) {
return healthHelper.initialize(parentQueue);
} else {
return healthHelper.initialize();
}
}
MessageQueueId_t HealthDevice::getCommandQueue() const {
return commandQueue->getId();
}
void HealthDevice::setParentQueue(MessageQueueId_t parentQueue) {
healthHelper.setParentQueue(parentQueue);
}
bool HealthDevice::hasHealthChanged() {
bool changed;
HealthState currentHealth = healthHelper.getHealth();
changed = currentHealth != lastHealth;
lastHealth = currentHealth;
return changed;
}
ReturnValue_t HealthDevice::setHealth(HealthState health) {
healthHelper.setHealth(health);
return HasReturnvaluesIF::RETURN_OK;
}
HasHealthIF::HealthState HealthDevice::getHealth() {
return healthHelper.getHealth();
}
#include "../devicehandlers/HealthDevice.h"
#include "../ipc/QueueFactory.h"
HealthDevice::HealthDevice(object_id_t setObjectId,
MessageQueueId_t parentQueue) :
SystemObject(setObjectId), lastHealth(HEALTHY), parentQueue(
parentQueue), commandQueue(), healthHelper(this, setObjectId) {
commandQueue = QueueFactory::instance()->createMessageQueue(3, CommandMessage::MINIMUM_COMMAND_MESSAGE_SIZE);
}
HealthDevice::~HealthDevice() {
QueueFactory::instance()->deleteMessageQueue(commandQueue);
}
ReturnValue_t HealthDevice::performOperation(uint8_t opCode) {
CommandMessage command;
ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) {
healthHelper.handleHealthCommand(&command);
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t HealthDevice::initialize() {
ReturnValue_t result = SystemObject::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (parentQueue != 0) {
return healthHelper.initialize(parentQueue);
} else {
return healthHelper.initialize();
}
}
MessageQueueId_t HealthDevice::getCommandQueue() const {
return commandQueue->getId();
}
void HealthDevice::setParentQueue(MessageQueueId_t parentQueue) {
healthHelper.setParentQueue(parentQueue);
}
bool HealthDevice::hasHealthChanged() {
bool changed;
HealthState currentHealth = healthHelper.getHealth();
changed = currentHealth != lastHealth;
lastHealth = currentHealth;
return changed;
}
ReturnValue_t HealthDevice::setHealth(HealthState health) {
healthHelper.setHealth(health);
return HasReturnvaluesIF::RETURN_OK;
}
HasHealthIF::HealthState HealthDevice::getHealth() {
return healthHelper.getHealth();
}

View File

@ -1,40 +1,40 @@
#ifndef HEALTHDEVICE_H_
#define HEALTHDEVICE_H_
#include "../health/HasHealthIF.h"
#include "../health/HealthHelper.h"
#include "../objectmanager/SystemObject.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../ipc/MessageQueueIF.h"
class HealthDevice: public SystemObject,
public ExecutableObjectIF,
public HasHealthIF {
public:
HealthDevice(object_id_t setObjectId, MessageQueueId_t parentQueue);
virtual ~HealthDevice();
ReturnValue_t performOperation(uint8_t opCode);
ReturnValue_t initialize();
virtual MessageQueueId_t getCommandQueue() const;
void setParentQueue(MessageQueueId_t parentQueue);
bool hasHealthChanged();
virtual ReturnValue_t setHealth(HealthState health);
virtual HealthState getHealth();
protected:
HealthState lastHealth;
MessageQueueId_t parentQueue;
MessageQueueIF* commandQueue;
public:
HealthHelper healthHelper;
};
#endif /* HEALTHDEVICE_H_ */
#ifndef HEALTHDEVICE_H_
#define HEALTHDEVICE_H_
#include "../health/HasHealthIF.h"
#include "../health/HealthHelper.h"
#include "../objectmanager/SystemObject.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../ipc/MessageQueueIF.h"
class HealthDevice: public SystemObject,
public ExecutableObjectIF,
public HasHealthIF {
public:
HealthDevice(object_id_t setObjectId, MessageQueueId_t parentQueue);
virtual ~HealthDevice();
ReturnValue_t performOperation(uint8_t opCode);
ReturnValue_t initialize();
virtual MessageQueueId_t getCommandQueue() const;
void setParentQueue(MessageQueueId_t parentQueue);
bool hasHealthChanged();
virtual ReturnValue_t setHealth(HealthState health);
virtual HealthState getHealth();
protected:
HealthState lastHealth;
MessageQueueId_t parentQueue;
MessageQueueIF* commandQueue;
public:
HealthHelper healthHelper;
};
#endif /* HEALTHDEVICE_H_ */