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-09 02:46:19 +02:00
|
|
|
#include <framework/ipc/MessageQueueMessage.h>
|
2018-07-12 16:29:32 +02:00
|
|
|
#include <framework/ipc/FwMessageTypes.h>
|
|
|
|
#include <config/ipc/MissionMessageTypes.h>
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-06-09 02:46:19 +02:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
#define MAKE_COMMAND_ID( number ) ((MESSAGE_ID << 8) + (number))
|
2020-06-07 23:38:15 +02:00
|
|
|
typedef uint16_t Command_t;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-02-27 19:00:51 +01:00
|
|
|
/**
|
2020-06-09 02:46:19 +02:00
|
|
|
* @brief Used to pass command messages between tasks. Primary message type
|
|
|
|
* for IPC. Contains sender, 2-byte command field, and 2 4-byte
|
|
|
|
* parameters.
|
|
|
|
* @details
|
|
|
|
* It operates on an external memory which is contained inside a
|
|
|
|
* MessageQueueMessage by taking its address.
|
|
|
|
* 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-07 23:38:15 +02:00
|
|
|
* @author Bastian Baetz
|
2020-02-27 19:00:51 +01:00
|
|
|
*/
|
2020-06-09 02:18:39 +02:00
|
|
|
class CommandMessage: public MessageQueueMessageIF {
|
2016-06-15 23:48:41 +02:00
|
|
|
public:
|
2018-07-12 16:29:32 +02:00
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_MESSAGE;
|
2020-06-09 02:18:39 +02:00
|
|
|
static const ReturnValue_t UNKNOWN_COMMAND = MAKE_RETURN_CODE(0x01);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
|
2020-06-08 12:25:20 +02:00
|
|
|
static const uint8_t MESSAGE_ID = messagetypes::COMMAND;
|
2020-06-07 23:38:15 +02:00
|
|
|
//! Used internally, will be ignored
|
|
|
|
static const Command_t CMD_NONE = MAKE_COMMAND_ID( 0 );
|
2016-06-15 23:48:41 +02:00
|
|
|
static const Command_t REPLY_COMMAND_OK = MAKE_COMMAND_ID( 3 );
|
2020-06-07 23:38:15 +02:00
|
|
|
//! Reply indicating that the current command was rejected,
|
|
|
|
//! par1 should contain the error code
|
|
|
|
static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID( 0xD1 );
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
/**
|
2020-06-08 01:22:21 +02:00
|
|
|
* This is the size of a message as it is seen by the MessageQueue.
|
|
|
|
* 14 of the 24 available MessageQueueMessage bytes are used.
|
2016-06-15 23:48:41 +02:00
|
|
|
*/
|
2020-06-09 02:18:39 +02:00
|
|
|
static const size_t COMMAND_MESSAGE_SIZE = MessageQueueMessage::HEADER_SIZE
|
2016-06-15 23:48:41 +02:00
|
|
|
+ sizeof(Command_t) + 2 * sizeof(uint32_t);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default Constructor, does not initialize anything.
|
|
|
|
*
|
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-09 02:18:39 +02:00
|
|
|
CommandMessage(MessageQueueMessage* receiverMessage);
|
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-09 02:18:39 +02:00
|
|
|
CommandMessage(MessageQueueMessage* messageToSet, Command_t command,
|
2016-06-15 23:48:41 +02:00
|
|
|
uint32_t parameter1, uint32_t parameter2);
|
|
|
|
|
|
|
|
/**
|
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-07 23:38:15 +02:00
|
|
|
* Read the DeviceHandlerCommand_t that is stored in the message,
|
|
|
|
* usually used after receiving.
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
|
|
|
* @return the Command stored in the Message
|
|
|
|
*/
|
|
|
|
Command_t getCommand() const;
|
|
|
|
|
2020-06-09 02:46:19 +02:00
|
|
|
/*
|
|
|
|
* MessageQueueMessageIF functions, which generally just call the
|
|
|
|
* respective functions of the internal message
|
2020-06-09 02:18:39 +02:00
|
|
|
*/
|
2020-06-09 02:46:19 +02:00
|
|
|
uint8_t * getBuffer() override;
|
|
|
|
const uint8_t * getBuffer() const override;
|
2020-06-09 02:18:39 +02:00
|
|
|
void setSender(MessageQueueId_t setId) override;
|
|
|
|
MessageQueueId_t getSender() const override;
|
2020-06-09 02:46:19 +02:00
|
|
|
uint8_t * getData() override;
|
|
|
|
const uint8_t* getData() const override;
|
|
|
|
size_t getMinimumMessageSize() const override;
|
2020-06-09 02:18:39 +02:00
|
|
|
|
2020-06-09 02:46:19 +02:00
|
|
|
/**
|
|
|
|
* Extract message ID, which is the first byte of the command ID.
|
|
|
|
* @return
|
|
|
|
*/
|
2020-06-08 12:25:20 +02:00
|
|
|
uint8_t getMessageType() const;
|
2016-06-15 23:48:41 +02:00
|
|
|
/**
|
2020-06-09 02:46:19 +02:00
|
|
|
* Set the command type of the message
|
2016-06-15 23:48:41 +02:00
|
|
|
* @param the Command to be sent
|
|
|
|
*/
|
|
|
|
void setCommand(Command_t command);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the second parameter of the message
|
|
|
|
* @return the second Parameter of the message
|
|
|
|
*/
|
|
|
|
uint32_t getParameter2() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the second parameter of the message
|
|
|
|
* @param the second parameter of the message
|
|
|
|
*/
|
|
|
|
void setParameter2(uint32_t parameter2);
|
|
|
|
|
2020-06-09 02:46:19 +02:00
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
/**
|
|
|
|
* Set the command to CMD_NONE and try to find
|
|
|
|
* the correct class to handle a more detailed
|
|
|
|
* clear.
|
2018-07-12 16:29:32 +02:00
|
|
|
* Also, calls a mission-specific clearMissionMessage
|
|
|
|
* function to separate between framework and mission
|
|
|
|
* messages. Not optimal, may be replaced by totally
|
|
|
|
* different auto-delete solution (e.g. smart pointers).
|
2016-06-15 23:48:41 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
void clearCommandMessage();
|
2020-06-09 02:46:19 +02:00
|
|
|
void clear() override;
|
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.
|
|
|
|
*/
|
2018-07-12 16:29:32 +02:00
|
|
|
void setToUnknownCommand();
|
2020-06-07 23:38:15 +02:00
|
|
|
void setReplyRejected(ReturnValue_t reason,
|
|
|
|
Command_t initialCommand = CMD_NONE);
|
2020-06-09 02:18:39 +02:00
|
|
|
|
|
|
|
private:
|
2020-06-09 02:46:19 +02:00
|
|
|
/**
|
|
|
|
* @brief Pointer to the message containing the data.
|
|
|
|
* @details
|
|
|
|
* The command message does not actually own the memory containing a
|
|
|
|
* message, it just oprates on it via a pointer to a message queue message.
|
|
|
|
*/
|
2020-06-09 02:18:39 +02:00
|
|
|
MessageQueueMessage* internalMessage;
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* COMMANDMESSAGE_H_ */
|