1
0
forked from fsfw/fsfw

evil hidden bug found.

CSB uses CommandMessageIF now
This commit is contained in:
2020-06-13 17:37:48 +02:00
parent 7b538e9750
commit 6b67f46c80
17 changed files with 214 additions and 92 deletions

View File

@ -9,18 +9,25 @@
#include <framework/tmstorage/TmStoreMessage.h>
#include <framework/parameters/ParameterMessage.h>
CommandMessage::CommandMessage(MessageQueueMessage* receiverMessage):
CommandMessage::CommandMessage(MessageQueueMessageIF* receiverMessage):
CommandMessageBase(receiverMessage) {
if(receiverMessage == nullptr) {
sif::error << "CommandMessage::CommandMessage: Don't pass a nullptr"
" as the message queue message, pass the address of an actual"
" message!" << std::endl;
return;
}
internalMessage->setMessageSize(COMMAND_MESSAGE_SIZE);
setCommand(CMD_NONE);
if(receiverMessage->getMaximumMessageSize() <
MINIMUM_COMMAND_MESSAGE_SIZE) {
sif::error << "CommandMessage::ComandMessage: Passed message buffer"
" can not hold minimum "<< MINIMUM_COMMAND_MESSAGE_SIZE
<< " bytes!" << std::endl;
return;
}
internalMessage->setMessageSize(MINIMUM_COMMAND_MESSAGE_SIZE);
}
CommandMessage::CommandMessage(MessageQueueMessage* messageToSet,
CommandMessage::CommandMessage(MessageQueueMessageIF* messageToSet,
Command_t command, uint32_t parameter1, uint32_t parameter2):
CommandMessageBase(messageToSet) {
if(messageToSet == nullptr) {
@ -28,7 +35,14 @@ CommandMessage::CommandMessage(MessageQueueMessage* messageToSet,
" as the message queue message, pass the address of an actual"
" message!" << std::endl;
}
internalMessage->setMessageSize(COMMAND_MESSAGE_SIZE);
if(messageToSet->getMaximumMessageSize() <
MINIMUM_COMMAND_MESSAGE_SIZE) {
sif::error << "CommandMessage::ComandMessage: Passed message buffer"
" can not hold minimum "<< MINIMUM_COMMAND_MESSAGE_SIZE
<< " bytes!" << std::endl;
return;
}
internalMessage->setMessageSize(MINIMUM_COMMAND_MESSAGE_SIZE);
setCommand(command);
setParameter(parameter1);
setParameter2(parameter2);
@ -57,7 +71,7 @@ void CommandMessage::setParameter2(uint32_t parameter2) {
}
size_t CommandMessage::getMinimumMessageSize() const {
return COMMAND_MESSAGE_SIZE;
return MINIMUM_COMMAND_MESSAGE_SIZE;
}
size_t CommandMessage::getMaximumMessageSize() const {
@ -81,6 +95,13 @@ void CommandMessage::setReplyRejected(ReturnValue_t reason,
setParameter2(initialCommand);
}
ReturnValue_t CommandMessage::getRejectedReplyReason(
Command_t* initialCommand) const {
if(initialCommand != nullptr) {
*initialCommand = getParameter2();
}
return getParameter();
}
void CommandMessage::clear() {
clearCommandMessage();

View File

@ -42,8 +42,9 @@ public:
* 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 = MessageQueueMessage::HEADER_SIZE
+ sizeof(Command_t) + 2 * sizeof(uint32_t);
static const size_t MINIMUM_COMMAND_MESSAGE_SIZE =
MessageQueueMessage::HEADER_SIZE + sizeof(Command_t) +
2 * sizeof(uint32_t);
/**
* Default Constructor, does not initialize anything.
@ -51,7 +52,7 @@ public:
* This constructor should be used when receiving a Message, as the
* content is filled by the MessageQueue.
*/
CommandMessage(MessageQueueMessage* receiverMessage);
CommandMessage(MessageQueueMessageIF* receiverMessage);
/**
* This constructor creates a new message with all message content
* initialized
@ -60,7 +61,7 @@ public:
* @param parameter1 The first parameter
* @param parameter2 The second parameter
*/
CommandMessage(MessageQueueMessage* messageToSet, Command_t command,
CommandMessage(MessageQueueMessageIF* messageToSet, Command_t command,
uint32_t parameter1, uint32_t parameter2);
/**
@ -121,8 +122,11 @@ public:
* Is needed quite often, so we better code it once only.
*/
void setToUnknownCommand();
void setReplyRejected(ReturnValue_t reason,
Command_t initialCommand = CMD_NONE);
ReturnValue_t getRejectedReplyReason(
Command_t* initialCommand = nullptr) const;
};

View File

@ -12,7 +12,7 @@ Command_t CommandMessageBase::getCommand() const {
}
void CommandMessageBase::setCommand(Command_t command) {
std::memcpy(internalMessage->getData(), &command, sizeof(command));
std::memcpy(internalMessage->getData(), &command, sizeof(Command_t));
}
uint8_t CommandMessageBase::getMessageType() const {
@ -53,3 +53,7 @@ void CommandMessageBase::setMessageSize(size_t messageSize) {
size_t CommandMessageBase::getMessageSize() const {
return internalMessage->getMessageSize();
}
MessageQueueMessageIF* CommandMessageBase::getInternalMessage() const {
return internalMessage;
}

View File

@ -22,6 +22,9 @@
*/
class CommandMessageBase: public CommandMessageIF {
public:
static constexpr size_t HEADER_SIZE = sizeof(MessageQueueId_t) +
sizeof(Command_t);
CommandMessageBase(MessageQueueMessageIF* message);
/**
@ -58,6 +61,7 @@ public:
virtual void setMessageSize(size_t messageSize) override;
virtual size_t getMessageSize() const override;
virtual MessageQueueMessageIF* getInternalMessage() const override;
protected:
/**
* @brief Pointer to the message containing the data.
@ -65,7 +69,7 @@ protected:
* 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.
*/
MessageQueueMessageIF* internalMessage;
MessageQueueMessageIF* internalMessage = nullptr;
};

View File

@ -6,6 +6,12 @@
#define MAKE_COMMAND_ID( number ) ((MESSAGE_ID << 8) + (number))
typedef uint16_t Command_t;
// TODO: actually, this interface propably does not have to implement
// MQM IF, because there is a getter function for the internal message..
// But it is also convenient to have the full access to all MQM IF functions.
// That way, I can just pass CommandMessages to functions expecting a MQM IF.
// The command message implementations just forwards the calls. Maybe
// we should just leave it like that.
class CommandMessageIF: public MessageQueueMessageIF {
public:
virtual ~CommandMessageIF() {};
@ -20,6 +26,16 @@ public:
* @return
*/
virtual uint8_t getMessageType() const = 0;
/**
* This function is used to get a pointer to the internal message, as
* the command message implementations always operate on the memory
* contained in the message queue message implementation.
* This pointer can be used to set the internal message of different
* command message implementations.
* @return
*/
virtual MessageQueueMessageIF* getInternalMessage() const = 0;
};
#endif /* FRAMEWORK_IPC_COMMANDMESSAGEIF_H_ */

View File

@ -88,12 +88,12 @@ public:
* queue in the system. So, a change here may have significant impact on
* the required resources.
*/
static const size_t MAX_MESSAGE_SIZE = MAX_DATA_SIZE + HEADER_SIZE;
static constexpr size_t MAX_MESSAGE_SIZE = MAX_DATA_SIZE + HEADER_SIZE;
/**
* @brief Defines the minimum size of a message where only the
* header is included
*/
static const size_t MIN_MESSAGE_SIZE = HEADER_SIZE;
static constexpr size_t MIN_MESSAGE_SIZE = HEADER_SIZE;
private:
/**
* @brief This is the internal buffer that contains the