thoughts on message queuee message

new interface. What if there are MQ messages with different sizes?
-> generic interface

furthermore, maybe command message should be refactored to operate
on a mq message instead of implementing it
This commit is contained in:
Robin Müller 2020-06-08 01:22:21 +02:00
parent 2649fa1507
commit 4c41456ddf
8 changed files with 100 additions and 19 deletions

View File

@ -41,7 +41,7 @@ ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
} }
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage( ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
CommandMessage *message) { MessageQueueMessage *message) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -46,7 +46,7 @@ public:
LocalDataPoolManager operator=(const LocalDataPoolManager&) = delete; LocalDataPoolManager operator=(const LocalDataPoolManager&) = delete;
ReturnValue_t generateHousekeepingPacket(sid_t sid); 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 * This function is used to fill the local data pool map with pool

View File

@ -8,6 +8,8 @@
#include <framework/datapoolglob/GlobalPoolVariable.h> #include <framework/datapoolglob/GlobalPoolVariable.h>
#include <framework/devicehandlers/DeviceTmReportingWrapper.h> #include <framework/devicehandlers/DeviceTmReportingWrapper.h>
#include <framework/globalfunctions/CRC.h> #include <framework/globalfunctions/CRC.h>
#include <framework/housekeeping/HousekeepingMessage.h>
#include <framework/ipc/MessageQueueMessage.h>
#include <framework/subsystem/SubsystemBase.h> #include <framework/subsystem/SubsystemBase.h>
#include <framework/ipc/QueueFactory.h> #include <framework/ipc/QueueFactory.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
@ -36,7 +38,7 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId,
transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode( transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(
SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { SUBMODE_NONE), deviceSwitch(setDeviceSwitch) {
commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize, commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize,
CommandMessage::MAX_MESSAGE_SIZE); MessageQueueMessage::MAX_MESSAGE_SIZE);
insertInCommandMap(RAW_COMMAND_ID); insertInCommandMap(RAW_COMMAND_ID);
cookieInfo.state = COOKIE_UNUSED; cookieInfo.state = COOKIE_UNUSED;
cookieInfo.pendingCommand = deviceCommandMap.end(); cookieInfo.pendingCommand = deviceCommandMap.end();
@ -212,40 +214,59 @@ void DeviceHandlerBase::readCommandQueue() {
return; return;
} }
CommandMessage message; // This is not ideal. What if it is not a command message? (e.g. another
ReturnValue_t result = commandQueue->receiveMessage(&message); // 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) { if (result != RETURN_OK) {
return; 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<CommandMessage*>(msgPtr);
// if(cmdMessage == nullptr) {
// sif::error << "DeviceHandlerBase::readCommandQueue: Could not cast"
// " message to CommandMessage!" << std::endl;
// return;
// }
if(healthHelperActive) { if(healthHelperActive) {
result = healthHelper.handleHealthCommand(&message); result = healthHelper.handleHealthCommand(&cmdMessage);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }
} }
result = modeHelper.handleModeCommand(&message); result = modeHelper.handleModeCommand(&cmdMessage);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }
result = actionHelper.handleActionMessage(&message); result = actionHelper.handleActionMessage(&cmdMessage);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }
result = parameterHelper.handleParameterMessage(&message); result = parameterHelper.handleParameterMessage(&cmdMessage);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }
result = handleDeviceHandlerMessage(&message); // HousekeepingMessage* hkMessage = dynamic_cast<HousekeepingMessage*>(msgPtr);
// result = hkManager.handleHousekeepingMessage(hkMessage);
// if (result == RETURN_OK) {
// return;
// }
result = handleDeviceHandlerMessage(&cmdMessage);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }
result = letChildHandleMessage(&message); result = letChildHandleMessage(&cmdMessage);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }

View File

@ -1,5 +1,13 @@
#include <framework/housekeeping/HousekeepingMessage.h> #include <framework/housekeeping/HousekeepingMessage.h>
HousekeepingMessage::HousekeepingMessage() {
}
void HousekeepingMessage::setHkReportMessage() {
}
//void HousekeepingMessage::setAddHkReportStructMessage(CommandMessage *message, //void HousekeepingMessage::setAddHkReportStructMessage(CommandMessage *message,
// set_t setId, store_address_t packet) { // set_t setId, store_address_t packet) {
// message->setCommand(ADD_HK_REPORT_STRUCT); // message->setCommand(ADD_HK_REPORT_STRUCT);

View File

@ -5,12 +5,14 @@
#include <limits> #include <limits>
union sid_t { union sid_t {
static constexpr uint64_t INVALID_ADDRESS = std::numeric_limits<uint64_t>::max(); static constexpr uint64_t INVALID_ADDRESS =
std::numeric_limits<uint64_t>::max();
sid_t(): raw(INVALID_ADDRESS) {} sid_t(): raw(INVALID_ADDRESS) {}
struct { struct {
object_id_t objectId ; 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 // For example, the DeviceCommandId_t is used for DeviceHandlers
uint32_t ownerSetId; uint32_t ownerSetId;
}; };
@ -19,15 +21,17 @@ union sid_t {
*/ */
uint64_t raw; uint64_t raw;
}; };
class HousekeepingMessage {
class HousekeepingMessage: public MessageQueueMessage {
public: public:
/** /**
* No instances of a message shall be created, instead * No instances of a message shall be created, instead
* a CommandMessage instance is manipulated. * a CommandMessage instance is manipulated.
*/ */
HousekeepingMessage() = delete; HousekeepingMessage();
HousekeepingMessage(const HousekeepingMessage&) = delete; // HousekeepingMessage(const HousekeepingMessage&) = delete;
HousekeepingMessage operator=(const HousekeepingMessage &) = delete; // HousekeepingMessage operator=(const HousekeepingMessage &) = delete;
static constexpr uint8_t MESSAGE_ID = MESSAGE_TYPE::HOUSEKEEPING; static constexpr uint8_t MESSAGE_ID = MESSAGE_TYPE::HOUSEKEEPING;
static constexpr Command_t ADD_HK_REPORT_STRUCT = static constexpr Command_t ADD_HK_REPORT_STRUCT =
@ -76,6 +80,7 @@ public:
// static void setAddHkReportStructMessage(CommandMessage* message, // static void setAddHkReportStructMessage(CommandMessage* message,
// DevisetId, store_address_t packet); // DevisetId, store_address_t packet);
static void setHkReportMessage();
}; };

View File

@ -28,7 +28,8 @@ public:
static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID( 0xD1 ); 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 static const size_t COMMAND_MESSAGE_SIZE = HEADER_SIZE
+ sizeof(Command_t) + 2 * sizeof(uint32_t); + sizeof(Command_t) + 2 * sizeof(uint32_t);

View File

@ -1,6 +1,7 @@
#ifndef MESSAGEQUEUEMESSAGE_H_ #ifndef MESSAGEQUEUEMESSAGE_H_
#define MESSAGEQUEUEMESSAGE_H_ #define MESSAGEQUEUEMESSAGE_H_
#include <framework/ipc/MessageQueueMessageIF.h>
#include <framework/ipc/MessageQueueSenderIF.h> #include <framework/ipc/MessageQueueSenderIF.h>
#include <stddef.h> #include <stddef.h>
@ -23,7 +24,7 @@
* receive messages from other tasks. * receive messages from other tasks.
* @ingroup message_queue * @ingroup message_queue
*/ */
class MessageQueueMessage { class MessageQueueMessage: public MessageQueueMessageIF {
public: public:
/** /**
* @brief The class is initialized empty with this constructor. * @brief The class is initialized empty with this constructor.
@ -43,6 +44,7 @@ public:
* MAX_MESSAGE_SIZE and larger than MIN_MESSAGE_SIZE. * MAX_MESSAGE_SIZE and larger than MIN_MESSAGE_SIZE.
*/ */
MessageQueueMessage(uint8_t* data, size_t size); MessageQueueMessage(uint8_t* data, size_t size);
/** /**
* @brief The size information of each message is stored in this attribute. * @brief The size information of each message is stored in this attribute.
* @details * @details

View File

@ -0,0 +1,44 @@
#ifndef FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_
#define FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_
#include <framework/ipc/MessageQueueSenderIF.h>
#include <cstddef>
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_ */