diff --git a/devicehandlers/CookieIF.h b/devicehandlers/CookieIF.h index d8781cd7..fc89c1af 100644 --- a/devicehandlers/CookieIF.h +++ b/devicehandlers/CookieIF.h @@ -8,6 +8,11 @@ #define FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_ #include +/** + * @brief Physical address type + */ +typedef uint32_t address_t; + class CookieIF { public: /** diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 068a62de..b1af2689 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -365,11 +365,8 @@ ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceComm info.expectedReplies = 0; info.isExecuting = false; info.sendReplyTo = NO_COMMANDER; - std::pair::iterator, bool> returnValue; - returnValue = deviceCommandMap.insert( - std::pair(deviceCommand, - info)); - if (returnValue.second) { + std::pair result = deviceCommandMap.emplace(deviceCommand,info); + if (result.second) { return RETURN_OK; } else { return RETURN_FAILED; @@ -489,7 +486,7 @@ void DeviceHandlerBase::replyToReply(DeviceReplyMap::iterator iter, return; } //Check if more replies are expected. If so, do nothing. - DeviceCommandInfo* info = &(iter->second.command->second); + DeviceCommandInfo * info = &(iter->second.command->second); if (--info->expectedReplies == 0) { //Check if it was transition or internal command. Don't send any replies in that case. if (info->sendReplyTo != NO_COMMANDER) { @@ -550,13 +547,17 @@ void DeviceHandlerBase::doSendRead() { requestLen = iter->second.replyLen; } else { - requestLen = 0; + requestLen = comCookie->getMaxReplyLen(); } result = communicationInterface->requestReceiveMessage(comCookie, requestLen); if (result == RETURN_OK) { cookieInfo.state = COOKIE_READ_SENT; - } else { + } + else if(result == NO_READ_REQUEST) { + return; + } + else { triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result); //We can't inform anyone, because we don't know which command was sent last. //So, we need to wait for a timeout. @@ -816,9 +817,9 @@ ReturnValue_t DeviceHandlerBase::enableReplyInReplyMap( iter = deviceReplyMap.find(command->first); } if (iter != deviceReplyMap.end()) { - DeviceReplyInfo & info = iter->second; - info.delayCycles = info.maxDelayCycles; - info.command = command; + DeviceReplyInfo * info = &(iter->second); + info->delayCycles = info->maxDelayCycles; + info->command = command; command->second.expectedReplies = expectedReplies; return RETURN_OK; } else { diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index b4882b9d..129fb288 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -194,6 +194,9 @@ protected: * different commands can built returned depending on the submode. * * #rawPacket and #rawPacketLen must be set by this method to the packet to be sent. + * If variable command frequence is required, a counter can be used and + * the frequency in the reply map has to be set manually + * by calling updateReplyMap(). * * @param[out] id the device command id that has been built * @return @@ -527,6 +530,7 @@ protected: MessageQueueId_t sendReplyTo; //!< if this is != NO_COMMANDER, DHB was commanded externally and shall report everything to commander. }; typedef std::map DeviceCommandMap; + typedef DeviceCommandMap::iterator DeviceCommandIter; /** * @brief Information about expected replies @@ -674,48 +678,6 @@ protected: */ virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom); - /** - * Is the combination of mode and submode valid? - * - * @param mode - * @param submode - * @return - * - @c RETURN_OK if valid - * - @c RETURN_FAILED if invalid - */ - virtual ReturnValue_t isModeCombinationValid(Mode_t mode, - Submode_t submode); - - /** - * Get the Rmap action for the current step. - * - * The step number can be read from #pstStep. - * - * @return The Rmap action to execute in this step - */ - virtual CommunicationAction_t getComAction(); - - /** - * Build the device command to send for raw mode. - * - * This is only called in @c MODE_RAW. It is for the rare case that in raw mode packets - * are to be sent by the handler itself. It is NOT needed for the raw commanding service. - * Its only current use is in the STR handler which gets its raw packets from a different - * source. - * Also it can be used for transitional commands, to get the device ready for @c MODE_RAW - * - * As it is almost never used, there is a default implementation returning @c NOTHING_TO_SEND. - * - * #rawPacket and #rawPacketLen must be set by this method to the packet to be sent. - * - * @param[out] id the device command id built - * @return - * - @c RETURN_OK when a command is to be sent - * - not @c NOTHING_TO_SEND when no command is to be sent - */ - virtual ReturnValue_t buildChildRawCommand(); - - /** * This is a helper method to facilitate inserting entries in the command map. * @param deviceCommand Identifier of the command to add. @@ -765,6 +727,47 @@ protected: */ uint8_t getReplyDelayCycles(DeviceCommandId_t deviceCommand); + /** + * Is the combination of mode and submode valid? + * + * @param mode + * @param submode + * @return + * - @c RETURN_OK if valid + * - @c RETURN_FAILED if invalid + */ + virtual ReturnValue_t isModeCombinationValid(Mode_t mode, + Submode_t submode); + + /** + * Get the Rmap action for the current step. + * + * The step number can be read from #pstStep. + * + * @return The Rmap action to execute in this step + */ + virtual CommunicationAction_t getComAction(); + + /** + * Build the device command to send for raw mode. + * + * This is only called in @c MODE_RAW. It is for the rare case that in raw mode packets + * are to be sent by the handler itself. It is NOT needed for the raw commanding service. + * Its only current use is in the STR handler which gets its raw packets from a different + * source. + * Also it can be used for transitional commands, to get the device ready for @c MODE_RAW + * + * As it is almost never used, there is a default implementation returning @c NOTHING_TO_SEND. + * + * #rawPacket and #rawPacketLen must be set by this method to the packet to be sent. + * + * @param[out] id the device command id built + * @return + * - @c RETURN_OK when a command is to be sent + * - not @c NOTHING_TO_SEND when no command is to be sent + */ + virtual ReturnValue_t buildChildRawCommand(); + /** * Construct a command reply containing a raw reply. * diff --git a/devicehandlers/DeviceHandlerIF.h b/devicehandlers/DeviceHandlerIF.h index 5ea527e9..c6baf7af 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/devicehandlers/DeviceHandlerIF.h @@ -7,11 +7,6 @@ #include #include -/** - * @brief Physical address type - */ -typedef uint32_t address_t; - /** * @brief This is the Interface used to communicate with a device handler. * @details Includes all expected return values, events and modes. @@ -95,6 +90,8 @@ public: // 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 buildNomalDeviceCommand + static const ReturnValue_t NO_READ_REQUEST = MAKE_RETURN_CODE(0xD2); // Standard codes used in getSwitches static const ReturnValue_t NO_SWITCH = MAKE_RETURN_CODE(0xE1); //!< Return in getSwitches() to specify there are no switches