1
0
forked from fsfw/fsfw

removed CommandMessageBase, changed interfaces

This commit is contained in:
2020-06-24 00:24:15 +02:00
parent 905c1a92e3
commit 3bf29a7315
34 changed files with 348 additions and 382 deletions

View File

@ -1,57 +1,64 @@
#include <framework/ipc/CommandMessage.h>
#include <framework/ipc/CommandMessageCleaner.h>
#include <cstring>
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;
}
// if(receiverMessage->getMessageSize() <
// getMinimumMessageSize()) {
// sif::error << "CommandMessage::ComandMessage: Passed message buffer"
// " can not hold minimum "<< getMinimumMessageSize()
// << " bytes!" << std::endl;
// return;
// }
// internalMessage->setMessageSize(getMinimumMessageSize());
CommandMessage::CommandMessage() {
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
setCommand(CMD_NONE);
}
CommandMessage::CommandMessage(MessageQueueMessageIF* messageToSet,
Command_t command, uint32_t parameter1, uint32_t parameter2):
CommandMessage(messageToSet) {
CommandMessage::CommandMessage(Command_t command, uint32_t parameter1,
uint32_t parameter2) {
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
setCommand(command);
setParameter(parameter1);
setParameter2(parameter2);
}
Command_t CommandMessage::getCommand() const {
Command_t command;
std::memcpy(&command, getData(), sizeof(Command_t));
return command;
}
void CommandMessage::setCommand(Command_t command) {
std::memcpy(getData(), &command, sizeof(Command_t));
}
uint8_t CommandMessage::getMessageType() const {
// first byte of command ID.
return getCommand() >> 8 & 0xff;
}
uint32_t CommandMessage::getParameter() const {
uint32_t parameter1;
std::memcpy(&parameter1, CommandMessageBase::getData(), sizeof(parameter1));
std::memcpy(&parameter1, MessageQueueMessage::getData(), sizeof(parameter1));
return parameter1;
}
void CommandMessage::setParameter(uint32_t parameter1) {
std::memcpy(CommandMessageBase::getData(), &parameter1, sizeof(parameter1));
std::memcpy(MessageQueueMessage::getData(), &parameter1, sizeof(parameter1));
}
uint32_t CommandMessage::getParameter2() const {
uint32_t parameter2;
std::memcpy(&parameter2, CommandMessageBase::getData() + sizeof(uint32_t),
std::memcpy(&parameter2, MessageQueueMessage::getData() + sizeof(uint32_t),
sizeof(parameter2));
return parameter2;
}
void CommandMessage::setParameter2(uint32_t parameter2) {
std::memcpy(CommandMessageBase::getData() + sizeof(uint32_t), &parameter2,
std::memcpy(MessageQueueMessage::getData() + sizeof(uint32_t), &parameter2,
sizeof(parameter2));
}
//size_t CommandMessage::getMinimumMessageSize() const {
// return MINIMUM_COMMAND_MESSAGE_SIZE;
//}
size_t CommandMessage::getMinimumMessageSize() const {
return MINIMUM_COMMAND_MESSAGE_SIZE;
}
void CommandMessage::clear() {
CommandMessageCleaner::clearCommandMessage(this);
}
bool CommandMessage::isClearedCommandMessage() {
return getCommand() == CMD_NONE;
@ -62,3 +69,21 @@ void CommandMessage::setToUnknownCommand() {
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));
}
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;
}

View File

@ -1,7 +1,7 @@
#ifndef FRAMEWORK_IPC_COMMANDMESSAGE_H_
#define FRAMEWORK_IPC_COMMANDMESSAGE_H_
#include <framework/ipc/CommandMessageBase.h>
#include <framework/ipc/CommandMessageIF.h>
#include <framework/ipc/MessageQueueMessage.h>
#include <framework/ipc/FwMessageTypes.h>
@ -20,23 +20,21 @@
* currently has an internal message size of 28 bytes.
* @author Bastian Baetz
*/
class CommandMessage: public CommandMessageBase {
class CommandMessage: public MessageQueueMessage, public CommandMessageIF {
public:
/**
* This is the size of a message as it is seen by the MessageQueue.
* It can hold the CommandMessage header plus 2 4-byte parameters.
* 14 of the 24 available MessageQueueMessage bytes are used.
*/
static const size_t MINIMUM_COMMAND_MESSAGE_SIZE =
CommandMessageIF::HEADER_SIZE + 2 * sizeof(uint32_t);
/**
* Default size can accomodate 2 4-byte parameters.
*/
static constexpr size_t DEFAULT_COMMAND_MESSAGE_SIZE =
CommandMessageIF::MINIMUM_COMMAND_MESSAGE_SIZE + sizeof(uint32_t);
/**
* Default Constructor, does not initialize anything.
*
* @brief Default Constructor, does not initialize anything.
* @details
* This constructor should be used when receiving a Message, as the
* content is filled by the MessageQueue.
*/
CommandMessage(MessageQueueMessageIF* receiverMessage);
CommandMessage();
/**
* This constructor creates a new message with all message content
* initialized
@ -45,17 +43,13 @@ public:
* @param parameter1 The first parameter
* @param parameter2 The second parameter
*/
CommandMessage(MessageQueueMessageIF* messageToSet, Command_t command,
uint32_t parameter1, uint32_t parameter2);
CommandMessage(Command_t command, uint32_t parameter1, uint32_t parameter2);
/**
* @brief Default Destructor
*/
virtual ~CommandMessage() {}
/** MessageQueueMessageIF functions used for minimum size check. */
//size_t getMinimumMessageSize() const override;
/**
* Get the first parameter of the message
* @return the first Parameter of the message
@ -91,8 +85,49 @@ public:
* Sets the command to REPLY_REJECTED with parameter UNKNOWN_COMMAND.
* Is needed quite often, so we better code it once only.
*/
void setToUnknownCommand();
void setToUnknownCommand() override;
/**
* 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;
/**
* 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.
* @return
*/
virtual uint8_t getMessageType() const override;
/** MessageQueueMessageIF functions used for minimum size check. */
size_t getMinimumMessageSize() const override;
};
#endif /* COMMANDMESSAGE_H_ */

View File

@ -1,86 +1,86 @@
#include <framework/ipc/CommandMessageBase.h>
#include <framework/ipc/CommandMessageCleaner.h>
#include <cstring>
CommandMessageBase::CommandMessageBase(MessageQueueMessageIF *message):
internalMessage(message) {
}
Command_t CommandMessageBase::getCommand() const {
Command_t command;
std::memcpy(&command, internalMessage->getData(), sizeof(Command_t));
return command;
}
void CommandMessageBase::setCommand(Command_t command) {
std::memcpy(internalMessage->getData(), &command, sizeof(Command_t));
}
uint8_t CommandMessageBase::getMessageType() const {
// first byte of command ID.
return getCommand() >> 8 & 0xff;
}
MessageQueueId_t CommandMessageBase::getSender() const {
return internalMessage->getSender();
}
uint8_t* CommandMessageBase::getBuffer() {
return internalMessage->getBuffer();
}
void CommandMessageBase::setSender(MessageQueueId_t setId) {
internalMessage->setSender(setId);
}
const uint8_t* CommandMessageBase::getBuffer() const {
return internalMessage->getBuffer();
}
// Header includes command ID.
uint8_t* CommandMessageBase::getData() {
return internalMessage->getData() + sizeof(Command_t);
}
// Header includes command ID.
const uint8_t* CommandMessageBase::getData() const {
return internalMessage->getData() + sizeof(Command_t);
}
//void CommandMessageBase::setMessageSize(size_t messageSize) {
// //internalMessage->setMessageSize(messageSize);
//#include <framework/ipc/CommandMessageBase.h>
//#include <framework/ipc/CommandMessageCleaner.h>
//#include <cstring>
//
//CommandMessageBase::CommandMessageBase(MessageQueueMessageIF *message):
// internalMessage(message) {
//}
size_t CommandMessageBase::getMessageSize() const {
return internalMessage->getMessageSize();
}
MessageQueueMessageIF* CommandMessageBase::getInternalMessage() const {
return internalMessage;
}
//size_t CommandMessageBase::getMinimumMessageSize() const {
// return MINIMUM_COMMAND_MESSAGE_BASE_SIZE;
//
//Command_t CommandMessageBase::getCommand() const {
// Command_t command;
// std::memcpy(&command, internalMessage->getData(), sizeof(Command_t));
// return command;
//}
//
//void CommandMessageBase::setCommand(Command_t command) {
// std::memcpy(internalMessage->getData(), &command, sizeof(Command_t));
//}
//
//uint8_t CommandMessageBase::getMessageType() const {
// // first byte of command ID.
// return getCommand() >> 8 & 0xff;
//}
//
//MessageQueueId_t CommandMessageBase::getSender() const {
// return internalMessage->getSender();
//}
//
//uint8_t* CommandMessageBase::getBuffer() {
// return internalMessage->getBuffer();
//}
//
//void CommandMessageBase::setSender(MessageQueueId_t setId) {
// internalMessage->setSender(setId);
//}
//
//const uint8_t* CommandMessageBase::getBuffer() const {
// return internalMessage->getBuffer();
//}
//
//// Header includes command ID.
//uint8_t* CommandMessageBase::getData() {
// return internalMessage->getData() + sizeof(Command_t);
//}
//
//// Header includes command ID.
//const uint8_t* CommandMessageBase::getData() const {
// return internalMessage->getData() + sizeof(Command_t);
//}
//
////void CommandMessageBase::setMessageSize(size_t messageSize) {
//// //internalMessage->setMessageSize(messageSize);
////}
//
//size_t CommandMessageBase::getMessageSize() const {
// return internalMessage->getMessageSize();
//}
//
//MessageQueueMessageIF* CommandMessageBase::getInternalMessage() const {
// return internalMessage;
//}
//
////size_t CommandMessageBase::getMinimumMessageSize() const {
//// return MINIMUM_COMMAND_MESSAGE_BASE_SIZE;
////}
//
//void CommandMessageBase::setReplyRejected(ReturnValue_t reason,
// Command_t initialCommand) {
// std::memcpy(getData(), &reason, sizeof(reason));
// std::memcpy(getData() + sizeof(reason), &initialCommand,
// sizeof(initialCommand));
//}
//
//ReturnValue_t CommandMessageBase::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;
//}
//
//void CommandMessageBase::clear() {
// CommandMessageCleaner::clearCommandMessage(this);
//}
void CommandMessageBase::setReplyRejected(ReturnValue_t reason,
Command_t initialCommand) {
std::memcpy(getData(), &reason, sizeof(reason));
std::memcpy(getData() + sizeof(reason), &initialCommand,
sizeof(initialCommand));
}
ReturnValue_t CommandMessageBase::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;
}
void CommandMessageBase::clear() {
CommandMessageCleaner::clearCommandMessage(this);
}

View File

@ -23,67 +23,28 @@
*/
class CommandMessageBase: public CommandMessageIF {
public:
//! This minimum size is derived from the interface requirement to be able
//! to set a rejected reply, which contains a returnvalue and the initial
//! command.
static constexpr size_t MINIMUM_COMMAND_MESSAGE_BASE_SIZE =
CommandMessageIF::HEADER_SIZE + sizeof(ReturnValue_t) +
sizeof(Command_t);
CommandMessageBase(MessageQueueMessageIF* message);
/**
* 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.
* @return
*/
virtual uint8_t getMessageType() const override;
/*
* MessageQueueMessageIF functions, which generally just call the
* respective functions of the internal message queue message.
*/
virtual uint8_t * getBuffer() override;
virtual const uint8_t * getBuffer() const override;
virtual void setSender(MessageQueueId_t setId) override;
virtual MessageQueueId_t getSender() const override;
virtual uint8_t * getData() override;
virtual const uint8_t* getData() const override;
virtual size_t getMessageSize() const override;
// /*
// * MessageQueueMessageIF functions, which generally just call the
// * respective functions of the internal message queue message.
// */
// virtual uint8_t * getBuffer() override;
// virtual const uint8_t * getBuffer() const override;
// virtual void setSender(MessageQueueId_t setId) override;
// virtual MessageQueueId_t getSender() const override;
// virtual uint8_t * getData() override;
// virtual const uint8_t* getData() const override;
// virtual size_t getMessageSize() const override;
/**
* 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 MessageQueueMessageIF* getInternalMessage() const override;
//virtual MessageQueueMessageIF* getInternalMessage() const override;
virtual void clear() override;
protected:
/**
* @brief Pointer to the message containing the data.

View File

@ -5,20 +5,24 @@
#include <framework/ipc/FwMessageTypes.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
#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 {
class CommandMessageIF: virtual public MessageQueueMessageIF {
public:
static constexpr size_t HEADER_SIZE = sizeof(MessageQueueId_t) +
/**
* Header consists of sender ID and command ID.
*/
static constexpr size_t HEADER_SIZE = MessageQueueMessageIF::HEADER_SIZE +
sizeof(Command_t);
/**
* This minimum size is derived from the interface requirement to be able
* to set a rejected reply, which contains a returnvalue and the initial
* command.
*/
static constexpr size_t MINIMUM_COMMAND_MESSAGE_SIZE =
CommandMessageIF::HEADER_SIZE + sizeof(ReturnValue_t) +
sizeof(Command_t);
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_MESSAGE;
static const ReturnValue_t UNKNOWN_COMMAND = MAKE_RETURN_CODE(0x01);
@ -60,15 +64,9 @@ public:
virtual ReturnValue_t getReplyRejectedReason(
Command_t* initialCommand = nullptr) 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;
virtual void setToUnknownCommand() = 0;
virtual void clear() = 0;
};

View File

@ -1,10 +1,10 @@
#include <framework/ipc/MessageQueueMessage.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <string.h>
#include <framework/globalfunctions/arrayprinter.h>
#include <cstring>
MessageQueueMessage::MessageQueueMessage() :
messageSize(this->HEADER_SIZE) {
messageSize(getMinimumMessageSize()) {
memset(this->internalBuffer, 0, sizeof(this->internalBuffer));
}
@ -51,17 +51,15 @@ void MessageQueueMessage::setSender(MessageQueueId_t setId) {
memcpy(this->internalBuffer, &setId, sizeof(MessageQueueId_t));
}
//size_t MessageQueueMessage::getMinimumMessageSize() const {
// return this->HEADER_SIZE;
//}
void MessageQueueMessage::print() {
sif::debug << "MessageQueueMessage has size: " << this->messageSize <<
std::hex << std::endl;
for (uint8_t count = 0; count < this->messageSize; count++) {
sif::debug << (uint32_t) this->internalBuffer[count] << ":";
void MessageQueueMessage::print(bool printWholeMessage) {
sif::debug << "MessageQueueMessage content: " << std::endl;
if(printWholeMessage) {
arrayprinter::print(getData(), getMaximumMessageSize());
}
sif::debug << std::dec << std::endl;
else {
arrayprinter::print(getData(), getMessageSize());
}
}
void MessageQueueMessage::clear() {
@ -69,9 +67,18 @@ void MessageQueueMessage::clear() {
}
size_t MessageQueueMessage::getMessageSize() const {
return this->MAX_MESSAGE_SIZE;
return this->messageSize;
}
void MessageQueueMessage::setMessageSize(size_t messageSize) {
this->messageSize = messageSize;
}
size_t MessageQueueMessage::getMinimumMessageSize() const {
return this->MIN_MESSAGE_SIZE;
}
size_t MessageQueueMessage::getMaximumMessageSize() const {
return this->MAX_MESSAGE_SIZE;
}
//void MessageQueueMessage::setMessageSize(size_t messageSize) {
// this->messageSize = messageSize;
//}

View File

@ -23,7 +23,7 @@
* receive messages from other tasks.
* @ingroup message_queue
*/
class MessageQueueMessage: public MessageQueueMessageIF {
class MessageQueueMessage: virtual public MessageQueueMessageIF {
public:
/**
* @brief The class is initialized empty with this constructor.
@ -74,11 +74,7 @@ public:
* as small as possible.
*/
static const size_t MAX_DATA_SIZE = 24;
/**
* @brief This constants defines the size of the header,
* which is added to every message.
*/
static const size_t HEADER_SIZE = sizeof(MessageQueueId_t);
/**
* @brief This constant defines the maximum total size in bytes
* of a sent message.
@ -141,12 +137,14 @@ public:
void setSender(MessageQueueId_t setId) override;
virtual size_t getMessageSize() const override;
virtual void setMessageSize(size_t messageSize) override;
virtual size_t getMinimumMessageSize() const override;
virtual size_t getMaximumMessageSize() const override;
/**
* @brief This is a debug method that prints the content
* (till messageSize) to the debug output.
* @brief This is a debug method that prints the content.
*/
void print();
void print(bool printWholeMessage);
};
#endif /* MESSAGEQUEUEMESSAGE_H_ */

View File

@ -18,7 +18,12 @@ typedef uint32_t MessageQueueId_t;
class MessageQueueMessageIF {
public:
static const MessageQueueId_t NO_QUEUE = 0xffffffff;
static const MessageQueueId_t NO_QUEUE = -1;
/**
* @brief This constants defines the size of the header,
* which is added to every message.
*/
static const size_t HEADER_SIZE = sizeof(MessageQueueId_t);
virtual ~MessageQueueMessageIF() {};
@ -73,6 +78,10 @@ public:
*/
virtual size_t getMessageSize() const = 0;
virtual void setMessageSize(size_t messageSize) = 0;
virtual size_t getMinimumMessageSize() const = 0;
virtual size_t getMaximumMessageSize() const = 0;
};