added the decoupling of DHB from powerSwitcher

+ some first hk maanger changes, might comment them out
This commit is contained in:
Robin Müller 2020-06-06 01:31:08 +02:00
parent 87f64d99cd
commit d600d48816
4 changed files with 273 additions and 209 deletions

View File

@ -14,7 +14,7 @@
#include <iomanip> #include <iomanip>
object_id_t DeviceHandlerBase::powerSwitcherId = 0; object_id_t DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT;
object_id_t DeviceHandlerBase::rawDataReceiverId = 0; object_id_t DeviceHandlerBase::rawDataReceiverId = 0;
object_id_t DeviceHandlerBase::defaultFDIRParentId = 0; object_id_t DeviceHandlerBase::defaultFDIRParentId = 0;
@ -26,12 +26,13 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId,
SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE), SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE),
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),
actionHelper(this, nullptr), hkManager(this),
deviceThermalStatePoolId(thermalStatePoolId), deviceThermalStatePoolId(thermalStatePoolId),
deviceThermalRequestPoolId(thermalRequestPoolId), deviceThermalRequestPoolId(thermalRequestPoolId),
healthHelper(this,setObjectId), modeHelper(this), parameterHelper(this),
childTransitionFailure(RETURN_OK), fdirInstance(fdirInstance), childTransitionFailure(RETURN_OK), fdirInstance(fdirInstance),
hkSwitcher(this), defaultFDIRUsed(fdirInstance == nullptr), hkSwitcher(this), defaultFDIRUsed(fdirInstance == nullptr),
switchOffWasReported(false), actionHelper(this, nullptr), cookieInfo(), switchOffWasReported(false), cookieInfo(),
childTransitionDelay(5000), childTransitionDelay(5000),
transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode( transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(
SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { SUBMODE_NONE), deviceSwitch(setDeviceSwitch) {
@ -52,7 +53,7 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId,
} }
DeviceHandlerBase::~DeviceHandlerBase() { DeviceHandlerBase::~DeviceHandlerBase() {
//communicationInterface->close(cookie); delete comCookie;
if (defaultFDIRUsed) { if (defaultFDIRUsed) {
delete fdirInstance; delete fdirInstance;
} }
@ -129,9 +130,11 @@ ReturnValue_t DeviceHandlerBase::initialize() {
defaultRawReceiver = rawReceiver->getDeviceQueue(); defaultRawReceiver = rawReceiver->getDeviceQueue();
powerSwitcher = objectManager->get<PowerSwitchIF>(powerSwitcherId); if(powerSwitcherId != objects::NO_OBJECT) {
if (powerSwitcher == NULL) { powerSwitcher = objectManager->get<PowerSwitchIF>(powerSwitcherId);
return RETURN_FAILED; if (powerSwitcher == NULL) {
return RETURN_FAILED;
}
} }
result = healthHelper.initialize(); result = healthHelper.initialize();
@ -162,6 +165,11 @@ ReturnValue_t DeviceHandlerBase::initialize() {
return result; return result;
} }
result = hkManager.initializeHousekeepingPoolEntriesOnce();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
fillCommandAndReplyMap(); fillCommandAndReplyMap();
//Set temperature target state to NON_OP. //Set temperature target state to NON_OP.
@ -271,7 +279,8 @@ void DeviceHandlerBase::doStateMachine() {
case _MODE_WAIT_ON: { case _MODE_WAIT_ON: {
uint32_t currentUptime; uint32_t currentUptime;
Clock::getUptime(&currentUptime); Clock::getUptime(&currentUptime);
if (currentUptime - timeoutStart >= powerSwitcher->getSwitchDelayMs()) { if (powerSwitcher != nullptr and currentUptime - timeoutStart >=
powerSwitcher->getSwitchDelayMs()) {
triggerEvent(MODE_TRANSITION_FAILED, PowerSwitchIF::SWITCH_TIMEOUT, triggerEvent(MODE_TRANSITION_FAILED, PowerSwitchIF::SWITCH_TIMEOUT,
0); 0);
setMode(_MODE_POWER_DOWN); setMode(_MODE_POWER_DOWN);
@ -341,9 +350,10 @@ ReturnValue_t DeviceHandlerBase::isModeCombinationValid(Mode_t mode,
} }
} }
ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand, ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(
uint16_t maxDelayCycles, size_t replyLen, uint8_t periodic, DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles,
bool hasDifferentReplyId, DeviceCommandId_t replyId) { size_t replyLen, bool periodic, 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) {
@ -354,7 +364,7 @@ ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(DeviceCommandId_t de
} }
ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId, ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId,
uint16_t maxDelayCycles, size_t replyLen, uint8_t periodic) { uint16_t maxDelayCycles, size_t replyLen, bool periodic) {
DeviceReplyInfo info; DeviceReplyInfo info;
info.maxDelayCycles = maxDelayCycles; info.maxDelayCycles = maxDelayCycles;
info.periodic = periodic; info.periodic = periodic;
@ -369,7 +379,8 @@ ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId,
} }
} }
ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceCommand) { ReturnValue_t DeviceHandlerBase::insertInCommandMap(
DeviceCommandId_t deviceCommand) {
DeviceCommandInfo info; DeviceCommandInfo info;
info.expectedReplies = 0; info.expectedReplies = 0;
info.isExecuting = false; info.isExecuting = false;
@ -383,7 +394,7 @@ ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceComm
} }
ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceReply, ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceReply,
uint16_t delayCycles, uint16_t maxDelayCycles, uint8_t periodic) { uint16_t delayCycles, uint16_t maxDelayCycles, bool periodic) {
std::map<DeviceCommandId_t, DeviceReplyInfo>::iterator iter = std::map<DeviceCommandId_t, DeviceReplyInfo>::iterator iter =
deviceReplyMap.find(deviceReply); deviceReplyMap.find(deviceReply);
if (iter == deviceReplyMap.end()) { if (iter == deviceReplyMap.end()) {
@ -576,11 +587,8 @@ void DeviceHandlerBase::doSendRead() {
} }
void DeviceHandlerBase::doGetRead() { void DeviceHandlerBase::doGetRead() {
size_t receivedDataLen; size_t receivedDataLen = 0;
uint8_t *receivedData; uint8_t *receivedData = nullptr;
DeviceCommandId_t foundId = 0xFFFFFFFF;
size_t foundLen = 0;
ReturnValue_t result;
if (cookieInfo.state != COOKIE_READ_SENT) { if (cookieInfo.state != COOKIE_READ_SENT) {
cookieInfo.state = COOKIE_UNUSED; cookieInfo.state = COOKIE_UNUSED;
@ -589,8 +597,8 @@ void DeviceHandlerBase::doGetRead() {
cookieInfo.state = COOKIE_UNUSED; cookieInfo.state = COOKIE_UNUSED;
result = communicationInterface->readReceivedMessage(comCookie, ReturnValue_t result = communicationInterface->readReceivedMessage(
&receivedData, &receivedDataLen); comCookie, &receivedData, &receivedDataLen);
if (result != RETURN_OK) { if (result != RETURN_OK) {
triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result); triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result);
@ -608,44 +616,90 @@ void DeviceHandlerBase::doGetRead() {
if (mode == MODE_RAW) { if (mode == MODE_RAW) {
replyRawReplyIfnotWiretapped(receivedData, receivedDataLen); replyRawReplyIfnotWiretapped(receivedData, receivedDataLen);
} else { }
//The loop may not execute more often than the number of received bytes (worst case). else {
//This approach avoids infinite loops due to buggy scanForReply routines (seen in bug 1077). parseReply(receivedData, receivedDataLen);
uint32_t remainingLength = receivedDataLen; }
for (uint32_t count = 0; count < receivedDataLen; count++) { }
result = scanForReply(receivedData, remainingLength, &foundId,
&foundLen); void DeviceHandlerBase::parseReply(const uint8_t* receivedData,
switch (result) { size_t receivedDataLen) {
case RETURN_OK: ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
handleReply(receivedData, foundId, foundLen); DeviceCommandId_t foundId = 0xFFFFFFFF;
break; size_t foundLen = 0;
case APERIODIC_REPLY: { // The loop may not execute more often than the number of received bytes
result = interpretDeviceReply(foundId, receivedData); // (worst case). This approach avoids infinite loops due to buggy
if (result != RETURN_OK) { // scanForReply routines.
replyRawReplyIfnotWiretapped(receivedData, foundLen); uint32_t remainingLength = receivedDataLen;
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result, for (uint32_t count = 0; count < receivedDataLen; count++) {
foundId); result = scanForReply(receivedData, remainingLength, &foundId,
} &foundLen);
} switch (result) {
break; case RETURN_OK:
case IGNORE_REPLY_DATA: handleReply(receivedData, foundId, foundLen);
break; break;
case IGNORE_FULL_PACKET: case APERIODIC_REPLY: {
return; result = interpretDeviceReply(foundId, receivedData);
default: if (result != RETURN_OK) {
//We need to wait for timeout.. don't know what command failed and who sent it.
replyRawReplyIfnotWiretapped(receivedData, foundLen); replyRawReplyIfnotWiretapped(receivedData, foundLen);
triggerEvent(DEVICE_READING_REPLY_FAILED, result, foundLen); triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result,
break; foundId);
}
receivedData += foundLen;
if (remainingLength > foundLen) {
remainingLength -= foundLen;
} else {
return;
} }
} }
break;
case IGNORE_REPLY_DATA:
break;
case IGNORE_FULL_PACKET:
return;
default:
//We need to wait for timeout.. don't know what command failed and who sent it.
replyRawReplyIfnotWiretapped(receivedData, foundLen);
triggerEvent(DEVICE_READING_REPLY_FAILED, result, foundLen);
break;
}
receivedData += foundLen;
if (remainingLength > foundLen) {
remainingLength -= foundLen;
} else {
return;
}
}
}
void DeviceHandlerBase::handleReply(const uint8_t* receivedData,
DeviceCommandId_t foundId, uint32_t foundLen) {
ReturnValue_t result;
DeviceReplyMap::iterator iter = deviceReplyMap.find(foundId);
if (iter == deviceReplyMap.end()) {
replyRawReplyIfnotWiretapped(receivedData, foundLen);
triggerEvent(DEVICE_UNKNOWN_REPLY, foundId);
return;
}
DeviceReplyInfo *info = &(iter->second);
if (info->delayCycles != 0) {
if (info->periodic != 0) {
info->delayCycles = info->maxDelayCycles;
} else {
info->delayCycles = 0;
}
result = interpretDeviceReply(foundId, receivedData);
if (result != RETURN_OK) {
// Report failed interpretation to FDIR.
replyRawReplyIfnotWiretapped(receivedData, foundLen);
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result, foundId);
}
replyToReply(iter, result);
} else {
// Other completion failure messages are created by timeout.
// Powering down the device might take some time during which periodic
// replies may still come in.
if (mode != _MODE_WAIT_OFF) {
triggerEvent(DEVICE_UNREQUESTED_REPLY, foundId);
}
} }
} }
@ -724,42 +778,6 @@ MessageQueueId_t DeviceHandlerBase::getCommandQueue() const {
return commandQueue->getId(); return commandQueue->getId();
} }
void DeviceHandlerBase::handleReply(const uint8_t* receivedData,
DeviceCommandId_t foundId, uint32_t foundLen) {
ReturnValue_t result;
DeviceReplyMap::iterator iter = deviceReplyMap.find(foundId);
if (iter == deviceReplyMap.end()) {
replyRawReplyIfnotWiretapped(receivedData, foundLen);
triggerEvent(DEVICE_UNKNOWN_REPLY, foundId);
return;
}
DeviceReplyInfo *info = &(iter->second);
if (info->delayCycles != 0) {
if (info->periodic != 0) {
info->delayCycles = info->maxDelayCycles;
} else {
info->delayCycles = 0;
}
result = interpretDeviceReply(foundId, receivedData);
if (result != RETURN_OK) {
//Report failed interpretation to FDIR.
replyRawReplyIfnotWiretapped(receivedData, foundLen);
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result, foundId);
}
replyToReply(iter, result);
} else {
//Other completion failure messages are created by timeout.
//Powering down the device might take some time during which periodic replies may still come in.
if (mode != _MODE_WAIT_OFF) {
triggerEvent(DEVICE_UNREQUESTED_REPLY, foundId);
}
}
}
//ReturnValue_t DeviceHandlerBase::switchCookieChannel(object_id_t newChannelId) { //ReturnValue_t DeviceHandlerBase::switchCookieChannel(object_id_t newChannelId) {
// DeviceCommunicationIF *newCommunication = objectManager->get< // DeviceCommunicationIF *newCommunication = objectManager->get<
// DeviceCommunicationIF>(newChannelId); // DeviceCommunicationIF>(newChannelId);
@ -791,6 +809,9 @@ void DeviceHandlerBase::buildRawDeviceCommand(CommandMessage* commandMessage) {
} }
void DeviceHandlerBase::commandSwitch(ReturnValue_t onOff) { void DeviceHandlerBase::commandSwitch(ReturnValue_t onOff) {
if(powerSwitcher == nullptr) {
return;
}
const uint8_t *switches; const uint8_t *switches;
uint8_t numberOfSwitches = 0; uint8_t numberOfSwitches = 0;
ReturnValue_t result = getSwitches(&switches, &numberOfSwitches); ReturnValue_t result = getSwitches(&switches, &numberOfSwitches);
@ -805,9 +826,7 @@ void DeviceHandlerBase::commandSwitch(ReturnValue_t onOff) {
ReturnValue_t DeviceHandlerBase::getSwitches(const uint8_t **switches, ReturnValue_t DeviceHandlerBase::getSwitches(const uint8_t **switches,
uint8_t *numberOfSwitches) { uint8_t *numberOfSwitches) {
*switches = &deviceSwitch; return DeviceHandlerBase::NO_SWITCH;
*numberOfSwitches = 1;
return RETURN_OK;
} }
void DeviceHandlerBase::modeChanged(void) { void DeviceHandlerBase::modeChanged(void) {
@ -843,6 +862,9 @@ uint32_t DeviceHandlerBase::getTransitionDelayMs(Mode_t modeFrom,
} }
ReturnValue_t DeviceHandlerBase::getStateOfSwitches(void) { ReturnValue_t DeviceHandlerBase::getStateOfSwitches(void) {
if(powerSwitcher == nullptr) {
return NO_SWITCH;
}
uint8_t numberOfSwitches = 0; uint8_t numberOfSwitches = 0;
const uint8_t *switches; const uint8_t *switches;
@ -1286,4 +1308,24 @@ void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_){
void DeviceHandlerBase::debugInterface(uint8_t positionTracker, void DeviceHandlerBase::debugInterface(uint8_t positionTracker,
object_id_t objectId, uint32_t parameter) {} object_id_t objectId, uint32_t parameter) {}
void DeviceHandlerBase::performOperationHook() {} void DeviceHandlerBase::performOperationHook() {
}
ReturnValue_t DeviceHandlerBase::initializeHousekeepingPoolEntries(
LocalDataPoolMap &localDataPoolMap) {
return RETURN_OK;
}
HousekeepingManager* DeviceHandlerBase::getHkManagerHandle() {
return &hkManager;
}
DataSetIF* DeviceHandlerBase::getDataSetHandle(sid_t sid) {
auto iter = deviceReplyMap.find(sid.ownerSetId);
if(iter != deviceReplyMap.end()) {
return iter->second.dataSet;
}
else {
return nullptr;
}
}

View File

@ -1,5 +1,5 @@
#ifndef DEVICEHANDLERBASE_H_ #ifndef DEVICEHANDLERS_DEVICEHANDLERBASE_H_
#define DEVICEHANDLERBASE_H_ #define DEVICEHANDLERS_DEVICEHANDLERBASE_H_
#include <framework/objectmanager/SystemObject.h> #include <framework/objectmanager/SystemObject.h>
#include <framework/tasks/ExecutableObjectIF.h> #include <framework/tasks/ExecutableObjectIF.h>
@ -11,12 +11,14 @@
#include <framework/modes/HasModesIF.h> #include <framework/modes/HasModesIF.h>
#include <framework/power/PowerSwitchIF.h> #include <framework/power/PowerSwitchIF.h>
#include <framework/ipc/MessageQueueIF.h> #include <framework/ipc/MessageQueueIF.h>
#include <framework/housekeeping/HasHkPoolParametersIF.h>
#include <framework/action/ActionHelper.h> #include <framework/action/ActionHelper.h>
#include <framework/health/HealthHelper.h> #include <framework/health/HealthHelper.h>
#include <framework/parameters/ParameterHelper.h> #include <framework/parameters/ParameterHelper.h>
#include <framework/datapool/HkSwitchHelper.h> #include <framework/datapool/HkSwitchHelper.h>
#include <framework/devicehandlers/DeviceHandlerFailureIsolation.h> #include <framework/devicehandlers/DeviceHandlerFailureIsolation.h>
#include <framework/housekeeping/HousekeepingManager.h>
#include <map> #include <map>
@ -46,14 +48,16 @@ class StorageManagerIF;
* If data has been received (GET_READ), the data will be interpreted. * If data has been received (GET_READ), the data will be interpreted.
* The action for each step can be defined by the child class but as most * The action for each step can be defined by the child class but as most
* device handlers share a 4-call (sendRead-getRead-sendWrite-getWrite) structure, * device handlers share a 4-call (sendRead-getRead-sendWrite-getWrite) structure,
* a default implementation is provided. NOTE: RMAP is a standard which is used for FLP. * 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.
* *
* Device handler instances should extend this class and implement the abstract functions. * Device handler instances should extend this class and implement the abstract
* Components and drivers can send so called cookies which are used for communication * functions. Components and drivers can send so called cookies which are used
* and contain information about the communcation (e.g. slave address for I2C or RMAP structs). * for communication and contain information about the communcation (e.g. slave
* address for I2C or RMAP structs).
* The following abstract methods must be implemented by a device handler: * The following abstract methods must be implemented by a device handler:
* 1. doStartUp() * 1. doStartUp()
* 2. doShutDown() * 2. doShutDown()
@ -82,7 +86,8 @@ class DeviceHandlerBase: public DeviceHandlerIF,
public HasModesIF, public HasModesIF,
public HasHealthIF, public HasHealthIF,
public HasActionsIF, public HasActionsIF,
public ReceivesParameterMessagesIF { public ReceivesParameterMessagesIF,
public HasHkPoolParametersIF {
friend void (Factory::setStaticFrameworkObjectIds)(); friend void (Factory::setStaticFrameworkObjectIds)();
public: public:
/** /**
@ -150,11 +155,9 @@ public:
* @return * @return
*/ */
virtual ReturnValue_t initialize(); virtual ReturnValue_t initialize();
/** Destructor. */
/**
* Destructor.
*/
virtual ~DeviceHandlerBase(); virtual ~DeviceHandlerBase();
protected: protected:
/** /**
* @brief This is used to let the child class handle the transition from * @brief This is used to let the child class handle the transition from
@ -322,12 +325,11 @@ protected:
* - @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
*/ */
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) = 0; const uint8_t *packet) = 0;
/** /**
* @brief fill the #deviceCommandMap * @brief fill the #DeviceCommandMap and #DeviceReplyMap
* called by the initialize() of the base class * called by the initialize() of the base class
* @details * @details
* This is used to let the base class know which replies are expected. * This is used to let the base class know which replies are expected.
@ -382,7 +384,7 @@ protected:
* - @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, uint8_t periodic = 0, uint16_t maxDelayCycles, size_t replyLen = 0, bool periodic = 0,
bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0); bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0);
/** /**
@ -396,7 +398,7 @@ 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, uint8_t periodic = 0); uint16_t maxDelayCycles, size_t replyLen = 0, bool periodic = 0);
/** /**
* @brief A simple command to add a command to the commandList. * @brief A simple command to add a command to the commandList.
@ -422,7 +424,7 @@ protected:
*/ */
ReturnValue_t updateReplyMapEntry(DeviceCommandId_t deviceReply, ReturnValue_t updateReplyMapEntry(DeviceCommandId_t deviceReply,
uint16_t delayCycles, uint16_t maxDelayCycles, uint16_t delayCycles, uint16_t maxDelayCycles,
uint8_t periodic = 0); bool periodic = 0);
/** /**
* @brief Can be implemented by child handler to * @brief Can be implemented by child handler to
@ -471,6 +473,18 @@ protected:
virtual ReturnValue_t getSwitches(const uint8_t **switches, virtual ReturnValue_t getSwitches(const uint8_t **switches,
uint8_t *numberOfSwitches); uint8_t *numberOfSwitches);
/**
* This function is used to initialize the local housekeeping pool
* entries. The default implementation leaves the pool empty.
* @param localDataPoolMap
* @return
*/
virtual ReturnValue_t initializeHousekeepingPoolEntries(
LocalDataPoolMap& localDataPoolMap) override;
/** Get the HK manager object handle */
virtual HousekeepingManager* 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.
@ -528,114 +542,136 @@ protected:
static const DeviceCommandId_t NO_COMMAND_ID = -2; static const DeviceCommandId_t NO_COMMAND_ID = -2;
static const MessageQueueId_t NO_COMMANDER = 0; static const MessageQueueId_t NO_COMMANDER = 0;
/** /** Pointer to the raw packet that will be sent.*/
* Pointer to the raw packet that will be sent.
*/
uint8_t *rawPacket = nullptr; uint8_t *rawPacket = nullptr;
/** /** Size of the #rawPacket. */
* Size of the #rawPacket.
*/
uint32_t rawPacketLen = 0; uint32_t rawPacketLen = 0;
/** /**
* The mode the device handler is currently in. * The mode the device handler is currently in.
*
* This should never be changed directly but only with setMode() * This should never be changed directly but only with setMode()
*/ */
Mode_t mode; Mode_t mode;
/** /**
* The submode the device handler is currently in. * The submode the device handler is currently in.
*
* This should never be changed directly but only with setMode() * This should never be changed directly but only with setMode()
*/ */
Submode_t submode; Submode_t submode;
/** /** This is the counter value from performOperation(). */
* This is the counter value from performOperation().
*/
uint8_t pstStep = 0; uint8_t pstStep = 0;
/** /**
* wiretapping flag: * Wiretapping flag:
* *
* indicates either that all raw messages to and from the device should be sent to #theOneWhoWantsToReadRawTraffic * indicates either that all raw messages to and from the device should be
* or that all device TM should be downlinked to #theOneWhoWantsToReadRawTraffic * sent to #defaultRawReceiver
* or that all device TM should be downlinked to #defaultRawReceiver.
*/ */
enum WiretappingMode { enum WiretappingMode {
OFF = 0, RAW = 1, TM = 2 OFF = 0, RAW = 1, TM = 2
} wiretappingMode; } wiretappingMode;
/** /**
* A message queue that accepts raw replies * @brief A message queue that accepts raw replies
* *
* Statically initialized in initialize() to a configurable object. Used when there is no method * Statically initialized in initialize() to a configurable object.
* of finding a recipient, ie raw mode and reporting erreonous replies * Used when there is no method of finding a recipient, ie raw mode and
* reporting erroneous replies
*/ */
MessageQueueId_t defaultRawReceiver = 0; MessageQueueId_t defaultRawReceiver = 0;
store_address_t storedRawData; store_address_t storedRawData;
/** /**
* the message queue which wants to read all raw traffic * @brief The message queue which wants to read all raw traffic
* * If #isWiretappingActive all raw communication from and to the device
* if #isWiretappingActive all raw communication from and to the device will be sent to this queue * will be sent to this queue
*/ */
MessageQueueId_t requestedRawTraffic = 0; MessageQueueId_t requestedRawTraffic = 0;
/**
* the object used to set power switches
*/
PowerSwitchIF *powerSwitcher = nullptr;
/** /**
* Pointer to the IPCStore. * Pointer to the IPCStore.
*
* This caches the pointer received from the objectManager in the constructor. * This caches the pointer received from the objectManager in the constructor.
*/ */
StorageManagerIF *IPCStore = nullptr; StorageManagerIF *IPCStore = nullptr;
/** The comIF object ID is cached for the intialize() function */
/**
* cached for init
*/
object_id_t deviceCommunicationId; object_id_t deviceCommunicationId;
/** Communication object used for device communication */
/**
* Communication object used for device communication
*/
DeviceCommunicationIF * communicationInterface = nullptr; DeviceCommunicationIF * communicationInterface = nullptr;
/** Cookie used for communication */
/**
* Cookie used for communication
*/
CookieIF * comCookie; CookieIF * comCookie;
/** Health helper for HasHealthIF */
HealthHelper healthHelper;
/** Mode helper for HasModesIF */
ModeHelper modeHelper;
/** Parameter helper for ReceivesParameterMessagesIF */
ParameterHelper parameterHelper;
/** Action helper for HasActionsIF */
ActionHelper actionHelper;
/** Housekeeping Manager */
HousekeepingManager hkManager;
/**
* @brief Information about commands
*/
struct DeviceCommandInfo { struct DeviceCommandInfo {
bool isExecuting; //!< Indicates if the command is already executing. //! Indicates if the command is already executing.
uint8_t expectedReplies; //!< Dynamic value to indicate how many replies are expected. Inititated with 0. bool isExecuting;
MessageQueueId_t sendReplyTo; //!< if this is != NO_COMMANDER, DHB was commanded externally and shall report everything to commander. //! Dynamic value to indicate how many replies are expected.
//! Inititated with 0.
uint8_t expectedReplies;
//! if this is != NO_COMMANDER, DHB was commanded externally and shall
//! report everything to commander.
MessageQueueId_t sendReplyTo;
}; };
using DeviceCommandMap = std::map<DeviceCommandId_t, DeviceCommandInfo> ; using DeviceCommandMap = std::map<DeviceCommandId_t, DeviceCommandInfo> ;
/**
* Information about commands
*/
DeviceCommandMap deviceCommandMap;
/** /**
* @brief Information about expected replies * @brief Information about expected replies
* * This is used to keep track of pending replies.
* This is used to keep track of pending replies
*/ */
struct DeviceReplyInfo { struct DeviceReplyInfo {
uint16_t maxDelayCycles; //!< The maximum number of cycles the handler should wait for a reply to this command. //! The maximum number of cycles the handler should wait for a reply
uint16_t delayCycles; //!< The currently remaining cycles the handler should wait for a reply, 0 means there is no reply expected //! to this command.
uint16_t maxDelayCycles;
//! The currently remaining cycles the handler should wait for a reply,
//! 0 means there is no reply expected
uint16_t delayCycles;
size_t replyLen = 0; //!< Expected size of the reply. size_t replyLen = 0; //!< Expected size of the reply.
uint8_t periodic; //!< if this is !=0, the delayCycles will not be reset to 0 but to maxDelayCycles //! if this is !=0, the delayCycles will not be reset to 0 but to
DeviceCommandMap::iterator command; //!< The command that expects this reply. //! maxDelayCycles
bool periodic;
//! The dataset used to access housekeeping data related to the
//! respective device reply. Will point to a dataset held by
//! the child handler (if one is specified)
DataSetIF* dataSet;
//! The command that expects this reply.
DeviceCommandMap::iterator command;
}; };
using DeviceReplyMap = std::map<DeviceCommandId_t, DeviceReplyInfo> ; using DeviceReplyMap = std::map<DeviceCommandId_t, DeviceReplyInfo> ;
using DeviceReplyIter = DeviceReplyMap::iterator; using DeviceReplyIter = DeviceReplyMap::iterator;
/** /**
* The MessageQueue used to receive device handler commands and to send replies. * This map is used to check and track correct reception of all replies.
*
* It has multiple use:
* - It stores the information on pending replies. If a command is sent,
* the DeviceCommandInfo.count is incremented.
* - It is used to time-out missing replies. If a command is sent, the
* DeviceCommandInfo.DelayCycles is set to MaxDelayCycles.
* - It is queried to check if a reply from the device can be interpreted.
* scanForReply() returns the id of the command a reply was found for.
* The reply is ignored in the following cases:
* - No entry for the returned id was found
* - The deviceReplyInfo.delayCycles is == 0
*/ */
DeviceReplyMap deviceReplyMap;
//! The MessageQueue used to receive device handler commands
//! and to send replies.
MessageQueueIF* commandQueue = nullptr; MessageQueueIF* commandQueue = nullptr;
/** /**
@ -652,15 +688,6 @@ protected:
*/ */
uint32_t deviceThermalRequestPoolId; uint32_t deviceThermalRequestPoolId;
/**
* Taking care of the health
*/
HealthHelper healthHelper;
ModeHelper modeHelper;
ParameterHelper parameterHelper;
/** /**
* Optional Error code * Optional Error code
* Can be set in doStartUp(), doShutDown() and doTransition() to signal cause for Transition failure. * Can be set in doStartUp(), doShutDown() and doTransition() to signal cause for Transition failure.
@ -966,24 +993,11 @@ protected:
bool commandIsExecuting(DeviceCommandId_t commandId); bool commandIsExecuting(DeviceCommandId_t commandId);
/** /**
* This map is used to check and track correct reception of all replies. * set all switches returned by getSwitches()
* *
* It has multiple use: * @param onOff on == @c SWITCH_ON; off != @c SWITCH_ON
* - it stores the information on pending replies. If a command is sent, the DeviceCommandInfo.count is incremented.
* - it is used to time-out missing replies. If a command is sent, the DeviceCommandInfo.DelayCycles is set to MaxDelayCycles.
* - it is queried to check if a reply from the device can be interpreted. scanForReply() returns the id of the command a reply was found for.
* The reply is ignored in the following cases:
* - No entry for the returned id was found
* - The deviceReplyInfo.delayCycles is == 0
*/ */
DeviceReplyMap deviceReplyMap; void commandSwitch(ReturnValue_t onOff);
/**
* Information about commands
*/
DeviceCommandMap deviceCommandMap;
ActionHelper actionHelper;
private: private:
/** /**
@ -1016,6 +1030,9 @@ private:
*/ */
CookieInfo cookieInfo; CookieInfo cookieInfo;
/** the object used to set power switches*/
PowerSwitchIF *powerSwitcher = nullptr;
/** /**
* Used for timing out mode transitions. * Used for timing out mode transitions.
* *
@ -1148,12 +1165,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);
/**
* set all switches returned by getSwitches()
*
* @param onOff on == @c SWITCH_ON; off != @c SWITCH_ON
*/
void commandSwitch(ReturnValue_t onOff);
/** /**
* @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!!!
@ -1178,6 +1189,10 @@ private:
ReturnValue_t switchCookieChannel(object_id_t newChannelId); ReturnValue_t switchCookieChannel(object_id_t newChannelId);
ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message); ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message);
void parseReply(const uint8_t* receivedData,
size_t receivedDataLen);
DataSetIF* getDataSetHandle(sid_t sid) override;
}; };
#endif /* DEVICEHANDLERBASE_H_ */ #endif /* DEVICEHANDLERBASE_H_ */

View File

@ -7,13 +7,15 @@
object_id_t DeviceHandlerFailureIsolation::powerConfirmationId = 0; object_id_t DeviceHandlerFailureIsolation::powerConfirmationId = 0;
DeviceHandlerFailureIsolation::DeviceHandlerFailureIsolation(object_id_t owner, object_id_t parent) : DeviceHandlerFailureIsolation::DeviceHandlerFailureIsolation(object_id_t owner,
FailureIsolationBase(owner, parent), strangeReplyCount(MAX_STRANGE_REPLIES, object_id_t parent) :
STRANGE_REPLIES_TIME_MS, parameterDomainBase++), missedReplyCount( FailureIsolationBase(owner, parent),
MAX_MISSED_REPLY_COUNT, MISSED_REPLY_TIME_MS, strangeReplyCount(MAX_STRANGE_REPLIES, STRANGE_REPLIES_TIME_MS,
parameterDomainBase++), recoveryCounter(MAX_REBOOT, parameterDomainBase++),
REBOOT_TIME_MS, parameterDomainBase++), fdirState(NONE), powerConfirmation( missedReplyCount( MAX_MISSED_REPLY_COUNT, MISSED_REPLY_TIME_MS,
0) { parameterDomainBase++),
recoveryCounter(MAX_REBOOT, REBOOT_TIME_MS, parameterDomainBase++),
fdirState(NONE), powerConfirmation(0) {
} }
DeviceHandlerFailureIsolation::~DeviceHandlerFailureIsolation() { DeviceHandlerFailureIsolation::~DeviceHandlerFailureIsolation() {
@ -68,9 +70,11 @@ ReturnValue_t DeviceHandlerFailureIsolation::eventReceived(EventMessage* event)
break; break;
//****Power***** //****Power*****
case PowerSwitchIF::SWITCH_WENT_OFF: case PowerSwitchIF::SWITCH_WENT_OFF:
result = sendConfirmationRequest(event, powerConfirmation); if(hasPowerConfirmation) {
if (result == RETURN_OK) { result = sendConfirmationRequest(event, powerConfirmation);
setFdirState(DEVICE_MIGHT_BE_OFF); if (result == RETURN_OK) {
setFdirState(DEVICE_MIGHT_BE_OFF);
}
} }
break; break;
case Fuse::FUSE_WENT_OFF: case Fuse::FUSE_WENT_OFF:
@ -142,7 +146,8 @@ void DeviceHandlerFailureIsolation::handleRecovery(Event reason) {
void DeviceHandlerFailureIsolation::wasParentsFault(EventMessage* event) { void DeviceHandlerFailureIsolation::wasParentsFault(EventMessage* event) {
//We'll better ignore the SWITCH_WENT_OFF event and await a system-wide reset. //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? //This means, no fault message will come through until a MODE_ or
//HEALTH_INFO message comes through -> Is that ok?
//Same issue in TxFailureIsolation! //Same issue in TxFailureIsolation!
// if ((event->getEvent() == PowerSwitchIF::SWITCH_WENT_OFF) // if ((event->getEvent() == PowerSwitchIF::SWITCH_WENT_OFF)
// && (fdirState != RECOVERY_ONGOING)) { // && (fdirState != RECOVERY_ONGOING)) {
@ -162,10 +167,11 @@ ReturnValue_t DeviceHandlerFailureIsolation::initialize() {
} }
ConfirmsFailuresIF* power = objectManager->get<ConfirmsFailuresIF>( ConfirmsFailuresIF* power = objectManager->get<ConfirmsFailuresIF>(
powerConfirmationId); powerConfirmationId);
if (power == NULL) { if (power != nullptr) {
return RETURN_FAILED; powerConfirmation = power->getEventReceptionQueue();
hasPowerConfirmation = true;
} }
powerConfirmation = power->getEventReceptionQueue();
return RETURN_OK; return RETURN_OK;
} }

View File

@ -28,6 +28,7 @@ protected:
NONE, RECOVERY_ONGOING, DEVICE_MIGHT_BE_OFF, AWAIT_SHUTDOWN NONE, RECOVERY_ONGOING, DEVICE_MIGHT_BE_OFF, AWAIT_SHUTDOWN
}; };
FDIRState fdirState; FDIRState fdirState;
bool hasPowerConfirmation = false;
MessageQueueId_t powerConfirmation; MessageQueueId_t powerConfirmation;
static object_id_t powerConfirmationId; static object_id_t powerConfirmationId;
static const uint32_t MAX_REBOOT = 1; static const uint32_t MAX_REBOOT = 1;