diff --git a/ipc/CommandMessage.cpp b/ipc/CommandMessage.cpp index 6aa433df..2b0c34d5 100644 --- a/ipc/CommandMessage.cpp +++ b/ipc/CommandMessage.cpp @@ -3,57 +3,57 @@ #include CommandMessage::CommandMessage() { - MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE); + MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE); setCommand(CMD_NONE); } CommandMessage::CommandMessage(Command_t command, uint32_t parameter1, uint32_t parameter2) { MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE); - setCommand(command); - setParameter(parameter1); - setParameter2(parameter2); + setCommand(command); + setParameter(parameter1); + setParameter2(parameter2); } Command_t CommandMessage::getCommand() const { - Command_t command; - std::memcpy(&command, getData(), sizeof(Command_t)); - return command; + Command_t command; + std::memcpy(&command, MessageQueueMessage::getData(), sizeof(Command_t)); + return command; } void CommandMessage::setCommand(Command_t command) { - std::memcpy(getData(), &command, sizeof(Command_t)); + std::memcpy(MessageQueueMessage::getData(), &command, sizeof(Command_t)); } uint8_t CommandMessage::getMessageType() const { - // first byte of command ID. - return getCommand() >> 8 & 0xff; + // first byte of command ID. + return getCommand() >> 8 & 0xff; } uint32_t CommandMessage::getParameter() const { - uint32_t parameter1; - std::memcpy(¶meter1, MessageQueueMessage::getData(), sizeof(parameter1)); - return parameter1; + uint32_t parameter1; + std::memcpy(¶meter1, this->getData(), sizeof(parameter1)); + return parameter1; } void CommandMessage::setParameter(uint32_t parameter1) { - std::memcpy(MessageQueueMessage::getData(), ¶meter1, sizeof(parameter1)); + std::memcpy(this->getData(), ¶meter1, sizeof(parameter1)); } uint32_t CommandMessage::getParameter2() const { - uint32_t parameter2; - std::memcpy(¶meter2, MessageQueueMessage::getData() + sizeof(uint32_t), - sizeof(parameter2)); - return parameter2; + uint32_t parameter2; + std::memcpy(¶meter2, this->getData() + sizeof(uint32_t), + sizeof(parameter2)); + return parameter2; } void CommandMessage::setParameter2(uint32_t parameter2) { - std::memcpy(MessageQueueMessage::getData() + sizeof(uint32_t), ¶meter2, - sizeof(parameter2)); + std::memcpy(this->getData() + sizeof(uint32_t), ¶meter2, + sizeof(parameter2)); } size_t CommandMessage::getMinimumMessageSize() const { - return MINIMUM_COMMAND_MESSAGE_SIZE; + return MINIMUM_COMMAND_MESSAGE_SIZE; } void CommandMessage::clear() { @@ -61,29 +61,37 @@ void CommandMessage::clear() { } bool CommandMessage::isClearedCommandMessage() { - return getCommand() == CMD_NONE; + return getCommand() == CMD_NONE; } void CommandMessage::setToUnknownCommand() { - Command_t initialCommand = getCommand(); - this->clear(); - setReplyRejected(UNKNOWN_COMMAND, initialCommand); + Command_t initialCommand = getCommand(); + this->clear(); + setReplyRejected(UNKNOWN_COMMAND, initialCommand); } void CommandMessage::setReplyRejected(ReturnValue_t reason, - Command_t initialCommand) { - std::memcpy(getData(), &reason, sizeof(reason)); - std::memcpy(getData() + sizeof(reason), &initialCommand, - sizeof(initialCommand)); + Command_t initialCommand) { + std::memcpy(getData(), &reason, sizeof(reason)); + std::memcpy(getData() + sizeof(reason), &initialCommand, + sizeof(initialCommand)); } ReturnValue_t CommandMessage::getReplyRejectedReason( - Command_t *initialCommand) const { - ReturnValue_t reason = HasReturnvaluesIF::RETURN_FAILED; - std::memcpy(&reason, getData(), sizeof(reason)); - if(initialCommand != nullptr) { - std::memcpy(initialCommand, getData() + sizeof(reason), - sizeof(Command_t)); - } - return reason; + Command_t *initialCommand) const { + ReturnValue_t reason = HasReturnvaluesIF::RETURN_FAILED; + std::memcpy(&reason, getData(), sizeof(reason)); + if(initialCommand != nullptr) { + std::memcpy(initialCommand, getData() + sizeof(reason), + sizeof(Command_t)); + } + return reason; +} + +uint8_t* CommandMessage::getData() { + return MessageQueueMessage::getData() + sizeof(Command_t); +} + +const uint8_t* CommandMessage::getData() const { + return MessageQueueMessage::getData() + sizeof(Command_t); } diff --git a/ipc/CommandMessage.h b/ipc/CommandMessage.h index a319a0cf..53df1c08 100644 --- a/ipc/CommandMessage.h +++ b/ipc/CommandMessage.h @@ -50,6 +50,22 @@ public: */ virtual ~CommandMessage() {} + /** + * Read the DeviceHandlerCommand_t that is stored in the message, + * usually used after receiving. + * + * @return the Command stored in the Message + */ + virtual Command_t getCommand() const override; + /** + * Set the command type of the message. Default implementation also + * sets the message type, which will be the first byte of the command ID. + * @param the Command to be sent + */ + virtual void setCommand(Command_t command); + + virtual uint8_t* getData() override; + virtual const uint8_t* getData() const override; /** * Get the first parameter of the message * @return the first Parameter of the message @@ -105,20 +121,6 @@ public: virtual void clear() override; - /** - * Read the DeviceHandlerCommand_t that is stored in the message, - * usually used after receiving. - * - * @return the Command stored in the Message - */ - virtual Command_t getCommand() const override; - /** - * Set the command type of the message. Default implementation also - * sets the message type, which will be the first byte of the command ID. - * @param the Command to be sent - */ - virtual void setCommand(Command_t command); - /** * Extract message ID, which is the first byte of the command ID for the * default implementation. diff --git a/ipc/CommandMessageCleaner.cpp b/ipc/CommandMessageCleaner.cpp index 7153a8e7..23e6e168 100644 --- a/ipc/CommandMessageCleaner.cpp +++ b/ipc/CommandMessageCleaner.cpp @@ -9,34 +9,34 @@ #include #include -void CommandMessageCleaner::clearCommandMessage(CommandMessageIF* message) { +void CommandMessageCleaner::clearCommandMessage(CommandMessage* message) { switch(message->getMessageType()){ case messagetypes::MODE_COMMAND: - ModeMessage::clear(dynamic_cast(message)); + ModeMessage::clear(message); break; case messagetypes::HEALTH_COMMAND: - HealthMessage::clear(dynamic_cast(message)); + HealthMessage::clear(message); break; case messagetypes::MODE_SEQUENCE: - ModeSequenceMessage::clear(dynamic_cast(message)); + ModeSequenceMessage::clear(message); break; case messagetypes::ACTION: - ActionMessage::clear(dynamic_cast(message)); + ActionMessage::clear(message); break; case messagetypes::DEVICE_HANDLER_COMMAND: - DeviceHandlerMessage::clear(dynamic_cast(message)); + DeviceHandlerMessage::clear(message); break; case messagetypes::MEMORY: - MemoryMessage::clear(dynamic_cast(message)); + MemoryMessage::clear(message); break; case messagetypes::MONITORING: - MonitoringMessage::clear(dynamic_cast(message)); + MonitoringMessage::clear(message); break; case messagetypes::TM_STORE: - TmStoreMessage::clear(dynamic_cast(message)); + TmStoreMessage::clear(message); break; case messagetypes::PARAMETER: - ParameterMessage::clear(dynamic_cast(message)); + ParameterMessage::clear(message); break; default: messagetypes::clearMissionMessage(message); diff --git a/ipc/CommandMessageCleaner.h b/ipc/CommandMessageCleaner.h index 0bd369a2..48aaa478 100644 --- a/ipc/CommandMessageCleaner.h +++ b/ipc/CommandMessageCleaner.h @@ -1,15 +1,15 @@ #ifndef FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_ #define FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_ -#include +#include namespace messagetypes { // Implemented in config. -void clearMissionMessage(CommandMessageIF* message); +void clearMissionMessage(CommandMessage* message); } class CommandMessageCleaner { public: - static void clearCommandMessage(CommandMessageIF* message); + static void clearCommandMessage(CommandMessage* message); }; diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index 464a4f16..8eb669ed 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -80,12 +80,6 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message, } ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) { - if(message->getMessageSize() < maxMessageSize) { - sif::error << "MessageQueue::receiveMessage: Message size " - << message->getMessageSize() << - " too small to receive data!" << std::endl; - return HasReturnvaluesIF::RETURN_FAILED; - } BaseType_t result = xQueueReceive(handle,reinterpret_cast( message->getBuffer()), 0); if (result == pdPASS){