diff --git a/datapoollocal/LocalDataPoolManager.cpp b/datapoollocal/LocalDataPoolManager.cpp index 0a5747dc..37dbed36 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/datapoollocal/LocalDataPoolManager.cpp @@ -41,7 +41,7 @@ ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() { } ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage( - CommandMessage *message) { + MessageQueueMessage *message) { return HasReturnvaluesIF::RETURN_OK; } diff --git a/datapoollocal/LocalDataPoolManager.h b/datapoollocal/LocalDataPoolManager.h index 14e7693c..1d25fa48 100644 --- a/datapoollocal/LocalDataPoolManager.h +++ b/datapoollocal/LocalDataPoolManager.h @@ -46,7 +46,7 @@ public: LocalDataPoolManager operator=(const LocalDataPoolManager&) = delete; ReturnValue_t generateHousekeepingPacket(sid_t sid); - ReturnValue_t handleHousekeepingMessage(CommandMessage* message); + ReturnValue_t handleHousekeepingMessage(MessageQueueMessage* message); /** * This function is used to fill the local data pool map with pool diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 59bfb6af..94c9dc63 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -36,7 +38,7 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode( SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize, - CommandMessage::MAX_MESSAGE_SIZE); + MessageQueueMessage::MAX_MESSAGE_SIZE); insertInCommandMap(RAW_COMMAND_ID); cookieInfo.state = COOKIE_UNUSED; cookieInfo.pendingCommand = deviceCommandMap.end(); @@ -212,40 +214,59 @@ void DeviceHandlerBase::readCommandQueue() { return; } - CommandMessage message; - ReturnValue_t result = commandQueue->receiveMessage(&message); + // This is not ideal. What if it is not a command message? (e.g. another + // message with 3 parameters). The full buffer is filled anyway + // and I could just copy the content into the other message but + // all I need are few additional functions the other message type offers. + CommandMessage cmdMessage; + ReturnValue_t result = commandQueue->receiveMessage(&cmdMessage); if (result != RETURN_OK) { return; } + // This is really annoying. I can't cast a parent object to a child. + // But I want to use another message format.. +// CommandMessage* cmdMessage = dynamic_cast(msgPtr); +// if(cmdMessage == nullptr) { +// sif::error << "DeviceHandlerBase::readCommandQueue: Could not cast" +// " message to CommandMessage!" << std::endl; +// return; +// } + if(healthHelperActive) { - result = healthHelper.handleHealthCommand(&message); + result = healthHelper.handleHealthCommand(&cmdMessage); if (result == RETURN_OK) { return; } } - result = modeHelper.handleModeCommand(&message); + result = modeHelper.handleModeCommand(&cmdMessage); if (result == RETURN_OK) { return; } - result = actionHelper.handleActionMessage(&message); + result = actionHelper.handleActionMessage(&cmdMessage); if (result == RETURN_OK) { return; } - result = parameterHelper.handleParameterMessage(&message); + result = parameterHelper.handleParameterMessage(&cmdMessage); if (result == RETURN_OK) { return; } - result = handleDeviceHandlerMessage(&message); +// HousekeepingMessage* hkMessage = dynamic_cast(msgPtr); +// result = hkManager.handleHousekeepingMessage(hkMessage); +// if (result == RETURN_OK) { +// return; +// } + + result = handleDeviceHandlerMessage(&cmdMessage); if (result == RETURN_OK) { return; } - result = letChildHandleMessage(&message); + result = letChildHandleMessage(&cmdMessage); if (result == RETURN_OK) { return; } diff --git a/housekeeping/HousekeepingMessage.cpp b/housekeeping/HousekeepingMessage.cpp index b0109e5d..c94a69d7 100644 --- a/housekeeping/HousekeepingMessage.cpp +++ b/housekeeping/HousekeepingMessage.cpp @@ -1,5 +1,13 @@ #include +HousekeepingMessage::HousekeepingMessage() { + +} + +void HousekeepingMessage::setHkReportMessage() { +} + + //void HousekeepingMessage::setAddHkReportStructMessage(CommandMessage *message, // set_t setId, store_address_t packet) { // message->setCommand(ADD_HK_REPORT_STRUCT); diff --git a/housekeeping/HousekeepingMessage.h b/housekeeping/HousekeepingMessage.h index e7ba68ba..67edc4ed 100644 --- a/housekeeping/HousekeepingMessage.h +++ b/housekeeping/HousekeepingMessage.h @@ -5,12 +5,14 @@ #include union sid_t { - static constexpr uint64_t INVALID_ADDRESS = std::numeric_limits::max(); + static constexpr uint64_t INVALID_ADDRESS = + std::numeric_limits::max(); sid_t(): raw(INVALID_ADDRESS) {} struct { object_id_t objectId ; - // A generic 32 bit ID to identify unique HK packets for a single object. + // A generic 32 bit ID to identify unique HK packets for a single + // object. // For example, the DeviceCommandId_t is used for DeviceHandlers uint32_t ownerSetId; }; @@ -19,15 +21,17 @@ union sid_t { */ uint64_t raw; }; -class HousekeepingMessage { + + +class HousekeepingMessage: public MessageQueueMessage { public: /** * No instances of a message shall be created, instead * a CommandMessage instance is manipulated. */ - HousekeepingMessage() = delete; - HousekeepingMessage(const HousekeepingMessage&) = delete; - HousekeepingMessage operator=(const HousekeepingMessage &) = delete; + HousekeepingMessage(); +// HousekeepingMessage(const HousekeepingMessage&) = delete; +// HousekeepingMessage operator=(const HousekeepingMessage &) = delete; static constexpr uint8_t MESSAGE_ID = MESSAGE_TYPE::HOUSEKEEPING; static constexpr Command_t ADD_HK_REPORT_STRUCT = @@ -76,6 +80,7 @@ public: // static void setAddHkReportStructMessage(CommandMessage* message, // DevisetId, store_address_t packet); + static void setHkReportMessage(); }; diff --git a/ipc/CommandMessage.h b/ipc/CommandMessage.h index 6190e903..d7b6820d 100644 --- a/ipc/CommandMessage.h +++ b/ipc/CommandMessage.h @@ -28,7 +28,8 @@ public: static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID( 0xD1 ); /** - * This is the size of a message as it is seen by the MessageQueue + * This is the size of a message as it is seen by the MessageQueue. + * 14 of the 24 available MessageQueueMessage bytes are used. */ static const size_t COMMAND_MESSAGE_SIZE = HEADER_SIZE + sizeof(Command_t) + 2 * sizeof(uint32_t); diff --git a/ipc/MessageQueueMessage.h b/ipc/MessageQueueMessage.h index 4d82bd88..93671321 100644 --- a/ipc/MessageQueueMessage.h +++ b/ipc/MessageQueueMessage.h @@ -1,6 +1,7 @@ #ifndef MESSAGEQUEUEMESSAGE_H_ #define MESSAGEQUEUEMESSAGE_H_ +#include #include #include @@ -23,7 +24,7 @@ * receive messages from other tasks. * @ingroup message_queue */ -class MessageQueueMessage { +class MessageQueueMessage: public MessageQueueMessageIF { public: /** * @brief The class is initialized empty with this constructor. @@ -43,6 +44,7 @@ public: * MAX_MESSAGE_SIZE and larger than MIN_MESSAGE_SIZE. */ MessageQueueMessage(uint8_t* data, size_t size); + /** * @brief The size information of each message is stored in this attribute. * @details diff --git a/ipc/MessageQueueMessageIF.h b/ipc/MessageQueueMessageIF.h new file mode 100644 index 00000000..3bd4a9d6 --- /dev/null +++ b/ipc/MessageQueueMessageIF.h @@ -0,0 +1,44 @@ +#ifndef FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_ +#define FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_ +#include +#include + +class MessageQueueMessageIF { +public: + virtual ~MessageQueueMessageIF() {}; + + /** + * @brief With this method, the whole content and the message + * size is set to zero. + */ + virtual void clear() = 0; + /** + * @brief This is a debug method that prints the content + * (till messageSize) to the debug output. + */ + virtual void print() = 0; + virtual const uint8_t* getBuffer() const = 0; + /** + * @brief This method is used to get the complete data of the message. + */ + virtual uint8_t* getBuffer() = 0; + /** + * @brief This method is used to set the sender's message queue id + * information prior to sending the message. + * @param setId The message queue id that identifies the sending message queue. + */ + virtual void setSender(MessageQueueId_t setId) = 0; + /** + * @brief This helper function is used by the MessageQueue class to + * check the size of an incoming message. + * @details + * The method must be overwritten by child classes if size checks shall + * be more strict. + * @return The default implementation returns HEADER_SIZE. + */ + virtual size_t getMinimumMessageSize() = 0; +}; + + + +#endif /* FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_ */