updating code from Flying Laptop
This is the framework of Flying Laptop OBSW version A.13.0.
This commit is contained in:
@ -13,7 +13,12 @@
|
||||
#include <framework/monitoring/MonitoringMessage.h>
|
||||
#include <framework/subsystem/modes/ModeSequenceMessage.h>
|
||||
#include <framework/tmstorage/TmStoreMessage.h>
|
||||
#include <mission/payloaddevices/commonPayloadStuff/PayloadHandlerMessage.h>
|
||||
#include <framework/parameters/ParameterMessage.h>
|
||||
|
||||
namespace MESSAGE_TYPE {
|
||||
void clearMissionMessage(CommandMessage* message);
|
||||
}
|
||||
|
||||
|
||||
CommandMessage::CommandMessage() {
|
||||
this->messageSize = COMMAND_MESSAGE_SIZE;
|
||||
@ -62,35 +67,35 @@ void CommandMessage::setParameter2(uint32_t parameter2) {
|
||||
|
||||
void CommandMessage::clearCommandMessage() {
|
||||
switch((getCommand()>>8) & 0xff){
|
||||
case MODE_COMMAND_MESSAGE_ID:
|
||||
case MESSAGE_TYPE::MODE_COMMAND:
|
||||
ModeMessage::clear(this);
|
||||
break;
|
||||
case HEALTH_COMMAND_MESSAGE_ID:
|
||||
case MESSAGE_TYPE::HEALTH_COMMAND:
|
||||
HealthMessage::clear(this);
|
||||
break;
|
||||
case MODE_SEQUENCE_MESSAGE_ID:
|
||||
case MESSAGE_TYPE::MODE_SEQUENCE:
|
||||
ModeSequenceMessage::clear(this);
|
||||
break;
|
||||
case FUNCTION_MESSAGE_ID:
|
||||
case MESSAGE_TYPE::ACTION:
|
||||
ActionMessage::clear(this);
|
||||
break;
|
||||
case DEVICE_HANDLER_COMMAND_MESSAGE_ID:
|
||||
case MESSAGE_TYPE::DEVICE_HANDLER_COMMAND:
|
||||
DeviceHandlerMessage::clear(this);
|
||||
break;
|
||||
case MEMORY_MESSAGE_ID:
|
||||
case MESSAGE_TYPE::MEMORY:
|
||||
MemoryMessage::clear(this);
|
||||
break;
|
||||
case PAYLOAD_HANDLER_MESSAGE_ID:
|
||||
PayloadHandlerMessage::clear(this);
|
||||
break;
|
||||
case LIMIT_MESSAGE_ID:
|
||||
case MESSAGE_TYPE::MONITORING:
|
||||
MonitoringMessage::clear(this);
|
||||
break;
|
||||
case TM_STORE_MESSAGE_ID:
|
||||
case MESSAGE_TYPE::TM_STORE:
|
||||
TmStoreMessage::clear(this);
|
||||
break;
|
||||
case MESSAGE_TYPE::PARAMETER:
|
||||
ParameterMessage::clear(this);
|
||||
break;
|
||||
default:
|
||||
setCommand(CMD_NONE);
|
||||
MESSAGE_TYPE::clearMissionMessage(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -103,7 +108,9 @@ size_t CommandMessage::getMinimumMessageSize() const {
|
||||
return COMMAND_MESSAGE_SIZE;
|
||||
}
|
||||
|
||||
void CommandMessage::setToUnknownCommand(Command_t initialCommand) {
|
||||
void CommandMessage::setToUnknownCommand() {
|
||||
Command_t initialCommand = getCommand();
|
||||
clearCommandMessage();
|
||||
setReplyRejected(UNKNOW_COMMAND, initialCommand);
|
||||
}
|
||||
|
||||
|
@ -8,19 +8,9 @@
|
||||
#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/FwMessageTypes.h>
|
||||
#include <config/ipc/MissionMessageTypes.h>
|
||||
|
||||
#include <framework/ipc/MessageQueueMessage.h>
|
||||
|
||||
@ -29,11 +19,11 @@ typedef ReturnValue_t Command_t;
|
||||
|
||||
class CommandMessage : public MessageQueueMessage {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = COMMAND_MESSAGE;
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_MESSAGE;
|
||||
static const ReturnValue_t UNKNOW_COMMAND = MAKE_RETURN_CODE(0x01);
|
||||
|
||||
|
||||
static const uint8_t MESSAGE_ID = 0;
|
||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::COMMAND;
|
||||
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
|
||||
@ -112,6 +102,10 @@ public:
|
||||
* Set the command to CMD_NONE and try to find
|
||||
* the correct class to handle a more detailed
|
||||
* clear.
|
||||
* Also, calls a mission-specific clearMissionMessage
|
||||
* function to separate between framework and mission
|
||||
* messages. Not optimal, may be replaced by totally
|
||||
* different auto-delete solution (e.g. smart pointers).
|
||||
*
|
||||
*/
|
||||
void clearCommandMessage();
|
||||
@ -128,7 +122,7 @@ public:
|
||||
* 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 setToUnknownCommand();
|
||||
void setReplyRejected(ReturnValue_t reason, Command_t initialCommand = CMD_NONE);
|
||||
size_t getMinimumMessageSize() const;
|
||||
};
|
||||
|
21
ipc/FwMessageTypes.h
Normal file
21
ipc/FwMessageTypes.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef FRAMEWORK_IPC_FWMESSAGETYPES_H_
|
||||
#define FRAMEWORK_IPC_FWMESSAGETYPES_H_
|
||||
|
||||
namespace MESSAGE_TYPE {
|
||||
//Remember to add new Message Types to the clearCommandMessage function!
|
||||
enum FW_MESSAGE_TYPE {
|
||||
COMMAND = 0,
|
||||
MODE_COMMAND,
|
||||
HEALTH_COMMAND,
|
||||
MODE_SEQUENCE,
|
||||
ACTION,
|
||||
TM_STORE,
|
||||
DEVICE_HANDLER_COMMAND,
|
||||
MONITORING,
|
||||
MEMORY,
|
||||
PARAMETER,
|
||||
FW_MESSAGES_COUNT
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* FRAMEWORK_IPC_FWMESSAGETYPES_H_ */
|
22
ipc/Makefile
22
ipc/Makefile
@ -1,22 +0,0 @@
|
||||
#!/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
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* 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_ */
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* 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;
|
@ -1,127 +0,0 @@
|
||||
/**
|
||||
* @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_ */
|
90
ipc/MessageQueueIF.h
Normal file
90
ipc/MessageQueueIF.h
Normal file
@ -0,0 +1,90 @@
|
||||
#ifndef FRAMEWORK_IPC_MESSAGEQUEUEIF_H_
|
||||
#define FRAMEWORK_IPC_MESSAGEQUEUEIF_H_
|
||||
|
||||
#include <framework/ipc/MessageQueueMessage.h>
|
||||
#include <framework/ipc/MessageQueueSenderIF.h>
|
||||
class MessageQueueIF {
|
||||
public:
|
||||
|
||||
static const MessageQueueId_t NO_QUEUE = MessageQueueSenderIF::NO_QUEUE; //!< Ugly hack.
|
||||
|
||||
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.
|
||||
*/
|
||||
virtual ReturnValue_t reply( MessageQueueMessage* 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(MessageQueueMessage* 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 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.
|
||||
*/
|
||||
virtual ReturnValue_t receiveMessage(MessageQueueMessage* 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 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.
|
||||
* \param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full (if implemented).
|
||||
*/
|
||||
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false ) = 0;
|
||||
|
||||
/**
|
||||
* \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, bool ignoreFault = false ) = 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 /* FRAMEWORK_IPC_MESSAGEQUEUEIF_H_ */
|
@ -1,12 +1,8 @@
|
||||
/*
|
||||
* MessageQueueMessage.cpp
|
||||
*
|
||||
* Created on: 22.11.2012
|
||||
* Author: baetz
|
||||
*/
|
||||
#include <framework/ipc/MessageQueueMessage.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
MessageQueueMessage::MessageQueueMessage() :
|
||||
messageSize(this->HEADER_SIZE) {
|
||||
memset(this->internalBuffer, 0, sizeof(this->internalBuffer));
|
||||
|
@ -1,10 +1,9 @@
|
||||
#ifndef MESSAGEQUEUEMESSAGE_H_
|
||||
#define MESSAGEQUEUEMESSAGE_H_
|
||||
|
||||
#include <framework/osal/OSAL.h>
|
||||
#include <framework/ipc/MessageQueueSenderIF.h>
|
||||
#include <stddef.h>
|
||||
|
||||
class MessageQueue;
|
||||
class MessageQueueSender;
|
||||
/**
|
||||
* \brief This class is the representation and data organizer for interprocess messages.
|
||||
*
|
||||
@ -20,8 +19,6 @@ class MessageQueueSender;
|
||||
* \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.
|
||||
@ -44,20 +41,6 @@ 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.
|
||||
@ -117,6 +100,19 @@ public:
|
||||
* \brief This is a debug method that prints the content (till messageSize) to the debug output.
|
||||
*/
|
||||
void print();
|
||||
/**
|
||||
* \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();
|
||||
};
|
||||
|
||||
#endif /* MESSAGEQUEUEMESSAGE_H_ */
|
||||
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
#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_ */
|
37
ipc/MessageQueueSenderIF.h
Normal file
37
ipc/MessageQueueSenderIF.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_
|
||||
#define FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_
|
||||
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
class MessageQueueMessage;
|
||||
|
||||
|
||||
//TODO: Actually, the definition of this ID to be a uint32_t is not ideal and breaks layering.
|
||||
//However, it is difficult to keep layering, as the ID is stored in many places and sent around in
|
||||
//MessageQueueMessage.
|
||||
//Ideally, one would use the (current) object_id_t only, however, doing a lookup of queueIDs for every
|
||||
//call does not sound ideal.
|
||||
//In a first step, I'll circumvent the issue by not touching it, maybe in a second step.
|
||||
//This also influences Interface design (getCommandQueue) and some other issues..
|
||||
typedef uint32_t MessageQueueId_t;
|
||||
|
||||
class MessageQueueSenderIF {
|
||||
public:
|
||||
static const MessageQueueId_t NO_QUEUE = 0;
|
||||
|
||||
virtual ~MessageQueueSenderIF() {}
|
||||
|
||||
/**
|
||||
* Allows sending messages without actually "owing" a message queue.
|
||||
* Not sure whether this is actually a good idea.
|
||||
* Must be implemented by a subclass.
|
||||
*/
|
||||
static ReturnValue_t sendMessage(MessageQueueId_t sendTo,
|
||||
MessageQueueMessage* message, MessageQueueId_t sentFrom =
|
||||
MessageQueueSenderIF::NO_QUEUE);
|
||||
private:
|
||||
MessageQueueSenderIF() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_ */
|
34
ipc/MutexFactory.h
Normal file
34
ipc/MutexFactory.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef FRAMEWORK_IPC_MUTEXFACTORY_H_
|
||||
#define FRAMEWORK_IPC_MUTEXFACTORY_H_
|
||||
|
||||
#include <framework/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_ */
|
16
ipc/MutexIF.h
Normal file
16
ipc/MutexIF.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef FRAMEWORK_IPC_MUTEXIF_H_
|
||||
#define FRAMEWORK_IPC_MUTEXIF_H_
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
|
||||
class MutexIF {
|
||||
public:
|
||||
static const uint32_t NO_TIMEOUT; //!< Needs to be defined in implementation.
|
||||
virtual ~MutexIF() {}
|
||||
virtual ReturnValue_t lockMutex(uint32_t timeoutMs) = 0;
|
||||
virtual ReturnValue_t unlockMutex() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MUTEXIF_H_ */
|
33
ipc/QueueFactory.h
Normal file
33
ipc/QueueFactory.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef FRAMEWORK_IPC_QUEUEFACTORY_H_
|
||||
#define FRAMEWORK_IPC_QUEUEFACTORY_H_
|
||||
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
#include <stdint.h>
|
||||
/**
|
||||
* 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 message_depth = 3,
|
||||
uint32_t max_message_size = MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||
|
||||
void deleteMessageQueue(MessageQueueIF* queue);
|
||||
private:
|
||||
/**
|
||||
* External instantiation is not allowed.
|
||||
*/
|
||||
QueueFactory();
|
||||
static QueueFactory* factoryInstance;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_IPC_QUEUEFACTORY_H_ */
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* @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_ */
|
Reference in New Issue
Block a user