DHB update

This commit is contained in:
Robin Müller 2020-10-01 12:30:53 +02:00
parent 322ff54f58
commit 196cde4075
2 changed files with 214 additions and 127 deletions

View File

@ -2,15 +2,17 @@
#include "AcceptsDeviceResponsesIF.h" #include "AcceptsDeviceResponsesIF.h"
#include "DeviceTmReportingWrapper.h" #include "DeviceTmReportingWrapper.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/GlobalPoolVariable.h"
#include "../objectmanager/ObjectManager.h" #include "../objectmanager/ObjectManager.h"
#include "../storagemanager/StorageManagerIF.h" #include "../storagemanager/StorageManagerIF.h"
#include "../thermal/ThermalComponentIF.h" #include "../thermal/ThermalComponentIF.h"
#include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/GlobalPoolVariable.h"
#include "../globalfunctions/CRC.h" #include "../globalfunctions/CRC.h"
#include "../subsystem/SubsystemBase.h" #include "../housekeeping/HousekeepingMessage.h"
#include "../ipc/MessageQueueMessage.h"
#include "../ipc/QueueFactory.h" #include "../ipc/QueueFactory.h"
#include "../serviceinterface/ServiceInterfaceStream.h" #include "../subsystem/SubsystemBase.h"
#include <iomanip> #include <iomanip>
@ -25,10 +27,11 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId,
wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS), wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS),
deviceCommunicationId(deviceCommunication), comCookie(comCookie), deviceCommunicationId(deviceCommunication), comCookie(comCookie),
healthHelper(this,setObjectId), modeHelper(this), parameterHelper(this), healthHelper(this,setObjectId), modeHelper(this), parameterHelper(this),
actionHelper(this, nullptr), childTransitionFailure(RETURN_OK), actionHelper(this, nullptr), hkManager(this, nullptr),
fdirInstance(fdirInstance), hkSwitcher(this), childTransitionFailure(RETURN_OK), fdirInstance(fdirInstance),
defaultFDIRUsed(fdirInstance == nullptr), switchOffWasReported(false), hkSwitcher(this), defaultFDIRUsed(fdirInstance == nullptr),
childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), switchOffWasReported(false), childTransitionDelay(5000),
transitionSourceMode(_MODE_POWER_DOWN),
transitionSourceSubMode(SUBMODE_NONE) { transitionSourceSubMode(SUBMODE_NONE) {
commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize, commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize,
MessageQueueMessage::MAX_MESSAGE_SIZE); MessageQueueMessage::MAX_MESSAGE_SIZE);
@ -48,6 +51,10 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId,
} }
} }
void DeviceHandlerBase::setHkDestination(object_id_t hkDestination) {
this->hkDestination = hkDestination;
}
void DeviceHandlerBase::setThermalStateRequestPoolIds( void DeviceHandlerBase::setThermalStateRequestPoolIds(
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId) { uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId) {
this->deviceThermalRequestPoolId = thermalStatePoolId; this->deviceThermalRequestPoolId = thermalStatePoolId;
@ -74,6 +81,7 @@ ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) {
decrementDeviceReplyMap(); decrementDeviceReplyMap();
fdirInstance->checkForFailures(); fdirInstance->checkForFailures();
hkSwitcher.performOperation(); hkSwitcher.performOperation();
hkManager.performHkOperation();
performOperationHook(); performOperationHook();
} }
if (mode == MODE_OFF) { if (mode == MODE_OFF) {
@ -120,6 +128,8 @@ ReturnValue_t DeviceHandlerBase::initialize() {
result = communicationInterface->initializeInterface(comCookie); result = communicationInterface->initializeInterface(comCookie);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::error << "DeviceHandlerBase::initialize: Initializing "
"communication interface failed!" << std::endl;
return result; return result;
} }
@ -183,11 +193,16 @@ ReturnValue_t DeviceHandlerBase::initialize() {
return result; return result;
} }
result = hkManager.initialize(commandQueue);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
fillCommandAndReplyMap(); fillCommandAndReplyMap();
//Set temperature target state to NON_OP. //Set temperature target state to NON_OP.
GlobDataSet mySet; GlobDataSet mySet;
gp_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet, gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
PoolVariableIF::VAR_WRITE); PoolVariableIF::VAR_WRITE);
mySet.read(); mySet.read();
thermalRequest = ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL; thermalRequest = ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL;
@ -245,10 +260,10 @@ void DeviceHandlerBase::readCommandQueue() {
return; return;
} }
// result = hkManager.handleHousekeepingMessage(&command); result = hkManager.handleHousekeepingMessage(&command);
// if (result == RETURN_OK) { if (result == RETURN_OK) {
// return; return;
// } }
result = handleDeviceHandlerMessage(&command); result = handleDeviceHandlerMessage(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
@ -376,24 +391,28 @@ ReturnValue_t DeviceHandlerBase::isModeCombinationValid(Mode_t mode,
ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap( ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(
DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles, DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles,
size_t replyLen, bool periodic, bool hasDifferentReplyId, LocalPoolDataSetBase* replyDataSet, size_t replyLen, bool periodic,
DeviceCommandId_t replyId) { bool hasDifferentReplyId, DeviceCommandId_t replyId) {
//No need to check, as we may try to insert multiple times. //No need to check, as we may try to insert multiple times.
insertInCommandMap(deviceCommand); insertInCommandMap(deviceCommand);
if (hasDifferentReplyId) { if (hasDifferentReplyId) {
return insertInReplyMap(replyId, maxDelayCycles, replyLen, periodic); return insertInReplyMap(replyId, maxDelayCycles,
replyDataSet, replyLen, periodic);
} else { } else {
return insertInReplyMap(deviceCommand, maxDelayCycles, replyLen, periodic); return insertInReplyMap(deviceCommand, maxDelayCycles,
replyDataSet, replyLen, periodic);
} }
} }
ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId, ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId,
uint16_t maxDelayCycles, size_t replyLen, bool periodic) { uint16_t maxDelayCycles, LocalPoolDataSetBase* dataSet,
size_t replyLen, bool periodic) {
DeviceReplyInfo info; DeviceReplyInfo info;
info.maxDelayCycles = maxDelayCycles; info.maxDelayCycles = maxDelayCycles;
info.periodic = periodic; info.periodic = periodic;
info.delayCycles = 0; info.delayCycles = 0;
info.replyLen = replyLen; info.replyLen = replyLen;
info.dataSet = dataSet;
info.command = deviceCommandMap.end(); info.command = deviceCommandMap.end();
auto resultPair = deviceReplyMap.emplace(replyId, info); auto resultPair = deviceReplyMap.emplace(replyId, info);
if (resultPair.second) { if (resultPair.second) {
@ -419,13 +438,12 @@ ReturnValue_t DeviceHandlerBase::insertInCommandMap(
ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceReply, ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceReply,
uint16_t delayCycles, uint16_t maxDelayCycles, bool periodic) { uint16_t delayCycles, uint16_t maxDelayCycles, bool periodic) {
std::map<DeviceCommandId_t, DeviceReplyInfo>::iterator iter = auto replyIter = deviceReplyMap.find(deviceReply);
deviceReplyMap.find(deviceReply); if (replyIter == deviceReplyMap.end()) {
if (iter == deviceReplyMap.end()) {
triggerEvent(INVALID_DEVICE_COMMAND, deviceReply); triggerEvent(INVALID_DEVICE_COMMAND, deviceReply);
return RETURN_FAILED; return RETURN_FAILED;
} else { } else {
DeviceReplyInfo *info = &(iter->second); DeviceReplyInfo *info = &(replyIter->second);
if (maxDelayCycles != 0) { if (maxDelayCycles != 0) {
info->maxDelayCycles = maxDelayCycles; info->maxDelayCycles = maxDelayCycles;
} }
@ -435,6 +453,17 @@ ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceRep
} }
} }
ReturnValue_t DeviceHandlerBase::setReplyDataset(DeviceCommandId_t replyId,
LocalPoolDataSetBase *dataSet) {
auto replyIter = deviceReplyMap.find(replyId);
if(replyIter == deviceReplyMap.end()) {
return HasReturnvaluesIF::RETURN_FAILED;
}
replyIter->second.dataSet = dataSet;
return HasReturnvaluesIF::RETURN_OK;
}
void DeviceHandlerBase::callChildStatemachine() { void DeviceHandlerBase::callChildStatemachine() {
if (mode == _MODE_START_UP) { if (mode == _MODE_START_UP) {
doStartUp(); doStartUp();
@ -470,7 +499,7 @@ void DeviceHandlerBase::setMode(Mode_t newMode, uint8_t newSubmode) {
if (mode == MODE_OFF) { if (mode == MODE_OFF) {
GlobDataSet mySet; GlobDataSet mySet;
gp_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet, gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
PoolVariableIF::VAR_READ_WRITE); PoolVariableIF::VAR_READ_WRITE);
mySet.read(); mySet.read();
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) { if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
@ -649,7 +678,7 @@ void DeviceHandlerBase::doGetRead() {
void DeviceHandlerBase::parseReply(const uint8_t* receivedData, void DeviceHandlerBase::parseReply(const uint8_t* receivedData,
size_t receivedDataLen) { size_t receivedDataLen) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
DeviceCommandId_t foundId = 0xFFFFFFFF; DeviceCommandId_t foundId = 0xffffffff;
size_t foundLen = 0; size_t foundLen = 0;
// The loop may not execute more often than the number of received bytes // The loop may not execute more often than the number of received bytes
// (worst case). This approach avoids infinite loops due to buggy // (worst case). This approach avoids infinite loops due to buggy
@ -661,6 +690,10 @@ void DeviceHandlerBase::parseReply(const uint8_t* receivedData,
switch (result) { switch (result) {
case RETURN_OK: case RETURN_OK:
handleReply(receivedData, foundId, foundLen); handleReply(receivedData, foundId, foundLen);
if(foundLen == 0) {
sif::warning << "DeviceHandlerBase::parseReply: foundLen is 0!"
" Packet parsing will be stuck." << std::endl;
}
break; break;
case APERIODIC_REPLY: { case APERIODIC_REPLY: {
result = interpretDeviceReply(foundId, receivedData); result = interpretDeviceReply(foundId, receivedData);
@ -669,10 +702,14 @@ void DeviceHandlerBase::parseReply(const uint8_t* receivedData,
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result, triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result,
foundId); foundId);
} }
if(foundLen == 0) {
sif::warning << "DeviceHandlerBase::parseReply: foundLen is 0!"
" Packet parsing will be stuck." << std::endl;
} }
break; break;
}
case IGNORE_REPLY_DATA: case IGNORE_REPLY_DATA:
break; continue;
case IGNORE_FULL_PACKET: case IGNORE_FULL_PACKET:
return; return;
default: default:
@ -704,16 +741,19 @@ void DeviceHandlerBase::handleReply(const uint8_t* receivedData,
DeviceReplyInfo *info = &(iter->second); DeviceReplyInfo *info = &(iter->second);
if (info->delayCycles != 0) { if (info->delayCycles != 0) {
result = interpretDeviceReply(foundId, receivedData);
if (info->periodic != false) { if(result == IGNORE_REPLY_DATA) {
return;
}
if (info->periodic) {
info->delayCycles = info->maxDelayCycles; info->delayCycles = info->maxDelayCycles;
} }
else { else {
info->delayCycles = 0; info->delayCycles = 0;
} }
result = interpretDeviceReply(foundId, receivedData);
if (result != RETURN_OK) { if (result != RETURN_OK) {
// Report failed interpretation to FDIR. // Report failed interpretation to FDIR.
replyRawReplyIfnotWiretapped(receivedData, foundLen); replyRawReplyIfnotWiretapped(receivedData, foundLen);
@ -927,9 +967,9 @@ ReturnValue_t DeviceHandlerBase::checkModeCommand(Mode_t commandedMode,
if ((commandedMode == MODE_ON) && (mode == MODE_OFF) if ((commandedMode == MODE_ON) && (mode == MODE_OFF)
&& (deviceThermalStatePoolId != PoolVariableIF::NO_PARAMETER)) { && (deviceThermalStatePoolId != PoolVariableIF::NO_PARAMETER)) {
GlobDataSet mySet; GlobDataSet mySet;
gp_int8_t thermalState(deviceThermalStatePoolId, &mySet, gp_uint8_t thermalState(deviceThermalStatePoolId, &mySet,
PoolVariableIF::VAR_READ); PoolVariableIF::VAR_READ);
gp_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet, gp_uint8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
PoolVariableIF::VAR_READ); PoolVariableIF::VAR_READ);
mySet.read(); mySet.read();
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) { if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
@ -1089,19 +1129,6 @@ ReturnValue_t DeviceHandlerBase::handleDeviceHandlerMessage(
} }
replyReturnvalueToCommand(RETURN_OK); replyReturnvalueToCommand(RETURN_OK);
return RETURN_OK; return RETURN_OK;
// case DeviceHandlerMessage::CMD_SWITCH_IOBOARD:
// if (mode != MODE_OFF) {
// replyReturnvalueToCommand(WRONG_MODE_FOR_COMMAND);
// } else {
// result = switchCookieChannel(
// DeviceHandlerMessage::getIoBoardObjectId(message));
// if (result == RETURN_OK) {
// replyReturnvalueToCommand(RETURN_OK);
// } else {
// replyReturnvalueToCommand(CANT_SWITCH_IO_ADDRESS);
// }
// }
// return RETURN_OK;
case DeviceHandlerMessage::CMD_RAW: case DeviceHandlerMessage::CMD_RAW:
if ((mode != MODE_RAW)) { if ((mode != MODE_RAW)) {
DeviceHandlerMessage::clear(message); DeviceHandlerMessage::clear(message);
@ -1248,10 +1275,14 @@ void DeviceHandlerBase::buildInternalCommand(void) {
if (iter == deviceCommandMap.end()) { if (iter == deviceCommandMap.end()) {
result = COMMAND_NOT_SUPPORTED; result = COMMAND_NOT_SUPPORTED;
} else if (iter->second.isExecuting) { } else if (iter->second.isExecuting) {
//so we can track misconfigurations
sif::debug << std::hex << getObjectId() sif::debug << std::hex << getObjectId()
<< ": DHB::buildInternalCommand: Command " << ": DHB::buildInternalCommand: Command "
<< deviceCommandId << " isExecuting" << std::endl; //so we can track misconfigurations << deviceCommandId << " isExecuting" << std::dec
return; //this is an internal command, no need to report a failure here, missed reply will track if a reply is too late, otherwise, it's ok << std::endl;
// this is an internal command, no need to report a failure here,
// missed reply will track if a reply is too late, otherwise, it's ok
return;
} else { } else {
iter->second.sendReplyTo = NO_COMMANDER; iter->second.sendReplyTo = NO_COMMANDER;
iter->second.isExecuting = true; iter->second.isExecuting = true;
@ -1340,12 +1371,50 @@ void DeviceHandlerBase::debugInterface(uint8_t positionTracker,
void DeviceHandlerBase::performOperationHook() { void DeviceHandlerBase::performOperationHook() {
} }
ReturnValue_t DeviceHandlerBase::initializeLocalDataPool(
LocalDataPool &localDataPoolMap,
LocalDataPoolManager& poolManager) {
return RETURN_OK;
}
LocalDataPoolManager* DeviceHandlerBase::getHkManagerHandle() {
return &hkManager;
}
ReturnValue_t DeviceHandlerBase::initializeAfterTaskCreation() { ReturnValue_t DeviceHandlerBase::initializeAfterTaskCreation() {
// In this function, the task handle should be valid if the task // In this function, the task handle should be valid if the task
// was implemented correctly. We still check to be 1000 % sure :-) // was implemented correctly. We still check to be 1000 % sure :-)
if(executingTask != nullptr) { if(executingTask != nullptr) {
pstIntervalMs = executingTask->getPeriodMs(); pstIntervalMs = executingTask->getPeriodMs();
} }
this->hkManager.initializeAfterTaskCreation();
if(setStartupImmediately) {
startTransition(MODE_ON, SUBMODE_NONE);
}
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
LocalPoolDataSetBase* DeviceHandlerBase::getDataSetHandle(sid_t sid) {
auto iter = deviceReplyMap.find(sid.ownerSetId);
if(iter != deviceReplyMap.end()) {
return iter->second.dataSet;
}
else {
return nullptr;
}
}
object_id_t DeviceHandlerBase::getObjectId() const {
return SystemObject::getObjectId();
}
void DeviceHandlerBase::setStartUpImmediately() {
this->setStartupImmediately = true;
}
dur_millis_t DeviceHandlerBase::getPeriodicOperationFrequency() const {
return pstIntervalMs;
}

View File

@ -1,12 +1,11 @@
#ifndef FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ #ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
#define FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ #define FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
#include "DeviceHandlerIF.h" #include "DeviceHandlerIF.h"
#include "DeviceCommunicationIF.h" #include "DeviceCommunicationIF.h"
#include "DeviceHandlerFailureIsolation.h" #include "DeviceHandlerFailureIsolation.h"
#include "../objectmanager/SystemObject.h" #include "../objectmanager/SystemObject.h"
#include "../tasks/PeriodicTaskIF.h"
#include "../tasks/ExecutableObjectIF.h" #include "../tasks/ExecutableObjectIF.h"
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
#include "../action/HasActionsIF.h" #include "../action/HasActionsIF.h"
@ -14,10 +13,13 @@
#include "../modes/HasModesIF.h" #include "../modes/HasModesIF.h"
#include "../power/PowerSwitchIF.h" #include "../power/PowerSwitchIF.h"
#include "../ipc/MessageQueueIF.h" #include "../ipc/MessageQueueIF.h"
#include "../tasks/PeriodicTaskIF.h"
#include "../action/ActionHelper.h" #include "../action/ActionHelper.h"
#include "../health/HealthHelper.h" #include "../health/HealthHelper.h"
#include "../parameters/ParameterHelper.h" #include "../parameters/ParameterHelper.h"
#include "../datapool/HkSwitchHelper.h" #include "../datapool/HkSwitchHelper.h"
#include "../datapoollocal/HasLocalDataPoolIF.h"
#include "../datapoollocal/LocalDataPoolManager.h"
#include <map> #include <map>
@ -38,17 +40,16 @@ class StorageManagerIF;
* Documentation: Dissertation Baetz p.138,139, p.141-149 * Documentation: Dissertation Baetz p.138,139, p.141-149
* *
* It features handling of @link DeviceHandlerIF::Mode_t Modes @endlink, * It features handling of @link DeviceHandlerIF::Mode_t Modes @endlink,
* communication with physical devices, using the @link DeviceCommunicationIF @endlink, * communication with physical devices, using the
* and communication with commanding objects. * @link DeviceCommunicationIF @endlink, and communication with commanding
* It inherits SystemObject and thus can be created by the ObjectManagerIF. * objects. It inherits SystemObject and thus can be created by the
* ObjectManagerIF.
* *
* This class uses the opcode of ExecutableObjectIF to perform a step-wise execution. * This class uses the opcode of ExecutableObjectIF to perform a
* For each step an RMAP action is selected and executed. * step-wise execution. For each step a different action is selected and
* If data has been received (GET_READ), the data will be interpreted. * executed. Currently, the device handler base performs a 4-step
* The action for each step can be defined by the child class but as most * execution related to 4 communication steps (based on RMAP).
* device handlers share a 4-call (sendRead-getRead-sendWrite-getWrite) structure, * NOTE: RMAP is a standard which is used for Flying Laptop.
* a default implementation is provided.
* NOTE: RMAP is a standard which is used for FLP.
* RMAP communication is not mandatory for projects implementing the FSFW. * RMAP communication is not mandatory for projects implementing the FSFW.
* However, the communication principles are similar to RMAP as there are * However, the communication principles are similar to RMAP as there are
* two write and two send calls involved. * two write and two send calls involved.
@ -69,9 +70,6 @@ class StorageManagerIF;
* *
* Other important virtual methods with a default implementation * Other important virtual methods with a default implementation
* are the getTransitionDelayMs() function and the getSwitches() function. * are the getTransitionDelayMs() function and the getSwitches() function.
* Please ensure that getSwitches() returns DeviceHandlerIF::NO_SWITCHES if
* power switches are not implemented yet. Otherwise, the device handler will
* not transition to MODE_ON, even if setMode(MODE_ON) is called.
* If a transition to MODE_ON is desired without commanding, override the * If a transition to MODE_ON is desired without commanding, override the
* intialize() function and call setMode(_MODE_START_UP) before calling * intialize() function and call setMode(_MODE_START_UP) before calling
* DeviceHandlerBase::initialize(). * DeviceHandlerBase::initialize().
@ -85,20 +83,18 @@ class DeviceHandlerBase: public DeviceHandlerIF,
public HasModesIF, public HasModesIF,
public HasHealthIF, public HasHealthIF,
public HasActionsIF, public HasActionsIF,
public ReceivesParameterMessagesIF { public ReceivesParameterMessagesIF,
public HasLocalDataPoolIF {
friend void (Factory::setStaticFrameworkObjectIds)(); friend void (Factory::setStaticFrameworkObjectIds)();
public: public:
/** /**
* The constructor passes the objectId to the SystemObject(). * The constructor passes the objectId to the SystemObject().
* *
* @param setObjectId the ObjectId to pass to the SystemObject() Constructor * @param setObjectId the ObjectId to pass to the SystemObject() Constructor
* @param maxDeviceReplyLen the length the RMAP getRead call will be sent with
* @param setDeviceSwitch the switch the device is connected to,
* for devices using two switches, overwrite getSwitches()
* @param deviceCommuncation Communcation Interface object which is used * @param deviceCommuncation Communcation Interface object which is used
* to implement communication functions * to implement communication functions
* @param thermalStatePoolId * @param comCookie This object will be passed to the communication inter-
* @param thermalRequestPoolId * face and can contain user-defined information about the communication.
* @param fdirInstance * @param fdirInstance
* @param cmdQueueSize * @param cmdQueueSize
*/ */
@ -106,8 +102,21 @@ public:
CookieIF * comCookie, FailureIsolationBase* fdirInstance = nullptr, CookieIF * comCookie, FailureIsolationBase* fdirInstance = nullptr,
size_t cmdQueueSize = 20); size_t cmdQueueSize = 20);
void setHkDestination(object_id_t hkDestination);
void setThermalStateRequestPoolIds(uint32_t thermalStatePoolId, void setThermalStateRequestPoolIds(uint32_t thermalStatePoolId,
uint32_t thermalRequestPoolId); uint32_t thermalRequestPoolId);
/**
* @brief Helper function to ease device handler development.
* This will instruct the transition to MODE_ON immediately
* (leading to doStartUp() being called for the transition to the ON mode),
* so external mode commanding is not necessary anymore.
*
* This has to be called before the task is started!
* (e.g. in the task factory). This is only a helper function for
* development. Regular mode commanding should be performed by commanding
* the AssemblyBase or Subsystem objects resposible for the device handler.
*/
void setStartUpImmediately();
/** /**
* @brief This function is the device handler base core component and is * @brief This function is the device handler base core component and is
@ -153,6 +162,14 @@ public:
* @return * @return
*/ */
virtual ReturnValue_t initialize(); virtual ReturnValue_t initialize();
/**
* @brief Intialization steps performed after all tasks have been created.
* This function will be called by the executing task.
* @return
*/
virtual ReturnValue_t initializeAfterTaskCreation() override;
/** Destructor. */ /** Destructor. */
virtual ~DeviceHandlerBase(); virtual ~DeviceHandlerBase();
@ -320,6 +337,8 @@ protected:
* @param packet * @param packet
* @return * @return
* - @c RETURN_OK when the reply was interpreted. * - @c RETURN_OK when the reply was interpreted.
* - @c IGNORE_REPLY_DATA Ignore the reply and don't reset reply cycle
* counter.
* - @c RETURN_FAILED when the reply could not be interpreted, * - @c RETURN_FAILED when the reply could not be interpreted,
* e.g. logical errors or range violations occurred * e.g. logical errors or range violations occurred
*/ */
@ -347,22 +366,10 @@ protected:
* set to the maximum expected number of PST cycles between two replies * set to the maximum expected number of PST cycles between two replies
* (also a tolerance should be added, as an FDIR message will be * (also a tolerance should be added, as an FDIR message will be
* generated if it is missed). * generated if it is missed).
*
* (Robin) This part confuses me. "must do as soon as" implies that
* the developer must do something somewhere else in the code. Is
* that really the case? If I understood correctly, DHB performs
* almost everything (e.g. in erirm function) as long as the commands
* are inserted correctly.
*
* As soon as the replies are enabled, DeviceCommandInfo.periodic must
* be set to true, DeviceCommandInfo.delayCycles to
* DeviceCommandInfo.maxDelayCycles.
* From then on, the base class handles the reception. * From then on, the base class handles the reception.
* Then, scanForReply returns the id of the reply or the placeholder id * Then, scanForReply returns the id of the reply or the placeholder id
* and the base class will take care of checking that all replies are * and the base class will take care of checking that all replies are
* received and the interval is correct. * received and the interval is correct.
* When the replies are disabled, DeviceCommandInfo.periodic must be set
* to 0, DeviceCommandInfo.delayCycles to 0;
* *
* - Aperiodic, unrequested replies. These are replies that are sent * - Aperiodic, unrequested replies. These are replies that are sent
* by the device without any preceding command and not in a defined * by the device without any preceding command and not in a defined
@ -376,13 +383,17 @@ protected:
* @param deviceCommand Identifier of the command to add. * @param deviceCommand Identifier of the command to add.
* @param maxDelayCycles The maximum number of delay cycles the command * @param maxDelayCycles The maximum number of delay cycles the command
* waits until it times out. * waits until it times out.
* @param replyLen Will be supplied to the requestReceiveMessage call of
* the communication interface.
* @param periodic Indicates if the command is periodic (i.e. it is sent * @param periodic Indicates if the command is periodic (i.e. it is sent
* by the device repeatedly without request) or not. Default is aperiodic (0) * by the device repeatedly without request) or not. Default is aperiodic (0)
* @return - @c RETURN_OK when the command was successfully inserted, * @return - @c RETURN_OK when the command was successfully inserted,
* - @c RETURN_FAILED else. * - @c RETURN_FAILED else.
*/ */
ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand, ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand,
uint16_t maxDelayCycles, size_t replyLen = 0, bool periodic = false, uint16_t maxDelayCycles,
LocalPoolDataSetBase* replyDataSet = nullptr,
size_t replyLen = 0, bool periodic = false,
bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0); bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0);
/** /**
@ -396,7 +407,8 @@ protected:
* - @c RETURN_FAILED else. * - @c RETURN_FAILED else.
*/ */
ReturnValue_t insertInReplyMap(DeviceCommandId_t deviceCommand, ReturnValue_t insertInReplyMap(DeviceCommandId_t deviceCommand,
uint16_t maxDelayCycles, size_t replyLen = 0, bool periodic = false); uint16_t maxDelayCycles, LocalPoolDataSetBase* dataSet = nullptr,
size_t replyLen = 0, bool periodic = false);
/** /**
* @brief A simple command to add a command to the commandList. * @brief A simple command to add a command to the commandList.
@ -424,6 +436,9 @@ protected:
uint16_t delayCycles, uint16_t maxDelayCycles, uint16_t delayCycles, uint16_t maxDelayCycles,
bool periodic = false); bool periodic = false);
ReturnValue_t setReplyDataset(DeviceCommandId_t replyId,
LocalPoolDataSetBase* dataset);
/** /**
* @brief Can be implemented by child handler to * @brief Can be implemented by child handler to
* perform debugging * perform debugging
@ -477,18 +492,22 @@ protected:
* @param localDataPoolMap * @param localDataPoolMap
* @return * @return
*/ */
//virtual ReturnValue_t initializePoolEntries( virtual ReturnValue_t initializeLocalDataPool(LocalDataPool& localDataPoolMap,
// LocalDataPool& localDataPoolMap) override; LocalDataPoolManager& poolManager) override;
/** Get the HK manager object handle */ /** Get the HK manager object handle */
//virtual LocalDataPoolManager* getHkManagerHandle() override; virtual LocalDataPoolManager* getHkManagerHandle() override;
/** /**
* @brief Hook function for child handlers which is called once per * @brief Hook function for child handlers which is called once per
* performOperation(). Default implementation is empty. * performOperation(). Default implementation is empty.
*/ */
virtual void performOperationHook(); virtual void performOperationHook();
public: public:
/** Explicit interface implementation of getObjectId */
virtual object_id_t getObjectId() const override;
/** /**
* @param parentQueueId * @param parentQueueId
*/ */
@ -608,7 +627,7 @@ protected:
/** Action helper for HasActionsIF */ /** Action helper for HasActionsIF */
ActionHelper actionHelper; ActionHelper actionHelper;
/** Housekeeping Manager */ /** Housekeeping Manager */
//LocalDataPoolManager hkManager; LocalDataPoolManager hkManager;
/** /**
* @brief Information about commands * @brief Information about commands
@ -647,7 +666,7 @@ protected:
//! The dataset used to access housekeeping data related to the //! The dataset used to access housekeeping data related to the
//! respective device reply. Will point to a dataset held by //! respective device reply. Will point to a dataset held by
//! the child handler (if one is specified) //! the child handler (if one is specified)
// DataSetIF* dataSet = nullptr; LocalPoolDataSetBase* dataSet;
//! The command that expects this reply. //! The command that expects this reply.
DeviceCommandMap::iterator command; DeviceCommandMap::iterator command;
}; };
@ -689,14 +708,18 @@ protected:
uint32_t deviceThermalRequestPoolId = PoolVariableIF::NO_PARAMETER; uint32_t deviceThermalRequestPoolId = PoolVariableIF::NO_PARAMETER;
/** /**
* Optional Error code * Optional Error code. Can be set in doStartUp(), doShutDown() and
* Can be set in doStartUp(), doShutDown() and doTransition() to signal cause for Transition failure. * doTransition() to signal cause for Transition failure.
*/ */
ReturnValue_t childTransitionFailure; ReturnValue_t childTransitionFailure;
uint32_t ignoreMissedRepliesCount = 0; //!< Counts if communication channel lost a reply, so some missed replys can be ignored. /** Counts if communication channel lost a reply, so some missed
* replys can be ignored. */
uint32_t ignoreMissedRepliesCount = 0;
FailureIsolationBase* fdirInstance; //!< Pointer to the used FDIR instance. If not provided by child, default class is instantiated. /** Pointer to the used FDIR instance. If not provided by child,
* default class is instantiated. */
FailureIsolationBase* fdirInstance;
HkSwitchHelper hkSwitcher; HkSwitchHelper hkSwitcher;
@ -944,14 +967,17 @@ protected:
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t *msToReachTheMode); uint32_t *msToReachTheMode);
virtual void startTransition(Mode_t mode, Submode_t submode);
virtual void setToExternalControl(); /* HasModesIF overrides */
virtual void announceMode(bool recursive); virtual void startTransition(Mode_t mode, Submode_t submode) override;
virtual void setToExternalControl() override;
virtual void announceMode(bool recursive) override;
virtual ReturnValue_t letChildHandleMessage(CommandMessage *message); virtual ReturnValue_t letChildHandleMessage(CommandMessage *message);
/** /**
* Overwrites SystemObject::triggerEvent in order to inform FDIR"Helper" faster about executed events. * Overwrites SystemObject::triggerEvent in order to inform FDIR"Helper"
* faster about executed events.
* This is a bit sneaky, but improves responsiveness of the device FDIR. * This is a bit sneaky, but improves responsiveness of the device FDIR.
* @param event The event to be thrown * @param event The event to be thrown
* @param parameter1 Optional parameter 1 * @param parameter1 Optional parameter 1
@ -1034,12 +1060,17 @@ private:
/** the object used to set power switches */ /** the object used to set power switches */
PowerSwitchIF *powerSwitcher = nullptr; PowerSwitchIF *powerSwitcher = nullptr;
/** HK destination can also be set individually */
object_id_t hkDestination = objects::NO_OBJECT;
/** /**
* @brief Used for timing out mode transitions. * @brief Used for timing out mode transitions.
* Set when setMode() is called. * Set when setMode() is called.
*/ */
uint32_t timeoutStart = 0; uint32_t timeoutStart = 0;
bool setStartupImmediately = false;
/** /**
* Delay for the current mode transition, used for time out * Delay for the current mode transition, used for time out
*/ */
@ -1080,11 +1111,6 @@ private:
void buildRawDeviceCommand(CommandMessage* message); void buildRawDeviceCommand(CommandMessage* message);
void buildInternalCommand(void); void buildInternalCommand(void);
// /**
// * Send a reply with the current mode and submode.
// */
// void announceMode(void);
/** /**
* Decrement the counter for the timout of replies. * Decrement the counter for the timout of replies.
* *
@ -1111,10 +1137,14 @@ private:
/** /**
* Build and send a command to the device. * Build and send a command to the device.
* *
* This routine checks whether a raw or direct command has been received, checks the content of the received command and * This routine checks whether a raw or direct command has been received,
* calls buildCommandFromCommand() for direct commands or sets #rawpacket to the received raw packet. * checks the content of the received command and calls
* If no external command is received or the received command is invalid and the current mode is @c MODE_NORMAL or a transitional mode, * buildCommandFromCommand() for direct commands or sets #rawpacket
* it asks the child class to build a command (via getNormalDeviceCommand() or getTransitionalDeviceCommand() and buildCommand()) and * to the received raw packet.
* If no external command is received or the received command is invalid and
* the current mode is @c MODE_NORMAL or a transitional mode, it asks the
* child class to build a command (via getNormalDeviceCommand() or
* getTransitionalDeviceCommand() and buildCommand()) and
* sends the command via RMAP. * sends the command via RMAP.
*/ */
void doSendWrite(void); void doSendWrite(void);
@ -1159,7 +1189,6 @@ private:
ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data, ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data,
uint32_t *len); uint32_t *len);
/** /**
* @param modeTo either @c MODE_ON, MODE_NORMAL or MODE_RAW NOTHING ELSE!!! * @param modeTo either @c MODE_ON, MODE_NORMAL or MODE_RAW NOTHING ELSE!!!
*/ */
@ -1170,25 +1199,14 @@ private:
*/ */
void callChildStatemachine(); void callChildStatemachine();
/**
* Switches the channel of the cookie used for the communication
*
*
* @param newChannel the object Id of the channel to switch to
* @return
* - @c RETURN_OK when cookie was changed
* - @c RETURN_FAILED when cookies could not be changed, eg because the newChannel is not enabled
* - @c returnvalues of RMAPChannelIF::isActive()
*/
ReturnValue_t switchCookieChannel(object_id_t newChannelId);
ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message); ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message);
virtual ReturnValue_t initializeAfterTaskCreation() override; virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
virtual dur_millis_t getPeriodicOperationFrequency() const override;
void parseReply(const uint8_t* receivedData, void parseReply(const uint8_t* receivedData,
size_t receivedDataLen); size_t receivedDataLen);
}; };
#endif /* FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ */ #endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ */