2020-06-07 23:38:15 +02:00
|
|
|
#ifndef FRAMEWORK_IPC_COMMANDMESSAGE_H_
|
|
|
|
#define FRAMEWORK_IPC_COMMANDMESSAGE_H_
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-06-24 00:24:15 +02:00
|
|
|
#include <framework/ipc/CommandMessageIF.h>
|
2020-06-09 02:46:19 +02:00
|
|
|
#include <framework/ipc/MessageQueueMessage.h>
|
2018-07-12 16:29:32 +02:00
|
|
|
#include <framework/ipc/FwMessageTypes.h>
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-02-27 19:00:51 +01:00
|
|
|
/**
|
2020-06-12 20:23:39 +02:00
|
|
|
* @brief Default command message used to pass command messages between tasks.
|
|
|
|
* Primary message type for IPC. Contains sender, 2-byte command ID
|
|
|
|
* field, and 2 4-byte parameters.
|
2020-06-09 02:46:19 +02:00
|
|
|
* @details
|
|
|
|
* It operates on an external memory which is contained inside a
|
2020-06-12 20:23:39 +02:00
|
|
|
* class implementing MessageQueueMessageIF by taking its address.
|
2020-06-09 02:46:19 +02:00
|
|
|
* This allows for a more flexible designs of message implementations.
|
|
|
|
* The pointer can be passed to different message implementations without
|
|
|
|
* the need of unnecessary copying.
|
2020-06-12 20:23:39 +02:00
|
|
|
*
|
|
|
|
* The command message is based of the generic MessageQueueMessage which
|
|
|
|
* currently has an internal message size of 28 bytes.
|
2020-06-07 23:38:15 +02:00
|
|
|
* @author Bastian Baetz
|
2020-02-27 19:00:51 +01:00
|
|
|
*/
|
2020-06-24 00:24:15 +02:00
|
|
|
class CommandMessage: public MessageQueueMessage, public CommandMessageIF {
|
2016-06-15 23:48:41 +02:00
|
|
|
public:
|
2020-06-24 00:24:15 +02:00
|
|
|
/**
|
|
|
|
* Default size can accomodate 2 4-byte parameters.
|
|
|
|
*/
|
|
|
|
static constexpr size_t DEFAULT_COMMAND_MESSAGE_SIZE =
|
|
|
|
CommandMessageIF::MINIMUM_COMMAND_MESSAGE_SIZE + sizeof(uint32_t);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
2020-06-24 00:24:15 +02:00
|
|
|
* @brief Default Constructor, does not initialize anything.
|
|
|
|
* @details
|
2020-06-07 23:38:15 +02:00
|
|
|
* This constructor should be used when receiving a Message, as the
|
|
|
|
* content is filled by the MessageQueue.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2020-06-24 00:24:15 +02:00
|
|
|
CommandMessage();
|
2016-06-15 23:48:41 +02:00
|
|
|
/**
|
2020-06-07 23:38:15 +02:00
|
|
|
* This constructor creates a new message with all message content
|
|
|
|
* initialized
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
|
|
|
* @param command The DeviceHandlerCommand_t that will be sent
|
|
|
|
* @param parameter1 The first parameter
|
|
|
|
* @param parameter2 The second parameter
|
|
|
|
*/
|
2020-06-24 00:24:15 +02:00
|
|
|
CommandMessage(Command_t command, uint32_t parameter1, uint32_t parameter2);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
2020-06-09 02:46:19 +02:00
|
|
|
* @brief Default Destructor
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2020-06-09 02:46:19 +02:00
|
|
|
virtual ~CommandMessage() {}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-06-24 00:49:13 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
2020-06-24 02:00:26 +02:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
/**
|
|
|
|
* Get the first parameter of the message
|
|
|
|
* @return the first Parameter of the message
|
|
|
|
*/
|
|
|
|
uint32_t getParameter() const;
|
|
|
|
/**
|
|
|
|
* Set the first parameter of the message
|
|
|
|
* @param the first parameter of the message
|
|
|
|
*/
|
|
|
|
void setParameter(uint32_t parameter1);
|
|
|
|
uint32_t getParameter2() const;
|
|
|
|
void setParameter2(uint32_t parameter2);
|
2020-06-24 02:00:26 +02:00
|
|
|
uint32_t getParameter3() const;
|
|
|
|
void setParameter3(uint32_t parameter3);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* check if a message was cleared
|
|
|
|
*
|
|
|
|
* @return if the command is CMD_NONE
|
|
|
|
*/
|
|
|
|
bool isClearedCommandMessage();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the command to REPLY_REJECTED with parameter UNKNOWN_COMMAND.
|
|
|
|
* Is needed quite often, so we better code it once only.
|
|
|
|
*/
|
2020-06-24 00:24:15 +02:00
|
|
|
void setToUnknownCommand() override;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-06-24 00:24:15 +02:00
|
|
|
/**
|
|
|
|
* A command message can be rejected and needs to offer a function
|
|
|
|
* to set a rejected reply
|
|
|
|
* @param reason
|
|
|
|
* @param initialCommand
|
|
|
|
*/
|
|
|
|
void setReplyRejected(ReturnValue_t reason,
|
|
|
|
Command_t initialCommand) override;
|
|
|
|
/**
|
|
|
|
* Corrensonding getter function.
|
|
|
|
* @param initialCommand
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
ReturnValue_t getReplyRejectedReason(
|
|
|
|
Command_t* initialCommand = nullptr) const override;
|
|
|
|
|
|
|
|
virtual void clear() override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract message ID, which is the first byte of the command ID for the
|
|
|
|
* default implementation.
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
virtual uint8_t getMessageType() const override;
|
|
|
|
|
|
|
|
/** MessageQueueMessageIF functions used for minimum size check. */
|
|
|
|
size_t getMinimumMessageSize() const override;
|
|
|
|
};
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
#endif /* COMMANDMESSAGE_H_ */
|