Line data Source code
1 : #ifndef FSFW_IPC_COMMANDMESSAGE_H_ 2 : #define FSFW_IPC_COMMANDMESSAGE_H_ 3 : 4 : #include "CommandMessageIF.h" 5 : #include "FwMessageTypes.h" 6 : #include "MessageQueueMessage.h" 7 : 8 : /** 9 : * @brief Default command message used to pass command messages between tasks. 10 : * Primary message type for IPC. Contains sender, 2-byte command ID 11 : * field, and 3 4-byte parameter 12 : * @details 13 : * It operates on an external memory which is contained inside a 14 : * class implementing MessageQueueMessageIF by taking its address. 15 : * This allows for a more flexible designs of message implementations. 16 : * The pointer can be passed to different message implementations without 17 : * the need of unnecessary copying. 18 : * 19 : * The command message is based of the generic MessageQueueMessage which 20 : * currently has an internal message size of 28 bytes. 21 : * @author Bastian Baetz 22 : */ 23 : class CommandMessage : public MessageQueueMessage, public CommandMessageIF { 24 : public: 25 : /** 26 : * Default size can accomodate 3 4-byte parameters. 27 : */ 28 : static constexpr size_t DEFAULT_COMMAND_MESSAGE_SIZE = 29 : CommandMessageIF::MINIMUM_COMMAND_MESSAGE_SIZE + 3 * sizeof(uint32_t); 30 : 31 : /** 32 : * @brief Default Constructor, does not initialize anything. 33 : * @details 34 : * This constructor should be used when receiving a Message, as the 35 : * content is filled by the MessageQueue. 36 : */ 37 : CommandMessage(); 38 : /** 39 : * This constructor creates a new message with all message content 40 : * initialized 41 : * 42 : * @param command The DeviceHandlerCommand_t that will be sent 43 : * @param parameter1 The first parameter 44 : * @param parameter2 The second parameter 45 : */ 46 : CommandMessage(Command_t command, uint32_t parameter1, uint32_t parameter2); 47 : 48 : /** 49 : * @brief Default Destructor 50 : */ 51 102 : virtual ~CommandMessage() {} 52 : 53 : /** 54 : * Read the DeviceHandlerCommand_t that is stored in the message, 55 : * usually used after receiving. 56 : * 57 : * @return the Command stored in the Message 58 : */ 59 : virtual Command_t getCommand() const override; 60 : /** 61 : * Set the command type of the message. Default implementation also 62 : * sets the message type, which will be the first byte of the command ID. 63 : * @param the Command to be sent 64 : */ 65 : virtual void setCommand(Command_t command); 66 : 67 : virtual uint8_t* getData() override; 68 : virtual const uint8_t* getData() const override; 69 : 70 : /** 71 : * Get the first parameter of the message 72 : * @return the first Parameter of the message 73 : */ 74 : uint32_t getParameter() const; 75 : /** 76 : * Set the first parameter of the message 77 : * @param the first parameter of the message 78 : */ 79 : void setParameter(uint32_t parameter1); 80 : uint32_t getParameter2() const; 81 : void setParameter2(uint32_t parameter2); 82 : uint32_t getParameter3() const; 83 : void setParameter3(uint32_t parameter3); 84 : 85 : /** 86 : * check if a message was cleared 87 : * 88 : * @return if the command is CMD_NONE 89 : */ 90 : bool isClearedCommandMessage(); 91 : 92 : /** 93 : * Sets the command to REPLY_REJECTED with parameter UNKNOWN_COMMAND. 94 : * Is needed quite often, so we better code it once only. 95 : */ 96 : void setToUnknownCommand() override; 97 : 98 : /** 99 : * A command message can be rejected and needs to offer a function 100 : * to set a rejected reply 101 : * @param reason 102 : * @param initialCommand 103 : */ 104 : void setReplyRejected(ReturnValue_t reason, Command_t initialCommand) override; 105 : /** 106 : * Corrensonding getter function. 107 : * @param initialCommand 108 : * @return 109 : */ 110 : ReturnValue_t getReplyRejectedReason(Command_t* initialCommand = nullptr) const override; 111 : 112 : virtual void clear() override; 113 : void clearCommandMessage(); 114 : 115 : /** 116 : * Extract message ID, which is the first byte of the command ID for the 117 : * default implementation. 118 : * @return 119 : */ 120 : virtual uint8_t getMessageType() const override; 121 : 122 : /** MessageQueueMessageIF functions used for minimum size check. */ 123 : size_t getMinimumMessageSize() const override; 124 : }; 125 : 126 : #endif /* FSFW_IPC_COMMANDMESSAGE_H_ */