renormalized line endings
This commit is contained in:
@ -1,111 +1,111 @@
|
||||
#include "CommandMessage.h"
|
||||
#include "CommandMessageCleaner.h"
|
||||
#include <cstring>
|
||||
|
||||
CommandMessage::CommandMessage() {
|
||||
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
|
||||
setCommand(CMD_NONE);
|
||||
}
|
||||
|
||||
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, MessageQueueMessage::getData(), sizeof(Command_t));
|
||||
return command;
|
||||
}
|
||||
|
||||
void CommandMessage::setCommand(Command_t command) {
|
||||
std::memcpy(MessageQueueMessage::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(¶meter1, this->getData(), sizeof(parameter1));
|
||||
return parameter1;
|
||||
}
|
||||
|
||||
void CommandMessage::setParameter(uint32_t parameter1) {
|
||||
std::memcpy(this->getData(), ¶meter1, sizeof(parameter1));
|
||||
}
|
||||
|
||||
uint32_t CommandMessage::getParameter2() const {
|
||||
uint32_t parameter2;
|
||||
std::memcpy(¶meter2, this->getData() + sizeof(uint32_t),
|
||||
sizeof(parameter2));
|
||||
return parameter2;
|
||||
}
|
||||
|
||||
void CommandMessage::setParameter2(uint32_t parameter2) {
|
||||
std::memcpy(this->getData() + sizeof(uint32_t), ¶meter2,
|
||||
sizeof(parameter2));
|
||||
}
|
||||
|
||||
uint32_t CommandMessage::getParameter3() const {
|
||||
uint32_t parameter3;
|
||||
std::memcpy(¶meter3, this->getData() + 2 * sizeof(uint32_t),
|
||||
sizeof(parameter3));
|
||||
return parameter3;
|
||||
}
|
||||
|
||||
void CommandMessage::setParameter3(uint32_t parameter3) {
|
||||
std::memcpy(this->getData() + 2 * sizeof(uint32_t), ¶meter3,
|
||||
sizeof(parameter3));
|
||||
}
|
||||
|
||||
size_t CommandMessage::getMinimumMessageSize() const {
|
||||
return MINIMUM_COMMAND_MESSAGE_SIZE;
|
||||
}
|
||||
|
||||
void CommandMessage::clearCommandMessage() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void CommandMessage::clear() {
|
||||
CommandMessageCleaner::clearCommandMessage(this);
|
||||
}
|
||||
|
||||
bool CommandMessage::isClearedCommandMessage() {
|
||||
return getCommand() == CMD_NONE;
|
||||
}
|
||||
|
||||
void CommandMessage::setToUnknownCommand() {
|
||||
Command_t initialCommand = getCommand();
|
||||
this->clear();
|
||||
setReplyRejected(UNKNOWN_COMMAND, initialCommand);
|
||||
}
|
||||
|
||||
void CommandMessage::setReplyRejected(ReturnValue_t reason,
|
||||
Command_t initialCommand) {
|
||||
setCommand(REPLY_REJECTED);
|
||||
setParameter(reason);
|
||||
setParameter2(initialCommand);
|
||||
}
|
||||
|
||||
ReturnValue_t CommandMessage::getReplyRejectedReason(
|
||||
Command_t *initialCommand) const {
|
||||
ReturnValue_t reason = getParameter();
|
||||
if(initialCommand != nullptr) {
|
||||
*initialCommand = getParameter2();
|
||||
}
|
||||
return reason;
|
||||
}
|
||||
|
||||
uint8_t* CommandMessage::getData() {
|
||||
return MessageQueueMessage::getData() + sizeof(Command_t);
|
||||
}
|
||||
|
||||
const uint8_t* CommandMessage::getData() const {
|
||||
return MessageQueueMessage::getData() + sizeof(Command_t);
|
||||
}
|
||||
#include "CommandMessage.h"
|
||||
#include "CommandMessageCleaner.h"
|
||||
#include <cstring>
|
||||
|
||||
CommandMessage::CommandMessage() {
|
||||
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
|
||||
setCommand(CMD_NONE);
|
||||
}
|
||||
|
||||
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, MessageQueueMessage::getData(), sizeof(Command_t));
|
||||
return command;
|
||||
}
|
||||
|
||||
void CommandMessage::setCommand(Command_t command) {
|
||||
std::memcpy(MessageQueueMessage::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(¶meter1, this->getData(), sizeof(parameter1));
|
||||
return parameter1;
|
||||
}
|
||||
|
||||
void CommandMessage::setParameter(uint32_t parameter1) {
|
||||
std::memcpy(this->getData(), ¶meter1, sizeof(parameter1));
|
||||
}
|
||||
|
||||
uint32_t CommandMessage::getParameter2() const {
|
||||
uint32_t parameter2;
|
||||
std::memcpy(¶meter2, this->getData() + sizeof(uint32_t),
|
||||
sizeof(parameter2));
|
||||
return parameter2;
|
||||
}
|
||||
|
||||
void CommandMessage::setParameter2(uint32_t parameter2) {
|
||||
std::memcpy(this->getData() + sizeof(uint32_t), ¶meter2,
|
||||
sizeof(parameter2));
|
||||
}
|
||||
|
||||
uint32_t CommandMessage::getParameter3() const {
|
||||
uint32_t parameter3;
|
||||
std::memcpy(¶meter3, this->getData() + 2 * sizeof(uint32_t),
|
||||
sizeof(parameter3));
|
||||
return parameter3;
|
||||
}
|
||||
|
||||
void CommandMessage::setParameter3(uint32_t parameter3) {
|
||||
std::memcpy(this->getData() + 2 * sizeof(uint32_t), ¶meter3,
|
||||
sizeof(parameter3));
|
||||
}
|
||||
|
||||
size_t CommandMessage::getMinimumMessageSize() const {
|
||||
return MINIMUM_COMMAND_MESSAGE_SIZE;
|
||||
}
|
||||
|
||||
void CommandMessage::clearCommandMessage() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void CommandMessage::clear() {
|
||||
CommandMessageCleaner::clearCommandMessage(this);
|
||||
}
|
||||
|
||||
bool CommandMessage::isClearedCommandMessage() {
|
||||
return getCommand() == CMD_NONE;
|
||||
}
|
||||
|
||||
void CommandMessage::setToUnknownCommand() {
|
||||
Command_t initialCommand = getCommand();
|
||||
this->clear();
|
||||
setReplyRejected(UNKNOWN_COMMAND, initialCommand);
|
||||
}
|
||||
|
||||
void CommandMessage::setReplyRejected(ReturnValue_t reason,
|
||||
Command_t initialCommand) {
|
||||
setCommand(REPLY_REJECTED);
|
||||
setParameter(reason);
|
||||
setParameter2(initialCommand);
|
||||
}
|
||||
|
||||
ReturnValue_t CommandMessage::getReplyRejectedReason(
|
||||
Command_t *initialCommand) const {
|
||||
ReturnValue_t reason = getParameter();
|
||||
if(initialCommand != nullptr) {
|
||||
*initialCommand = getParameter2();
|
||||
}
|
||||
return reason;
|
||||
}
|
||||
|
||||
uint8_t* CommandMessage::getData() {
|
||||
return MessageQueueMessage::getData() + sizeof(Command_t);
|
||||
}
|
||||
|
||||
const uint8_t* CommandMessage::getData() const {
|
||||
return MessageQueueMessage::getData() + sizeof(Command_t);
|
||||
}
|
||||
|
@ -1,129 +1,129 @@
|
||||
#ifndef FSFW_IPC_COMMANDMESSAGE_H_
|
||||
#define FSFW_IPC_COMMANDMESSAGE_H_
|
||||
|
||||
#include "CommandMessageIF.h"
|
||||
#include "MessageQueueMessage.h"
|
||||
#include "FwMessageTypes.h"
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @details
|
||||
* It operates on an external memory which is contained inside a
|
||||
* class implementing MessageQueueMessageIF 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.
|
||||
*
|
||||
* The command message is based of the generic MessageQueueMessage which
|
||||
* currently has an internal message size of 28 bytes.
|
||||
* @author Bastian Baetz
|
||||
*/
|
||||
class CommandMessage: public MessageQueueMessage, public CommandMessageIF {
|
||||
public:
|
||||
/**
|
||||
* Default size can accomodate 2 4-byte parameters.
|
||||
*/
|
||||
static constexpr size_t DEFAULT_COMMAND_MESSAGE_SIZE =
|
||||
CommandMessageIF::MINIMUM_COMMAND_MESSAGE_SIZE + sizeof(uint32_t);
|
||||
|
||||
/**
|
||||
* @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();
|
||||
/**
|
||||
* This constructor creates a new message with all message content
|
||||
* initialized
|
||||
*
|
||||
* @param command The DeviceHandlerCommand_t that will be sent
|
||||
* @param parameter1 The first parameter
|
||||
* @param parameter2 The second parameter
|
||||
*/
|
||||
CommandMessage(Command_t command, uint32_t parameter1, uint32_t parameter2);
|
||||
|
||||
/**
|
||||
* @brief Default Destructor
|
||||
*/
|
||||
virtual ~CommandMessage() {}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
uint32_t getParameter3() const;
|
||||
void setParameter3(uint32_t parameter3);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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;
|
||||
void clearCommandMessage();
|
||||
|
||||
/**
|
||||
* 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 /* FSFW_IPC_COMMANDMESSAGE_H_ */
|
||||
#ifndef FSFW_IPC_COMMANDMESSAGE_H_
|
||||
#define FSFW_IPC_COMMANDMESSAGE_H_
|
||||
|
||||
#include "CommandMessageIF.h"
|
||||
#include "MessageQueueMessage.h"
|
||||
#include "FwMessageTypes.h"
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @details
|
||||
* It operates on an external memory which is contained inside a
|
||||
* class implementing MessageQueueMessageIF 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.
|
||||
*
|
||||
* The command message is based of the generic MessageQueueMessage which
|
||||
* currently has an internal message size of 28 bytes.
|
||||
* @author Bastian Baetz
|
||||
*/
|
||||
class CommandMessage: public MessageQueueMessage, public CommandMessageIF {
|
||||
public:
|
||||
/**
|
||||
* Default size can accomodate 2 4-byte parameters.
|
||||
*/
|
||||
static constexpr size_t DEFAULT_COMMAND_MESSAGE_SIZE =
|
||||
CommandMessageIF::MINIMUM_COMMAND_MESSAGE_SIZE + sizeof(uint32_t);
|
||||
|
||||
/**
|
||||
* @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();
|
||||
/**
|
||||
* This constructor creates a new message with all message content
|
||||
* initialized
|
||||
*
|
||||
* @param command The DeviceHandlerCommand_t that will be sent
|
||||
* @param parameter1 The first parameter
|
||||
* @param parameter2 The second parameter
|
||||
*/
|
||||
CommandMessage(Command_t command, uint32_t parameter1, uint32_t parameter2);
|
||||
|
||||
/**
|
||||
* @brief Default Destructor
|
||||
*/
|
||||
virtual ~CommandMessage() {}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
uint32_t getParameter3() const;
|
||||
void setParameter3(uint32_t parameter3);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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;
|
||||
void clearCommandMessage();
|
||||
|
||||
/**
|
||||
* 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 /* FSFW_IPC_COMMANDMESSAGE_H_ */
|
||||
|
@ -1,45 +1,45 @@
|
||||
#include "../ipc/CommandMessageCleaner.h"
|
||||
|
||||
#include "../devicehandlers/DeviceHandlerMessage.h"
|
||||
#include "../health/HealthMessage.h"
|
||||
#include "../memory/MemoryMessage.h"
|
||||
#include "../modes/ModeMessage.h"
|
||||
#include "../monitoring/MonitoringMessage.h"
|
||||
#include "../subsystem/modes/ModeSequenceMessage.h"
|
||||
#include "../tmstorage/TmStoreMessage.h"
|
||||
#include "../parameters/ParameterMessage.h"
|
||||
|
||||
void CommandMessageCleaner::clearCommandMessage(CommandMessage* message) {
|
||||
switch(message->getMessageType()){
|
||||
case messagetypes::MODE_COMMAND:
|
||||
ModeMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::HEALTH_COMMAND:
|
||||
HealthMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::MODE_SEQUENCE:
|
||||
ModeSequenceMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::ACTION:
|
||||
ActionMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::DEVICE_HANDLER_COMMAND:
|
||||
DeviceHandlerMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::MEMORY:
|
||||
MemoryMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::MONITORING:
|
||||
MonitoringMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::TM_STORE:
|
||||
TmStoreMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::PARAMETER:
|
||||
ParameterMessage::clear(message);
|
||||
break;
|
||||
default:
|
||||
messagetypes::clearMissionMessage(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#include "../ipc/CommandMessageCleaner.h"
|
||||
|
||||
#include "../devicehandlers/DeviceHandlerMessage.h"
|
||||
#include "../health/HealthMessage.h"
|
||||
#include "../memory/MemoryMessage.h"
|
||||
#include "../modes/ModeMessage.h"
|
||||
#include "../monitoring/MonitoringMessage.h"
|
||||
#include "../subsystem/modes/ModeSequenceMessage.h"
|
||||
#include "../tmstorage/TmStoreMessage.h"
|
||||
#include "../parameters/ParameterMessage.h"
|
||||
|
||||
void CommandMessageCleaner::clearCommandMessage(CommandMessage* message) {
|
||||
switch(message->getMessageType()){
|
||||
case messagetypes::MODE_COMMAND:
|
||||
ModeMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::HEALTH_COMMAND:
|
||||
HealthMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::MODE_SEQUENCE:
|
||||
ModeSequenceMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::ACTION:
|
||||
ActionMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::DEVICE_HANDLER_COMMAND:
|
||||
DeviceHandlerMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::MEMORY:
|
||||
MemoryMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::MONITORING:
|
||||
MonitoringMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::TM_STORE:
|
||||
TmStoreMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::PARAMETER:
|
||||
ParameterMessage::clear(message);
|
||||
break;
|
||||
default:
|
||||
messagetypes::clearMissionMessage(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
#ifndef FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_
|
||||
#define FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_
|
||||
#include "../ipc/CommandMessage.h"
|
||||
|
||||
namespace messagetypes {
|
||||
// Implemented in config.
|
||||
void clearMissionMessage(CommandMessage* message);
|
||||
}
|
||||
|
||||
class CommandMessageCleaner {
|
||||
public:
|
||||
static void clearCommandMessage(CommandMessage* message);
|
||||
};
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_ */
|
||||
#ifndef FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_
|
||||
#define FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_
|
||||
#include "../ipc/CommandMessage.h"
|
||||
|
||||
namespace messagetypes {
|
||||
// Implemented in config.
|
||||
void clearMissionMessage(CommandMessage* message);
|
||||
}
|
||||
|
||||
class CommandMessageCleaner {
|
||||
public:
|
||||
static void clearCommandMessage(CommandMessage* message);
|
||||
};
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_ */
|
||||
|
@ -1,73 +1,73 @@
|
||||
#ifndef FSFW_IPC_COMMANDMESSAGEIF_H_
|
||||
#define FSFW_IPC_COMMANDMESSAGEIF_H_
|
||||
|
||||
#include "MessageQueueMessageIF.h"
|
||||
#include "FwMessageTypes.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
#define MAKE_COMMAND_ID( number ) ((MESSAGE_ID << 8) + (number))
|
||||
typedef uint16_t Command_t;
|
||||
|
||||
class CommandMessageIF {
|
||||
public:
|
||||
/**
|
||||
* 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);
|
||||
|
||||
static const uint8_t MESSAGE_ID = messagetypes::COMMAND;
|
||||
//! Used internally, shall be ignored
|
||||
static const Command_t CMD_NONE = MAKE_COMMAND_ID( 0 );
|
||||
static const Command_t REPLY_COMMAND_OK = MAKE_COMMAND_ID( 1 );
|
||||
//! Reply indicating that the current command was rejected,
|
||||
//! par1 should contain the error code
|
||||
static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID( 2 );
|
||||
|
||||
virtual ~CommandMessageIF() {};
|
||||
|
||||
/**
|
||||
* A command message shall have a uint16_t command ID field.
|
||||
* @return
|
||||
*/
|
||||
virtual Command_t getCommand() const = 0;
|
||||
/**
|
||||
* A command message shall have a uint8_t message type ID field.
|
||||
* @return
|
||||
*/
|
||||
virtual uint8_t getMessageType() const = 0;
|
||||
|
||||
/**
|
||||
* A command message can be rejected and needs to offer a function
|
||||
* to set a rejected reply
|
||||
* @param reason
|
||||
* @param initialCommand
|
||||
*/
|
||||
virtual void setReplyRejected(ReturnValue_t reason,
|
||||
Command_t initialCommand) = 0;
|
||||
/**
|
||||
* Corrensonding getter function.
|
||||
* @param initialCommand
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t getReplyRejectedReason(
|
||||
Command_t* initialCommand = nullptr) const = 0;
|
||||
|
||||
virtual void setToUnknownCommand() = 0;
|
||||
|
||||
virtual void clear() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /* FSFW_IPC_COMMANDMESSAGEIF_H_ */
|
||||
#ifndef FSFW_IPC_COMMANDMESSAGEIF_H_
|
||||
#define FSFW_IPC_COMMANDMESSAGEIF_H_
|
||||
|
||||
#include "MessageQueueMessageIF.h"
|
||||
#include "FwMessageTypes.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
#define MAKE_COMMAND_ID( number ) ((MESSAGE_ID << 8) + (number))
|
||||
typedef uint16_t Command_t;
|
||||
|
||||
class CommandMessageIF {
|
||||
public:
|
||||
/**
|
||||
* 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);
|
||||
|
||||
static const uint8_t MESSAGE_ID = messagetypes::COMMAND;
|
||||
//! Used internally, shall be ignored
|
||||
static const Command_t CMD_NONE = MAKE_COMMAND_ID( 0 );
|
||||
static const Command_t REPLY_COMMAND_OK = MAKE_COMMAND_ID( 1 );
|
||||
//! Reply indicating that the current command was rejected,
|
||||
//! par1 should contain the error code
|
||||
static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID( 2 );
|
||||
|
||||
virtual ~CommandMessageIF() {};
|
||||
|
||||
/**
|
||||
* A command message shall have a uint16_t command ID field.
|
||||
* @return
|
||||
*/
|
||||
virtual Command_t getCommand() const = 0;
|
||||
/**
|
||||
* A command message shall have a uint8_t message type ID field.
|
||||
* @return
|
||||
*/
|
||||
virtual uint8_t getMessageType() const = 0;
|
||||
|
||||
/**
|
||||
* A command message can be rejected and needs to offer a function
|
||||
* to set a rejected reply
|
||||
* @param reason
|
||||
* @param initialCommand
|
||||
*/
|
||||
virtual void setReplyRejected(ReturnValue_t reason,
|
||||
Command_t initialCommand) = 0;
|
||||
/**
|
||||
* Corrensonding getter function.
|
||||
* @param initialCommand
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t getReplyRejectedReason(
|
||||
Command_t* initialCommand = nullptr) const = 0;
|
||||
|
||||
virtual void setToUnknownCommand() = 0;
|
||||
|
||||
virtual void clear() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /* FSFW_IPC_COMMANDMESSAGEIF_H_ */
|
||||
|
@ -1,171 +1,171 @@
|
||||
#ifndef FSFW_IPC_MESSAGEQUEUEIF_H_
|
||||
#define FSFW_IPC_MESSAGEQUEUEIF_H_
|
||||
|
||||
// COULDDO: We could support blocking calls
|
||||
// semaphores are being implemented, which makes this idea even more iteresting.
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup message_queue Message Queue
|
||||
* @brief Message Queue related software components
|
||||
*/
|
||||
|
||||
#include "../ipc/MessageQueueMessage.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
class MessageQueueIF {
|
||||
public:
|
||||
static const MessageQueueId_t NO_QUEUE = MessageQueueMessageIF::NO_QUEUE; //!< Ugly hack.
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MESSAGE_QUEUE_IF;
|
||||
//! No new messages on the queue
|
||||
static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(1);
|
||||
//! No space left for more messages
|
||||
static const ReturnValue_t FULL = MAKE_RETURN_CODE(2);
|
||||
//! Returned if a reply method was called without partner
|
||||
static const ReturnValue_t NO_REPLY_PARTNER = MAKE_RETURN_CODE(3);
|
||||
//! Returned if the target destination is invalid.
|
||||
static constexpr ReturnValue_t DESTINVATION_INVALID = MAKE_RETURN_CODE(4);
|
||||
|
||||
virtual ~MessageQueueIF() {}
|
||||
/**
|
||||
* @brief This operation sends a message to the last communication partner.
|
||||
* @details
|
||||
* This operation simplifies answering an incoming message by using the
|
||||
* stored lastParnter information as destination. If there was no message
|
||||
* received yet (i.e. lastPartner is zero), an error code is returned.
|
||||
* @param message
|
||||
* A pointer to a previously created message, which is sent.
|
||||
* @return
|
||||
* -@c RETURN_OK if ok
|
||||
* -@c NO_REPLY_PARTNER Should return NO_REPLY_PARTNER if partner was found.
|
||||
*/
|
||||
virtual ReturnValue_t reply(MessageQueueMessageIF* message) = 0;
|
||||
|
||||
/**
|
||||
* @brief This function reads available messages from the message queue
|
||||
* and returns the sender.
|
||||
* @details
|
||||
* It works identically to the other receiveMessage call, but in addition
|
||||
* returns the sender's queue id.
|
||||
* @param message
|
||||
* A pointer to a message in which the received data is stored.
|
||||
* @param receivedFrom
|
||||
* A pointer to a queue id in which the sender's id is stored.
|
||||
*/
|
||||
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
|
||||
MessageQueueId_t *receivedFrom) = 0;
|
||||
|
||||
/**
|
||||
* @brief This function reads available messages from the message queue.
|
||||
* @details
|
||||
* If data is available it is stored in the passed message pointer.
|
||||
* The message's original content is overwritten and the sendFrom
|
||||
* information is stored in theblastPartner attribute. Else, the lastPartner
|
||||
* information remains untouched, the message's content is cleared and the
|
||||
* function returns immediately.
|
||||
* @param message
|
||||
* A pointer to a message in which the received data is stored.
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c MessageQueueIF::EMPTY if queue is empty
|
||||
*/
|
||||
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) = 0;
|
||||
/**
|
||||
* Deletes all pending messages in the queue.
|
||||
* @param count The number of flushed messages.
|
||||
* @return RETURN_OK on success.
|
||||
*/
|
||||
virtual ReturnValue_t flush(uint32_t* count) = 0;
|
||||
/**
|
||||
* @brief This method returns the message queue
|
||||
* id of the last communication partner.
|
||||
*/
|
||||
virtual MessageQueueId_t getLastPartner() const = 0;
|
||||
/**
|
||||
* @brief This method returns the message queue
|
||||
* id of this class's message queue.
|
||||
*/
|
||||
virtual MessageQueueId_t getId() const = 0;
|
||||
|
||||
/**
|
||||
* @brief With the sendMessage call, a queue message
|
||||
* is sent to a receiving queue.
|
||||
* @details
|
||||
* This method takes the message provided, adds the sentFrom information
|
||||
* and passes it on to the destination provided with an operating system
|
||||
* call. The OS's returnvalue is returned.
|
||||
* @param sendTo
|
||||
* This parameter specifies the message queue id to send the message to.
|
||||
* @param message
|
||||
* This is a pointer to a previously created message, which is sent.
|
||||
* @param sentFrom
|
||||
* The sentFrom information can be set to inject the sender's queue id
|
||||
* into the message. This variable is set to zero by default.
|
||||
* @param ignoreFault
|
||||
* If set to true, the internal software fault counter is not incremented
|
||||
* if queue is full (if implemented).
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c MessageQueueIF::FULL if queue is full
|
||||
*/
|
||||
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault = false ) = 0;
|
||||
|
||||
/**
|
||||
* @brief This operation sends a message to the given destination.
|
||||
* @details
|
||||
* It directly uses the sendMessage call of the MessageQueueSender parent,
|
||||
* but passes its queue id as "sentFrom" parameter.
|
||||
* @param sendTo
|
||||
* This parameter specifies the message queue id of the destination
|
||||
* message queue.
|
||||
* @param message
|
||||
* A pointer to a previously created message, which is sent.
|
||||
* @param ignoreFault
|
||||
* If set to true, the internal software fault counter is not incremented
|
||||
* if queue is full.
|
||||
*/
|
||||
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, bool ignoreFault = false ) = 0;
|
||||
|
||||
/**
|
||||
* @brief The sendToDefaultFrom method sends a queue message
|
||||
* to the default destination.
|
||||
* @details
|
||||
* In all other aspects, it works identical to the sendMessage method.
|
||||
* @param message
|
||||
* This is a pointer to a previously created message, which is sent.
|
||||
* @param sentFrom
|
||||
* The sentFrom information can be set to inject the sender's queue id
|
||||
* into the message. This variable is set to zero by default.
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c MessageQueueIF::FULL if queue is full
|
||||
*/
|
||||
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom, bool ignoreFault = false ) = 0;
|
||||
/**
|
||||
* @brief This operation sends a message to the default destination.
|
||||
* @details
|
||||
* As in the sendMessage method, this function uses the sendToDefault
|
||||
* call of the Implementation class and adds its queue id as
|
||||
* "sentFrom" information.
|
||||
* @param message A pointer to a previously created message, which is sent.
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c MessageQueueIF::FULL if queue is full
|
||||
*/
|
||||
virtual ReturnValue_t sendToDefault( MessageQueueMessageIF* message ) = 0;
|
||||
/**
|
||||
* @brief This method is a simple setter for the default destination.
|
||||
*/
|
||||
virtual void setDefaultDestination(MessageQueueId_t defaultDestination) = 0;
|
||||
/**
|
||||
* @brief This method is a simple getter for the default destination.
|
||||
*/
|
||||
virtual MessageQueueId_t getDefaultDestination() const = 0;
|
||||
|
||||
virtual bool isDefaultDestinationSet() const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_IPC_MESSAGEQUEUEIF_H_ */
|
||||
#ifndef FSFW_IPC_MESSAGEQUEUEIF_H_
|
||||
#define FSFW_IPC_MESSAGEQUEUEIF_H_
|
||||
|
||||
// COULDDO: We could support blocking calls
|
||||
// semaphores are being implemented, which makes this idea even more iteresting.
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup message_queue Message Queue
|
||||
* @brief Message Queue related software components
|
||||
*/
|
||||
|
||||
#include "../ipc/MessageQueueMessage.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
class MessageQueueIF {
|
||||
public:
|
||||
static const MessageQueueId_t NO_QUEUE = MessageQueueMessageIF::NO_QUEUE; //!< Ugly hack.
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MESSAGE_QUEUE_IF;
|
||||
//! No new messages on the queue
|
||||
static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(1);
|
||||
//! No space left for more messages
|
||||
static const ReturnValue_t FULL = MAKE_RETURN_CODE(2);
|
||||
//! Returned if a reply method was called without partner
|
||||
static const ReturnValue_t NO_REPLY_PARTNER = MAKE_RETURN_CODE(3);
|
||||
//! Returned if the target destination is invalid.
|
||||
static constexpr ReturnValue_t DESTINVATION_INVALID = MAKE_RETURN_CODE(4);
|
||||
|
||||
virtual ~MessageQueueIF() {}
|
||||
/**
|
||||
* @brief This operation sends a message to the last communication partner.
|
||||
* @details
|
||||
* This operation simplifies answering an incoming message by using the
|
||||
* stored lastParnter information as destination. If there was no message
|
||||
* received yet (i.e. lastPartner is zero), an error code is returned.
|
||||
* @param message
|
||||
* A pointer to a previously created message, which is sent.
|
||||
* @return
|
||||
* -@c RETURN_OK if ok
|
||||
* -@c NO_REPLY_PARTNER Should return NO_REPLY_PARTNER if partner was found.
|
||||
*/
|
||||
virtual ReturnValue_t reply(MessageQueueMessageIF* message) = 0;
|
||||
|
||||
/**
|
||||
* @brief This function reads available messages from the message queue
|
||||
* and returns the sender.
|
||||
* @details
|
||||
* It works identically to the other receiveMessage call, but in addition
|
||||
* returns the sender's queue id.
|
||||
* @param message
|
||||
* A pointer to a message in which the received data is stored.
|
||||
* @param receivedFrom
|
||||
* A pointer to a queue id in which the sender's id is stored.
|
||||
*/
|
||||
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
|
||||
MessageQueueId_t *receivedFrom) = 0;
|
||||
|
||||
/**
|
||||
* @brief This function reads available messages from the message queue.
|
||||
* @details
|
||||
* If data is available it is stored in the passed message pointer.
|
||||
* The message's original content is overwritten and the sendFrom
|
||||
* information is stored in theblastPartner attribute. Else, the lastPartner
|
||||
* information remains untouched, the message's content is cleared and the
|
||||
* function returns immediately.
|
||||
* @param message
|
||||
* A pointer to a message in which the received data is stored.
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c MessageQueueIF::EMPTY if queue is empty
|
||||
*/
|
||||
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) = 0;
|
||||
/**
|
||||
* Deletes all pending messages in the queue.
|
||||
* @param count The number of flushed messages.
|
||||
* @return RETURN_OK on success.
|
||||
*/
|
||||
virtual ReturnValue_t flush(uint32_t* count) = 0;
|
||||
/**
|
||||
* @brief This method returns the message queue
|
||||
* id of the last communication partner.
|
||||
*/
|
||||
virtual MessageQueueId_t getLastPartner() const = 0;
|
||||
/**
|
||||
* @brief This method returns the message queue
|
||||
* id of this class's message queue.
|
||||
*/
|
||||
virtual MessageQueueId_t getId() const = 0;
|
||||
|
||||
/**
|
||||
* @brief With the sendMessage call, a queue message
|
||||
* is sent to a receiving queue.
|
||||
* @details
|
||||
* This method takes the message provided, adds the sentFrom information
|
||||
* and passes it on to the destination provided with an operating system
|
||||
* call. The OS's returnvalue is returned.
|
||||
* @param sendTo
|
||||
* This parameter specifies the message queue id to send the message to.
|
||||
* @param message
|
||||
* This is a pointer to a previously created message, which is sent.
|
||||
* @param sentFrom
|
||||
* The sentFrom information can be set to inject the sender's queue id
|
||||
* into the message. This variable is set to zero by default.
|
||||
* @param ignoreFault
|
||||
* If set to true, the internal software fault counter is not incremented
|
||||
* if queue is full (if implemented).
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c MessageQueueIF::FULL if queue is full
|
||||
*/
|
||||
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault = false ) = 0;
|
||||
|
||||
/**
|
||||
* @brief This operation sends a message to the given destination.
|
||||
* @details
|
||||
* It directly uses the sendMessage call of the MessageQueueSender parent,
|
||||
* but passes its queue id as "sentFrom" parameter.
|
||||
* @param sendTo
|
||||
* This parameter specifies the message queue id of the destination
|
||||
* message queue.
|
||||
* @param message
|
||||
* A pointer to a previously created message, which is sent.
|
||||
* @param ignoreFault
|
||||
* If set to true, the internal software fault counter is not incremented
|
||||
* if queue is full.
|
||||
*/
|
||||
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, bool ignoreFault = false ) = 0;
|
||||
|
||||
/**
|
||||
* @brief The sendToDefaultFrom method sends a queue message
|
||||
* to the default destination.
|
||||
* @details
|
||||
* In all other aspects, it works identical to the sendMessage method.
|
||||
* @param message
|
||||
* This is a pointer to a previously created message, which is sent.
|
||||
* @param sentFrom
|
||||
* The sentFrom information can be set to inject the sender's queue id
|
||||
* into the message. This variable is set to zero by default.
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c MessageQueueIF::FULL if queue is full
|
||||
*/
|
||||
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom, bool ignoreFault = false ) = 0;
|
||||
/**
|
||||
* @brief This operation sends a message to the default destination.
|
||||
* @details
|
||||
* As in the sendMessage method, this function uses the sendToDefault
|
||||
* call of the Implementation class and adds its queue id as
|
||||
* "sentFrom" information.
|
||||
* @param message A pointer to a previously created message, which is sent.
|
||||
* @return -@c RETURN_OK on success
|
||||
* -@c MessageQueueIF::FULL if queue is full
|
||||
*/
|
||||
virtual ReturnValue_t sendToDefault( MessageQueueMessageIF* message ) = 0;
|
||||
/**
|
||||
* @brief This method is a simple setter for the default destination.
|
||||
*/
|
||||
virtual void setDefaultDestination(MessageQueueId_t defaultDestination) = 0;
|
||||
/**
|
||||
* @brief This method is a simple getter for the default destination.
|
||||
*/
|
||||
virtual MessageQueueId_t getDefaultDestination() const = 0;
|
||||
|
||||
virtual bool isDefaultDestinationSet() const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_IPC_MESSAGEQUEUEIF_H_ */
|
||||
|
@ -1,84 +1,84 @@
|
||||
#include "MessageQueueMessage.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../globalfunctions/arrayprinter.h"
|
||||
#include <cstring>
|
||||
|
||||
MessageQueueMessage::MessageQueueMessage() :
|
||||
messageSize(getMinimumMessageSize()) {
|
||||
memset(this->internalBuffer, 0, sizeof(this->internalBuffer));
|
||||
}
|
||||
|
||||
MessageQueueMessage::MessageQueueMessage(uint8_t* data, size_t size) :
|
||||
messageSize(this->HEADER_SIZE + size) {
|
||||
if (size <= this->MAX_DATA_SIZE) {
|
||||
memcpy(this->getData(), data, size);
|
||||
this->messageSize = this->HEADER_SIZE + size;
|
||||
}
|
||||
else {
|
||||
sif::warning << "MessageQueueMessage: Passed size larger than maximum"
|
||||
"allowed size! Setting content to 0" << std::endl;
|
||||
memset(this->internalBuffer, 0, sizeof(this->internalBuffer));
|
||||
this->messageSize = this->HEADER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
MessageQueueMessage::~MessageQueueMessage() {
|
||||
}
|
||||
|
||||
const uint8_t* MessageQueueMessage::getBuffer() const {
|
||||
return this->internalBuffer;
|
||||
}
|
||||
|
||||
uint8_t* MessageQueueMessage::getBuffer() {
|
||||
return this->internalBuffer;
|
||||
}
|
||||
|
||||
const uint8_t* MessageQueueMessage::getData() const {
|
||||
return this->internalBuffer + this->HEADER_SIZE;
|
||||
}
|
||||
|
||||
uint8_t* MessageQueueMessage::getData() {
|
||||
return this->internalBuffer + this->HEADER_SIZE;
|
||||
}
|
||||
|
||||
MessageQueueId_t MessageQueueMessage::getSender() const {
|
||||
MessageQueueId_t temp_id;
|
||||
memcpy(&temp_id, this->internalBuffer, sizeof(MessageQueueId_t));
|
||||
return temp_id;
|
||||
}
|
||||
|
||||
void MessageQueueMessage::setSender(MessageQueueId_t setId) {
|
||||
memcpy(this->internalBuffer, &setId, sizeof(MessageQueueId_t));
|
||||
}
|
||||
|
||||
void MessageQueueMessage::print(bool printWholeMessage) {
|
||||
sif::debug << "MessageQueueMessage content: " << std::endl;
|
||||
if(printWholeMessage) {
|
||||
arrayprinter::print(getData(), getMaximumMessageSize());
|
||||
}
|
||||
else {
|
||||
arrayprinter::print(getData(), getMessageSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MessageQueueMessage::clear() {
|
||||
memset(this->getBuffer(), 0, this->MAX_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
size_t MessageQueueMessage::getMessageSize() const {
|
||||
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;
|
||||
}
|
||||
|
||||
#include "MessageQueueMessage.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../globalfunctions/arrayprinter.h"
|
||||
#include <cstring>
|
||||
|
||||
MessageQueueMessage::MessageQueueMessage() :
|
||||
messageSize(getMinimumMessageSize()) {
|
||||
memset(this->internalBuffer, 0, sizeof(this->internalBuffer));
|
||||
}
|
||||
|
||||
MessageQueueMessage::MessageQueueMessage(uint8_t* data, size_t size) :
|
||||
messageSize(this->HEADER_SIZE + size) {
|
||||
if (size <= this->MAX_DATA_SIZE) {
|
||||
memcpy(this->getData(), data, size);
|
||||
this->messageSize = this->HEADER_SIZE + size;
|
||||
}
|
||||
else {
|
||||
sif::warning << "MessageQueueMessage: Passed size larger than maximum"
|
||||
"allowed size! Setting content to 0" << std::endl;
|
||||
memset(this->internalBuffer, 0, sizeof(this->internalBuffer));
|
||||
this->messageSize = this->HEADER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
MessageQueueMessage::~MessageQueueMessage() {
|
||||
}
|
||||
|
||||
const uint8_t* MessageQueueMessage::getBuffer() const {
|
||||
return this->internalBuffer;
|
||||
}
|
||||
|
||||
uint8_t* MessageQueueMessage::getBuffer() {
|
||||
return this->internalBuffer;
|
||||
}
|
||||
|
||||
const uint8_t* MessageQueueMessage::getData() const {
|
||||
return this->internalBuffer + this->HEADER_SIZE;
|
||||
}
|
||||
|
||||
uint8_t* MessageQueueMessage::getData() {
|
||||
return this->internalBuffer + this->HEADER_SIZE;
|
||||
}
|
||||
|
||||
MessageQueueId_t MessageQueueMessage::getSender() const {
|
||||
MessageQueueId_t temp_id;
|
||||
memcpy(&temp_id, this->internalBuffer, sizeof(MessageQueueId_t));
|
||||
return temp_id;
|
||||
}
|
||||
|
||||
void MessageQueueMessage::setSender(MessageQueueId_t setId) {
|
||||
memcpy(this->internalBuffer, &setId, sizeof(MessageQueueId_t));
|
||||
}
|
||||
|
||||
void MessageQueueMessage::print(bool printWholeMessage) {
|
||||
sif::debug << "MessageQueueMessage content: " << std::endl;
|
||||
if(printWholeMessage) {
|
||||
arrayprinter::print(getData(), getMaximumMessageSize());
|
||||
}
|
||||
else {
|
||||
arrayprinter::print(getData(), getMessageSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MessageQueueMessage::clear() {
|
||||
memset(this->getBuffer(), 0, this->MAX_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
size_t MessageQueueMessage::getMessageSize() const {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1,150 +1,150 @@
|
||||
#ifndef FSFW_IPC_MESSAGEQUEUEMESSAGE_H_
|
||||
#define FSFW_IPC_MESSAGEQUEUEMESSAGE_H_
|
||||
|
||||
#include "../ipc/MessageQueueMessageIF.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief This class is the representation and data organizer
|
||||
* for interprocess messages.
|
||||
* @details
|
||||
* To facilitate and standardize interprocess communication, this class was
|
||||
* created to handle a lightweight "interprocess message protocol".
|
||||
*
|
||||
* It adds a header with the sender's queue id to every sent message and
|
||||
* defines the maximum total message size. Specialized messages, such as
|
||||
* device commanding messages, can be created by inheriting from this class
|
||||
* and filling the buffer provided by getData with additional content.
|
||||
*
|
||||
* If larger amounts of data must be sent between processes, the data shall
|
||||
* be stored in the IPC Store object and only the storage id is passed in a
|
||||
* queue message.The class is used both to generate and send messages and to
|
||||
* receive messages from other tasks.
|
||||
* @ingroup message_queue
|
||||
*/
|
||||
class MessageQueueMessage: public MessageQueueMessageIF {
|
||||
public:
|
||||
/**
|
||||
* @brief The class is initialized empty with this constructor.
|
||||
* @details
|
||||
* The messageSize attribute is set to the header's size and the whole
|
||||
* content is set to zero.
|
||||
*/
|
||||
MessageQueueMessage();
|
||||
/**
|
||||
* @brief With this constructor the class is initialized with
|
||||
* the given content.
|
||||
* @details
|
||||
* If the passed message size fits into the buffer, the passed data is
|
||||
* copied to the internal buffer and the messageSize information is set.
|
||||
* Otherwise, messageSize is set to the header's size and the whole
|
||||
* content is set to zero.
|
||||
* @param data The data to be put in the message.
|
||||
* @param size Size of the data to be copied. Must be smaller than
|
||||
* MAX_MESSAGE_SIZE and larger than MIN_MESSAGE_SIZE.
|
||||
*/
|
||||
MessageQueueMessage(uint8_t* data, size_t size);
|
||||
|
||||
/**
|
||||
* @brief As no memory is allocated in this class,
|
||||
* the destructor is empty.
|
||||
*/
|
||||
virtual ~MessageQueueMessage();
|
||||
|
||||
/**
|
||||
* @brief The size information of each message is stored in
|
||||
* this attribute.
|
||||
* @details
|
||||
* It is public to simplify usage and to allow for passing the size
|
||||
* address as a pointer. Care must be taken when inheriting from this class,
|
||||
* as every child class is responsible for managing the size information by
|
||||
* itself. When using the class to receive a message, the size information
|
||||
* is updated automatically.
|
||||
*
|
||||
* Please note that the minimum size is limited by the size of the header
|
||||
* while the maximum size is limited by the maximum allowed message size.
|
||||
*/
|
||||
size_t messageSize;
|
||||
/**
|
||||
* @brief This constant defines the maximum size of the data content,
|
||||
* excluding the header.
|
||||
* @details
|
||||
* It may be changed if necessary, but in general should be kept
|
||||
* as small as possible.
|
||||
*/
|
||||
static const size_t MAX_DATA_SIZE = 24;
|
||||
|
||||
/**
|
||||
* @brief This constant defines the maximum total size in bytes
|
||||
* of a sent message.
|
||||
* @details
|
||||
* It is the sum of the maximum data and the header size. Be aware that
|
||||
* this constant is used to define the buffer sizes for every message
|
||||
* queue in the system. So, a change here may have significant impact on
|
||||
* the required resources.
|
||||
*/
|
||||
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 constexpr size_t MIN_MESSAGE_SIZE = HEADER_SIZE;
|
||||
private:
|
||||
/**
|
||||
* @brief This is the internal buffer that contains the
|
||||
* actual message data.
|
||||
*/
|
||||
uint8_t internalBuffer[MAX_MESSAGE_SIZE];
|
||||
public:
|
||||
/**
|
||||
* @brief This method is used to get the complete data of the message.
|
||||
*/
|
||||
const uint8_t* getBuffer() const override;
|
||||
/**
|
||||
* @brief This method is used to get the complete data of the message.
|
||||
*/
|
||||
uint8_t* getBuffer() override;
|
||||
/**
|
||||
* @brief This method is used to fetch the data content of the message.
|
||||
* @details
|
||||
* It shall be used by child classes to add data at the right position.
|
||||
*/
|
||||
const uint8_t* getData() const override;
|
||||
/**
|
||||
* @brief This method is used to fetch the data content of the message.
|
||||
* @details
|
||||
* It shall be used by child classes to add data at the right position.
|
||||
*/
|
||||
uint8_t* getData() override;
|
||||
/**
|
||||
* @brief This method is used to extract the sender's message
|
||||
* queue id information from a received message.
|
||||
*/
|
||||
MessageQueueId_t getSender() const override;
|
||||
/**
|
||||
* @brief With this method, the whole content
|
||||
* and the message size is set to zero.
|
||||
*/
|
||||
void clear() override;
|
||||
|
||||
/**
|
||||
* @brief This method is used to set the sender's message queue id
|
||||
* information prior to ing the message.
|
||||
* @param setId
|
||||
* The message queue id that identifies the sending message queue.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
void print(bool printWholeMessage);
|
||||
};
|
||||
|
||||
#endif /* FSFW_IPC_MESSAGEQUEUEMESSAGE_H_ */
|
||||
#ifndef FSFW_IPC_MESSAGEQUEUEMESSAGE_H_
|
||||
#define FSFW_IPC_MESSAGEQUEUEMESSAGE_H_
|
||||
|
||||
#include "../ipc/MessageQueueMessageIF.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief This class is the representation and data organizer
|
||||
* for interprocess messages.
|
||||
* @details
|
||||
* To facilitate and standardize interprocess communication, this class was
|
||||
* created to handle a lightweight "interprocess message protocol".
|
||||
*
|
||||
* It adds a header with the sender's queue id to every sent message and
|
||||
* defines the maximum total message size. Specialized messages, such as
|
||||
* device commanding messages, can be created by inheriting from this class
|
||||
* and filling the buffer provided by getData with additional content.
|
||||
*
|
||||
* If larger amounts of data must be sent between processes, the data shall
|
||||
* be stored in the IPC Store object and only the storage id is passed in a
|
||||
* queue message.The class is used both to generate and send messages and to
|
||||
* receive messages from other tasks.
|
||||
* @ingroup message_queue
|
||||
*/
|
||||
class MessageQueueMessage: public MessageQueueMessageIF {
|
||||
public:
|
||||
/**
|
||||
* @brief The class is initialized empty with this constructor.
|
||||
* @details
|
||||
* The messageSize attribute is set to the header's size and the whole
|
||||
* content is set to zero.
|
||||
*/
|
||||
MessageQueueMessage();
|
||||
/**
|
||||
* @brief With this constructor the class is initialized with
|
||||
* the given content.
|
||||
* @details
|
||||
* If the passed message size fits into the buffer, the passed data is
|
||||
* copied to the internal buffer and the messageSize information is set.
|
||||
* Otherwise, messageSize is set to the header's size and the whole
|
||||
* content is set to zero.
|
||||
* @param data The data to be put in the message.
|
||||
* @param size Size of the data to be copied. Must be smaller than
|
||||
* MAX_MESSAGE_SIZE and larger than MIN_MESSAGE_SIZE.
|
||||
*/
|
||||
MessageQueueMessage(uint8_t* data, size_t size);
|
||||
|
||||
/**
|
||||
* @brief As no memory is allocated in this class,
|
||||
* the destructor is empty.
|
||||
*/
|
||||
virtual ~MessageQueueMessage();
|
||||
|
||||
/**
|
||||
* @brief The size information of each message is stored in
|
||||
* this attribute.
|
||||
* @details
|
||||
* It is public to simplify usage and to allow for passing the size
|
||||
* address as a pointer. Care must be taken when inheriting from this class,
|
||||
* as every child class is responsible for managing the size information by
|
||||
* itself. When using the class to receive a message, the size information
|
||||
* is updated automatically.
|
||||
*
|
||||
* Please note that the minimum size is limited by the size of the header
|
||||
* while the maximum size is limited by the maximum allowed message size.
|
||||
*/
|
||||
size_t messageSize;
|
||||
/**
|
||||
* @brief This constant defines the maximum size of the data content,
|
||||
* excluding the header.
|
||||
* @details
|
||||
* It may be changed if necessary, but in general should be kept
|
||||
* as small as possible.
|
||||
*/
|
||||
static const size_t MAX_DATA_SIZE = 24;
|
||||
|
||||
/**
|
||||
* @brief This constant defines the maximum total size in bytes
|
||||
* of a sent message.
|
||||
* @details
|
||||
* It is the sum of the maximum data and the header size. Be aware that
|
||||
* this constant is used to define the buffer sizes for every message
|
||||
* queue in the system. So, a change here may have significant impact on
|
||||
* the required resources.
|
||||
*/
|
||||
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 constexpr size_t MIN_MESSAGE_SIZE = HEADER_SIZE;
|
||||
private:
|
||||
/**
|
||||
* @brief This is the internal buffer that contains the
|
||||
* actual message data.
|
||||
*/
|
||||
uint8_t internalBuffer[MAX_MESSAGE_SIZE];
|
||||
public:
|
||||
/**
|
||||
* @brief This method is used to get the complete data of the message.
|
||||
*/
|
||||
const uint8_t* getBuffer() const override;
|
||||
/**
|
||||
* @brief This method is used to get the complete data of the message.
|
||||
*/
|
||||
uint8_t* getBuffer() override;
|
||||
/**
|
||||
* @brief This method is used to fetch the data content of the message.
|
||||
* @details
|
||||
* It shall be used by child classes to add data at the right position.
|
||||
*/
|
||||
const uint8_t* getData() const override;
|
||||
/**
|
||||
* @brief This method is used to fetch the data content of the message.
|
||||
* @details
|
||||
* It shall be used by child classes to add data at the right position.
|
||||
*/
|
||||
uint8_t* getData() override;
|
||||
/**
|
||||
* @brief This method is used to extract the sender's message
|
||||
* queue id information from a received message.
|
||||
*/
|
||||
MessageQueueId_t getSender() const override;
|
||||
/**
|
||||
* @brief With this method, the whole content
|
||||
* and the message size is set to zero.
|
||||
*/
|
||||
void clear() override;
|
||||
|
||||
/**
|
||||
* @brief This method is used to set the sender's message queue id
|
||||
* information prior to ing the message.
|
||||
* @param setId
|
||||
* The message queue id that identifies the sending message queue.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
void print(bool printWholeMessage);
|
||||
};
|
||||
|
||||
#endif /* FSFW_IPC_MESSAGEQUEUEMESSAGE_H_ */
|
||||
|
@ -1,25 +1,25 @@
|
||||
#ifndef FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_
|
||||
#define FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_
|
||||
|
||||
#include "../ipc/MessageQueueMessageIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
|
||||
class MessageQueueSenderIF {
|
||||
public:
|
||||
|
||||
virtual ~MessageQueueSenderIF() {}
|
||||
|
||||
/**
|
||||
* Allows sending messages without actually "owning" a message queue.
|
||||
* Not sure whether this is actually a good idea.
|
||||
*/
|
||||
static ReturnValue_t sendMessage(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom = MessageQueueMessageIF::NO_QUEUE,
|
||||
bool ignoreFault = false);
|
||||
private:
|
||||
MessageQueueSenderIF() {}
|
||||
};
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_ */
|
||||
#ifndef FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_
|
||||
#define FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_
|
||||
|
||||
#include "../ipc/MessageQueueMessageIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
|
||||
class MessageQueueSenderIF {
|
||||
public:
|
||||
|
||||
virtual ~MessageQueueSenderIF() {}
|
||||
|
||||
/**
|
||||
* Allows sending messages without actually "owning" a message queue.
|
||||
* Not sure whether this is actually a good idea.
|
||||
*/
|
||||
static ReturnValue_t sendMessage(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom = MessageQueueMessageIF::NO_QUEUE,
|
||||
bool ignoreFault = false);
|
||||
private:
|
||||
MessageQueueSenderIF() {}
|
||||
};
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_ */
|
||||
|
@ -1,34 +1,34 @@
|
||||
#ifndef FRAMEWORK_IPC_MUTEXFACTORY_H_
|
||||
#define FRAMEWORK_IPC_MUTEXFACTORY_H_
|
||||
|
||||
#include "../ipc/MutexIF.h"
|
||||
/**
|
||||
* Creates Mutex.
|
||||
* This class is a "singleton" interface, i.e. it provides an
|
||||
* interface, but also is the base class for a singleton.
|
||||
*/
|
||||
class MutexFactory {
|
||||
public:
|
||||
virtual ~MutexFactory();
|
||||
/**
|
||||
* Returns the single instance of MutexFactory.
|
||||
* The implementation of #instance is found in its subclasses.
|
||||
* Thus, we choose link-time variability of the instance.
|
||||
*/
|
||||
static MutexFactory* instance();
|
||||
|
||||
MutexIF* createMutex();
|
||||
|
||||
void deleteMutex(MutexIF* mutex);
|
||||
|
||||
private:
|
||||
/**
|
||||
* External instantiation is not allowed.
|
||||
*/
|
||||
MutexFactory();
|
||||
static MutexFactory* factoryInstance;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MUTEXFACTORY_H_ */
|
||||
#ifndef FRAMEWORK_IPC_MUTEXFACTORY_H_
|
||||
#define FRAMEWORK_IPC_MUTEXFACTORY_H_
|
||||
|
||||
#include "../ipc/MutexIF.h"
|
||||
/**
|
||||
* Creates Mutex.
|
||||
* This class is a "singleton" interface, i.e. it provides an
|
||||
* interface, but also is the base class for a singleton.
|
||||
*/
|
||||
class MutexFactory {
|
||||
public:
|
||||
virtual ~MutexFactory();
|
||||
/**
|
||||
* Returns the single instance of MutexFactory.
|
||||
* The implementation of #instance is found in its subclasses.
|
||||
* Thus, we choose link-time variability of the instance.
|
||||
*/
|
||||
static MutexFactory* instance();
|
||||
|
||||
MutexIF* createMutex();
|
||||
|
||||
void deleteMutex(MutexIF* mutex);
|
||||
|
||||
private:
|
||||
/**
|
||||
* External instantiation is not allowed.
|
||||
*/
|
||||
MutexFactory();
|
||||
static MutexFactory* factoryInstance;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MUTEXFACTORY_H_ */
|
||||
|
@ -1,30 +1,30 @@
|
||||
#ifndef FRAMEWORK_IPC_MUTEXHELPER_H_
|
||||
#define FRAMEWORK_IPC_MUTEXHELPER_H_
|
||||
|
||||
#include "MutexFactory.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
class MutexHelper {
|
||||
public:
|
||||
MutexHelper(MutexIF* mutex, MutexIF::TimeoutType timeoutType =
|
||||
MutexIF::TimeoutType::BLOCKING, uint32_t timeoutMs = 0) :
|
||||
internalMutex(mutex) {
|
||||
ReturnValue_t status = mutex->lockMutex(timeoutType,
|
||||
timeoutMs);
|
||||
if(status == MutexIF::MUTEX_TIMEOUT) {
|
||||
sif::error << "MutexHelper: Lock of mutex failed with timeout of "
|
||||
<< timeoutMs << " milliseconds!" << std::endl;
|
||||
}
|
||||
else if(status != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "MutexHelper: Lock of Mutex failed with code "
|
||||
<< status << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
~MutexHelper() {
|
||||
internalMutex->unlockMutex();
|
||||
}
|
||||
private:
|
||||
MutexIF* internalMutex;
|
||||
};
|
||||
#endif /* FRAMEWORK_IPC_MUTEXHELPER_H_ */
|
||||
#ifndef FRAMEWORK_IPC_MUTEXHELPER_H_
|
||||
#define FRAMEWORK_IPC_MUTEXHELPER_H_
|
||||
|
||||
#include "MutexFactory.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
class MutexHelper {
|
||||
public:
|
||||
MutexHelper(MutexIF* mutex, MutexIF::TimeoutType timeoutType =
|
||||
MutexIF::TimeoutType::BLOCKING, uint32_t timeoutMs = 0) :
|
||||
internalMutex(mutex) {
|
||||
ReturnValue_t status = mutex->lockMutex(timeoutType,
|
||||
timeoutMs);
|
||||
if(status == MutexIF::MUTEX_TIMEOUT) {
|
||||
sif::error << "MutexHelper: Lock of mutex failed with timeout of "
|
||||
<< timeoutMs << " milliseconds!" << std::endl;
|
||||
}
|
||||
else if(status != HasReturnvaluesIF::RETURN_OK){
|
||||
sif::error << "MutexHelper: Lock of Mutex failed with code "
|
||||
<< status << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
~MutexHelper() {
|
||||
internalMutex->unlockMutex();
|
||||
}
|
||||
private:
|
||||
MutexIF* internalMutex;
|
||||
};
|
||||
#endif /* FRAMEWORK_IPC_MUTEXHELPER_H_ */
|
||||
|
178
ipc/MutexIF.h
178
ipc/MutexIF.h
@ -1,89 +1,89 @@
|
||||
#ifndef FRAMEWORK_IPC_MUTEXIF_H_
|
||||
#define FRAMEWORK_IPC_MUTEXIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
/**
|
||||
* @brief Common interface for OS Mutex objects which provide MUTual EXclusion.
|
||||
* @details https://en.wikipedia.org/wiki/Lock_(computer_science)
|
||||
* @ingroup osal
|
||||
* @ingroup interface
|
||||
*/
|
||||
class MutexIF {
|
||||
public:
|
||||
/**
|
||||
* Different types of timeout for the mutex lock.
|
||||
*/
|
||||
enum TimeoutType {
|
||||
POLLING, //!< If mutex is not available, return immediately
|
||||
WAITING, //!< Wait a specified time for the mutex to become available
|
||||
BLOCKING //!< Block indefinitely until the mutex becomes available.
|
||||
};
|
||||
|
||||
/**
|
||||
* Lock the mutex. The timeout value will only be used for
|
||||
* TimeoutType::WAITING
|
||||
* @param timeoutType
|
||||
* @param timeoutMs
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t lockMutex(TimeoutType timeoutType =
|
||||
TimeoutType::BLOCKING, uint32_t timeoutMs = 0) = 0;
|
||||
virtual ReturnValue_t unlockMutex() = 0;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MUTEX_IF;
|
||||
/**
|
||||
* The system lacked the necessary resources (other than memory) to initialize another mutex.
|
||||
*/
|
||||
static const ReturnValue_t NOT_ENOUGH_RESOURCES = MAKE_RETURN_CODE(1);
|
||||
/**
|
||||
* Insufficient memory to create or init Mutex
|
||||
*/
|
||||
static const ReturnValue_t INSUFFICIENT_MEMORY = MAKE_RETURN_CODE(2);
|
||||
/**
|
||||
* Caller does not have enough or right privilege
|
||||
*/
|
||||
static const ReturnValue_t NO_PRIVILEGE = MAKE_RETURN_CODE(3);
|
||||
/**
|
||||
* Wrong Attribute Setting
|
||||
*/
|
||||
static const ReturnValue_t WRONG_ATTRIBUTE_SETTING = MAKE_RETURN_CODE(4);
|
||||
/**
|
||||
* The mutex is already locked
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_ALREADY_LOCKED = MAKE_RETURN_CODE(5);
|
||||
/**
|
||||
* Mutex object not found
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_NOT_FOUND = MAKE_RETURN_CODE(6);
|
||||
/**
|
||||
* Mutex could not be locked because max amount of recursive locks
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_MAX_LOCKS = MAKE_RETURN_CODE(7);
|
||||
/**
|
||||
* The current thread already owns this mutex
|
||||
*/
|
||||
static const ReturnValue_t CURR_THREAD_ALREADY_OWNS_MUTEX = MAKE_RETURN_CODE(8);
|
||||
/**
|
||||
* Current thread does not own this mutex
|
||||
*/
|
||||
static const ReturnValue_t CURR_THREAD_DOES_NOT_OWN_MUTEX = MAKE_RETURN_CODE(9);
|
||||
/**
|
||||
* The Mutex could not be blocked before timeout
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_TIMEOUT = MAKE_RETURN_CODE(10);
|
||||
/**
|
||||
* Invalid Mutex ID
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_INVALID_ID = MAKE_RETURN_CODE(11);
|
||||
/**
|
||||
* Mutex destroyed while waiting
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_DESTROYED_WHILE_WAITING = MAKE_RETURN_CODE(12);
|
||||
|
||||
virtual ~MutexIF() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MUTEXIF_H_ */
|
||||
#ifndef FRAMEWORK_IPC_MUTEXIF_H_
|
||||
#define FRAMEWORK_IPC_MUTEXIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
/**
|
||||
* @brief Common interface for OS Mutex objects which provide MUTual EXclusion.
|
||||
* @details https://en.wikipedia.org/wiki/Lock_(computer_science)
|
||||
* @ingroup osal
|
||||
* @ingroup interface
|
||||
*/
|
||||
class MutexIF {
|
||||
public:
|
||||
/**
|
||||
* Different types of timeout for the mutex lock.
|
||||
*/
|
||||
enum TimeoutType {
|
||||
POLLING, //!< If mutex is not available, return immediately
|
||||
WAITING, //!< Wait a specified time for the mutex to become available
|
||||
BLOCKING //!< Block indefinitely until the mutex becomes available.
|
||||
};
|
||||
|
||||
/**
|
||||
* Lock the mutex. The timeout value will only be used for
|
||||
* TimeoutType::WAITING
|
||||
* @param timeoutType
|
||||
* @param timeoutMs
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t lockMutex(TimeoutType timeoutType =
|
||||
TimeoutType::BLOCKING, uint32_t timeoutMs = 0) = 0;
|
||||
virtual ReturnValue_t unlockMutex() = 0;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MUTEX_IF;
|
||||
/**
|
||||
* The system lacked the necessary resources (other than memory) to initialize another mutex.
|
||||
*/
|
||||
static const ReturnValue_t NOT_ENOUGH_RESOURCES = MAKE_RETURN_CODE(1);
|
||||
/**
|
||||
* Insufficient memory to create or init Mutex
|
||||
*/
|
||||
static const ReturnValue_t INSUFFICIENT_MEMORY = MAKE_RETURN_CODE(2);
|
||||
/**
|
||||
* Caller does not have enough or right privilege
|
||||
*/
|
||||
static const ReturnValue_t NO_PRIVILEGE = MAKE_RETURN_CODE(3);
|
||||
/**
|
||||
* Wrong Attribute Setting
|
||||
*/
|
||||
static const ReturnValue_t WRONG_ATTRIBUTE_SETTING = MAKE_RETURN_CODE(4);
|
||||
/**
|
||||
* The mutex is already locked
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_ALREADY_LOCKED = MAKE_RETURN_CODE(5);
|
||||
/**
|
||||
* Mutex object not found
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_NOT_FOUND = MAKE_RETURN_CODE(6);
|
||||
/**
|
||||
* Mutex could not be locked because max amount of recursive locks
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_MAX_LOCKS = MAKE_RETURN_CODE(7);
|
||||
/**
|
||||
* The current thread already owns this mutex
|
||||
*/
|
||||
static const ReturnValue_t CURR_THREAD_ALREADY_OWNS_MUTEX = MAKE_RETURN_CODE(8);
|
||||
/**
|
||||
* Current thread does not own this mutex
|
||||
*/
|
||||
static const ReturnValue_t CURR_THREAD_DOES_NOT_OWN_MUTEX = MAKE_RETURN_CODE(9);
|
||||
/**
|
||||
* The Mutex could not be blocked before timeout
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_TIMEOUT = MAKE_RETURN_CODE(10);
|
||||
/**
|
||||
* Invalid Mutex ID
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_INVALID_ID = MAKE_RETURN_CODE(11);
|
||||
/**
|
||||
* Mutex destroyed while waiting
|
||||
*/
|
||||
static const ReturnValue_t MUTEX_DESTROYED_WHILE_WAITING = MAKE_RETURN_CODE(12);
|
||||
|
||||
virtual ~MutexIF() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MUTEXIF_H_ */
|
||||
|
@ -1,33 +1,33 @@
|
||||
#ifndef FRAMEWORK_IPC_QUEUEFACTORY_H_
|
||||
#define FRAMEWORK_IPC_QUEUEFACTORY_H_
|
||||
|
||||
#include "MessageQueueIF.h"
|
||||
#include <cstdint>
|
||||
/**
|
||||
* Creates message queues.
|
||||
* This class is a "singleton" interface, i.e. it provides an
|
||||
* interface, but also is the base class for a singleton.
|
||||
*/
|
||||
class QueueFactory {
|
||||
public:
|
||||
virtual ~QueueFactory();
|
||||
/**
|
||||
* Returns the single instance of QueueFactory.
|
||||
* The implementation of #instance is found in its subclasses.
|
||||
* Thus, we choose link-time variability of the instance.
|
||||
*/
|
||||
static QueueFactory* instance();
|
||||
|
||||
MessageQueueIF* createMessageQueue(uint32_t messageDepth = 3,
|
||||
size_t maxMessageSize = MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||
|
||||
void deleteMessageQueue(MessageQueueIF* queue);
|
||||
private:
|
||||
/**
|
||||
* External instantiation is not allowed.
|
||||
*/
|
||||
QueueFactory();
|
||||
static QueueFactory* factoryInstance;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_IPC_QUEUEFACTORY_H_ */
|
||||
#ifndef FRAMEWORK_IPC_QUEUEFACTORY_H_
|
||||
#define FRAMEWORK_IPC_QUEUEFACTORY_H_
|
||||
|
||||
#include "MessageQueueIF.h"
|
||||
#include <cstdint>
|
||||
/**
|
||||
* Creates message queues.
|
||||
* This class is a "singleton" interface, i.e. it provides an
|
||||
* interface, but also is the base class for a singleton.
|
||||
*/
|
||||
class QueueFactory {
|
||||
public:
|
||||
virtual ~QueueFactory();
|
||||
/**
|
||||
* Returns the single instance of QueueFactory.
|
||||
* The implementation of #instance is found in its subclasses.
|
||||
* Thus, we choose link-time variability of the instance.
|
||||
*/
|
||||
static QueueFactory* instance();
|
||||
|
||||
MessageQueueIF* createMessageQueue(uint32_t messageDepth = 3,
|
||||
size_t maxMessageSize = MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||
|
||||
void deleteMessageQueue(MessageQueueIF* queue);
|
||||
private:
|
||||
/**
|
||||
* External instantiation is not allowed.
|
||||
*/
|
||||
QueueFactory();
|
||||
static QueueFactory* factoryInstance;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_IPC_QUEUEFACTORY_H_ */
|
||||
|
Reference in New Issue
Block a user