reapply clang format
This commit is contained in:
@ -8,12 +8,12 @@
|
||||
* 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;
|
||||
public:
|
||||
/**
|
||||
* Default empty virtual destructor.
|
||||
*/
|
||||
virtual ~AcceptsDeviceResponsesIF() {}
|
||||
virtual MessageQueueId_t getDeviceQueue() = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DEVICEHANDLERS_ACCEPTSDEVICERESPONSESIF_H_ */
|
||||
|
@ -1,273 +1,268 @@
|
||||
#include "fsfw/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(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() {
|
||||
}
|
||||
AssemblyBase::~AssemblyBase() {}
|
||||
|
||||
ReturnValue_t AssemblyBase::handleCommandMessage(CommandMessage* message) {
|
||||
return handleHealthReply(message);
|
||||
return handleHealthReply(message);
|
||||
}
|
||||
|
||||
void AssemblyBase::performChildOperation() {
|
||||
if (isInTransition()) {
|
||||
handleChildrenTransition();
|
||||
} else {
|
||||
handleChildrenChanged();
|
||||
}
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
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);
|
||||
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();
|
||||
}
|
||||
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);
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
// 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++;
|
||||
}
|
||||
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);
|
||||
}
|
||||
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;
|
||||
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;
|
||||
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) {
|
||||
uint32_t* msToReachTheMode) {
|
||||
// always accept transition to OFF
|
||||
if (mode == MODE_OFF) {
|
||||
if (submode != SUBMODE_NONE) {
|
||||
return INVALID_SUBMODE;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
//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 ((mode != MODE_ON) && (mode != DeviceHandlerIF::MODE_NORMAL)) {
|
||||
return INVALID_MODE;
|
||||
}
|
||||
if (internalState != STATE_NONE) {
|
||||
return IN_TRANSITION;
|
||||
}
|
||||
|
||||
if (internalState != STATE_NONE) {
|
||||
return IN_TRANSITION;
|
||||
}
|
||||
|
||||
return isModeCombinationValid(mode, submode);
|
||||
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;
|
||||
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;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef FSFW_DEVICEHANDLERS_ASSEMBLYBASE_H_
|
||||
#define FSFW_DEVICEHANDLERS_ASSEMBLYBASE_H_
|
||||
|
||||
#include "DeviceHandlerBase.h"
|
||||
#include "../container/FixedArrayList.h"
|
||||
#include "../subsystem/SubsystemBase.h"
|
||||
#include "DeviceHandlerBase.h"
|
||||
|
||||
/**
|
||||
* @brief Base class to implement reconfiguration and failure handling for
|
||||
@ -32,149 +32,142 @@
|
||||
* (This will call the function in SubsystemBase)
|
||||
*
|
||||
*/
|
||||
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);
|
||||
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();
|
||||
AssemblyBase(object_id_t objectId, object_id_t parentId, uint16_t commandQueueDepth = 8);
|
||||
virtual ~AssemblyBase();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* 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;
|
||||
protected:
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Check whether a combination of mode and submode is valid.
|
||||
*
|
||||
* Ground Controller like precise return values from HasModesIF.
|
||||
* So, please return any of them.
|
||||
*
|
||||
* @param mode The targeted mode
|
||||
* @param submode The targeted submmode
|
||||
* @return Any information why this combination is invalid from HasModesIF
|
||||
* like HasModesIF::INVALID_SUBMODE.
|
||||
* On success return HasReturnvaluesIF::RETURN_OK
|
||||
*/
|
||||
virtual ReturnValue_t isModeCombinationValid(Mode_t mode,
|
||||
Submode_t submode) = 0;
|
||||
/**
|
||||
* Check whether a combination of mode and submode is valid.
|
||||
*
|
||||
* Ground Controller like precise return values from HasModesIF.
|
||||
* So, please return any of them.
|
||||
*
|
||||
* @param mode The targeted mode
|
||||
* @param submode The targeted submmode
|
||||
* @return Any information why this combination is invalid from HasModesIF
|
||||
* like HasModesIF::INVALID_SUBMODE.
|
||||
* On success return HasReturnvaluesIF::RETURN_OK
|
||||
*/
|
||||
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 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;
|
||||
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 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;
|
||||
/**
|
||||
* the submode the current transition is trying to achieve.
|
||||
* Can be different from the modehelper.commandedSubmode!
|
||||
*/
|
||||
Submode_t targetSubmode;
|
||||
|
||||
Countdown recoveryOffTimer;
|
||||
Countdown recoveryOffTimer;
|
||||
|
||||
static const uint32_t POWER_OFF_TIME_MS = 1000;
|
||||
static const uint32_t POWER_OFF_TIME_MS = 1000;
|
||||
|
||||
virtual ReturnValue_t handleCommandMessage(CommandMessage *message);
|
||||
virtual ReturnValue_t handleCommandMessage(CommandMessage *message);
|
||||
|
||||
virtual ReturnValue_t handleHealthReply(CommandMessage *message);
|
||||
virtual ReturnValue_t handleHealthReply(CommandMessage *message);
|
||||
|
||||
virtual void performChildOperation();
|
||||
virtual void performChildOperation();
|
||||
|
||||
bool handleChildrenChanged();
|
||||
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);
|
||||
/**
|
||||
* 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();
|
||||
bool handleChildrenChangedHealth();
|
||||
|
||||
virtual void handleChildrenTransition();
|
||||
virtual void handleChildrenTransition();
|
||||
|
||||
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t *msToReachTheMode);
|
||||
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, uint32_t *msToReachTheMode);
|
||||
|
||||
virtual void startTransition(Mode_t mode, Submode_t submode);
|
||||
virtual void startTransition(Mode_t mode, Submode_t submode);
|
||||
|
||||
virtual void doStartTransition(Mode_t mode, Submode_t submode);
|
||||
virtual void doStartTransition(Mode_t mode, Submode_t submode);
|
||||
|
||||
virtual bool isInTransition();
|
||||
virtual bool isInTransition();
|
||||
|
||||
virtual void handleModeReached();
|
||||
virtual void handleModeReached();
|
||||
|
||||
virtual void handleModeTransitionFailed(ReturnValue_t result);
|
||||
virtual void handleModeTransitionFailed(ReturnValue_t result);
|
||||
|
||||
void sendHealthCommand(MessageQueueId_t sendTo, HealthState health);
|
||||
void sendHealthCommand(MessageQueueId_t sendTo, HealthState health);
|
||||
|
||||
virtual ReturnValue_t checkChildrenStateOff();
|
||||
virtual ReturnValue_t checkChildrenStateOff();
|
||||
|
||||
ReturnValue_t checkChildrenState();
|
||||
ReturnValue_t checkChildrenState();
|
||||
|
||||
virtual ReturnValue_t checkChildOff(uint32_t objectId);
|
||||
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);
|
||||
/**
|
||||
* 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 /* FSFW_DEVICEHANDLERS_ASSEMBLYBASE_H_ */
|
||||
|
@ -1,46 +1,43 @@
|
||||
#include "fsfw/devicehandlers/ChildHandlerBase.h"
|
||||
|
||||
#include "fsfw/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(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() {
|
||||
}
|
||||
ChildHandlerBase::~ChildHandlerBase() {}
|
||||
|
||||
ReturnValue_t ChildHandlerBase::initialize() {
|
||||
ReturnValue_t result = DeviceHandlerBase::initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
ReturnValue_t result = DeviceHandlerBase::initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
MessageQueueId_t parentQueue = 0;
|
||||
MessageQueueId_t parentQueue = 0;
|
||||
|
||||
if (parentId != objects::NO_OBJECT) {
|
||||
SubsystemBase *parent = ObjectManager::instance()->get<SubsystemBase>(parentId);
|
||||
if (parent == NULL) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
parentQueue = parent->getCommandQueue();
|
||||
if (parentId != objects::NO_OBJECT) {
|
||||
SubsystemBase* parent = ObjectManager::instance()->get<SubsystemBase>(parentId);
|
||||
if (parent == NULL) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
parentQueue = parent->getCommandQueue();
|
||||
|
||||
parent->registerChild(getObjectId());
|
||||
}
|
||||
parent->registerChild(getObjectId());
|
||||
}
|
||||
|
||||
healthHelper.setParentQueue(parentQueue);
|
||||
healthHelper.setParentQueue(parentQueue);
|
||||
|
||||
modeHelper.setParentQueue(parentQueue);
|
||||
modeHelper.setParentQueue(parentQueue);
|
||||
|
||||
return RETURN_OK;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
@ -1,26 +1,23 @@
|
||||
#ifndef FSFW_DEVICEHANDLER_CHILDHANDLERBASE_H_
|
||||
#define FSFW_DEVICEHANDLER_CHILDHANDLERBASE_H_
|
||||
|
||||
#include "DeviceHandlerBase.h"
|
||||
#include "ChildHandlerFDIR.h"
|
||||
#include "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);
|
||||
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 ~ChildHandlerBase();
|
||||
|
||||
virtual ReturnValue_t initialize();
|
||||
|
||||
protected:
|
||||
const uint32_t parentId;
|
||||
ChildHandlerFDIR childHandlerFdir;
|
||||
virtual ReturnValue_t initialize();
|
||||
|
||||
protected:
|
||||
const uint32_t parentId;
|
||||
ChildHandlerFDIR childHandlerFdir;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DEVICEHANDLER_CHILDHANDLERBASE_H_ */
|
||||
|
@ -1,11 +1,9 @@
|
||||
#include "fsfw/devicehandlers/ChildHandlerFDIR.h"
|
||||
|
||||
ChildHandlerFDIR::ChildHandlerFDIR(object_id_t owner,
|
||||
object_id_t faultTreeParent, uint32_t recoveryCount) :
|
||||
DeviceHandlerFailureIsolation(owner, faultTreeParent) {
|
||||
recoveryCounter.setFailureThreshold(recoveryCount);
|
||||
}
|
||||
|
||||
ChildHandlerFDIR::~ChildHandlerFDIR() {
|
||||
ChildHandlerFDIR::ChildHandlerFDIR(object_id_t owner, object_id_t faultTreeParent,
|
||||
uint32_t recoveryCount)
|
||||
: DeviceHandlerFailureIsolation(owner, faultTreeParent) {
|
||||
recoveryCounter.setFailureThreshold(recoveryCount);
|
||||
}
|
||||
|
||||
ChildHandlerFDIR::~ChildHandlerFDIR() {}
|
||||
|
@ -8,13 +8,14 @@
|
||||
* 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;
|
||||
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_ */
|
||||
|
@ -27,8 +27,8 @@ using address_t = uint32_t;
|
||||
* @ingroup comm
|
||||
*/
|
||||
class CookieIF {
|
||||
public:
|
||||
virtual ~CookieIF() {};
|
||||
public:
|
||||
virtual ~CookieIF(){};
|
||||
};
|
||||
|
||||
#endif /* FSFW_DEVICEHANDLER_COOKIE_H_ */
|
||||
|
@ -1,10 +1,9 @@
|
||||
#ifndef FSFW_DEVICES_DEVICECOMMUNICATIONIF_H_
|
||||
#define FSFW_DEVICES_DEVICECOMMUNICATIONIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "CookieIF.h"
|
||||
#include "DeviceHandlerIF.h"
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
/**
|
||||
* @defgroup interfaces Interfaces
|
||||
* @brief Interfaces for flight software objects
|
||||
@ -35,95 +34,92 @@
|
||||
* @ingroup interfaces
|
||||
* @ingroup comm
|
||||
*/
|
||||
class DeviceCommunicationIF: public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF;
|
||||
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);
|
||||
//! 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);
|
||||
//! 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() {}
|
||||
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;
|
||||
/**
|
||||
* @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 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 successfully but a reply is expected
|
||||
* - NO_REPLY_EXPECTED if data was sent successfully and no reply is expected
|
||||
* - Everything else to indicate failure
|
||||
*/
|
||||
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 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 successfully but a reply is expected
|
||||
* - NO_REPLY_EXPECTED if data was sent successfully and no reply is expected
|
||||
* - Everything else to indicate failure
|
||||
*/
|
||||
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 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;
|
||||
/**
|
||||
* 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 /* FSFW_DEVICES_DEVICECOMMUNICATIONIF_H_ */
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,269 +1,260 @@
|
||||
#include "fsfw/devicehandlers/DeviceHandlerFailureIsolation.h"
|
||||
|
||||
#include "fsfw/devicehandlers/DeviceHandlerIF.h"
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/modes/HasModesIF.h"
|
||||
#include "fsfw/health/HealthTableIF.h"
|
||||
#include "fsfw/modes/HasModesIF.h"
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/power/Fuse.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "fsfw/thermal/ThermalComponentIF.h"
|
||||
|
||||
object_id_t DeviceHandlerFailureIsolation::powerConfirmationId =
|
||||
objects::NO_OBJECT;
|
||||
object_id_t DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT;
|
||||
|
||||
DeviceHandlerFailureIsolation::DeviceHandlerFailureIsolation(object_id_t owner,
|
||||
object_id_t parent) :
|
||||
FailureIsolationBase(owner, parent),
|
||||
strangeReplyCount(DEFAULT_MAX_STRANGE_REPLIES,
|
||||
DEFAULT_STRANGE_REPLIES_TIME_MS,
|
||||
parameterDomainBase++),
|
||||
missedReplyCount( DEFAULT_MAX_MISSED_REPLY_COUNT,
|
||||
DEFAULT_MISSED_REPLY_TIME_MS,
|
||||
parameterDomainBase++),
|
||||
recoveryCounter(DEFAULT_MAX_REBOOT, DEFAULT_REBOOT_TIME_MS,
|
||||
parameterDomainBase++),
|
||||
fdirState(NONE) {
|
||||
}
|
||||
DeviceHandlerFailureIsolation::DeviceHandlerFailureIsolation(object_id_t owner, object_id_t parent)
|
||||
: FailureIsolationBase(owner, parent),
|
||||
strangeReplyCount(DEFAULT_MAX_STRANGE_REPLIES, DEFAULT_STRANGE_REPLIES_TIME_MS,
|
||||
parameterDomainBase++),
|
||||
missedReplyCount(DEFAULT_MAX_MISSED_REPLY_COUNT, DEFAULT_MISSED_REPLY_TIME_MS,
|
||||
parameterDomainBase++),
|
||||
recoveryCounter(DEFAULT_MAX_REBOOT, DEFAULT_REBOOT_TIME_MS, parameterDomainBase++),
|
||||
fdirState(NONE) {}
|
||||
|
||||
DeviceHandlerFailureIsolation::~DeviceHandlerFailureIsolation() {
|
||||
}
|
||||
DeviceHandlerFailureIsolation::~DeviceHandlerFailureIsolation() {}
|
||||
|
||||
ReturnValue_t DeviceHandlerFailureIsolation::eventReceived(EventMessage* event) {
|
||||
if(isFdirInActionOrAreWeFaulty(event)) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
switch (event->getEvent()) {
|
||||
case HasModesIF::MODE_TRANSITION_FAILED:
|
||||
case HasModesIF::OBJECT_IN_INVALID_MODE:
|
||||
//We'll try a recovery as long as defined in MAX_REBOOT.
|
||||
//Might cause some AssemblyBase cycles, so keep number low.
|
||||
handleRecovery(event->getEvent());
|
||||
break;
|
||||
case DeviceHandlerIF::DEVICE_INTERPRETING_REPLY_FAILED:
|
||||
case DeviceHandlerIF::DEVICE_READING_REPLY_FAILED:
|
||||
case DeviceHandlerIF::DEVICE_UNREQUESTED_REPLY:
|
||||
case DeviceHandlerIF::DEVICE_UNKNOWN_REPLY: //Some DH's generate generic reply-ids.
|
||||
case DeviceHandlerIF::DEVICE_BUILDING_COMMAND_FAILED:
|
||||
//These faults all mean that there were stupid replies from a device.
|
||||
if (strangeReplyCount.incrementAndCheck()) {
|
||||
handleRecovery(event->getEvent());
|
||||
}
|
||||
break;
|
||||
case DeviceHandlerIF::DEVICE_SENDING_COMMAND_FAILED:
|
||||
case DeviceHandlerIF::DEVICE_REQUESTING_REPLY_FAILED:
|
||||
//The two above should never be confirmed.
|
||||
case DeviceHandlerIF::DEVICE_MISSED_REPLY:
|
||||
result = sendConfirmationRequest(event);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
break;
|
||||
}
|
||||
//else
|
||||
if (missedReplyCount.incrementAndCheck()) {
|
||||
handleRecovery(event->getEvent());
|
||||
}
|
||||
break;
|
||||
case StorageManagerIF::GET_DATA_FAILED:
|
||||
case StorageManagerIF::STORE_DATA_FAILED:
|
||||
//Rather strange bugs, occur in RAW mode only. Ignore.
|
||||
break;
|
||||
case DeviceHandlerIF::INVALID_DEVICE_COMMAND:
|
||||
//Ignore, is bad configuration. We can't do anything in flight.
|
||||
break;
|
||||
case HasHealthIF::HEALTH_INFO:
|
||||
case HasModesIF::MODE_INFO:
|
||||
case HasModesIF::CHANGING_MODE:
|
||||
//Do nothing, but mark as handled.
|
||||
break;
|
||||
//****Power*****
|
||||
case PowerSwitchIF::SWITCH_WENT_OFF:
|
||||
if(powerConfirmation != MessageQueueIF::NO_QUEUE) {
|
||||
result = sendConfirmationRequest(event, powerConfirmation);
|
||||
if (result == RETURN_OK) {
|
||||
setFdirState(DEVICE_MIGHT_BE_OFF);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Fuse::FUSE_WENT_OFF:
|
||||
//Not so good, because PCDU reacted.
|
||||
case Fuse::POWER_ABOVE_HIGH_LIMIT:
|
||||
//Better, because software detected over-current.
|
||||
setFaulty(event->getEvent());
|
||||
break;
|
||||
case Fuse::POWER_BELOW_LOW_LIMIT:
|
||||
//Device might got stuck during boot, retry.
|
||||
handleRecovery(event->getEvent());
|
||||
break;
|
||||
//****Thermal*****
|
||||
case ThermalComponentIF::COMPONENT_TEMP_LOW:
|
||||
case ThermalComponentIF::COMPONENT_TEMP_HIGH:
|
||||
case ThermalComponentIF::COMPONENT_TEMP_OOL_LOW:
|
||||
case ThermalComponentIF::COMPONENT_TEMP_OOL_HIGH:
|
||||
//Well, the device is not really faulty, but it is required to stay off as long as possible.
|
||||
setFaulty(event->getEvent());
|
||||
break;
|
||||
case ThermalComponentIF::TEMP_NOT_IN_OP_RANGE:
|
||||
//Ignore, is information only.
|
||||
break;
|
||||
//*******Default monitoring variables. Are currently not used.*****
|
||||
// case DeviceHandlerIF::MONITORING_LIMIT_EXCEEDED:
|
||||
// setFaulty(event->getEvent());
|
||||
// break;
|
||||
// case DeviceHandlerIF::MONITORING_AMBIGUOUS:
|
||||
// break;
|
||||
default:
|
||||
//We don't know the event, someone else should handle it.
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
return RETURN_OK;
|
||||
if (isFdirInActionOrAreWeFaulty(event)) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
switch (event->getEvent()) {
|
||||
case HasModesIF::MODE_TRANSITION_FAILED:
|
||||
case HasModesIF::OBJECT_IN_INVALID_MODE:
|
||||
// We'll try a recovery as long as defined in MAX_REBOOT.
|
||||
// Might cause some AssemblyBase cycles, so keep number low.
|
||||
handleRecovery(event->getEvent());
|
||||
break;
|
||||
case DeviceHandlerIF::DEVICE_INTERPRETING_REPLY_FAILED:
|
||||
case DeviceHandlerIF::DEVICE_READING_REPLY_FAILED:
|
||||
case DeviceHandlerIF::DEVICE_UNREQUESTED_REPLY:
|
||||
case DeviceHandlerIF::DEVICE_UNKNOWN_REPLY: // Some DH's generate generic reply-ids.
|
||||
case DeviceHandlerIF::DEVICE_BUILDING_COMMAND_FAILED:
|
||||
// These faults all mean that there were stupid replies from a device.
|
||||
if (strangeReplyCount.incrementAndCheck()) {
|
||||
handleRecovery(event->getEvent());
|
||||
}
|
||||
break;
|
||||
case DeviceHandlerIF::DEVICE_SENDING_COMMAND_FAILED:
|
||||
case DeviceHandlerIF::DEVICE_REQUESTING_REPLY_FAILED:
|
||||
// The two above should never be confirmed.
|
||||
case DeviceHandlerIF::DEVICE_MISSED_REPLY:
|
||||
result = sendConfirmationRequest(event);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
break;
|
||||
}
|
||||
// else
|
||||
if (missedReplyCount.incrementAndCheck()) {
|
||||
handleRecovery(event->getEvent());
|
||||
}
|
||||
break;
|
||||
case StorageManagerIF::GET_DATA_FAILED:
|
||||
case StorageManagerIF::STORE_DATA_FAILED:
|
||||
// Rather strange bugs, occur in RAW mode only. Ignore.
|
||||
break;
|
||||
case DeviceHandlerIF::INVALID_DEVICE_COMMAND:
|
||||
// Ignore, is bad configuration. We can't do anything in flight.
|
||||
break;
|
||||
case HasHealthIF::HEALTH_INFO:
|
||||
case HasModesIF::MODE_INFO:
|
||||
case HasModesIF::CHANGING_MODE:
|
||||
// Do nothing, but mark as handled.
|
||||
break;
|
||||
//****Power*****
|
||||
case PowerSwitchIF::SWITCH_WENT_OFF:
|
||||
if (powerConfirmation != MessageQueueIF::NO_QUEUE) {
|
||||
result = sendConfirmationRequest(event, powerConfirmation);
|
||||
if (result == RETURN_OK) {
|
||||
setFdirState(DEVICE_MIGHT_BE_OFF);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Fuse::FUSE_WENT_OFF:
|
||||
// Not so good, because PCDU reacted.
|
||||
case Fuse::POWER_ABOVE_HIGH_LIMIT:
|
||||
// Better, because software detected over-current.
|
||||
setFaulty(event->getEvent());
|
||||
break;
|
||||
case Fuse::POWER_BELOW_LOW_LIMIT:
|
||||
// Device might got stuck during boot, retry.
|
||||
handleRecovery(event->getEvent());
|
||||
break;
|
||||
//****Thermal*****
|
||||
case ThermalComponentIF::COMPONENT_TEMP_LOW:
|
||||
case ThermalComponentIF::COMPONENT_TEMP_HIGH:
|
||||
case ThermalComponentIF::COMPONENT_TEMP_OOL_LOW:
|
||||
case ThermalComponentIF::COMPONENT_TEMP_OOL_HIGH:
|
||||
// Well, the device is not really faulty, but it is required to stay off as long as possible.
|
||||
setFaulty(event->getEvent());
|
||||
break;
|
||||
case ThermalComponentIF::TEMP_NOT_IN_OP_RANGE:
|
||||
// Ignore, is information only.
|
||||
break;
|
||||
//*******Default monitoring variables. Are currently not used.*****
|
||||
// case DeviceHandlerIF::MONITORING_LIMIT_EXCEEDED:
|
||||
// setFaulty(event->getEvent());
|
||||
// break;
|
||||
// case DeviceHandlerIF::MONITORING_AMBIGUOUS:
|
||||
// break;
|
||||
default:
|
||||
// We don't know the event, someone else should handle it.
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void DeviceHandlerFailureIsolation::eventConfirmed(EventMessage* event) {
|
||||
switch (event->getEvent()) {
|
||||
case DeviceHandlerIF::DEVICE_SENDING_COMMAND_FAILED:
|
||||
case DeviceHandlerIF::DEVICE_REQUESTING_REPLY_FAILED:
|
||||
case DeviceHandlerIF::DEVICE_MISSED_REPLY:
|
||||
if (missedReplyCount.incrementAndCheck()) {
|
||||
handleRecovery(event->getEvent());
|
||||
}
|
||||
break;
|
||||
case PowerSwitchIF::SWITCH_WENT_OFF:
|
||||
//This means the switch went off only for one device.
|
||||
handleRecovery(event->getEvent());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (event->getEvent()) {
|
||||
case DeviceHandlerIF::DEVICE_SENDING_COMMAND_FAILED:
|
||||
case DeviceHandlerIF::DEVICE_REQUESTING_REPLY_FAILED:
|
||||
case DeviceHandlerIF::DEVICE_MISSED_REPLY:
|
||||
if (missedReplyCount.incrementAndCheck()) {
|
||||
handleRecovery(event->getEvent());
|
||||
}
|
||||
break;
|
||||
case PowerSwitchIF::SWITCH_WENT_OFF:
|
||||
// This means the switch went off only for one device.
|
||||
handleRecovery(event->getEvent());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceHandlerFailureIsolation::decrementFaultCounters() {
|
||||
strangeReplyCount.checkForDecrement();
|
||||
missedReplyCount.checkForDecrement();
|
||||
recoveryCounter.checkForDecrement();
|
||||
strangeReplyCount.checkForDecrement();
|
||||
missedReplyCount.checkForDecrement();
|
||||
recoveryCounter.checkForDecrement();
|
||||
}
|
||||
|
||||
void DeviceHandlerFailureIsolation::handleRecovery(Event reason) {
|
||||
clearFaultCounters();
|
||||
if (not recoveryCounter.incrementAndCheck()) {
|
||||
startRecovery(reason);
|
||||
} else {
|
||||
setFaulty(reason);
|
||||
}
|
||||
clearFaultCounters();
|
||||
if (not recoveryCounter.incrementAndCheck()) {
|
||||
startRecovery(reason);
|
||||
} else {
|
||||
setFaulty(reason);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceHandlerFailureIsolation::wasParentsFault(EventMessage* event) {
|
||||
//We'll better ignore the SWITCH_WENT_OFF event and await a system-wide reset.
|
||||
//This means, no fault message will come through until a MODE_ or
|
||||
//HEALTH_INFO message comes through -> Is that ok?
|
||||
//Same issue in TxFailureIsolation!
|
||||
// if ((event->getEvent() == PowerSwitchIF::SWITCH_WENT_OFF)
|
||||
// && (fdirState != RECOVERY_ONGOING)) {
|
||||
// setFdirState(NONE);
|
||||
// }
|
||||
// We'll better ignore the SWITCH_WENT_OFF event and await a system-wide reset.
|
||||
// This means, no fault message will come through until a MODE_ or
|
||||
// HEALTH_INFO message comes through -> Is that ok?
|
||||
// Same issue in TxFailureIsolation!
|
||||
// if ((event->getEvent() == PowerSwitchIF::SWITCH_WENT_OFF)
|
||||
// && (fdirState != RECOVERY_ONGOING)) {
|
||||
// setFdirState(NONE);
|
||||
// }
|
||||
}
|
||||
|
||||
void DeviceHandlerFailureIsolation::clearFaultCounters() {
|
||||
strangeReplyCount.clear();
|
||||
missedReplyCount.clear();
|
||||
strangeReplyCount.clear();
|
||||
missedReplyCount.clear();
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerFailureIsolation::initialize() {
|
||||
ReturnValue_t result = FailureIsolationBase::initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
ReturnValue_t result = FailureIsolationBase::initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "DeviceHandlerFailureIsolation::initialize: Could not"
|
||||
" initialize FailureIsolationBase." << std::endl;
|
||||
sif::error << "DeviceHandlerFailureIsolation::initialize: Could not"
|
||||
" initialize FailureIsolationBase."
|
||||
<< std::endl;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
ConfirmsFailuresIF* power = ObjectManager::instance()->get<ConfirmsFailuresIF>(
|
||||
powerConfirmationId);
|
||||
if (power != nullptr) {
|
||||
powerConfirmation = power->getEventReceptionQueue();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
ConfirmsFailuresIF* power =
|
||||
ObjectManager::instance()->get<ConfirmsFailuresIF>(powerConfirmationId);
|
||||
if (power != nullptr) {
|
||||
powerConfirmation = power->getEventReceptionQueue();
|
||||
}
|
||||
|
||||
return RETURN_OK;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void DeviceHandlerFailureIsolation::setFdirState(FDIRState state) {
|
||||
FailureIsolationBase::throwFdirEvent(FDIR_CHANGED_STATE, state, fdirState);
|
||||
fdirState = state;
|
||||
FailureIsolationBase::throwFdirEvent(FDIR_CHANGED_STATE, state, fdirState);
|
||||
fdirState = state;
|
||||
}
|
||||
|
||||
void DeviceHandlerFailureIsolation::triggerEvent(Event event, uint32_t parameter1,
|
||||
uint32_t parameter2) {
|
||||
//Do not throw error events if fdirState != none.
|
||||
//This will still forward MODE and HEALTH INFO events in any case.
|
||||
if (fdirState == NONE || event::getSeverity(event) == severity::INFO) {
|
||||
FailureIsolationBase::triggerEvent(event, parameter1, parameter2);
|
||||
}
|
||||
uint32_t parameter2) {
|
||||
// Do not throw error events if fdirState != none.
|
||||
// This will still forward MODE and HEALTH INFO events in any case.
|
||||
if (fdirState == NONE || event::getSeverity(event) == severity::INFO) {
|
||||
FailureIsolationBase::triggerEvent(event, parameter1, parameter2);
|
||||
}
|
||||
}
|
||||
|
||||
bool DeviceHandlerFailureIsolation::isFdirActionInProgress() {
|
||||
return (fdirState != NONE);
|
||||
}
|
||||
bool DeviceHandlerFailureIsolation::isFdirActionInProgress() { return (fdirState != NONE); }
|
||||
|
||||
void DeviceHandlerFailureIsolation::startRecovery(Event reason) {
|
||||
throwFdirEvent(FDIR_STARTS_RECOVERY, event::getEventId(reason));
|
||||
setOwnerHealth(HasHealthIF::NEEDS_RECOVERY);
|
||||
setFdirState(RECOVERY_ONGOING);
|
||||
throwFdirEvent(FDIR_STARTS_RECOVERY, event::getEventId(reason));
|
||||
setOwnerHealth(HasHealthIF::NEEDS_RECOVERY);
|
||||
setFdirState(RECOVERY_ONGOING);
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerFailureIsolation::getParameter(uint8_t domainId,
|
||||
uint8_t uniqueId, ParameterWrapper* parameterWrapper,
|
||||
const ParameterWrapper* newValues, uint16_t startAtIndex) {
|
||||
ReturnValue_t result = strangeReplyCount.getParameter(domainId, uniqueId,
|
||||
parameterWrapper, newValues, startAtIndex);
|
||||
if (result != INVALID_DOMAIN_ID) {
|
||||
return result;
|
||||
}
|
||||
result = missedReplyCount.getParameter(domainId, uniqueId, parameterWrapper, newValues,
|
||||
startAtIndex);
|
||||
if (result != INVALID_DOMAIN_ID) {
|
||||
return result;
|
||||
}
|
||||
result = recoveryCounter.getParameter(domainId, uniqueId, parameterWrapper, newValues,
|
||||
startAtIndex);
|
||||
if (result != INVALID_DOMAIN_ID) {
|
||||
return result;
|
||||
}
|
||||
return INVALID_DOMAIN_ID;
|
||||
ReturnValue_t DeviceHandlerFailureIsolation::getParameter(uint8_t domainId, uint8_t uniqueId,
|
||||
ParameterWrapper* parameterWrapper,
|
||||
const ParameterWrapper* newValues,
|
||||
uint16_t startAtIndex) {
|
||||
ReturnValue_t result =
|
||||
strangeReplyCount.getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex);
|
||||
if (result != INVALID_DOMAIN_ID) {
|
||||
return result;
|
||||
}
|
||||
result =
|
||||
missedReplyCount.getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex);
|
||||
if (result != INVALID_DOMAIN_ID) {
|
||||
return result;
|
||||
}
|
||||
result =
|
||||
recoveryCounter.getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex);
|
||||
if (result != INVALID_DOMAIN_ID) {
|
||||
return result;
|
||||
}
|
||||
return INVALID_DOMAIN_ID;
|
||||
}
|
||||
|
||||
void DeviceHandlerFailureIsolation::setFaulty(Event reason) {
|
||||
throwFdirEvent(FDIR_TURNS_OFF_DEVICE, event::getEventId(reason));
|
||||
setOwnerHealth(HasHealthIF::FAULTY);
|
||||
setFdirState(AWAIT_SHUTDOWN);
|
||||
throwFdirEvent(FDIR_TURNS_OFF_DEVICE, event::getEventId(reason));
|
||||
setOwnerHealth(HasHealthIF::FAULTY);
|
||||
setFdirState(AWAIT_SHUTDOWN);
|
||||
}
|
||||
|
||||
bool DeviceHandlerFailureIsolation::isFdirInActionOrAreWeFaulty(
|
||||
EventMessage* event) {
|
||||
if (fdirState != NONE) {
|
||||
//Only wait for those events, ignore all others.
|
||||
if (event->getParameter1() == HasHealthIF::HEALTHY
|
||||
&& event->getEvent() == HasHealthIF::HEALTH_INFO) {
|
||||
setFdirState(NONE);
|
||||
}
|
||||
if (event->getEvent() == HasModesIF::MODE_INFO
|
||||
&& fdirState != RECOVERY_ONGOING) {
|
||||
setFdirState(NONE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool DeviceHandlerFailureIsolation::isFdirInActionOrAreWeFaulty(EventMessage* event) {
|
||||
if (fdirState != NONE) {
|
||||
// Only wait for those events, ignore all others.
|
||||
if (event->getParameter1() == HasHealthIF::HEALTHY &&
|
||||
event->getEvent() == HasHealthIF::HEALTH_INFO) {
|
||||
setFdirState(NONE);
|
||||
}
|
||||
if (event->getEvent() == HasModesIF::MODE_INFO && fdirState != RECOVERY_ONGOING) {
|
||||
setFdirState(NONE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (owner == nullptr) {
|
||||
// Configuration error.
|
||||
if (owner == nullptr) {
|
||||
// Configuration error.
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "DeviceHandlerFailureIsolation::"
|
||||
<< "isFdirInActionOrAreWeFaulty: Owner not set!" << std::endl;
|
||||
sif::error << "DeviceHandlerFailureIsolation::"
|
||||
<< "isFdirInActionOrAreWeFaulty: Owner not set!" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (owner->getHealth() == HasHealthIF::FAULTY
|
||||
|| owner->getHealth() == HasHealthIF::PERMANENT_FAULTY) {
|
||||
//Ignore all events in case device is already faulty.
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (owner->getHealth() == HasHealthIF::FAULTY ||
|
||||
owner->getHealth() == HasHealthIF::PERMANENT_FAULTY) {
|
||||
// Ignore all events in case device is already faulty.
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1,57 +1,56 @@
|
||||
#ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERFAILUREISOLATION_H_
|
||||
#define FSFW_DEVICEHANDLERS_DEVICEHANDLERFAILUREISOLATION_H_
|
||||
|
||||
#include "../fdir/FaultCounter.h"
|
||||
#include "../fdir/FailureIsolationBase.h"
|
||||
#include "../fdir/FaultCounter.h"
|
||||
|
||||
namespace Factory{
|
||||
namespace Factory {
|
||||
void setStaticFrameworkObjectIds();
|
||||
}
|
||||
|
||||
class DeviceHandlerFailureIsolation: public FailureIsolationBase {
|
||||
friend void (Factory::setStaticFrameworkObjectIds)();
|
||||
friend class Heater;
|
||||
public:
|
||||
DeviceHandlerFailureIsolation(object_id_t owner, object_id_t parent);
|
||||
~DeviceHandlerFailureIsolation();
|
||||
ReturnValue_t initialize();
|
||||
void triggerEvent(Event event, uint32_t parameter1 = 0,
|
||||
uint32_t parameter2 = 0);bool isFdirActionInProgress();
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
|
||||
ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues,
|
||||
uint16_t startAtIndex);
|
||||
class DeviceHandlerFailureIsolation : public FailureIsolationBase {
|
||||
friend void(Factory::setStaticFrameworkObjectIds)();
|
||||
friend class Heater;
|
||||
|
||||
protected:
|
||||
FaultCounter strangeReplyCount;
|
||||
FaultCounter missedReplyCount;
|
||||
FaultCounter recoveryCounter;
|
||||
public:
|
||||
DeviceHandlerFailureIsolation(object_id_t owner, object_id_t parent);
|
||||
~DeviceHandlerFailureIsolation();
|
||||
ReturnValue_t initialize();
|
||||
void triggerEvent(Event event, uint32_t parameter1 = 0, uint32_t parameter2 = 0);
|
||||
bool isFdirActionInProgress();
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
|
||||
ParameterWrapper* parameterWrapper,
|
||||
const ParameterWrapper* newValues, uint16_t startAtIndex);
|
||||
|
||||
enum FDIRState {
|
||||
NONE, RECOVERY_ONGOING, DEVICE_MIGHT_BE_OFF, AWAIT_SHUTDOWN
|
||||
};
|
||||
FDIRState fdirState;
|
||||
protected:
|
||||
FaultCounter strangeReplyCount;
|
||||
FaultCounter missedReplyCount;
|
||||
FaultCounter recoveryCounter;
|
||||
|
||||
MessageQueueId_t powerConfirmation = MessageQueueIF::NO_QUEUE;
|
||||
static object_id_t powerConfirmationId;
|
||||
enum FDIRState { NONE, RECOVERY_ONGOING, DEVICE_MIGHT_BE_OFF, AWAIT_SHUTDOWN };
|
||||
FDIRState fdirState;
|
||||
|
||||
static const uint32_t DEFAULT_MAX_REBOOT = 1;
|
||||
static const uint32_t DEFAULT_REBOOT_TIME_MS = 180000;
|
||||
static const uint32_t DEFAULT_MAX_STRANGE_REPLIES = 10;
|
||||
static const uint32_t DEFAULT_STRANGE_REPLIES_TIME_MS = 10000;
|
||||
static const uint32_t DEFAULT_MAX_MISSED_REPLY_COUNT = 5;
|
||||
static const uint32_t DEFAULT_MISSED_REPLY_TIME_MS = 10000;
|
||||
MessageQueueId_t powerConfirmation = MessageQueueIF::NO_QUEUE;
|
||||
static object_id_t powerConfirmationId;
|
||||
|
||||
virtual ReturnValue_t eventReceived(EventMessage* event);
|
||||
virtual void eventConfirmed(EventMessage* event);
|
||||
void wasParentsFault(EventMessage* event);
|
||||
void decrementFaultCounters();
|
||||
void handleRecovery(Event reason);
|
||||
virtual void clearFaultCounters();
|
||||
void setFdirState(FDIRState state);
|
||||
void startRecovery(Event reason);
|
||||
void setFaulty(Event reason);
|
||||
static const uint32_t DEFAULT_MAX_REBOOT = 1;
|
||||
static const uint32_t DEFAULT_REBOOT_TIME_MS = 180000;
|
||||
static const uint32_t DEFAULT_MAX_STRANGE_REPLIES = 10;
|
||||
static const uint32_t DEFAULT_STRANGE_REPLIES_TIME_MS = 10000;
|
||||
static const uint32_t DEFAULT_MAX_MISSED_REPLY_COUNT = 5;
|
||||
static const uint32_t DEFAULT_MISSED_REPLY_TIME_MS = 10000;
|
||||
|
||||
bool isFdirInActionOrAreWeFaulty(EventMessage* event);
|
||||
virtual ReturnValue_t eventReceived(EventMessage* event);
|
||||
virtual void eventConfirmed(EventMessage* event);
|
||||
void wasParentsFault(EventMessage* event);
|
||||
void decrementFaultCounters();
|
||||
void handleRecovery(Event reason);
|
||||
virtual void clearFaultCounters();
|
||||
void setFdirState(FDIRState state);
|
||||
void startRecovery(Event reason);
|
||||
void setFaulty(Event reason);
|
||||
|
||||
bool isFdirInActionOrAreWeFaulty(EventMessage* event);
|
||||
};
|
||||
|
||||
#endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERFAILUREISOLATION_H_ */
|
||||
|
@ -1,13 +1,12 @@
|
||||
#ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_
|
||||
#define FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_
|
||||
|
||||
#include "DeviceHandlerMessage.h"
|
||||
|
||||
#include "../datapoollocal/localPoolDefinitions.h"
|
||||
#include "../action/HasActionsIF.h"
|
||||
#include "../datapoollocal/localPoolDefinitions.h"
|
||||
#include "../events/Event.h"
|
||||
#include "../modes/HasModesIF.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
#include "../modes/HasModesIF.h"
|
||||
#include "DeviceHandlerMessage.h"
|
||||
|
||||
/**
|
||||
* This is used to uniquely identify commands that are sent to a device
|
||||
@ -21,159 +20,163 @@ using DeviceCommandId_t = uint32_t;
|
||||
*
|
||||
*/
|
||||
class DeviceHandlerIF {
|
||||
public:
|
||||
static const DeviceCommandId_t RAW_COMMAND_ID = -1;
|
||||
static const DeviceCommandId_t NO_COMMAND_ID = -2;
|
||||
public:
|
||||
static const DeviceCommandId_t RAW_COMMAND_ID = -1;
|
||||
static const DeviceCommandId_t NO_COMMAND_ID = -2;
|
||||
|
||||
static constexpr uint8_t TRANSITION_MODE_CHILD_ACTION_MASK = 0x20;
|
||||
static constexpr uint8_t TRANSITION_MODE_BASE_ACTION_MASK = 0x10;
|
||||
static constexpr uint8_t TRANSITION_MODE_CHILD_ACTION_MASK = 0x20;
|
||||
static constexpr uint8_t TRANSITION_MODE_BASE_ACTION_MASK = 0x10;
|
||||
|
||||
using dh_heater_request_t = uint8_t;
|
||||
using dh_thermal_state_t = int8_t;
|
||||
using dh_heater_request_t = uint8_t;
|
||||
using dh_thermal_state_t = int8_t;
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
/**
|
||||
* @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;
|
||||
// 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);
|
||||
//! [EXPORT] : [COMMENT] Indicates a SW bug in child class.
|
||||
static const Event INVALID_DEVICE_COMMAND = MAKE_EVENT(8, severity::LOW);
|
||||
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 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);
|
||||
//! [EXPORT] : [COMMENT] Indicates a SW bug in child class.
|
||||
static const Event INVALID_DEVICE_COMMAND = MAKE_EVENT(8, severity::LOW);
|
||||
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;
|
||||
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);
|
||||
//!< Used to indicate that this is a command-only command.
|
||||
static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8);
|
||||
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 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);
|
||||
//!< Used to indicate that this is a command-only command.
|
||||
static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8);
|
||||
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 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 UNKNOWN_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 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 UNKNOWN_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);
|
||||
// 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: uint8_t {
|
||||
PERFORM_OPERATION,
|
||||
SEND_WRITE,//!< Send write
|
||||
GET_WRITE, //!< Get write
|
||||
SEND_READ, //!< Send read
|
||||
GET_READ, //!< Get read
|
||||
NOTHING //!< Do nothing.
|
||||
};
|
||||
/**
|
||||
* Communication action that will be executed.
|
||||
*
|
||||
* This is used by the child class to tell the base class what to do.
|
||||
*/
|
||||
enum CommunicationAction : uint8_t {
|
||||
PERFORM_OPERATION,
|
||||
SEND_WRITE, //!< Send write
|
||||
GET_WRITE, //!< Get write
|
||||
SEND_READ, //!< Send read
|
||||
GET_READ, //!< Get read
|
||||
NOTHING //!< Do nothing.
|
||||
};
|
||||
|
||||
static constexpr uint32_t DEFAULT_THERMAL_SET_ID = sid_t::INVALID_SET_ID - 1;
|
||||
static constexpr uint32_t DEFAULT_THERMAL_SET_ID = sid_t::INVALID_SET_ID - 1;
|
||||
|
||||
static constexpr lp_id_t DEFAULT_THERMAL_STATE_POOL_ID =
|
||||
localpool::INVALID_LPID - 2;
|
||||
static constexpr lp_id_t DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID =
|
||||
localpool::INVALID_LPID - 1;
|
||||
static constexpr lp_id_t DEFAULT_THERMAL_STATE_POOL_ID = localpool::INVALID_LPID - 2;
|
||||
static constexpr lp_id_t DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID = localpool::INVALID_LPID - 1;
|
||||
|
||||
/**
|
||||
* Default Destructor
|
||||
*/
|
||||
virtual ~DeviceHandlerIF() {}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* This MessageQueue is used to command the device handler.
|
||||
* @return the id of the MessageQueue
|
||||
*/
|
||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_ */
|
||||
|
@ -1,88 +1,83 @@
|
||||
#include "fsfw/devicehandlers/DeviceHandlerMessage.h"
|
||||
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
|
||||
store_address_t DeviceHandlerMessage::getStoreAddress(
|
||||
const CommandMessage* message) {
|
||||
return store_address_t(message->getParameter2());
|
||||
store_address_t DeviceHandlerMessage::getStoreAddress(const CommandMessage* message) {
|
||||
return store_address_t(message->getParameter2());
|
||||
}
|
||||
|
||||
uint32_t DeviceHandlerMessage::getDeviceCommandId(
|
||||
const CommandMessage* message) {
|
||||
return message->getParameter();
|
||||
uint32_t DeviceHandlerMessage::getDeviceCommandId(const CommandMessage* message) {
|
||||
return message->getParameter();
|
||||
}
|
||||
|
||||
object_id_t DeviceHandlerMessage::getIoBoardObjectId(
|
||||
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();
|
||||
uint8_t DeviceHandlerMessage::getWiretappingMode(const CommandMessage* message) {
|
||||
return message->getParameter();
|
||||
}
|
||||
|
||||
void DeviceHandlerMessage::setDeviceHandlerRawCommandMessage(
|
||||
CommandMessage* message, store_address_t rawPacketStoreId) {
|
||||
message->setCommand(CMD_RAW);
|
||||
message->setParameter2(rawPacketStoreId.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::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);
|
||||
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();
|
||||
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::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);
|
||||
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 REPLY_RAW_COMMAND:
|
||||
case REPLY_RAW_REPLY:
|
||||
case REPLY_DIRECT_COMMAND_DATA: {
|
||||
StorageManagerIF *ipcStore = ObjectManager::instance()->get<StorageManagerIF>(
|
||||
objects::IPC_STORE);
|
||||
if (ipcStore != nullptr) {
|
||||
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;
|
||||
}
|
||||
|
||||
switch (message->getCommand()) {
|
||||
case CMD_RAW:
|
||||
case REPLY_RAW_COMMAND:
|
||||
case REPLY_RAW_REPLY:
|
||||
case REPLY_DIRECT_COMMAND_DATA: {
|
||||
StorageManagerIF* ipcStore =
|
||||
ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
if (ipcStore != nullptr) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -8,66 +8,63 @@
|
||||
// SHOULDDO: rework the static constructors to name the type of command
|
||||
// they are building, maybe even hide setting the commandID.
|
||||
|
||||
|
||||
/**
|
||||
* @brief The DeviceHandlerMessage is used to send commands to classes
|
||||
* implementing DeviceHandlerIF
|
||||
*/
|
||||
class DeviceHandlerMessage {
|
||||
public:
|
||||
/**
|
||||
* Instantiation forbidden. Instead, use static functions to operate
|
||||
* on messages.
|
||||
*/
|
||||
DeviceHandlerMessage() = delete;
|
||||
virtual ~DeviceHandlerMessage() {}
|
||||
public:
|
||||
/**
|
||||
* Instantiation forbidden. Instead, use static functions to operate
|
||||
* on messages.
|
||||
*/
|
||||
DeviceHandlerMessage() = delete;
|
||||
virtual ~DeviceHandlerMessage() {}
|
||||
|
||||
/**
|
||||
* These are the commands that can be sent to a DeviceHandlerBase
|
||||
*/
|
||||
static const uint8_t MESSAGE_ID = messagetypes::DEVICE_HANDLER_COMMAND;
|
||||
//! Sends a raw command, setParameter is a storeId containing the
|
||||
//! raw packet to send
|
||||
static const Command_t CMD_RAW = MAKE_COMMAND_ID(1);
|
||||
//! Requests a IO-Board switch, setParameter() is the IO-Board identifier
|
||||
static const Command_t CMD_SWITCH_ADDRESS = MAKE_COMMAND_ID(3);
|
||||
//! (De)Activates the monitoring of all raw traffic in DeviceHandlers,
|
||||
//! setParameter is 0 to deactivate, 1 to activate
|
||||
static const Command_t CMD_WIRETAPPING = MAKE_COMMAND_ID(4);
|
||||
/**
|
||||
* These are the commands that can be sent to a DeviceHandlerBase
|
||||
*/
|
||||
static const uint8_t MESSAGE_ID = messagetypes::DEVICE_HANDLER_COMMAND;
|
||||
//! Sends a raw command, setParameter is a storeId containing the
|
||||
//! raw packet to send
|
||||
static const Command_t CMD_RAW = MAKE_COMMAND_ID(1);
|
||||
//! Requests a IO-Board switch, setParameter() is the IO-Board identifier
|
||||
static const Command_t CMD_SWITCH_ADDRESS = MAKE_COMMAND_ID(3);
|
||||
//! (De)Activates the monitoring of all raw traffic in DeviceHandlers,
|
||||
//! setParameter is 0 to deactivate, 1 to activate
|
||||
static const Command_t CMD_WIRETAPPING = MAKE_COMMAND_ID(4);
|
||||
|
||||
//! Signals that a direct command was sent
|
||||
static const Command_t REPLY_DIRECT_COMMAND_SENT = ActionMessage::STEP_SUCCESS;
|
||||
//! Contains a raw command sent to the Device
|
||||
static const Command_t REPLY_RAW_COMMAND = MAKE_COMMAND_ID(0x11);
|
||||
//! 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_RAW_REPLY = MAKE_COMMAND_ID(0x12);
|
||||
static const Command_t REPLY_DIRECT_COMMAND_DATA = ActionMessage::DATA_REPLY;
|
||||
//! Signals that a direct command was sent
|
||||
static const Command_t REPLY_DIRECT_COMMAND_SENT = ActionMessage::STEP_SUCCESS;
|
||||
//! Contains a raw command sent to the Device
|
||||
static const Command_t REPLY_RAW_COMMAND = MAKE_COMMAND_ID(0x11);
|
||||
//! 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_RAW_REPLY = MAKE_COMMAND_ID(0x12);
|
||||
static const Command_t REPLY_DIRECT_COMMAND_DATA = ActionMessage::DATA_REPLY;
|
||||
|
||||
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 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 setDeviceHandlerDirectCommandReply(CommandMessage* message,
|
||||
object_id_t deviceObjectid,
|
||||
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 setDeviceHandlerRawCommandMessage(CommandMessage* message,
|
||||
store_address_t rawPacketStoreId);
|
||||
|
||||
static void setDeviceHandlerRawReplyMessage(CommandMessage* message,
|
||||
object_id_t deviceObjectid, store_address_t rawPacketStoreId,
|
||||
bool isCommand);
|
||||
static void setDeviceHandlerRawReplyMessage(CommandMessage* message, object_id_t deviceObjectid,
|
||||
store_address_t rawPacketStoreId, bool isCommand);
|
||||
|
||||
static void setDeviceHandlerWiretappingMessage(CommandMessage* message,
|
||||
uint8_t wiretappingMode);
|
||||
static void setDeviceHandlerSwitchIoBoardMessage(CommandMessage* message,
|
||||
object_id_t ioBoardIdentifier);
|
||||
static void setDeviceHandlerWiretappingMessage(CommandMessage* message, uint8_t wiretappingMode);
|
||||
static void setDeviceHandlerSwitchIoBoardMessage(CommandMessage* message,
|
||||
object_id_t ioBoardIdentifier);
|
||||
|
||||
static void clear(CommandMessage* message);
|
||||
static void clear(CommandMessage* message);
|
||||
};
|
||||
|
||||
#endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERMESSAGE_H_ */
|
||||
|
@ -1,44 +1,33 @@
|
||||
#ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERTHERMALSET_H_
|
||||
#define FSFW_DEVICEHANDLERS_DEVICEHANDLERTHERMALSET_H_
|
||||
|
||||
#include "DeviceHandlerIF.h"
|
||||
#include "../datapoollocal/StaticLocalDataSet.h"
|
||||
#include "../datapoollocal/LocalPoolVariable.h"
|
||||
#include "../datapoollocal/StaticLocalDataSet.h"
|
||||
#include "DeviceHandlerIF.h"
|
||||
|
||||
class DeviceHandlerThermalSet : public StaticLocalDataSet<2> {
|
||||
public:
|
||||
DeviceHandlerThermalSet(
|
||||
HasLocalDataPoolIF* hkOwner, uint32_t setId = DeviceHandlerIF::DEFAULT_THERMAL_SET_ID,
|
||||
lp_id_t thermalStateId = DeviceHandlerIF::DEFAULT_THERMAL_STATE_POOL_ID,
|
||||
lp_id_t heaterRequestId = DeviceHandlerIF::DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID)
|
||||
: DeviceHandlerThermalSet(hkOwner->getObjectId(), setId, thermalStateId, heaterRequestId) {}
|
||||
|
||||
class DeviceHandlerThermalSet: public StaticLocalDataSet<2> {
|
||||
public:
|
||||
DeviceHandlerThermalSet(
|
||||
object_id_t deviceHandler, uint32_t setId = DeviceHandlerIF::DEFAULT_THERMAL_SET_ID,
|
||||
lp_id_t thermalStateId = DeviceHandlerIF::DEFAULT_THERMAL_STATE_POOL_ID,
|
||||
lp_id_t thermalStateRequestId = DeviceHandlerIF::DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID)
|
||||
: StaticLocalDataSet(sid_t(deviceHandler, setId)),
|
||||
thermalStatePoolId(thermalStateId),
|
||||
heaterRequestPoolId(thermalStateRequestId) {}
|
||||
|
||||
DeviceHandlerThermalSet(HasLocalDataPoolIF* hkOwner, uint32_t setId =
|
||||
DeviceHandlerIF::DEFAULT_THERMAL_SET_ID,
|
||||
lp_id_t thermalStateId =
|
||||
DeviceHandlerIF::DEFAULT_THERMAL_STATE_POOL_ID,
|
||||
lp_id_t heaterRequestId =
|
||||
DeviceHandlerIF::DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID):
|
||||
DeviceHandlerThermalSet(hkOwner->getObjectId(), setId,
|
||||
thermalStateId, heaterRequestId) {}
|
||||
const lp_id_t thermalStatePoolId;
|
||||
const lp_id_t heaterRequestPoolId;
|
||||
|
||||
DeviceHandlerThermalSet(object_id_t deviceHandler, uint32_t setId =
|
||||
DeviceHandlerIF::DEFAULT_THERMAL_SET_ID,
|
||||
lp_id_t thermalStateId =
|
||||
DeviceHandlerIF::DEFAULT_THERMAL_STATE_POOL_ID,
|
||||
lp_id_t thermalStateRequestId =
|
||||
DeviceHandlerIF::DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID):
|
||||
StaticLocalDataSet(sid_t(deviceHandler, setId)),
|
||||
thermalStatePoolId(thermalStateId),
|
||||
heaterRequestPoolId(thermalStateRequestId) {}
|
||||
|
||||
const lp_id_t thermalStatePoolId;
|
||||
const lp_id_t heaterRequestPoolId;
|
||||
|
||||
lp_var_t<DeviceHandlerIF::dh_thermal_state_t> thermalState =
|
||||
lp_var_t<DeviceHandlerIF::dh_thermal_state_t>(
|
||||
thermalStatePoolId, sid.objectId, this);
|
||||
lp_var_t<DeviceHandlerIF::dh_heater_request_t> heaterRequest =
|
||||
lp_var_t<DeviceHandlerIF::dh_heater_request_t>(
|
||||
heaterRequestPoolId, sid.objectId, this);
|
||||
lp_var_t<DeviceHandlerIF::dh_thermal_state_t> thermalState =
|
||||
lp_var_t<DeviceHandlerIF::dh_thermal_state_t>(thermalStatePoolId, sid.objectId, this);
|
||||
lp_var_t<DeviceHandlerIF::dh_heater_request_t> heaterRequest =
|
||||
lp_var_t<DeviceHandlerIF::dh_heater_request_t>(heaterRequestPoolId, sid.objectId, this);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERTHERMALSET_H_ */
|
||||
|
@ -1,45 +1,40 @@
|
||||
#include "fsfw/devicehandlers/DeviceTmReportingWrapper.h"
|
||||
|
||||
#include "fsfw/serialize/SerializeAdapter.h"
|
||||
|
||||
DeviceTmReportingWrapper::DeviceTmReportingWrapper(object_id_t objectId,
|
||||
ActionId_t actionId, SerializeIF* data) :
|
||||
objectId(objectId), actionId(actionId), data(data) {
|
||||
}
|
||||
DeviceTmReportingWrapper::DeviceTmReportingWrapper(object_id_t objectId, ActionId_t actionId,
|
||||
SerializeIF* data)
|
||||
: objectId(objectId), actionId(actionId), data(data) {}
|
||||
|
||||
DeviceTmReportingWrapper::~DeviceTmReportingWrapper() {
|
||||
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);
|
||||
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();
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
@ -5,23 +5,23 @@
|
||||
#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();
|
||||
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 ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
Endianness streamEndianness) const override;
|
||||
|
||||
virtual size_t getSerializedSize() 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;
|
||||
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 /* FSFW_DEVICEHANDLERS_DEVICETMREPORTINGWRAPPER_H_ */
|
||||
|
@ -1,59 +1,56 @@
|
||||
#include "fsfw/devicehandlers/HealthDevice.h"
|
||||
|
||||
#include "fsfw/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);
|
||||
HealthDevice::HealthDevice(object_id_t setObjectId, MessageQueueId_t parentQueue)
|
||||
: SystemObject(setObjectId),
|
||||
lastHealth(HEALTHY),
|
||||
parentQueue(parentQueue),
|
||||
commandQueue(),
|
||||
healthHelper(this, setObjectId) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(3);
|
||||
}
|
||||
|
||||
HealthDevice::~HealthDevice() {
|
||||
QueueFactory::instance()->deleteMessageQueue(commandQueue);
|
||||
}
|
||||
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) {
|
||||
result = healthHelper.handleHealthCommand(&command);
|
||||
}
|
||||
return result;
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
result = healthHelper.handleHealthCommand(&command);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
MessageQueueId_t HealthDevice::getCommandQueue() const { return commandQueue->getId(); }
|
||||
|
||||
void HealthDevice::setParentQueue(MessageQueueId_t parentQueue) {
|
||||
healthHelper.setParentQueue(parentQueue);
|
||||
healthHelper.setParentQueue(parentQueue);
|
||||
}
|
||||
|
||||
bool HealthDevice::hasHealthChanged() {
|
||||
bool changed;
|
||||
HealthState currentHealth = healthHelper.getHealth();
|
||||
changed = currentHealth != lastHealth;
|
||||
lastHealth = currentHealth;
|
||||
return changed;
|
||||
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;
|
||||
healthHelper.setHealth(health);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
HasHealthIF::HealthState HealthDevice::getHealth() {
|
||||
return healthHelper.getHealth();
|
||||
}
|
||||
HasHealthIF::HealthState HealthDevice::getHealth() { return healthHelper.getHealth(); }
|
||||
|
@ -3,38 +3,37 @@
|
||||
|
||||
#include "fsfw/health/HasHealthIF.h"
|
||||
#include "fsfw/health/HealthHelper.h"
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
|
||||
class HealthDevice: public SystemObject,
|
||||
public ExecutableObjectIF,
|
||||
public HasHealthIF {
|
||||
public:
|
||||
HealthDevice(object_id_t setObjectId, MessageQueueId_t parentQueue);
|
||||
virtual ~HealthDevice();
|
||||
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 performOperation(uint8_t opCode);
|
||||
|
||||
ReturnValue_t initialize();
|
||||
ReturnValue_t initialize();
|
||||
|
||||
virtual MessageQueueId_t getCommandQueue() const;
|
||||
virtual MessageQueueId_t getCommandQueue() const;
|
||||
|
||||
void setParentQueue(MessageQueueId_t parentQueue);
|
||||
void setParentQueue(MessageQueueId_t parentQueue);
|
||||
|
||||
bool hasHealthChanged();
|
||||
bool hasHealthChanged();
|
||||
|
||||
virtual ReturnValue_t setHealth(HealthState health);
|
||||
virtual ReturnValue_t setHealth(HealthState health);
|
||||
|
||||
virtual HealthState getHealth();
|
||||
virtual HealthState getHealth();
|
||||
|
||||
protected:
|
||||
HealthState lastHealth;
|
||||
protected:
|
||||
HealthState lastHealth;
|
||||
|
||||
MessageQueueId_t parentQueue;
|
||||
MessageQueueIF* commandQueue;
|
||||
public:
|
||||
HealthHelper healthHelper;
|
||||
MessageQueueId_t parentQueue;
|
||||
MessageQueueIF* commandQueue;
|
||||
|
||||
public:
|
||||
HealthHelper healthHelper;
|
||||
};
|
||||
|
||||
#endif /* FSFW_DEVICEHANDLERS_HEALTHDEVICE_H_ */
|
||||
|
Reference in New Issue
Block a user