1
0
forked from fsfw/fsfw

Today's the day. Renamed platform to framework.

This commit is contained in:
Bastian Baetz
2016-06-15 23:48:41 +02:00
committed by Ulrich Mohr
parent 40987d0b27
commit 1d22a6c97e
356 changed files with 33946 additions and 3 deletions

115
ipc/CommandMessage.cpp Normal file
View File

@ -0,0 +1,115 @@
/**
* @file CommandMessage.cpp
* @brief This file defines the CommandMessage class.
* @date 20.06.2013
* @author baetz
*/
#include <framework/devicehandlers/DeviceHandlerMessage.h>
#include <framework/health/HealthMessage.h>
#include <framework/ipc/CommandMessage.h>
#include <framework/memory/MemoryMessage.h>
#include <framework/modes/ModeMessage.h>
#include <framework/monitoring/MonitoringMessage.h>
#include <framework/subsystem/modes/ModeSequenceMessage.h>
#include <framework/tmstorage/TmStoreMessage.h>
#include <mission/payloaddevices/commonPayloadStuff/PayloadHandlerMessage.h>
CommandMessage::CommandMessage() {
this->messageSize = COMMAND_MESSAGE_SIZE;
setCommand(CMD_NONE);
}
CommandMessage::CommandMessage(Command_t command, uint32_t parameter1,
uint32_t parameter2) {
this->messageSize = COMMAND_MESSAGE_SIZE;
setCommand(command);
setParameter(parameter1);
setParameter2(parameter2);
}
Command_t CommandMessage::getCommand() const {
Command_t command;
memcpy(&command, getData(), sizeof(Command_t));
return command;
}
void CommandMessage::setCommand(Command_t command) {
memcpy(getData(), &command, sizeof(command));
}
uint32_t CommandMessage::getParameter() const {
uint32_t parameter1;
memcpy(&parameter1, getData() + sizeof(Command_t), sizeof(parameter1));
return parameter1;
}
void CommandMessage::setParameter(uint32_t parameter1) {
memcpy(getData() + sizeof(Command_t), &parameter1, sizeof(parameter1));
}
uint32_t CommandMessage::getParameter2() const {
uint32_t parameter2;
memcpy(&parameter2, getData() + sizeof(Command_t) + sizeof(uint32_t),
sizeof(parameter2));
return parameter2;
}
void CommandMessage::setParameter2(uint32_t parameter2) {
memcpy(getData() + sizeof(Command_t) + sizeof(uint32_t), &parameter2,
sizeof(parameter2));
}
void CommandMessage::clearCommandMessage() {
switch((getCommand()>>8) & 0xff){
case MODE_COMMAND_MESSAGE_ID:
ModeMessage::clear(this);
break;
case HEALTH_COMMAND_MESSAGE_ID:
HealthMessage::clear(this);
break;
case MODE_SEQUENCE_MESSAGE_ID:
ModeSequenceMessage::clear(this);
break;
case FUNCTION_MESSAGE_ID:
ActionMessage::clear(this);
break;
case DEVICE_HANDLER_COMMAND_MESSAGE_ID:
DeviceHandlerMessage::clear(this);
break;
case MEMORY_MESSAGE_ID:
MemoryMessage::clear(this);
break;
case PAYLOAD_HANDLER_MESSAGE_ID:
PayloadHandlerMessage::clear(this);
break;
case LIMIT_MESSAGE_ID:
MonitoringMessage::clear(this);
break;
case TM_STORE_MESSAGE_ID:
TmStoreMessage::clear(this);
break;
default:
setCommand(CMD_NONE);
break;
}
}
bool CommandMessage::isClearedCommandMessage() {
return getCommand() == CMD_NONE;
}
size_t CommandMessage::getMinimumMessageSize() const {
return COMMAND_MESSAGE_SIZE;
}
void CommandMessage::setToUnknownCommand(Command_t initialCommand) {
setReplyRejected(UNKNOW_COMMAND, initialCommand);
}
void CommandMessage::setReplyRejected(ReturnValue_t reason,
Command_t initialCommand) {
setCommand(REPLY_REJECTED);
setParameter(reason);
setParameter2(initialCommand);
}

137
ipc/CommandMessage.h Normal file
View File

@ -0,0 +1,137 @@
/**
* @file CommandMessage.h
* @brief This file defines the CommandMessage class.
* @date 20.06.2013
* @author baetz
*/
#ifndef COMMANDMESSAGE_H_
#define COMMANDMESSAGE_H_
//Remember to add new Message Types to the clear function!
#define MODE_COMMAND_MESSAGE_ID 1
#define HEALTH_COMMAND_MESSAGE_ID 2
#define MODE_SEQUENCE_MESSAGE_ID 3
#define FUNCTION_MESSAGE_ID 4
#define TM_STORE_MESSAGE_ID 5
#define TTC_TM_MESSAGE_ID 0x10
#define DEVICE_HANDLER_COMMAND_MESSAGE_ID 0x44
#define LIMIT_MESSAGE_ID 0x4C
#define MEMORY_MESSAGE_ID 0x4D
#define PAYLOAD_HANDLER_MESSAGE_ID 0x50
#define PARAMETER_MESSAGE_ID 0x60
#include <framework/ipc/MessageQueueMessage.h>
#define MAKE_COMMAND_ID( number ) ((MESSAGE_ID << 8) + (number))
typedef ReturnValue_t Command_t;
class CommandMessage : public MessageQueueMessage {
public:
static const uint8_t INTERFACE_ID = COMMAND_MESSAGE;
static const ReturnValue_t UNKNOW_COMMAND = MAKE_RETURN_CODE(0x01);
static const uint8_t MESSAGE_ID = 0;
static const Command_t CMD_NONE = MAKE_COMMAND_ID( 0 );//!< Used internally, will be ignored
static const Command_t REPLY_COMMAND_OK = MAKE_COMMAND_ID( 3 );
static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID( 0xD1 );//!< Reply indicating that the current command was rejected, par1 should contain the error code
/**
* This is the size of a message as it is seen by the MessageQueue
*/
static const size_t COMMAND_MESSAGE_SIZE = HEADER_SIZE
+ sizeof(Command_t) + 2 * sizeof(uint32_t);
/**
* Default Constructor, does not initialize anything.
*
* 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);
/**
* 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
*/
Command_t getCommand() const;
/**
* Set the DeviceHandlerCOmmand_t of the message
*
* @param the Command to be sent
*/
void setCommand(Command_t command);
/**
* Get the first parameter of the message
*
* @return the first Parameter of the message
*/
uint32_t getParameter() const;
/**
* Set the first parameter of the message
*
* @param the first parameter of the message
*/
void setParameter(uint32_t parameter1);
/**
* Get the second parameter of the message
*
* @return the second Parameter of the message
*/
uint32_t getParameter2() const;
/**
* Set the second parameter of the message
*
* @param the second parameter of the message
*/
void setParameter2(uint32_t parameter2);
/**
* Set the command to CMD_NONE and try to find
* the correct class to handle a more detailed
* clear.
*
*/
void clearCommandMessage();
/**
* 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(Command_t initialCommand);
void setReplyRejected(ReturnValue_t reason, Command_t initialCommand = CMD_NONE);
size_t getMinimumMessageSize() const;
};
#endif /* COMMANDMESSAGE_H_ */

22
ipc/Makefile Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
#
# OSAL makefile
#
# Created on: Mar 04, 2010
# Author: ziemke
# Author: Claas Ziemke
# Copyright 2010, Claas Ziemke <claas.ziemke@gmx.net>
#
BASEDIR=../../
include $(BASEDIR)options.mk
OBJ = $(BUILDDIR)/OPUSMessageQueue.o
all: $(OBJ)
$(BUILDDIR)/%.o: %.cpp %.h
$(CPP) $(CFLAGS) $(DEFINES) $(CCOPT) ${INCLUDE} -c $< -o $@
clean:
$(RM) *.o *.gcno *.gcda

102
ipc/MessageProxy.cpp Normal file
View File

@ -0,0 +1,102 @@
/*
* MessageProxy.cpp
*
* Created on: 18.03.2015
* Author: baetz
*/
#include <framework/ipc/MessageProxy.h>
MessageProxy::~MessageProxy() {
}
MessageQueueId_t MessageProxy::getReceiver() const {
return receiver;
}
MessageQueueId_t MessageProxy::getCommandQueue() const {
return commandQueue.getId();
}
void MessageProxy::setReceiver(MessageQueueId_t configuredReceiver) {
this->receiver = configuredReceiver;
}
MessageProxy::MessageProxy(size_t queueDepth, MessageQueueId_t setReceiver) :
receiver(setReceiver), currentRequest(0), commandQueue(queueDepth) {
}
void MessageProxy::checkCommandQueue() {
CommandMessage message;
MessageQueueId_t senderId;
ReturnValue_t result = commandQueue.receiveMessage(&message, &senderId);
if (result != HasReturnvaluesIF::RETURN_OK) {
return;
}
if (senderId != receiver) {
//It's a command.
if (currentRequest == 0) {
result = commandQueue.sendMessage(receiver, &message);
if (result == HasReturnvaluesIF::RETURN_OK) {
currentRequest = senderId;
}
} else {
result = commandFifo.insert(message);
}
if (result != HasReturnvaluesIF::RETURN_OK) {
message.clear();
CommandMessage reply;
reply.setReplyRejected(result, message.getCommand());
commandQueue.reply(&reply);
}
} else {
//It's a reply.
if (currentRequest != 0) {
//Failed forwarding is ignored.
commandQueue.sendMessage(currentRequest, &message);
//This request is finished.
currentRequest = 0;
//Check if there's another request in FIFO:
result = commandFifo.retrieve(&message);
if (result != HasReturnvaluesIF::RETURN_OK) {
//Nothing in FIFO.
return;
}
currentRequest = message.getSender();
result = commandQueue.sendMessage(receiver, &message);
if (result != HasReturnvaluesIF::RETURN_OK) {
message.clear();
CommandMessage reply;
reply.setReplyRejected(result, message.getCommand());
commandQueue.reply(&reply);
currentRequest = 0;
}
} else {
//We don't expect a reply. Ignore.
}
}
}
void MessageProxy::flush() {
CommandMessage command;
CommandMessage reply;
if (currentRequest != 0) {
commandQueue.sendMessage(currentRequest, &reply);
currentRequest = 0;
}
for (ReturnValue_t result = commandQueue.receiveMessage(&command);
result == HasReturnvaluesIF::RETURN_OK;
result = commandQueue.receiveMessage(&command)) {
reply.setReplyRejected(FLUSHED, command.getCommand());
commandQueue.reply(&reply);
command.clear();
}
for (ReturnValue_t result = commandFifo.retrieve(&command);
result == HasReturnvaluesIF::RETURN_OK;
result = commandFifo.retrieve(&command)) {
reply.setReplyRejected(FLUSHED, command.getCommand());
commandQueue.sendMessage(command.getSender(), &reply);
command.clear();
}
}

43
ipc/MessageProxy.h Normal file
View File

@ -0,0 +1,43 @@
/*
* MessageProxy.h
*
* Created on: 18.03.2015
* Author: baetz
*/
#ifndef FRAMEWORK_IPC_MESSAGEPROXY_H_
#define FRAMEWORK_IPC_MESSAGEPROXY_H_
#include <framework/container/FIFO.h>
#include <framework/ipc/CommandMessage.h>
#include <framework/ipc/MessageQueue.h>
/**
* Simple "one message forwarding" proxy.
* Could be extended to forwarding to multiple recipients in parallel
* with a small forwarding map.
*/
class MessageProxy {
public:
MessageProxy(size_t queueDepth = DEFAULT_QUEUE_DEPTH, MessageQueueId_t setReceiver = 0);
virtual ~MessageProxy();
MessageQueueId_t getCommandQueue() const;
MessageQueueId_t getReceiver() const;
void setReceiver(MessageQueueId_t configuredReceiver);
/**
* Checks the commandQueue for commands from other stuff or replies from the Receiver.
* There's the implicit assumption, that we get commands from anywhere, but replies only from the
* #configuredReceiver.
*/
void checkCommandQueue();
void flush();
static const uint8_t INTERFACE_ID = MESSAGE_PROXY;
static const ReturnValue_t FLUSHED = MAKE_RETURN_CODE(1);
private:
static const size_t DEFAULT_QUEUE_DEPTH = 5;
MessageQueueId_t receiver;
MessageQueueId_t currentRequest;
MessageQueue commandQueue;
FIFO<CommandMessage, DEFAULT_QUEUE_DEPTH> commandFifo; //!< Required because there might be small bursts of commands coming in parallel.
};
#endif /* FRAMEWORK_IPC_MESSAGEPROXY_H_ */

87
ipc/MessageQueue.cpp Normal file
View File

@ -0,0 +1,87 @@
/*
* MessageQueue.cpp
*
* Created on: Oct 2, 2012
* Author: baetz
*/
#include <framework/ipc/MessageQueue.h>
#include <framework/ipc/MessageQueueMessage.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
MessageQueue::MessageQueue( size_t message_depth, size_t max_message_size ) :
id(0), lastPartner(0) {
Name_t name = ('Q' << 24) + (queueCounter++ << 8);
ReturnValue_t status = OSAL::createMessageQueue(name, message_depth, max_message_size, 0, &(this->id));
if (status != RETURN_OK) {
error << "MessageQueue::MessageQueue: Creating Queue " << std::hex << name << std::dec << " failed with status:" << (uint32_t)status << std::endl;
this->id = 0;
} else {
//Creating the MQ was successful
// if (id == 0x220100f8) {
// debug << "Queue found! " << std::endl;
// }
}
}
MessageQueue::~MessageQueue() {
OSAL::deleteMessageQueue(&this->id);
}
ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message) {
return this->MessageQueueSender::sendMessage(sendTo, message, this->getId() );
}
ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessage* message) {
return this->MessageQueueSender::sendToDefault(message, this->getId() );
}
ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) {
if (this->lastPartner != 0) {
return this->MessageQueueSender::sendMessage( this->lastPartner, message, this->getId() );
} else {
return OSAL::INCORRECT_STATE;
}
}
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message,
MessageQueueId_t* receivedFrom) {
ReturnValue_t status = this->receiveMessage(message);
*receivedFrom = this->lastPartner;
return status;
}
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) {
ReturnValue_t status = OSAL::receiveMessage(this->id, message->getBuffer(), message->MAX_MESSAGE_SIZE,
&(message->messageSize), OSAL::NO_WAIT, 1);
if (status == RETURN_OK) {
this->lastPartner = message->getSender();
//Check size of incoming message.
if ( message->messageSize < message->getMinimumMessageSize() ) {
status = RETURN_FAILED;
}
} else {
//No message was received. Keep lastPartner anyway, I might send something later.
//But still, delete packet content.
memset(message->getData(),0,message->MAX_DATA_SIZE);
}
return status;
}
MessageQueueId_t MessageQueue::getLastPartner() {
return this->lastPartner;
}
ReturnValue_t MessageQueue::flush(uint32_t* count) {
return OSAL::flushMessageQueue(this->id, count);
}
MessageQueueId_t MessageQueue::getId() const {
return this->id;
}
uint16_t MessageQueue::queueCounter = 0;

127
ipc/MessageQueue.h Normal file
View File

@ -0,0 +1,127 @@
/**
* @file MessageQueue.h
*
* @date 10/02/2012
* @author Bastian Baetz
*
* @brief This file contains the definition of the MessageQueue class.
*/
#ifndef MESSAGEQUEUE_H_
#define MESSAGEQUEUE_H_
#include <framework/ipc/MessageQueueSender.h>
/**
* @brief This class manages sending and receiving of message queue messages.
*
* @details Message queues are used to pass asynchronous messages between processes.
* They work like post boxes, where all incoming messages are stored in FIFO
* order. This class creates a new receiving queue and provides methods to fetch
* received messages. Being a child of MessageQueueSender, this class also provides
* methods to send a message to a user-defined or a default destination. In addition
* it also provides a reply method to answer to the queue it received its last message
* from.
* The MessageQueue should be used as "post box" for a single owning object. So all
* message queue communication is "n-to-one".
* For creating the queue, as well as sending and receiving messages, the class makes
* use of the operating system calls provided.
* \ingroup message_queue
*/
class MessageQueue : public MessageQueueSender {
private:
/**
* @brief The class stores the queue id it got assigned from the operating system in this attribute.
* If initialization fails, the queue id is set to zero.
*/
MessageQueueId_t id;
/**
* @brief In this attribute, the queue id of the last communication partner is stored
* to allow for replying.
*/
MessageQueueId_t lastPartner;
/**
* @brief The message queue's name -a user specific information for the operating system- is
* generated automatically with the help of this static counter.
*/
static uint16_t queueCounter;
public:
/**
* @brief The constructor initializes and configures the message queue.
* @details By making use of the according operating system call, a message queue is created
* and initialized. The message depth - the maximum number of messages to be
* buffered - may be set with the help of a parameter, whereas the message size is
* automatically set to the maximum message queue message size. The operating system
* sets the message queue id, or i case of failure, it is set to zero.
* @param message_depth The number of messages to be buffered before passing an error to the
* sender. Default is three.
* @param max_message_size With this parameter, the maximum message size can be adjusted.
* This should be left default.
*/
MessageQueue( size_t message_depth = 3, size_t max_message_size = MessageQueueMessage::MAX_MESSAGE_SIZE );
/**
* @brief The destructor deletes the formerly created message queue.
* @details This is accomplished by using the delete call provided by the operating system.
*/
virtual ~MessageQueue();
/**
* @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.
*/
ReturnValue_t sendMessage( MessageQueueId_t sendTo, MessageQueueMessage* message );
/**
* @brief This operation sends a message to the default destination.
* @details As in the sendMessage method, this function uses the sendToDefault call of the
* MessageQueueSender parent class and adds its queue id as "sentFrom" information.
* @param message A pointer to a previously created message, which is sent.
*/
ReturnValue_t sendToDefault( MessageQueueMessage* message );
/**
* @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.
*/
ReturnValue_t reply( MessageQueueMessage* message );
/**
* @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.
*/
ReturnValue_t receiveMessage(MessageQueueMessage* message,
MessageQueueId_t *receivedFrom);
/**
* @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 the
* lastPartner 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.
*/
ReturnValue_t receiveMessage(MessageQueueMessage* message);
/**
* Deletes all pending messages in the queue.
* @param count The number of flushed messages.
* @return RETURN_OK on success.
*/
ReturnValue_t flush(uint32_t* count);
/**
* @brief This method returns the message queue id of the last communication partner.
*/
MessageQueueId_t getLastPartner();
/**
* @brief This method returns the message queue id of this class's message queue.
*/
MessageQueueId_t getId() const;
};
#endif /* MESSAGEQUEUE_H_ */

View File

@ -0,0 +1,69 @@
/*
* MessageQueueMessage.cpp
*
* Created on: 22.11.2012
* Author: baetz
*/
#include <framework/ipc/MessageQueueMessage.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
MessageQueueMessage::MessageQueueMessage() :
messageSize(this->HEADER_SIZE) {
memset(this->internalBuffer, 0, sizeof(this->internalBuffer));
}
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));
}
MessageQueueMessage::MessageQueueMessage(uint8_t* data, uint32_t size) :
messageSize(this->HEADER_SIZE + size) {
if (size <= this->MAX_DATA_SIZE) {
memcpy(this->getData(), data, size);
} else {
memset(this->internalBuffer, 0, sizeof(this->internalBuffer));
this->messageSize = this->HEADER_SIZE;
}
}
size_t MessageQueueMessage::getMinimumMessageSize() {
return this->HEADER_SIZE;
}
void MessageQueueMessage::print() {
debug << "MessageQueueMessage has size: " << this->messageSize << std::hex
<< std::endl;
for (uint8_t count = 0; count < this->messageSize; count++) {
debug << (uint32_t) this->internalBuffer[count] << ":";
}
debug << std::dec << std::endl;
}
void MessageQueueMessage::clear() {
memset(this->getBuffer(), 0, this->MAX_MESSAGE_SIZE);
}

122
ipc/MessageQueueMessage.h Normal file
View File

@ -0,0 +1,122 @@
#ifndef MESSAGEQUEUEMESSAGE_H_
#define MESSAGEQUEUEMESSAGE_H_
#include <framework/osal/OSAL.h>
class MessageQueue;
class MessageQueueSender;
/**
* \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 {
friend class MessageQueue;
friend class MessageQueueSender;
public:
/**
* \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 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.
* \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 const size_t MAX_MESSAGE_SIZE = MAX_DATA_SIZE + HEADER_SIZE;
private:
/**
* \brief This is the internal buffer that contains the actual message data.
*/
uint8_t internalBuffer[MAX_MESSAGE_SIZE];
protected:
/**
* \brief This method is used to set the sender's message queue id information prior to
* sending the message.
* \param setId The message queue id that identifies the sending message queue.
*/
void setSender(MessageQueueId_t setId);
/**
* \brief This helper function is used by the MessageQueue class to check the size of an
* incoming message.
* \details The method must be overwritten by child classes if size checks shall be more strict.
* @return The default implementation returns HEADER_SIZE.
*/
virtual size_t getMinimumMessageSize();
public:
/**
* \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 variable's 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.
*/
size_t messageSize;
/**
* \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.
*/
MessageQueueMessage(uint8_t* data, uint32_t size);
/**
* \brief As no memory is allocated in this class, the destructor is empty.
*/
virtual ~MessageQueueMessage();
/**
* \brief This method is used to get the complete data of the message.
*/
const uint8_t* getBuffer() const;
/**
* \brief This method is used to get the complete data of the message.
*/
uint8_t* getBuffer();
/**
* \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;
/**
* \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();
/**
* \brief This method is used to extract the sender's message queue id information from a
* received message.
*/
MessageQueueId_t getSender() const;
/**
* \brief With this method, the whole content and the message size is set to zero.
*/
void clear();
/**
* \brief This is a debug method that prints the content (till messageSize) to the debug output.
*/
void print();
};
#endif /* MESSAGEQUEUEMESSAGE_H_ */

View File

@ -0,0 +1,56 @@
/*
* MessageQueueSender.cpp
*
* Created on: 22.11.2012
* Author: baetz
*/
#include <framework/ipc/MessageQueueMessage.h>
#include <framework/ipc/MessageQueueSender.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
MessageQueueSender::MessageQueueSender(MessageQueueId_t set_default_destination) :
default_destination(set_default_destination) {
//Nothing to do in ctor.
}
void MessageQueueSender::setDefaultDestination(
MessageQueueId_t defaultDestination) {
default_destination = defaultDestination;
}
MessageQueueSender::~MessageQueueSender() {
//Nothing to do in dtor.
}
ReturnValue_t MessageQueueSender::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom) {
message->setSender(sentFrom);
ReturnValue_t result = OSAL::sendMessage(sendTo, message->getBuffer(),
message->messageSize);
if (result != RETURN_OK) {
debug << "MessageQueueSender. Sending message from " << std::hex
<< sentFrom << " to " << sendTo << " failed with " << result
<< std::endl;
}
return result;
}
ReturnValue_t MessageQueueSender::sendToDefault(MessageQueueMessage* message,
MessageQueueId_t sentFrom) {
message->setSender(sentFrom);
ReturnValue_t result = OSAL::sendMessage(this->default_destination,
message->getBuffer(), message->messageSize);
if (result != RETURN_OK) {
debug << "MessageQueueSender. Sending message from " << std::hex
<< sentFrom << " to " << default_destination << " failed with "
<< result << std::endl;
}
return result;
}
MessageQueueId_t MessageQueueSender::getDefaultDestination() {
return this->default_destination;
}

79
ipc/MessageQueueSender.h Normal file
View File

@ -0,0 +1,79 @@
#ifndef MESSAGEQUEUESENDER_H_
#define MESSAGEQUEUESENDER_H_
#include <framework/events/Event.h>
#include <framework/ipc/MessageQueueMessage.h>
#include <framework/osal/OSAL.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
/**
* \defgroup message_queue Message Queues
* This group contains all Message Queue elements, but also the different message
* types sent over these queues.
*/
/**
* \brief This class manages sending of messages to receiving message queues.
*
* \details Message queues are a typical method of interprocess communication.
* They work like post boxes, where all incoming messages are stored in FIFO
* order. This class provides an interface to simplify sending messages to
* receiving queues without the necessity of owing a "post box" itself. It makes
* use of the underlying operating system's message queue features.
* \ingroup message_queue
*/
class MessageQueueSender : public HasReturnvaluesIF {
private:
/**
* \brief This attribute stores a default destination to send messages to.
* \details It is stored to simplify sending to always-the-same receiver. The attribute may
* be set in the constructor or by a setter call to setDefaultDestination.
*/
MessageQueueId_t default_destination;
public:
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::OBSW_1;
static const Event SEND_MSG_FAILED = MAKE_EVENT(0, SEVERITY::LOW);
static const MessageQueueId_t NO_QUEUE = 0;
/**
* \brief In the constructor of the class, the default destination may be set.
* \details As the MessageQueueSender class has no receiving queue by itself, no
* operating system call to create a message queue is required.
* \param set_default_destination With this parameter, the default destination is set.
* If no value is provided, it is set to zero.
*/
MessageQueueSender( MessageQueueId_t set_default_destination = NO_QUEUE );
/**
* \brief As almost nothing is done in the constructor, there's nothing done in the destructor as well.
*/
virtual ~MessageQueueSender();
/**
* \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 return
* value 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.
*/
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE );
/**
* \brief The sendToDefault 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.
*/
virtual ReturnValue_t sendToDefault( MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE );
/**
* \brief This method is a simple setter for the default destination.
*/
void setDefaultDestination(MessageQueueId_t defaultDestination);
/**
* \brief This method is a simple getter for the default destination.
*/
MessageQueueId_t getDefaultDestination();
};
#endif /* MESSAGEQUEUESENDER_H_ */

29
ipc/ReplyMessage.h Normal file
View File

@ -0,0 +1,29 @@
/**
* @file ReplyMessage.h
* @brief This file defines the ReplyMessage class.
* @date 20.06.2013
* @author baetz
*/
#ifndef REPLYMESSAGE_H_
#define REPLYMESSAGE_H_
#include <framework/ipc/CommandMessage.h>
class ReplyMessage: public CommandMessage {
public:
static const uint8_t MESSAGE_ID = 1;
static const Command_t REPLY_MODE = MAKE_COMMAND_ID( 3 ); //!< Reply to a @c CMD_MODE or @c CMD_READ_MODE, getParameter contains a DeviceHandlerIF::DeviceHandlerMode_t, getParameter2 the submode
static const Command_t REPLY_TRANSITION_DELAY = MAKE_COMMAND_ID( 4 ); //!< Reply to a @c CMD_MODE, indicates that the transition will take some time, getParameter contains the maximum duration in ms
static const Command_t REPLY_INVALID_MODE = MAKE_COMMAND_ID( 5 ); //!< Reply to a @c CMD_MODE, indicates that the requested DeviceHandlerIF::DeviceHandlerMode_t was invalid
static const Command_t REPLY_CANT_REACH_MODE = MAKE_COMMAND_ID( 6 ); //!< Reply to a @c CMD_MODE, indicates that the requested DeviceHandlerIF::DeviceHandlerMode_t can not be reached from the current mode, getParameter() is the DeviceHandlerIF::DeviceHandlerMode_t, getParameter2() is the submode number
ReplyMessage() :
CommandMessage() {
}
ReplyMessage(Command_t command, uint32_t parameter1, uint32_t parameter2) :
CommandMessage(command, parameter1, parameter2) {
}
virtual ~ReplyMessage() {}
};
#endif /* REPLYMESSAGE_H_ */