Merge branch 'mueller_framework' into front_branch

This commit is contained in:
Robin Müller 2020-06-11 16:22:50 +02:00
commit 60aed39bc5
47 changed files with 836 additions and 561 deletions

View File

@ -16,7 +16,7 @@ ReturnValue_t ActionHelper::handleActionMessage(CommandMessage* command) {
ActionMessage::getStoreId(command)); ActionMessage::getStoreId(command));
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} else { } else {
return CommandMessage::UNKNOW_COMMAND; return CommandMessage::UNKNOWN_COMMAND;
} }
} }
@ -33,13 +33,15 @@ ReturnValue_t ActionHelper::initialize(MessageQueueIF* queueToUse_) {
} }
void ActionHelper::step(uint8_t step, MessageQueueId_t reportTo, ActionId_t commandId, ReturnValue_t result) { void ActionHelper::step(uint8_t step, MessageQueueId_t reportTo, ActionId_t commandId, ReturnValue_t result) {
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
ActionMessage::setStepReply(&reply, commandId, step + STEP_OFFSET, result); ActionMessage::setStepReply(&reply, commandId, step + STEP_OFFSET, result);
queueToUse->sendMessage(reportTo, &reply); queueToUse->sendMessage(reportTo, &reply);
} }
void ActionHelper::finish(MessageQueueId_t reportTo, ActionId_t commandId, ReturnValue_t result) { void ActionHelper::finish(MessageQueueId_t reportTo, ActionId_t commandId, ReturnValue_t result) {
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
ActionMessage::setCompletionReply(&reply, commandId, result); ActionMessage::setCompletionReply(&reply, commandId, result);
queueToUse->sendMessage(reportTo, &reply); queueToUse->sendMessage(reportTo, &reply);
} }
@ -54,7 +56,8 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t act
size_t size = 0; size_t size = 0;
ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size); ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
ActionMessage::setStepReply(&reply, actionId, 0, result); ActionMessage::setStepReply(&reply, actionId, 0, result);
queueToUse->sendMessage(commandedBy, &reply); queueToUse->sendMessage(commandedBy, &reply);
return; return;
@ -62,7 +65,8 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t act
result = owner->executeAction(actionId, commandedBy, dataPtr, size); result = owner->executeAction(actionId, commandedBy, dataPtr, size);
ipcStore->deleteData(dataAddress); ipcStore->deleteData(dataAddress);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
ActionMessage::setStepReply(&reply, actionId, 0, result); ActionMessage::setStepReply(&reply, actionId, 0, result);
queueToUse->sendMessage(commandedBy, &reply); queueToUse->sendMessage(commandedBy, &reply);
return; return;
@ -71,7 +75,8 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t act
ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo,
ActionId_t replyId, SerializeIF* data, bool hideSender) { ActionId_t replyId, SerializeIF* data, bool hideSender) {
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
store_address_t storeAddress; store_address_t storeAddress;
uint8_t *dataPtr; uint8_t *dataPtr;
size_t maxSize = data->getSerializedSize(); size_t maxSize = data->getSerializedSize();

View File

@ -53,7 +53,8 @@ ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo,
ReturnValue_t CommandActionHelper::sendCommand(MessageQueueId_t queueId, ReturnValue_t CommandActionHelper::sendCommand(MessageQueueId_t queueId,
ActionId_t actionId, store_address_t storeId) { ActionId_t actionId, store_address_t storeId) {
CommandMessage command; MessageQueueMessage message;
CommandMessage command(&message);
ActionMessage::setCommand(&command, actionId, storeId); ActionMessage::setCommand(&command, actionId, storeId);
ReturnValue_t result = queueToUse->sendMessage(queueId, &command); ReturnValue_t result = queueToUse->sendMessage(queueId, &command);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {

View File

@ -36,7 +36,8 @@ void SimpleActionHelper::resetHelper() {
void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy, void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy,
ActionId_t actionId, store_address_t dataAddress) { ActionId_t actionId, store_address_t dataAddress) {
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
if (isExecuting) { if (isExecuting) {
ipcStore->deleteData(dataAddress); ipcStore->deleteData(dataAddress);
ActionMessage::setStepReply(&reply, actionId, 0, ActionMessage::setStepReply(&reply, actionId, 0,

View File

@ -56,26 +56,27 @@ MessageQueueId_t ControllerBase::getCommandQueue() const {
} }
void ControllerBase::handleQueue() { void ControllerBase::handleQueue() {
CommandMessage message; MessageQueueMessage message;
CommandMessage command(&message);
ReturnValue_t result; ReturnValue_t result;
for (result = commandQueue->receiveMessage(&message); result == RETURN_OK; for (result = commandQueue->receiveMessage(&command); result == RETURN_OK;
result = commandQueue->receiveMessage(&message)) { result = commandQueue->receiveMessage(&command)) {
result = modeHelper.handleModeCommand(&message); result = modeHelper.handleModeCommand(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
continue; continue;
} }
result = healthHelper.handleHealthCommand(&message); result = healthHelper.handleHealthCommand(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
continue; continue;
} }
result = handleCommandMessage(&message); result = handleCommandMessage(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
continue; continue;
} }
message.setToUnknownCommand(); command.setToUnknownCommand();
commandQueue->reply(&message); commandQueue->reply(&command);
} }
} }

View File

@ -16,9 +16,9 @@
MapPacketExtraction::MapPacketExtraction(uint8_t setMapId, MapPacketExtraction::MapPacketExtraction(uint8_t setMapId,
object_id_t setPacketDestination) : object_id_t setPacketDestination) :
lastSegmentationFlag(NO_SEGMENTATION), mapId(setMapId), packetLength(0), bufferPosition( lastSegmentationFlag(NO_SEGMENTATION), mapId(setMapId), packetLength(0),
packetBuffer), packetDestination(setPacketDestination), packetStore( bufferPosition(packetBuffer), packetDestination(setPacketDestination),
NULL), tcQueueId(MessageQueueSenderIF::NO_QUEUE) { packetStore(nullptr), tcQueueId(MessageQueueMessageIF::NO_QUEUE) {
memset(packetBuffer, 0, sizeof(packetBuffer)); memset(packetBuffer, 0, sizeof(packetBuffer));
} }

View File

@ -36,7 +36,7 @@ ReturnValue_t DataSetBase::read(uint32_t lockTimeout) {
if (state == States::DATA_SET_UNINITIALISED) { if (state == States::DATA_SET_UNINITIALISED) {
lockDataPool(lockTimeout); lockDataPool(lockTimeout);
for (uint16_t count = 0; count < fillCount; count++) { for (uint16_t count = 0; count < fillCount; count++) {
ReturnValue_t result = readVariable(count); result = readVariable(count);
if(result != RETURN_OK) { if(result != RETURN_OK) {
break; break;
} }
@ -46,14 +46,15 @@ ReturnValue_t DataSetBase::read(uint32_t lockTimeout) {
} }
else { else {
sif::error << "DataSet::read(): " sif::error << "DataSet::read(): "
"Call made in wrong position." << std::endl; "Call made in wrong position. Don't forget to commit"
" member datasets!" << std::endl;
result = SET_WAS_ALREADY_READ; result = SET_WAS_ALREADY_READ;
} }
return result; return result;
} }
ReturnValue_t DataSetBase::readVariable(uint16_t count) { ReturnValue_t DataSetBase::readVariable(uint16_t count) {
ReturnValue_t result = DataSetIF::INVALID_PARAMETER_DEFINITION; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
// These checks are often performed by the respective // These checks are often performed by the respective
// variable implementation too, but I guess a double check does not hurt. // variable implementation too, but I guess a double check does not hurt.
if (registeredVariables[count]->getReadWriteMode() != if (registeredVariables[count]->getReadWriteMode() !=
@ -62,6 +63,9 @@ ReturnValue_t DataSetBase::readVariable(uint16_t count) {
!= PoolVariableIF::NO_PARAMETER) != PoolVariableIF::NO_PARAMETER)
{ {
result = registeredVariables[count]->readWithoutLock(); result = registeredVariables[count]->readWithoutLock();
if(result != HasReturnvaluesIF::RETURN_OK) {
result = INVALID_PARAMETER_DEFINITION;
}
} }
return result; return result;
} }

View File

@ -21,14 +21,15 @@ ReturnValue_t HkSwitchHelper::initialize() {
} }
ReturnValue_t HkSwitchHelper::performOperation(uint8_t operationCode) { ReturnValue_t HkSwitchHelper::performOperation(uint8_t operationCode) {
CommandMessage message; MessageQueueMessage message;
while (actionQueue->receiveMessage(&message) == HasReturnvaluesIF::RETURN_OK) { CommandMessage command(&message);
ReturnValue_t result = commandActionHelper.handleReply(&message); while (actionQueue->receiveMessage(&command) == HasReturnvaluesIF::RETURN_OK) {
ReturnValue_t result = commandActionHelper.handleReply(&command);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
continue; continue;
} }
message.setToUnknownCommand(); command.setToUnknownCommand();
actionQueue->reply(&message); actionQueue->reply(&command);
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;

View File

@ -66,7 +66,8 @@ ReturnValue_t DataPoolAdmin::getParameter(uint8_t domainId,
} }
void DataPoolAdmin::handleCommand() { void DataPoolAdmin::handleCommand() {
CommandMessage command; MessageQueueMessage message;
CommandMessage command(&message);
ReturnValue_t result = commandQueue->receiveMessage(&command); ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return; return;
@ -282,7 +283,8 @@ ReturnValue_t DataPoolAdmin::sendParameter(MessageQueueId_t to, uint32_t id,
return result; return result;
} }
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
ParameterMessage::setParameterDumpReply(&reply, id, address); ParameterMessage::setParameterDumpReply(&reply, id, address);
@ -294,7 +296,8 @@ ReturnValue_t DataPoolAdmin::sendParameter(MessageQueueId_t to, uint32_t id,
//identical to ParameterHelper::rejectCommand() //identical to ParameterHelper::rejectCommand()
void DataPoolAdmin::rejectCommand(MessageQueueId_t to, ReturnValue_t reason, void DataPoolAdmin::rejectCommand(MessageQueueId_t to, ReturnValue_t reason,
Command_t initialCommand) { Command_t initialCommand) {
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
reply.setReplyRejected(reason, initialCommand); reply.setReplyRejected(reason, initialCommand);
commandQueue->sendMessage(to, &reply); commandQueue->sendMessage(to, &reply);
} }

View File

@ -148,7 +148,8 @@ void AssemblyBase::handleModeTransitionFailed(ReturnValue_t result) {
void AssemblyBase::sendHealthCommand(MessageQueueId_t sendTo, void AssemblyBase::sendHealthCommand(MessageQueueId_t sendTo,
HealthState health) { HealthState health) {
CommandMessage command; MessageQueueMessage message;
CommandMessage command(&message);
HealthMessage::setHealthMessage(&command, HealthMessage::HEALTH_SET, HealthMessage::setHealthMessage(&command, HealthMessage::HEALTH_SET,
health); health);
if (commandQueue->sendMessage(sendTo, &command) == RETURN_OK) { if (commandQueue->sendMessage(sendTo, &command) == RETURN_OK) {

View File

@ -218,8 +218,9 @@ void DeviceHandlerBase::readCommandQueue() {
// message with 3 parameters). The full buffer is filled anyway // message with 3 parameters). The full buffer is filled anyway
// and I could just copy the content into the other message but // and I could just copy the content into the other message but
// all I need are few additional functions the other message type offers. // all I need are few additional functions the other message type offers.
CommandMessage cmdMessage; MessageQueueMessage message;
ReturnValue_t result = commandQueue->receiveMessage(&cmdMessage); CommandMessage command(&message);
ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return; return;
} }
@ -234,23 +235,23 @@ void DeviceHandlerBase::readCommandQueue() {
// } // }
if(healthHelperActive) { if(healthHelperActive) {
result = healthHelper.handleHealthCommand(&cmdMessage); result = healthHelper.handleHealthCommand(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }
} }
result = modeHelper.handleModeCommand(&cmdMessage); result = modeHelper.handleModeCommand(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }
result = actionHelper.handleActionMessage(&cmdMessage); result = actionHelper.handleActionMessage(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }
result = parameterHelper.handleParameterMessage(&cmdMessage); result = parameterHelper.handleParameterMessage(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }
@ -261,17 +262,17 @@ void DeviceHandlerBase::readCommandQueue() {
// return; // return;
// } // }
result = handleDeviceHandlerMessage(&cmdMessage); result = handleDeviceHandlerMessage(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }
result = letChildHandleMessage(&cmdMessage); result = letChildHandleMessage(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
return; return;
} }
replyReturnvalueToCommand(CommandMessage::UNKNOW_COMMAND); replyReturnvalueToCommand(CommandMessage::UNKNOWN_COMMAND);
} }
@ -492,12 +493,13 @@ void DeviceHandlerBase::setMode(Mode_t newMode) {
void DeviceHandlerBase::replyReturnvalueToCommand(ReturnValue_t status, void DeviceHandlerBase::replyReturnvalueToCommand(ReturnValue_t status,
uint32_t parameter) { uint32_t parameter) {
MessageQueueMessage message;
//This is actually the reply protocol for raw and misc DH commands. //This is actually the reply protocol for raw and misc DH commands.
if (status == RETURN_OK) { if (status == RETURN_OK) {
CommandMessage reply(CommandMessage::REPLY_COMMAND_OK, 0, parameter); CommandMessage reply(&message, CommandMessage::REPLY_COMMAND_OK, 0, parameter);
commandQueue->reply(&reply); commandQueue->reply(&reply);
} else { } else {
CommandMessage reply(CommandMessage::REPLY_REJECTED, status, parameter); CommandMessage reply(&message, CommandMessage::REPLY_REJECTED, status, parameter);
commandQueue->reply(&reply); commandQueue->reply(&reply);
} }
} }
@ -767,9 +769,10 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
return; return;
} }
CommandMessage message; MessageQueueMessage message;
CommandMessage command(&message);
DeviceHandlerMessage::setDeviceHandlerRawReplyMessage(&message, DeviceHandlerMessage::setDeviceHandlerRawReplyMessage(&command,
getObjectId(), address, isCommand); getObjectId(), address, isCommand);
// this->DeviceHandlerCommand = CommandMessage::CMD_NONE; // this->DeviceHandlerCommand = CommandMessage::CMD_NONE;

View File

@ -13,10 +13,11 @@ HealthDevice::~HealthDevice() {
} }
ReturnValue_t HealthDevice::performOperation(uint8_t opCode) { ReturnValue_t HealthDevice::performOperation(uint8_t opCode) {
CommandMessage message; MessageQueueMessage message;
ReturnValue_t result = commandQueue->receiveMessage(&message); CommandMessage command(&message);
ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
healthHelper.handleHealthCommand(&message); healthHelper.handleHealthCommand(&command);
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -62,32 +62,34 @@ void HealthHelper::setHealth(HasHealthIF::HealthState health) {
void HealthHelper::informParent(HasHealthIF::HealthState health, void HealthHelper::informParent(HasHealthIF::HealthState health,
HasHealthIF::HealthState oldHealth) { HasHealthIF::HealthState oldHealth) {
if (parentQueue == 0) { if (parentQueue == MessageQueueMessageIF::NO_QUEUE) {
return; return;
} }
CommandMessage message; MessageQueueMessage message;
HealthMessage::setHealthMessage(&message, HealthMessage::HEALTH_INFO, CommandMessage information(&message);
HealthMessage::setHealthMessage(&information, HealthMessage::HEALTH_INFO,
health, oldHealth); health, oldHealth);
if (MessageQueueSenderIF::sendMessage(parentQueue, &message, if (MessageQueueSenderIF::sendMessage(parentQueue, &information,
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) { owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
sif::debug << "HealthHelper::informParent: sending health reply failed." sif::debug << "HealthHelper::informParent: sending health reply failed."
<< std::endl; << std::endl;
} }
} }
void HealthHelper::handleSetHealthCommand(CommandMessage* message) { void HealthHelper::handleSetHealthCommand(CommandMessage* command) {
ReturnValue_t result = owner->setHealth(HealthMessage::getHealth(message)); ReturnValue_t result = owner->setHealth(HealthMessage::getHealth(command));
if (message->getSender() == 0) { if (command->getSender() == MessageQueueMessageIF::NO_QUEUE) {
return; return;
} }
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
HealthMessage::setHealthMessage(&reply, HealthMessage::setHealthMessage(&reply,
HealthMessage::REPLY_HEALTH_SET); HealthMessage::REPLY_HEALTH_SET);
} else { } else {
reply.setReplyRejected(result, message->getCommand()); reply.setReplyRejected(result, command->getCommand());
} }
if (MessageQueueSenderIF::sendMessage(message->getSender(), &reply, if (MessageQueueSenderIF::sendMessage(command->getSender(), &reply,
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) { owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
sif::debug << "HealthHelper::handleHealthCommand: sending health " sif::debug << "HealthHelper::handleHealthCommand: sending health "
"reply failed." << std::endl; "reply failed." << std::endl;

View File

@ -14,14 +14,26 @@ void clearMissionMessage(CommandMessage* message);
} }
CommandMessage::CommandMessage() { CommandMessage::CommandMessage(MessageQueueMessage* receiverMessage):
this->messageSize = COMMAND_MESSAGE_SIZE; internalMessage(receiverMessage) {
if(receiverMessage == nullptr) {
sif::error << "CommandMessage::CommandMessage: Don't pass a nullptr"
" as the message queue message, pass the address of an actual"
" message!" << std::endl;
}
internalMessage->messageSize = COMMAND_MESSAGE_SIZE;
setCommand(CMD_NONE); setCommand(CMD_NONE);
} }
CommandMessage::CommandMessage(Command_t command, uint32_t parameter1, CommandMessage::CommandMessage(MessageQueueMessage* messageToSet,
uint32_t parameter2) { Command_t command, uint32_t parameter1, uint32_t parameter2):
this->messageSize = COMMAND_MESSAGE_SIZE; internalMessage(messageToSet) {
if(messageToSet == nullptr) {
sif::error << "CommandMessage::CommandMessage: Don't pass a nullptr"
" as the message queue message, pass the address of an actual"
" message!" << std::endl;
}
internalMessage->messageSize = COMMAND_MESSAGE_SIZE;
setCommand(command); setCommand(command);
setParameter(parameter1); setParameter(parameter1);
setParameter2(parameter2); setParameter2(parameter2);
@ -29,7 +41,7 @@ CommandMessage::CommandMessage(Command_t command, uint32_t parameter1,
Command_t CommandMessage::getCommand() const { Command_t CommandMessage::getCommand() const {
Command_t command; Command_t command;
memcpy(&command, getData(), sizeof(Command_t)); memcpy(&command, internalMessage->getData(), sizeof(Command_t));
return command; return command;
} }
@ -38,29 +50,35 @@ uint8_t CommandMessage::getMessageType() const {
} }
void CommandMessage::setCommand(Command_t command) { void CommandMessage::setCommand(Command_t command) {
memcpy(getData(), &command, sizeof(command)); memcpy(internalMessage->getData(), &command, sizeof(command));
} }
uint32_t CommandMessage::getParameter() const { uint32_t CommandMessage::getParameter() const {
uint32_t parameter1; uint32_t parameter1;
memcpy(&parameter1, getData() + sizeof(Command_t), sizeof(parameter1)); memcpy(&parameter1, internalMessage->getData() + sizeof(Command_t),
sizeof(parameter1));
return parameter1; return parameter1;
} }
void CommandMessage::setParameter(uint32_t parameter1) { void CommandMessage::setParameter(uint32_t parameter1) {
memcpy(getData() + sizeof(Command_t), &parameter1, sizeof(parameter1)); memcpy(internalMessage->getData() + sizeof(Command_t),
&parameter1, sizeof(parameter1));
} }
uint32_t CommandMessage::getParameter2() const { uint32_t CommandMessage::getParameter2() const {
uint32_t parameter2; uint32_t parameter2;
memcpy(&parameter2, getData() + sizeof(Command_t) + sizeof(uint32_t), memcpy(&parameter2, internalMessage->getData() + sizeof(Command_t)
sizeof(parameter2)); + sizeof(uint32_t), sizeof(parameter2));
return parameter2; return parameter2;
} }
void CommandMessage::setParameter2(uint32_t parameter2) { void CommandMessage::setParameter2(uint32_t parameter2) {
memcpy(getData() + sizeof(Command_t) + sizeof(uint32_t), &parameter2, memcpy(internalMessage-> getData() + sizeof(Command_t) + sizeof(uint32_t),
sizeof(parameter2)); &parameter2, sizeof(parameter2));
}
void CommandMessage::clear() {
clearCommandMessage();
} }
void CommandMessage::clearCommandMessage() { void CommandMessage::clearCommandMessage() {
@ -109,7 +127,7 @@ size_t CommandMessage::getMinimumMessageSize() const {
void CommandMessage::setToUnknownCommand() { void CommandMessage::setToUnknownCommand() {
Command_t initialCommand = getCommand(); Command_t initialCommand = getCommand();
clearCommandMessage(); clearCommandMessage();
setReplyRejected(UNKNOW_COMMAND, initialCommand); setReplyRejected(UNKNOWN_COMMAND, initialCommand);
} }
void CommandMessage::setReplyRejected(ReturnValue_t reason, void CommandMessage::setReplyRejected(ReturnValue_t reason,
@ -118,3 +136,35 @@ void CommandMessage::setReplyRejected(ReturnValue_t reason,
setParameter(reason); setParameter(reason);
setParameter2(initialCommand); setParameter2(initialCommand);
} }
MessageQueueId_t CommandMessage::getSender() const {
return internalMessage->getSender();
}
uint8_t* CommandMessage::getBuffer() {
return internalMessage->getBuffer();
}
void CommandMessage::setSender(MessageQueueId_t setId) {
internalMessage->setSender(setId);
}
const uint8_t* CommandMessage::getBuffer() const {
return internalMessage->getBuffer();
}
uint8_t* CommandMessage::getData() {
return internalMessage->getData();
}
const uint8_t* CommandMessage::getData() const {
return internalMessage->getData();
}
size_t CommandMessage::getMessageSize() const {
return COMMAND_MESSAGE_SIZE;
}
size_t CommandMessage::getMaximumMessageSize() const {
return MessageQueueMessage::MAX_MESSAGE_SIZE;
}

View File

@ -1,22 +1,31 @@
#ifndef FRAMEWORK_IPC_COMMANDMESSAGE_H_ #ifndef FRAMEWORK_IPC_COMMANDMESSAGE_H_
#define FRAMEWORK_IPC_COMMANDMESSAGE_H_ #define FRAMEWORK_IPC_COMMANDMESSAGE_H_
#include <framework/ipc/MessageQueueMessage.h>
#include <framework/ipc/FwMessageTypes.h> #include <framework/ipc/FwMessageTypes.h>
#include <config/ipc/MissionMessageTypes.h> #include <config/ipc/MissionMessageTypes.h>
#include <framework/ipc/MessageQueueMessage.h>
#define MAKE_COMMAND_ID( number ) ((MESSAGE_ID << 8) + (number)) #define MAKE_COMMAND_ID( number ) ((MESSAGE_ID << 8) + (number))
typedef uint16_t Command_t; typedef uint16_t Command_t;
/** /**
* @brief Used to pass command messages between tasks * @brief Used to pass command messages between tasks. Primary message type
* for IPC. Contains sender, 2-byte command field, and 2 4-byte
* parameters.
* @details
* It operates on an external memory which is contained inside a
* MessageQueueMessage 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.
* @author Bastian Baetz * @author Bastian Baetz
*/ */
class CommandMessage : public MessageQueueMessage { class CommandMessage: public MessageQueueMessageIF {
public: public:
static const uint8_t INTERFACE_ID = CLASS_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 ReturnValue_t UNKNOWN_COMMAND = MAKE_RETURN_CODE(0x01);
static const uint8_t MESSAGE_ID = messagetypes::COMMAND; static const uint8_t MESSAGE_ID = messagetypes::COMMAND;
@ -31,7 +40,7 @@ public:
* This is the size of a message as it is seen by the MessageQueue. * This is the size of a message as it is seen by the MessageQueue.
* 14 of the 24 available MessageQueueMessage bytes are used. * 14 of the 24 available MessageQueueMessage bytes are used.
*/ */
static const size_t COMMAND_MESSAGE_SIZE = HEADER_SIZE static const size_t COMMAND_MESSAGE_SIZE = MessageQueueMessage::HEADER_SIZE
+ sizeof(Command_t) + 2 * sizeof(uint32_t); + sizeof(Command_t) + 2 * sizeof(uint32_t);
/** /**
@ -40,7 +49,7 @@ public:
* This constructor should be used when receiving a Message, as the * This constructor should be used when receiving a Message, as the
* content is filled by the MessageQueue. * content is filled by the MessageQueue.
*/ */
CommandMessage(); CommandMessage(MessageQueueMessage* receiverMessage);
/** /**
* This constructor creates a new message with all message content * This constructor creates a new message with all message content
* initialized * initialized
@ -49,14 +58,13 @@ public:
* @param parameter1 The first parameter * @param parameter1 The first parameter
* @param parameter2 The second parameter * @param parameter2 The second parameter
*/ */
CommandMessage(Command_t command, CommandMessage(MessageQueueMessage* messageToSet, Command_t command,
uint32_t parameter1, uint32_t parameter2); uint32_t parameter1, uint32_t parameter2);
/** /**
* Default Destructor * @brief Default Destructor
*/ */
virtual ~CommandMessage() { virtual ~CommandMessage() {}
}
/** /**
* Read the DeviceHandlerCommand_t that is stored in the message, * Read the DeviceHandlerCommand_t that is stored in the message,
@ -66,42 +74,56 @@ public:
*/ */
Command_t getCommand() const; Command_t getCommand() const;
/*
* MessageQueueMessageIF functions, which generally just call the
* respective functions of the internal message
*/
uint8_t * getBuffer() override;
const uint8_t * getBuffer() const override;
void setSender(MessageQueueId_t setId) override;
MessageQueueId_t getSender() const override;
uint8_t * getData() override;
const uint8_t* getData() const override;
size_t getMinimumMessageSize() const override;
size_t getMessageSize() const override;
size_t getMaximumMessageSize() const override;
/**
* Extract message ID, which is the first byte of the command ID.
* @return
*/
uint8_t getMessageType() const; uint8_t getMessageType() const;
/** /**
* Set the DeviceHandlerCOmmand_t of the message * Set the command type of the message
*
* @param the Command to be sent * @param the Command to be sent
*/ */
void setCommand(Command_t command); void setCommand(Command_t command);
/** /**
* Get the first parameter of the message * Get the first parameter of the message
*
* @return the first Parameter of the message * @return the first Parameter of the message
*/ */
uint32_t getParameter() const; uint32_t getParameter() const;
/** /**
* Set the first parameter of the message * Set the first parameter of the message
*
* @param the first parameter of the message * @param the first parameter of the message
*/ */
void setParameter(uint32_t parameter1); void setParameter(uint32_t parameter1);
/** /**
* Get the second parameter of the message * Get the second parameter of the message
*
* @return the second Parameter of the message * @return the second Parameter of the message
*/ */
uint32_t getParameter2() const; uint32_t getParameter2() const;
/** /**
* Set the second parameter of the message * Set the second parameter of the message
*
* @param the second parameter of the message * @param the second parameter of the message
*/ */
void setParameter2(uint32_t parameter2); void setParameter2(uint32_t parameter2);
/** /**
* Set the command to CMD_NONE and try to find * Set the command to CMD_NONE and try to find
* the correct class to handle a more detailed * the correct class to handle a more detailed
@ -113,6 +135,7 @@ public:
* *
*/ */
void clearCommandMessage(); void clearCommandMessage();
void clear() override;
/** /**
* check if a message was cleared * check if a message was cleared
@ -121,7 +144,6 @@ public:
*/ */
bool isClearedCommandMessage(); bool isClearedCommandMessage();
/** /**
* Sets the command to REPLY_REJECTED with parameter UNKNOWN_COMMAND. * Sets the command to REPLY_REJECTED with parameter UNKNOWN_COMMAND.
* Is needed quite often, so we better code it once only. * Is needed quite often, so we better code it once only.
@ -129,7 +151,15 @@ public:
void setToUnknownCommand(); void setToUnknownCommand();
void setReplyRejected(ReturnValue_t reason, void setReplyRejected(ReturnValue_t reason,
Command_t initialCommand = CMD_NONE); Command_t initialCommand = CMD_NONE);
size_t getMinimumMessageSize() const;
private:
/**
* @brief Pointer to the message containing the data.
* @details
* The command message does not actually own the memory containing a
* message, it just oprates on it via a pointer to a message queue message.
*/
MessageQueueMessage* internalMessage;
}; };

View File

@ -15,7 +15,7 @@
#include <framework/returnvalues/HasReturnvaluesIF.h> #include <framework/returnvalues/HasReturnvaluesIF.h>
class MessageQueueIF { class MessageQueueIF {
public: public:
static const MessageQueueId_t NO_QUEUE = MessageQueueSenderIF::NO_QUEUE; //!< Ugly hack. static const MessageQueueId_t NO_QUEUE = MessageQueueMessageIF::NO_QUEUE; //!< Ugly hack.
static const uint8_t INTERFACE_ID = CLASS_ID::MESSAGE_QUEUE_IF; static const uint8_t INTERFACE_ID = CLASS_ID::MESSAGE_QUEUE_IF;
/** /**
@ -41,7 +41,7 @@ public:
* @return RETURN_OK if ok * @return RETURN_OK if ok
* @return NO_REPLY_PARTNER Should return NO_REPLY_PARTNER if partner was found * @return NO_REPLY_PARTNER Should return NO_REPLY_PARTNER if partner was found
*/ */
virtual ReturnValue_t reply( MessageQueueMessage* message ) = 0; virtual ReturnValue_t reply( MessageQueueMessageIF* message ) = 0;
/** /**
* @brief This function reads available messages from the message queue and returns the sender. * @brief This function reads available messages from the message queue and returns the sender.
@ -50,7 +50,7 @@ public:
* @param message A pointer to a message in which the received data is stored. * @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. * @param receivedFrom A pointer to a queue id in which the sender's id is stored.
*/ */
virtual ReturnValue_t receiveMessage(MessageQueueMessage* message, virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
MessageQueueId_t *receivedFrom) = 0; MessageQueueId_t *receivedFrom) = 0;
/** /**
@ -65,7 +65,7 @@ public:
* @return -@c RETURN_OK on success * @return -@c RETURN_OK on success
* -@c MessageQueueIF::EMPTY if queue is empty * -@c MessageQueueIF::EMPTY if queue is empty
*/ */
virtual ReturnValue_t receiveMessage(MessageQueueMessage* message) = 0; virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) = 0;
/** /**
* Deletes all pending messages in the queue. * Deletes all pending messages in the queue.
* @param count The number of flushed messages. * @param count The number of flushed messages.
@ -95,7 +95,7 @@ public:
* -@c MessageQueueIF::FULL if queue is full * -@c MessageQueueIF::FULL if queue is full
*/ */
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom, MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault = false ) = 0; bool ignoreFault = false ) = 0;
/** /**
@ -107,7 +107,7 @@ public:
* @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full. * @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, virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo,
MessageQueueMessage* message, bool ignoreFault = false ) = 0; MessageQueueMessageIF* message, bool ignoreFault = false ) = 0;
/** /**
* @brief The sendToDefaultFrom method sends a queue message to the default destination. * @brief The sendToDefaultFrom method sends a queue message to the default destination.
@ -118,7 +118,7 @@ public:
* @return -@c RETURN_OK on success * @return -@c RETURN_OK on success
* -@c MessageQueueIF::FULL if queue is full * -@c MessageQueueIF::FULL if queue is full
*/ */
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message, virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message,
MessageQueueId_t sentFrom, bool ignoreFault = false ) = 0; MessageQueueId_t sentFrom, bool ignoreFault = false ) = 0;
/** /**
* @brief This operation sends a message to the default destination. * @brief This operation sends a message to the default destination.
@ -128,7 +128,7 @@ public:
* @return -@c RETURN_OK on success * @return -@c RETURN_OK on success
* -@c MessageQueueIF::FULL if queue is full * -@c MessageQueueIF::FULL if queue is full
*/ */
virtual ReturnValue_t sendToDefault( MessageQueueMessage* message ) = 0; virtual ReturnValue_t sendToDefault( MessageQueueMessageIF* message ) = 0;
/** /**
* \brief This method is a simple setter for the default destination. * \brief This method is a simple setter for the default destination.
*/ */

View File

@ -51,7 +51,7 @@ void MessageQueueMessage::setSender(MessageQueueId_t setId) {
memcpy(this->internalBuffer, &setId, sizeof(MessageQueueId_t)); memcpy(this->internalBuffer, &setId, sizeof(MessageQueueId_t));
} }
size_t MessageQueueMessage::getMinimumMessageSize() { size_t MessageQueueMessage::getMinimumMessageSize() const {
return this->HEADER_SIZE; return this->HEADER_SIZE;
} }
@ -67,3 +67,11 @@ void MessageQueueMessage::print() {
void MessageQueueMessage::clear() { void MessageQueueMessage::clear() {
memset(this->getBuffer(), 0, this->MAX_MESSAGE_SIZE); memset(this->getBuffer(), 0, this->MAX_MESSAGE_SIZE);
} }
size_t MessageQueueMessage::getMessageSize() const {
return this->messageSize;
}
size_t MessageQueueMessage::getMaximumMessageSize() const {
return this->MAX_MESSAGE_SIZE;
}

View File

@ -1,5 +1,5 @@
#ifndef MESSAGEQUEUEMESSAGE_H_ #ifndef FRAMEWORK_IPC_MESSAGEQUEUEMESSAGE_H_
#define MESSAGEQUEUEMESSAGE_H_ #define FRAMEWORK_IPC_MESSAGEQUEUEMESSAGE_H_
#include <framework/ipc/MessageQueueMessageIF.h> #include <framework/ipc/MessageQueueMessageIF.h>
#include <framework/ipc/MessageQueueSenderIF.h> #include <framework/ipc/MessageQueueSenderIF.h>
@ -8,7 +8,6 @@
/** /**
* @brief This class is the representation and data organizer * @brief This class is the representation and data organizer
* for interprocess messages. * for interprocess messages.
*
* @details * @details
* To facilitate and standardize interprocess communication, this class was * To facilitate and standardize interprocess communication, this class was
* created to handle a lightweight "interprocess message protocol". * created to handle a lightweight "interprocess message protocol".
@ -28,12 +27,14 @@ class MessageQueueMessage: public MessageQueueMessageIF {
public: public:
/** /**
* @brief The class is initialized empty with this constructor. * @brief The class is initialized empty with this constructor.
* @details The messageSize attribute is set to the header's size and the * @details
* whole content is set to zero. * The messageSize attribute is set to the header's size and the whole
* content is set to zero.
*/ */
MessageQueueMessage(); MessageQueueMessage();
/** /**
* @brief With this constructor the class is initialized with the given content. * @brief With this constructor the class is initialized with
* the given content.
* @details * @details
* If the passed message size fits into the buffer, the passed data is * If the passed message size fits into the buffer, the passed data is
* copied to the internal buffer and the messageSize information is set. * copied to the internal buffer and the messageSize information is set.
@ -46,7 +47,14 @@ public:
MessageQueueMessage(uint8_t* data, size_t size); MessageQueueMessage(uint8_t* data, size_t size);
/** /**
* @brief The size information of each message is stored in this attribute. * @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 * @details
* It is public to simplify usage and to allow for passing the size * 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, * address as a pointer. Care must be taken when inheriting from this class,
@ -59,19 +67,26 @@ public:
*/ */
size_t messageSize; size_t messageSize;
/** /**
* @brief This constant defines the maximum size of the data content, excluding the header. * @brief This constant defines the maximum size of the data content,
* @details It may be changed if necessary, but in general should be kept as small as possible. * 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; static const size_t MAX_DATA_SIZE = 24;
/** /**
* @brief This constants defines the size of the header, which is added to every message. * @brief This constants defines the size of the header,
* which is added to every message.
*/ */
static const size_t HEADER_SIZE = sizeof(MessageQueueId_t); static const size_t HEADER_SIZE = sizeof(MessageQueueId_t);
/** /**
* @brief This constant defines the maximum total size in bytes of a sent message. * @brief This constant defines the maximum total size in bytes
* @details It is the sum of the maximum data and the header size. Be aware that this constant * of a sent message.
* is used to define the buffer sizes for every message queue in the system. So, a change * @details
* here may have significant impact on the required resources. * 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; static const size_t MAX_MESSAGE_SIZE = MAX_DATA_SIZE + HEADER_SIZE;
/** /**
@ -81,58 +96,68 @@ public:
static const size_t MIN_MESSAGE_SIZE = HEADER_SIZE; static const size_t MIN_MESSAGE_SIZE = HEADER_SIZE;
private: private:
/** /**
* @brief This is the internal buffer that contains the actual message data. * @brief This is the internal buffer that contains the
* actual message data.
*/ */
uint8_t internalBuffer[MAX_MESSAGE_SIZE]; uint8_t internalBuffer[MAX_MESSAGE_SIZE];
public: public:
/** /**
* @brief As no memory is allocated in this class, the destructor is empty. * @brief This method is used to get the complete data of the message.
*/ */
virtual ~MessageQueueMessage(); const uint8_t* getBuffer() const override;
/** /**
* @brief This method is used to get the complete data of the message. * @brief This method is used to get the complete data of the message.
*/ */
const uint8_t* getBuffer() const; uint8_t* getBuffer() override;
/**
* @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. * @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. * @details
* It shall be used by child classes to add data at the right position.
*/ */
const uint8_t* getData() const; const uint8_t* getData() const override;
/** /**
* @brief This method is used to fetch the data content of the message. * @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. * @details
* It shall be used by child classes to add data at the right position.
*/ */
uint8_t* getData(); uint8_t* getData() override;
/** /**
* @brief This method is used to extract the sender's message queue id information from a * @brief This method is used to extract the sender's message
* received message. * queue id information from a received message.
*/ */
MessageQueueId_t getSender() const; MessageQueueId_t getSender() const override;
/** /**
* @brief With this method, the whole content and the message size is set to zero. * @brief With this method, the whole content
* and the message size is set to zero.
*/ */
void clear(); void clear() override;
/** /**
* @brief This is a debug method that prints the content (till messageSize) to the debug output. * @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 print(); void setSender(MessageQueueId_t setId) override;
/** /**
* @brief This method is used to set the sender's message queue id information prior to * @brief This helper function is used by the MessageQueue class to check
* sending the message. * the size of an incoming message.
* @param setId The message queue id that identifies the sending message queue. * @details
*/ * The method must be overwritten by child classes if size
void setSender(MessageQueueId_t setId); * checks shall be more strict.
/**
* @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. * @return The default implementation returns HEADER_SIZE.
*/ */
virtual size_t getMinimumMessageSize(); virtual size_t getMinimumMessageSize() const override;
virtual size_t getMessageSize() const override;
virtual size_t getMaximumMessageSize() const override;
/**
* @brief This is a debug method that prints the content
* (till messageSize) to the debug output.
*/
void print();
}; };
#endif /* MESSAGEQUEUEMESSAGE_H_ */ #endif /* MESSAGEQUEUEMESSAGE_H_ */

View File

@ -1,10 +1,25 @@
#ifndef FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_ #ifndef FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_
#define FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_ #define FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_
#include <framework/ipc/MessageQueueSenderIF.h>
#include <cstddef> #include <cstddef>
#include <cstdint>
/*
* 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 MessageQueueMessageIF { class MessageQueueMessageIF {
public: public:
static const MessageQueueId_t NO_QUEUE = 0xffffffff;
virtual ~MessageQueueMessageIF() {}; virtual ~MessageQueueMessageIF() {};
/** /**
@ -12,14 +27,9 @@ public:
* size is set to zero. * size is set to zero.
*/ */
virtual void clear() = 0; virtual void clear() = 0;
/**
* @brief This is a debug method that prints the content
* (till messageSize) to the debug output.
*/
virtual void print() = 0;
/** /**
* @brief Get read-only pointer to the raw buffer. * @brief Get read-only pointer to the complete data of the message.
* @return * @return
*/ */
virtual const uint8_t* getBuffer() const = 0; virtual const uint8_t* getBuffer() const = 0;
@ -37,11 +47,42 @@ public:
*/ */
virtual void setSender(MessageQueueId_t setId) = 0; virtual void setSender(MessageQueueId_t setId) = 0;
/**
* @brief This method is used to extract the sender's message queue id
* information from a received message.
*/
virtual MessageQueueId_t getSender() const = 0;
/**
* @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.
*/
virtual const uint8_t* getData() const = 0;
/**
* @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.
*/
virtual uint8_t* getData() = 0;
/** /**
* @brief This helper function is used by the MessageQueue class to * @brief This helper function is used by the MessageQueue class to
* check the size of an incoming message. * check the size of an incoming message.
*/ */
virtual size_t getMinimumMessageSize() = 0; virtual size_t getMinimumMessageSize() const = 0;
/**
* Get message size of current message implementation.
* @return
*/
virtual size_t getMessageSize() const = 0;
/**
* Get maximum allowed size of current message implementation.
* @return
*/
virtual size_t getMaximumMessageSize() const = 0;
}; };

View File

@ -1,22 +1,11 @@
#ifndef FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_ #ifndef FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_
#define FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_ #define FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_
#include <framework/ipc/MessageQueueMessageIF.h>
#include <framework/objectmanager/ObjectManagerIF.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 { class MessageQueueSenderIF {
public: public:
static const MessageQueueId_t NO_QUEUE = 0xffffffff;
virtual ~MessageQueueSenderIF() {} virtual ~MessageQueueSenderIF() {}
@ -26,7 +15,8 @@ public:
* Must be implemented by a subclass. * Must be implemented by a subclass.
*/ */
static ReturnValue_t sendMessage(MessageQueueId_t sendTo, static ReturnValue_t sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom = MessageQueueSenderIF::NO_QUEUE, MessageQueueMessageIF* message,
MessageQueueId_t sentFrom = MessageQueueMessageIF::NO_QUEUE,
bool ignoreFault=false); bool ignoreFault=false);
private: private:
MessageQueueSenderIF() {} MessageQueueSenderIF() {}

View File

@ -51,14 +51,16 @@ void MemoryHelper::completeLoad(ReturnValue_t errorCode,
break; break;
default: default:
ipcStore->deleteData(ipcAddress); ipcStore->deleteData(ipcAddress);
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
MemoryMessage::setMemoryReplyFailed(&reply, errorCode, MemoryMessage::setMemoryReplyFailed(&reply, errorCode,
MemoryMessage::CMD_MEMORY_LOAD); MemoryMessage::CMD_MEMORY_LOAD);
queueToUse->sendMessage(lastSender, &reply); queueToUse->sendMessage(lastSender, &reply);
return; return;
} }
//Only reached on success //Only reached on success
CommandMessage reply(CommandMessage::REPLY_COMMAND_OK, 0, 0); MessageQueueMessage message;
CommandMessage reply(&message, CommandMessage::REPLY_COMMAND_OK, 0, 0);
queueToUse->sendMessage(lastSender, &reply); queueToUse->sendMessage(lastSender, &reply);
ipcStore->deleteData(ipcAddress); ipcStore->deleteData(ipcAddress);
} }
@ -66,7 +68,8 @@ void MemoryHelper::completeLoad(ReturnValue_t errorCode,
void MemoryHelper::completeDump(ReturnValue_t errorCode, void MemoryHelper::completeDump(ReturnValue_t errorCode,
const uint8_t* dataToCopy, const uint32_t size) { const uint8_t* dataToCopy, const uint32_t size) {
busy = false; busy = false;
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
MemoryMessage::setMemoryReplyFailed(&reply, errorCode, lastCommand); MemoryMessage::setMemoryReplyFailed(&reply, errorCode, lastCommand);
switch (errorCode) { switch (errorCode) {
case HasMemoryIF::DO_IT_MYSELF: case HasMemoryIF::DO_IT_MYSELF:
@ -151,7 +154,8 @@ void MemoryHelper::handleMemoryLoad(CommandMessage* message) {
completeLoad(returnCode, p_data, size, dataPointer); completeLoad(returnCode, p_data, size, dataPointer);
} else { } else {
//At least inform sender. //At least inform sender.
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
MemoryMessage::setMemoryReplyFailed(&reply, returnCode, MemoryMessage::setMemoryReplyFailed(&reply, returnCode,
MemoryMessage::CMD_MEMORY_LOAD); MemoryMessage::CMD_MEMORY_LOAD);
queueToUse->sendMessage(lastSender, &reply); queueToUse->sendMessage(lastSender, &reply);
@ -169,7 +173,8 @@ void MemoryHelper::handleMemoryCheckOrDump(CommandMessage* message) {
reservedSpaceInIPC); reservedSpaceInIPC);
completeDump(returnCode, dataPointer, size); completeDump(returnCode, dataPointer, size);
} else { } else {
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
MemoryMessage::setMemoryReplyFailed(&reply, returnCode, lastCommand); MemoryMessage::setMemoryReplyFailed(&reply, returnCode, lastCommand);
queueToUse->sendMessage(lastSender, &reply); queueToUse->sendMessage(lastSender, &reply);
} }

View File

@ -11,31 +11,32 @@ ModeHelper::~ModeHelper() {
} }
ReturnValue_t ModeHelper::handleModeCommand(CommandMessage* message) { ReturnValue_t ModeHelper::handleModeCommand(CommandMessage* command) {
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
Mode_t mode; Mode_t mode;
Submode_t submode; Submode_t submode;
switch (message->getCommand()) { switch (command->getCommand()) {
case ModeMessage::CMD_MODE_COMMAND_FORCED: case ModeMessage::CMD_MODE_COMMAND_FORCED:
forced = true; forced = true;
/* NO BREAK falls through*/ /* NO BREAK falls through*/
case ModeMessage::CMD_MODE_COMMAND: { case ModeMessage::CMD_MODE_COMMAND: {
mode = ModeMessage::getMode(message); mode = ModeMessage::getMode(command);
submode = ModeMessage::getSubmode(message); submode = ModeMessage::getSubmode(command);
uint32_t timeout; uint32_t timeout;
ReturnValue_t result = owner->checkModeCommand(mode, submode, &timeout); ReturnValue_t result = owner->checkModeCommand(mode, submode, &timeout);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
ModeMessage::cantReachMode(&reply, result); ModeMessage::cantReachMode(&reply, result);
MessageQueueSenderIF::sendMessage(message->getSender(), &reply, MessageQueueSenderIF::sendMessage(command->getSender(), &reply,
owner->getCommandQueue()); owner->getCommandQueue());
break; break;
} }
//Free to start transition //Free to start transition
theOneWhoCommandedAMode = message->getSender(); theOneWhoCommandedAMode = command->getSender();
commandedMode = mode; commandedMode = mode;
commandedSubmode = submode; commandedSubmode = submode;
if ((parentQueueId != MessageQueueSenderIF::NO_QUEUE) if ((parentQueueId != MessageQueueMessageIF::NO_QUEUE)
&& (theOneWhoCommandedAMode != parentQueueId)) { && (theOneWhoCommandedAMode != parentQueueId)) {
owner->setToExternalControl(); owner->setToExternalControl();
} }
@ -48,7 +49,7 @@ ReturnValue_t ModeHelper::handleModeCommand(CommandMessage* message) {
owner->getMode(&mode, &submode); owner->getMode(&mode, &submode);
ModeMessage::setModeMessage(&reply, ModeMessage::REPLY_MODE_REPLY, mode, ModeMessage::setModeMessage(&reply, ModeMessage::REPLY_MODE_REPLY, mode,
submode); submode);
MessageQueueSenderIF::sendMessage(message->getSender(), &reply, MessageQueueSenderIF::sendMessage(command->getSender(), &reply,
owner->getCommandQueue()); owner->getCommandQueue());
} }
break; break;
@ -73,13 +74,14 @@ void ModeHelper::modeChanged(Mode_t ownerMode, Submode_t ownerSubmode) {
forced = false; forced = false;
sendModeReplyMessage(ownerMode, ownerSubmode); sendModeReplyMessage(ownerMode, ownerSubmode);
sendModeInfoMessage(ownerMode, ownerSubmode); sendModeInfoMessage(ownerMode, ownerSubmode);
theOneWhoCommandedAMode = MessageQueueSenderIF::NO_QUEUE; theOneWhoCommandedAMode = MessageQueueMessageIF::NO_QUEUE;
} }
void ModeHelper::sendModeReplyMessage(Mode_t ownerMode, void ModeHelper::sendModeReplyMessage(Mode_t ownerMode,
Submode_t ownerSubmode) { Submode_t ownerSubmode) {
CommandMessage reply; MessageQueueMessage message;
if (theOneWhoCommandedAMode != MessageQueueSenderIF::NO_QUEUE) CommandMessage reply(&message);
if (theOneWhoCommandedAMode != MessageQueueMessageIF::NO_QUEUE)
{ {
if (ownerMode != commandedMode or ownerSubmode != commandedSubmode) if (ownerMode != commandedMode or ownerSubmode != commandedSubmode)
{ {
@ -99,9 +101,10 @@ void ModeHelper::sendModeReplyMessage(Mode_t ownerMode,
void ModeHelper::sendModeInfoMessage(Mode_t ownerMode, void ModeHelper::sendModeInfoMessage(Mode_t ownerMode,
Submode_t ownerSubmode) { Submode_t ownerSubmode) {
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
if (theOneWhoCommandedAMode != parentQueueId if (theOneWhoCommandedAMode != parentQueueId
and parentQueueId != MessageQueueSenderIF::NO_QUEUE) and parentQueueId != MessageQueueMessageIF::NO_QUEUE)
{ {
ModeMessage::setModeMessage(&reply, ModeMessage::REPLY_MODE_INFO, ModeMessage::setModeMessage(&reply, ModeMessage::REPLY_MODE_INFO,
ownerMode, ownerSubmode); ownerMode, ownerSubmode);

View File

@ -31,7 +31,8 @@ ReturnValue_t LimitViolationReporter::sendLimitViolationReport(const SerializeIF
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
CommandMessage report; MessageQueueMessage message;
CommandMessage report(&message);
MonitoringMessage::setLimitViolationReport(&report, storeId); MonitoringMessage::setLimitViolationReport(&report, storeId);
return MessageQueueSenderIF::sendMessage(reportQueue, &report); return MessageQueueSenderIF::sendMessage(reportQueue, &report);
} }

View File

@ -1,5 +1,6 @@
#include <framework/objectmanager/ObjectManager.h> #include <framework/objectmanager/ObjectManager.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <iomanip>
#include <cstdlib> #include <cstdlib>
ObjectManager::ObjectManager( void (*setProducer)() ): ObjectManager::ObjectManager( void (*setProducer)() ):

View File

@ -25,21 +25,21 @@ void MessageQueue::switchSystemContext(CallContext callContext) {
} }
ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, bool ignoreFault) { MessageQueueMessageIF* message, bool ignoreFault) {
return sendMessageFrom(sendTo, message, this->getId(), ignoreFault); return sendMessageFrom(sendTo, message, this->getId(), ignoreFault);
} }
ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessage* message) { ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessageIF* message) {
return sendToDefaultFrom(message, this->getId()); return sendToDefaultFrom(message, this->getId());
} }
ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessage* message, ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessageIF* message,
MessageQueueId_t sentFrom, bool ignoreFault) { MessageQueueId_t sentFrom, bool ignoreFault) {
return sendMessageFrom(defaultDestination,message,sentFrom,ignoreFault); return sendMessageFrom(defaultDestination,message,sentFrom,ignoreFault);
} }
ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) { ReturnValue_t MessageQueue::reply(MessageQueueMessageIF* message) {
if (this->lastPartner != 0) { if (this->lastPartner != MessageQueueMessageIF::NO_QUEUE) {
return sendMessageFrom(this->lastPartner, message, this->getId()); return sendMessageFrom(this->lastPartner, message, this->getId());
} else { } else {
return NO_REPLY_PARTNER; return NO_REPLY_PARTNER;
@ -47,7 +47,7 @@ ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) {
} }
ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom, MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault) { bool ignoreFault) {
return sendMessageFromMessageQueue(sendTo, message, sentFrom, return sendMessageFromMessageQueue(sendTo, message, sentFrom,
ignoreFault, callContext); ignoreFault, callContext);
@ -69,7 +69,7 @@ ReturnValue_t MessageQueue::handleSendResult(BaseType_t result, bool ignoreFault
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message, ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message,
MessageQueueId_t* receivedFrom) { MessageQueueId_t* receivedFrom) {
ReturnValue_t status = this->receiveMessage(message); ReturnValue_t status = this->receiveMessage(message);
if(status == HasReturnvaluesIF::RETURN_OK) { if(status == HasReturnvaluesIF::RETURN_OK) {
@ -78,7 +78,7 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message,
return status; return status;
} }
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) { ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
BaseType_t result = xQueueReceive(handle,reinterpret_cast<void*>( BaseType_t result = xQueueReceive(handle,reinterpret_cast<void*>(
message->getBuffer()), 0); message->getBuffer()), 0);
if (result == pdPASS){ if (result == pdPASS){
@ -120,7 +120,7 @@ bool MessageQueue::isDefaultDestinationSet() const {
// static core function to send messages. // static core function to send messages.
ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
MessageQueueMessage *message, MessageQueueId_t sentFrom, MessageQueueMessageIF *message, MessageQueueId_t sentFrom,
bool ignoreFault, CallContext callContext) { bool ignoreFault, CallContext callContext) {
message->setSender(sentFrom); message->setSender(sentFrom);
BaseType_t result; BaseType_t result;

View File

@ -85,14 +85,14 @@ public:
* @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full. * @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full.
*/ */
ReturnValue_t sendMessage(MessageQueueId_t sendTo, ReturnValue_t sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, bool ignoreFault = false ); MessageQueueMessageIF* message, bool ignoreFault = false );
/** /**
* @brief This operation sends a message to the default destination. * @brief This operation sends a message to the default destination.
* @details As in the sendMessage method, this function uses the sendToDefault call of the * @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. * MessageQueueSender parent class and adds its queue id as "sentFrom" information.
* @param message A pointer to a previously created message, which is sent. * @param message A pointer to a previously created message, which is sent.
*/ */
ReturnValue_t sendToDefault( MessageQueueMessage* message ); ReturnValue_t sendToDefault( MessageQueueMessageIF* message );
/** /**
* @brief This operation sends a message to the last communication partner. * @brief This operation sends a message to the last communication partner.
* @details This operation simplifies answering an incoming message by using the stored * @details This operation simplifies answering an incoming message by using the stored
@ -100,7 +100,7 @@ public:
* (i.e. lastPartner is zero), an error code is returned. * (i.e. lastPartner is zero), an error code is returned.
* @param message A pointer to a previously created message, which is sent. * @param message A pointer to a previously created message, which is sent.
*/ */
ReturnValue_t reply( MessageQueueMessage* message ); ReturnValue_t reply( MessageQueueMessageIF* message );
/** /**
* @brief With the sendMessage call, a queue message is sent to a receiving queue. * @brief With the sendMessage call, a queue message is sent to a receiving queue.
@ -113,8 +113,9 @@ public:
* This variable is set to zero by default. * 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. * @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full.
*/ */
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, MessageQueueMessage* message, virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false ); MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE,
bool ignoreFault = false );
/** /**
* @brief The sendToDefault method sends a queue message to the default destination. * @brief The sendToDefault method sends a queue message to the default destination.
@ -123,7 +124,7 @@ public:
* @param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. * @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. * This variable is set to zero by default.
*/ */
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message, virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message,
MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false ); MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false );
/** /**
@ -133,7 +134,7 @@ public:
* @param message A pointer to a message in which the received data is stored. * @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. * @param receivedFrom A pointer to a queue id in which the sender's id is stored.
*/ */
ReturnValue_t receiveMessage(MessageQueueMessage* message, ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
MessageQueueId_t *receivedFrom); MessageQueueId_t *receivedFrom);
/** /**
@ -144,7 +145,7 @@ public:
* message's content is cleared and the function returns immediately. * message's content is cleared and the function returns immediately.
* @param message A pointer to a message in which the received data is stored. * @param message A pointer to a message in which the received data is stored.
*/ */
ReturnValue_t receiveMessage(MessageQueueMessage* message); ReturnValue_t receiveMessage(MessageQueueMessageIF* message);
/** /**
* Deletes all pending messages in the queue. * Deletes all pending messages in the queue.
* @param count The number of flushed messages. * @param count The number of flushed messages.
@ -191,7 +192,7 @@ protected:
* @param context Specify whether call is made from task or from an ISR. * @param context Specify whether call is made from task or from an ISR.
*/ */
static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo, static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE,
bool ignoreFault=false, CallContext callContext = CallContext::TASK); bool ignoreFault=false, CallContext callContext = CallContext::TASK);
static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault); static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault);

View File

@ -7,7 +7,7 @@ QueueFactory* QueueFactory::factoryInstance = nullptr;
ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo, ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom, MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault) { bool ignoreFault) {
return MessageQueue::sendMessageFromMessageQueue(sendTo,message, return MessageQueue::sendMessageFromMessageQueue(sendTo,message,
sentFrom,ignoreFault); sentFrom,ignoreFault);

View File

@ -18,20 +18,20 @@ MessageQueue::~MessageQueue() {
} }
ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, bool ignoreFault) { MessageQueueMessageIF* message, bool ignoreFault) {
return sendMessageFrom(sendTo, message, this->getId(), ignoreFault); return sendMessageFrom(sendTo, message, this->getId(), ignoreFault);
} }
ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessage* message) { ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessageIF* message) {
return sendToDefaultFrom(message, this->getId()); return sendToDefaultFrom(message, this->getId());
} }
ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessage* message, ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessageIF* message,
MessageQueueId_t sentFrom, bool ignoreFault) { MessageQueueId_t sentFrom, bool ignoreFault) {
return sendMessageFrom(defaultDestination,message,sentFrom,ignoreFault); return sendMessageFrom(defaultDestination,message,sentFrom,ignoreFault);
} }
ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) { ReturnValue_t MessageQueue::reply(MessageQueueMessageIF* message) {
if (this->lastPartner != 0) { if (this->lastPartner != 0) {
return sendMessageFrom(this->lastPartner, message, this->getId()); return sendMessageFrom(this->lastPartner, message, this->getId());
} else { } else {
@ -40,13 +40,13 @@ ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) {
} }
ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom, MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault) { bool ignoreFault) {
return sendMessageFromMessageQueue(sendTo, message, sentFrom, return sendMessageFromMessageQueue(sendTo, message, sentFrom,
ignoreFault); ignoreFault);
} }
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message, ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message,
MessageQueueId_t* receivedFrom) { MessageQueueId_t* receivedFrom) {
ReturnValue_t status = this->receiveMessage(message); ReturnValue_t status = this->receiveMessage(message);
if(status == HasReturnvaluesIF::RETURN_OK) { if(status == HasReturnvaluesIF::RETURN_OK) {
@ -55,7 +55,7 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message,
return status; return status;
} }
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) { ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
if(messageQueue.empty()) { if(messageQueue.empty()) {
return MessageQueueIF::EMPTY; return MessageQueueIF::EMPTY;
} }
@ -102,9 +102,9 @@ bool MessageQueue::isDefaultDestinationSet() const {
// static core function to send messages. // static core function to send messages.
ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
MessageQueueMessage *message, MessageQueueId_t sentFrom, MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault) { bool ignoreFault) {
if(message->messageSize > MessageQueueMessage::MAX_DATA_SIZE) { if(message->getMessageSize() > message->getMaximumMessageSize()) {
// Actually, this should never happen or an error will be emitted // Actually, this should never happen or an error will be emitted
// in MessageQueueMessage. // in MessageQueueMessage.
// But I will still return a failure here. // But I will still return a failure here.
@ -127,7 +127,17 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
if(targetQueue->messageQueue.size() < targetQueue->messageDepth) { if(targetQueue->messageQueue.size() < targetQueue->messageDepth) {
MutexHelper mutexLock(targetQueue->queueLock, 20); MutexHelper mutexLock(targetQueue->queueLock, 20);
targetQueue->messageQueue.push(*message); // not ideal, works for now though.
MessageQueueMessage* mqmMessage =
dynamic_cast<MessageQueueMessage*>(message);
if(message != nullptr) {
targetQueue->messageQueue.push(*mqmMessage);
}
else {
sif::error << "MessageQueue::sendMessageFromMessageQueue: Message"
"is not MessageQueueMessage!" << std::endl;
}
} }
else { else {
return MessageQueueIF::FULL; return MessageQueueIF::FULL;

View File

@ -77,7 +77,7 @@ public:
* is not incremented if queue is full. * is not incremented if queue is full.
*/ */
ReturnValue_t sendMessage(MessageQueueId_t sendTo, ReturnValue_t sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, bool ignoreFault = false) override; MessageQueueMessageIF* message, bool ignoreFault = false) override;
/** /**
* @brief This operation sends a message to the default destination. * @brief This operation sends a message to the default destination.
* @details As in the sendMessage method, this function uses the * @details As in the sendMessage method, this function uses the
@ -85,7 +85,7 @@ public:
* queue id as "sentFrom" information. * queue id as "sentFrom" information.
* @param message A pointer to a previously created message, which is sent. * @param message A pointer to a previously created message, which is sent.
*/ */
ReturnValue_t sendToDefault(MessageQueueMessage* message) override; ReturnValue_t sendToDefault(MessageQueueMessageIF* message) override;
/** /**
* @brief This operation sends a message to the last communication partner. * @brief This operation sends a message to the last communication partner.
* @details This operation simplifies answering an incoming message by using * @details This operation simplifies answering an incoming message by using
@ -93,7 +93,7 @@ public:
* message received yet (i.e. lastPartner is zero), an error code is returned. * 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. * @param message A pointer to a previously created message, which is sent.
*/ */
ReturnValue_t reply(MessageQueueMessage* message) override; ReturnValue_t reply(MessageQueueMessageIF* message) override;
/** /**
* @brief With the sendMessage call, a queue message is sent to a * @brief With the sendMessage call, a queue message is sent to a
@ -113,7 +113,7 @@ public:
* is not incremented if queue is full. * is not incremented if queue is full.
*/ */
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE,
bool ignoreFault = false) override; bool ignoreFault = false) override;
/** /**
@ -127,7 +127,7 @@ public:
* sender's queue id into the message. This variable is set to zero by * sender's queue id into the message. This variable is set to zero by
* default. * default.
*/ */
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message, virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message,
MessageQueueId_t sentFrom = NO_QUEUE, MessageQueueId_t sentFrom = NO_QUEUE,
bool ignoreFault = false) override; bool ignoreFault = false) override;
@ -140,7 +140,7 @@ public:
* @param message A pointer to a message in which the received data is stored. * @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. * @param receivedFrom A pointer to a queue id in which the sender's id is stored.
*/ */
ReturnValue_t receiveMessage(MessageQueueMessage* message, ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
MessageQueueId_t *receivedFrom) override; MessageQueueId_t *receivedFrom) override;
/** /**
@ -153,7 +153,7 @@ public:
* function returns immediately. * function returns immediately.
* @param message A pointer to a message in which the received data is stored. * @param message A pointer to a message in which the received data is stored.
*/ */
ReturnValue_t receiveMessage(MessageQueueMessage* message) override; ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override;
/** /**
* Deletes all pending messages in the queue. * Deletes all pending messages in the queue.
* @param count The number of flushed messages. * @param count The number of flushed messages.
@ -205,7 +205,7 @@ protected:
* @param context Specify whether call is made from task or from an ISR. * @param context Specify whether call is made from task or from an ISR.
*/ */
static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo, static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE,
bool ignoreFault=false); bool ignoreFault=false);
//static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault); //static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault);

View File

@ -7,7 +7,7 @@ QueueFactory* QueueFactory::factoryInstance = nullptr;
ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo, ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom, MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault) { bool ignoreFault) {
return MessageQueue::sendMessageFromMessageQueue(sendTo,message, return MessageQueue::sendMessageFromMessageQueue(sendTo,message,
sentFrom,ignoreFault); sentFrom,ignoreFault);

View File

@ -118,15 +118,15 @@ ReturnValue_t MessageQueue::handleError(mq_attr* attributes,
} }
ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, bool ignoreFault) { MessageQueueMessageIF* message, bool ignoreFault) {
return sendMessageFrom(sendTo, message, this->getId(), false); return sendMessageFrom(sendTo, message, this->getId(), false);
} }
ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessage* message) { ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessageIF* message) {
return sendToDefaultFrom(message, this->getId()); return sendToDefaultFrom(message, this->getId());
} }
ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) { ReturnValue_t MessageQueue::reply(MessageQueueMessageIF* message) {
if (this->lastPartner != 0) { if (this->lastPartner != 0) {
return sendMessageFrom(this->lastPartner, message, this->getId()); return sendMessageFrom(this->lastPartner, message, this->getId());
} else { } else {
@ -134,21 +134,21 @@ ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) {
} }
} }
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message, ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message,
MessageQueueId_t* receivedFrom) { MessageQueueId_t* receivedFrom) {
ReturnValue_t status = this->receiveMessage(message); ReturnValue_t status = this->receiveMessage(message);
*receivedFrom = this->lastPartner; *receivedFrom = this->lastPartner;
return status; return status;
} }
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) { ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
unsigned int messagePriority = 0; unsigned int messagePriority = 0;
int status = mq_receive(id,reinterpret_cast<char*>(message->getBuffer()), int status = mq_receive(id,reinterpret_cast<char*>(message->getBuffer()),
message->MAX_MESSAGE_SIZE,&messagePriority); message->getMaximumMessageSize(),&messagePriority);
if (status > 0) { if (status > 0) {
this->lastPartner = message->getSender(); this->lastPartner = message->getSender();
//Check size of incoming message. //Check size of incoming message.
if (message->messageSize < message->getMinimumMessageSize()) { if (message->getMessageSize() < message->getMinimumMessageSize()) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
@ -158,7 +158,7 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) {
} else { } else {
//No message was received. Keep lastPartner anyway, I might send //No message was received. Keep lastPartner anyway, I might send
//something later. But still, delete packet content. //something later. But still, delete packet content.
memset(message->getData(), 0, message->MAX_DATA_SIZE); memset(message->getData(), 0, message->getMaximumMessageSize());
switch(errno){ switch(errno){
case EAGAIN: case EAGAIN:
//O_NONBLOCK or MQ_NONBLOCK was set and there are no messages //O_NONBLOCK or MQ_NONBLOCK was set and there are no messages
@ -259,13 +259,13 @@ void MessageQueue::setDefaultDestination(MessageQueueId_t defaultDestination) {
} }
ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom, MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault) { bool ignoreFault) {
return sendMessageFromMessageQueue(sendTo,message,sentFrom,ignoreFault); return sendMessageFromMessageQueue(sendTo,message,sentFrom,ignoreFault);
} }
ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessage* message, ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessageIF* message,
MessageQueueId_t sentFrom, bool ignoreFault) { MessageQueueId_t sentFrom, bool ignoreFault) {
return sendMessageFrom(defaultDestination, message, sentFrom, ignoreFault); return sendMessageFrom(defaultDestination, message, sentFrom, ignoreFault);
} }
@ -281,11 +281,12 @@ bool MessageQueue::isDefaultDestinationSet() const {
uint16_t MessageQueue::queueCounter = 0; uint16_t MessageQueue::queueCounter = 0;
ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
MessageQueueMessage *message, MessageQueueId_t sentFrom, MessageQueueMessageIF *message, MessageQueueId_t sentFrom,
bool ignoreFault) { bool ignoreFault) {
message->setSender(sentFrom); message->setSender(sentFrom);
int result = mq_send(sendTo, int result = mq_send(sendTo,
reinterpret_cast<const char*>(message->getBuffer()), message->messageSize,0); reinterpret_cast<const char*>(message->getBuffer()),
message->getMessageSize(),0);
//TODO: Check if we're in ISR. //TODO: Check if we're in ISR.
if (result != 0) { if (result != 0) {

View File

@ -56,14 +56,14 @@ public:
* @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full. * @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, virtual ReturnValue_t sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, bool ignoreFault = false ); MessageQueueMessageIF* message, bool ignoreFault = false );
/** /**
* @brief This operation sends a message to the default destination. * @brief This operation sends a message to the default destination.
* @details As in the sendMessage method, this function uses the sendToDefault call of the * @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. * MessageQueueSender parent class and adds its queue id as "sentFrom" information.
* @param message A pointer to a previously created message, which is sent. * @param message A pointer to a previously created message, which is sent.
*/ */
virtual ReturnValue_t sendToDefault( MessageQueueMessage* message ); virtual ReturnValue_t sendToDefault( MessageQueueMessageIF* message );
/** /**
* @brief This operation sends a message to the last communication partner. * @brief This operation sends a message to the last communication partner.
* @details This operation simplifies answering an incoming message by using the stored * @details This operation simplifies answering an incoming message by using the stored
@ -71,7 +71,7 @@ public:
* (i.e. lastPartner is zero), an error code is returned. * (i.e. lastPartner is zero), an error code is returned.
* @param message A pointer to a previously created message, which is sent. * @param message A pointer to a previously created message, which is sent.
*/ */
ReturnValue_t reply( MessageQueueMessage* message ); ReturnValue_t reply( MessageQueueMessageIF* message );
/** /**
* @brief This function reads available messages from the message queue and returns the sender. * @brief This function reads available messages from the message queue and returns the sender.
@ -80,7 +80,7 @@ public:
* @param message A pointer to a message in which the received data is stored. * @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. * @param receivedFrom A pointer to a queue id in which the sender's id is stored.
*/ */
ReturnValue_t receiveMessage(MessageQueueMessage* message, ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
MessageQueueId_t *receivedFrom); MessageQueueId_t *receivedFrom);
/** /**
@ -91,7 +91,7 @@ public:
* message's content is cleared and the function returns immediately. * message's content is cleared and the function returns immediately.
* @param message A pointer to a message in which the received data is stored. * @param message A pointer to a message in which the received data is stored.
*/ */
ReturnValue_t receiveMessage(MessageQueueMessage* message); ReturnValue_t receiveMessage(MessageQueueMessageIF* message);
/** /**
* Deletes all pending messages in the queue. * Deletes all pending messages in the queue.
* @param count The number of flushed messages. * @param count The number of flushed messages.
@ -114,7 +114,9 @@ public:
* This variable is set to zero by default. * 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. * \param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full.
*/ */
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom, bool ignoreFault = false ); virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault = false );
/** /**
* \brief The sendToDefault method sends a queue message to the default destination. * \brief The sendToDefault method sends a queue message to the default destination.
* \details In all other aspects, it works identical to the sendMessage method. * \details In all other aspects, it works identical to the sendMessage method.
@ -122,7 +124,8 @@ public:
* \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. * \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. * This variable is set to zero by default.
*/ */
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false ); virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message,
MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false );
/** /**
* \brief This method is a simple setter for the default destination. * \brief This method is a simple setter for the default destination.
*/ */
@ -145,7 +148,9 @@ protected:
* This variable is set to zero by default. * 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. * \param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full.
*/ */
static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo,MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE,bool ignoreFault=false); static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo,
MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE,
bool ignoreFault=false);
private: private:
/** /**
* @brief The class stores the queue id it got assigned from the operating system in this attribute. * @brief The class stores the queue id it got assigned from the operating system in this attribute.

View File

@ -9,7 +9,7 @@ QueueFactory* QueueFactory::factoryInstance = nullptr;
ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo, ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom, MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault) { bool ignoreFault) {
return MessageQueue::sendMessageFromMessageQueue(sendTo,message, return MessageQueue::sendMessageFromMessageQueue(sendTo,message,
sentFrom,ignoreFault); sentFrom,ignoreFault);

View File

@ -102,7 +102,8 @@ ReturnValue_t ParameterHelper::sendParameter(MessageQueueId_t to, uint32_t id,
return result; return result;
} }
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
ParameterMessage::setParameterDumpReply(&reply, id, address); ParameterMessage::setParameterDumpReply(&reply, id, address);
@ -123,8 +124,10 @@ ReturnValue_t ParameterHelper::initialize() {
} }
} }
void ParameterHelper::rejectCommand(MessageQueueId_t to, ReturnValue_t reason, Command_t initialCommand) { void ParameterHelper::rejectCommand(MessageQueueId_t to, ReturnValue_t reason,
CommandMessage reply; Command_t initialCommand) {
MessageQueueMessage message;
CommandMessage reply(&message);
reply.setReplyRejected(reason, initialCommand); reply.setReplyRejected(reason, initialCommand);
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId); MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
} }

View File

@ -163,7 +163,8 @@ void Fuse::setAllMonitorsToUnchecked() {
} }
void Fuse::checkCommandQueue() { void Fuse::checkCommandQueue() {
CommandMessage command; MessageQueueMessage message;
CommandMessage command(&message);
ReturnValue_t result = commandQueue->receiveMessage(&command); ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return; return;

View File

@ -74,7 +74,8 @@ void PowerSensor::setAllMonitorsToUnchecked() {
} }
void PowerSensor::checkCommandQueue() { void PowerSensor::checkCommandQueue() {
CommandMessage command; MessageQueueMessage message;
CommandMessage command(&message);
ReturnValue_t result = commandQueue->receiveMessage(&command); ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return; return;

View File

@ -21,29 +21,29 @@ SerialBufferAdapter<count_t>::~SerialBufferAdapter() {
} }
template<typename count_t> template<typename count_t>
ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer, ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer_,
size_t* size, const size_t max_size, bool bigEndian) const { size_t* size_, const size_t max_size, bool bigEndian) const {
uint32_t serializedLength = bufferLength; uint32_t serializedLength = bufferLength;
if (serializeLength) { if (serializeLength) {
serializedLength += AutoSerializeAdapter::getSerializedSize( serializedLength += AutoSerializeAdapter::getSerializedSize(
&bufferLength); &bufferLength);
} }
if (*size + serializedLength > max_size) { if (*size_ + serializedLength > max_size) {
return BUFFER_TOO_SHORT; return BUFFER_TOO_SHORT;
} else { } else {
if (serializeLength) { if (serializeLength) {
AutoSerializeAdapter::serialize(&bufferLength, buffer, size, AutoSerializeAdapter::serialize(&bufferLength, buffer_, size_,
max_size, bigEndian); max_size, bigEndian);
} }
if (constBuffer != nullptr) { if (constBuffer != nullptr) {
memcpy(*buffer, constBuffer, bufferLength); memcpy(*buffer_, this->constBuffer, bufferLength);
} else if (buffer != nullptr) { } else if (buffer != nullptr) {
memcpy(*buffer, buffer, bufferLength); memcpy(*buffer_, this->buffer, bufferLength);
} else { } else {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
*size += bufferLength; *size_ += bufferLength;
(*buffer) += bufferLength; (*buffer_) += bufferLength;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
} }

View File

@ -45,7 +45,7 @@ public:
virtual ~SerialBufferAdapter(); virtual ~SerialBufferAdapter();
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, virtual ReturnValue_t serialize(uint8_t** buffer_, size_t* size,
const size_t max_size, bool bigEndian) const override; const size_t max_size, bool bigEndian) const override;
virtual size_t getSerializedSize() const; virtual size_t getSerializedSize() const;

View File

@ -309,7 +309,8 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) {
break; break;
case ModeSequenceMessage::READ_FREE_SEQUENCE_SLOTS: { case ModeSequenceMessage::READ_FREE_SEQUENCE_SLOTS: {
uint32_t freeSlots = modeSequences.maxSize() - modeSequences.size(); uint32_t freeSlots = modeSequences.maxSize() - modeSequences.size();
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
ModeSequenceMessage::setModeSequenceMessage(&reply, ModeSequenceMessage::setModeSequenceMessage(&reply,
ModeSequenceMessage::FREE_SEQUENCE_SLOTS, freeSlots); ModeSequenceMessage::FREE_SEQUENCE_SLOTS, freeSlots);
commandQueue->reply(&reply); commandQueue->reply(&reply);
@ -317,7 +318,8 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) {
break; break;
case ModeSequenceMessage::READ_FREE_TABLE_SLOTS: { case ModeSequenceMessage::READ_FREE_TABLE_SLOTS: {
uint32_t free = modeTables.maxSize() - modeTables.size(); uint32_t free = modeTables.maxSize() - modeTables.size();
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
ModeSequenceMessage::setModeSequenceMessage(&reply, ModeSequenceMessage::setModeSequenceMessage(&reply,
ModeSequenceMessage::FREE_TABLE_SLOTS, free); ModeSequenceMessage::FREE_TABLE_SLOTS, free);
commandQueue->reply(&reply); commandQueue->reply(&reply);
@ -330,11 +332,12 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) {
} }
void Subsystem::replyToCommand(ReturnValue_t status, uint32_t parameter) { void Subsystem::replyToCommand(ReturnValue_t status, uint32_t parameter) {
MessageQueueMessage message;
if (status == RETURN_OK) { if (status == RETURN_OK) {
CommandMessage reply(CommandMessage::REPLY_COMMAND_OK, 0, 0); CommandMessage reply(&message, CommandMessage::REPLY_COMMAND_OK, 0, 0);
commandQueue->reply(&reply); commandQueue->reply(&reply);
} else { } else {
CommandMessage reply(CommandMessage::REPLY_REJECTED, status, 0); CommandMessage reply(&message, CommandMessage::REPLY_REJECTED, status, 0);
commandQueue->reply(&reply); commandQueue->reply(&reply);
} }
} }
@ -617,7 +620,8 @@ void Subsystem::sendSerializablesAsCommandMessage(Command_t command,
for (uint8_t i = 0; i < count; i++) { for (uint8_t i = 0; i < count; i++) {
elements[i]->serialize(&storeBuffer, &size, maxSize, true); elements[i]->serialize(&storeBuffer, &size, maxSize, true);
} }
CommandMessage reply; MessageQueueMessage message;
CommandMessage reply(&message);
ModeSequenceMessage::setModeSequenceMessage(&reply, command, address); ModeSequenceMessage::setModeSequenceMessage(&reply, command, address);
if (commandQueue->reply(&reply) != RETURN_OK) { if (commandQueue->reply(&reply) != RETURN_OK) {
IPCStore->deleteData(address); IPCStore->deleteData(address);

View File

@ -9,7 +9,7 @@ SubsystemBase::SubsystemBase(object_id_t setObjectId, object_id_t parent,
false), commandsOutstanding(0), commandQueue(NULL), healthHelper(this, false), commandsOutstanding(0), commandQueue(NULL), healthHelper(this,
setObjectId), modeHelper(this), parentId(parent) { setObjectId), modeHelper(this), parentId(parent) {
commandQueue = QueueFactory::instance()->createMessageQueue(commandQueueDepth, commandQueue = QueueFactory::instance()->createMessageQueue(commandQueueDepth,
CommandMessage::MAX_MESSAGE_SIZE); MessageQueueMessage::MAX_MESSAGE_SIZE);
} }
SubsystemBase::~SubsystemBase() { SubsystemBase::~SubsystemBase() {
@ -77,8 +77,8 @@ ReturnValue_t SubsystemBase::checkStateAgainstTable(
} }
void SubsystemBase::executeTable(HybridIterator<ModeListEntry> tableIter, Submode_t targetSubmode) { void SubsystemBase::executeTable(HybridIterator<ModeListEntry> tableIter, Submode_t targetSubmode) {
MessageQueueMessage message;
CommandMessage message; CommandMessage command(&message);
std::map<object_id_t, ChildInfo>::iterator iter; std::map<object_id_t, ChildInfo>::iterator iter;
@ -100,17 +100,17 @@ void SubsystemBase::executeTable(HybridIterator<ModeListEntry> tableIter, Submod
if (healthHelper.healthTable->hasHealth(object)) { if (healthHelper.healthTable->hasHealth(object)) {
if (healthHelper.healthTable->isFaulty(object)) { if (healthHelper.healthTable->isFaulty(object)) {
ModeMessage::setModeMessage(&message, ModeMessage::setModeMessage(&command,
ModeMessage::CMD_MODE_COMMAND, HasModesIF::MODE_OFF, ModeMessage::CMD_MODE_COMMAND, HasModesIF::MODE_OFF,
SUBMODE_NONE); SUBMODE_NONE);
} else { } else {
if (modeHelper.isForced()) { if (modeHelper.isForced()) {
ModeMessage::setModeMessage(&message, ModeMessage::setModeMessage(&command,
ModeMessage::CMD_MODE_COMMAND_FORCED, ModeMessage::CMD_MODE_COMMAND_FORCED,
tableIter.value->getMode(), submodeToCommand); tableIter.value->getMode(), submodeToCommand);
} else { } else {
if (healthHelper.healthTable->isCommandable(object)) { if (healthHelper.healthTable->isCommandable(object)) {
ModeMessage::setModeMessage(&message, ModeMessage::setModeMessage(&command,
ModeMessage::CMD_MODE_COMMAND, ModeMessage::CMD_MODE_COMMAND,
tableIter.value->getMode(), submodeToCommand); tableIter.value->getMode(), submodeToCommand);
} else { } else {
@ -119,12 +119,12 @@ void SubsystemBase::executeTable(HybridIterator<ModeListEntry> tableIter, Submod
} }
} }
} else { } else {
ModeMessage::setModeMessage(&message, ModeMessage::CMD_MODE_COMMAND, ModeMessage::setModeMessage(&command, ModeMessage::CMD_MODE_COMMAND,
tableIter.value->getMode(), submodeToCommand); tableIter.value->getMode(), submodeToCommand);
} }
if ((iter->second.mode == ModeMessage::getMode(&message)) if ((iter->second.mode == ModeMessage::getMode(&command))
&& (iter->second.submode == ModeMessage::getSubmode(&message)) && (iter->second.submode == ModeMessage::getSubmode(&command))
&& !modeHelper.isForced()) { && !modeHelper.isForced()) {
continue; //don't send redundant mode commands (produces event spam), but still command if mode is forced to reach lower levels continue; //don't send redundant mode commands (produces event spam), but still command if mode is forced to reach lower levels
} }
@ -297,7 +297,8 @@ void SubsystemBase::setToExternalControl() {
void SubsystemBase::announceMode(bool recursive) { void SubsystemBase::announceMode(bool recursive) {
triggerEvent(MODE_INFO, mode, submode); triggerEvent(MODE_INFO, mode, submode);
if (recursive) { if (recursive) {
CommandMessage command; MessageQueueMessage message;
CommandMessage command(&message);
ModeMessage::setModeMessage(&command, ModeMessage::setModeMessage(&command,
ModeMessage::CMD_MODE_ANNOUNCE_RECURSIVELY, 0, 0); ModeMessage::CMD_MODE_ANNOUNCE_RECURSIVELY, 0, 0);
commandAllChildren(&command); commandAllChildren(&command);
@ -306,31 +307,33 @@ void SubsystemBase::announceMode(bool recursive) {
void SubsystemBase::checkCommandQueue() { void SubsystemBase::checkCommandQueue() {
ReturnValue_t result; ReturnValue_t result;
CommandMessage message; MessageQueueMessage message;
CommandMessage command(&message);
for (result = commandQueue->receiveMessage(&message); result == RETURN_OK; for (result = commandQueue->receiveMessage(&command); result == RETURN_OK;
result = commandQueue->receiveMessage(&message)) { result = commandQueue->receiveMessage(&command)) {
result = healthHelper.handleHealthCommand(&message); result = healthHelper.handleHealthCommand(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
continue; continue;
} }
result = modeHelper.handleModeCommand(&message); result = modeHelper.handleModeCommand(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
continue; continue;
} }
result = handleModeReply(&message); result = handleModeReply(&command);
if (result == RETURN_OK) { if (result == RETURN_OK) {
continue; continue;
} }
result = handleCommandMessage(&message); result = handleCommandMessage(&command);
if (result != RETURN_OK) { if (result != RETURN_OK) {
CommandMessage reply; MessageQueueMessage message;
reply.setReplyRejected(CommandMessage::UNKNOW_COMMAND, CommandMessage reply(&message);
message.getCommand()); reply.setReplyRejected(CommandMessage::UNKNOWN_COMMAND,
command.getCommand());
replyToCommand(&reply); replyToCommand(&reply);
} }
} }

View File

@ -44,18 +44,19 @@ ReturnValue_t AbstractTemperatureSensor::performHealthOp() {
} }
void AbstractTemperatureSensor::handleCommandQueue() { void AbstractTemperatureSensor::handleCommandQueue() {
CommandMessage message; MessageQueueMessage message;
ReturnValue_t result = commandQueue->receiveMessage(&message); CommandMessage command(&message);
ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
result = healthHelper.handleHealthCommand(&message); result = healthHelper.handleHealthCommand(&command);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
return; return;
} }
result = parameterHelper.handleParameterMessage(&message); result = parameterHelper.handleParameterMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
return; return;
} }
message.setToUnknownCommand(); command.setToUnknownCommand();
commandQueue->reply(&message); commandQueue->reply(&message);
} }
} }

View File

@ -279,14 +279,15 @@ ReturnValue_t Heater::initialize() {
} }
void Heater::handleQueue() { void Heater::handleQueue() {
CommandMessage message; MessageQueueMessage message;
ReturnValue_t result = commandQueue->receiveMessage(&message); CommandMessage command(&message);
ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
result = healthHelper.handleHealthCommand(&message); result = healthHelper.handleHealthCommand(&command);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
return; return;
} }
parameterHelper.handleParameterMessage(&message); parameterHelper.handleParameterMessage(&command);
} }
} }

View File

@ -74,7 +74,7 @@ void TmStoreMessage::clear(CommandMessage* cmd) {
case DELETE_STORE_CONTENT_BLOCKS: case DELETE_STORE_CONTENT_BLOCKS:
case DOWNLINK_STORE_CONTENT_BLOCKS: case DOWNLINK_STORE_CONTENT_BLOCKS:
case REPORT_INDEX_REQUEST: case REPORT_INDEX_REQUEST:
cmd->setCommand(UNKNOW_COMMAND); cmd->setCommand(CommandMessage::UNKNOWN_COMMAND);
cmd->setParameter(0); cmd->setParameter(0);
cmd->setParameter2(0); cmd->setParameter2(0);
break; break;

View File

@ -5,7 +5,7 @@
#include <framework/storagemanager/StorageManagerIF.h> #include <framework/storagemanager/StorageManagerIF.h>
#include <framework/tmstorage/TmStorePackets.h> #include <framework/tmstorage/TmStorePackets.h>
#include <framework/objectmanager/SystemObjectIF.h> #include <framework/objectmanager/SystemObjectIF.h>
class TmStoreMessage: public CommandMessage { class TmStoreMessage {
public: public:
static ReturnValue_t setEnableStoringMessage(CommandMessage* cmd, static ReturnValue_t setEnableStoringMessage(CommandMessage* cmd,
bool setEnabled); bool setEnabled);

View File

@ -1,22 +1,21 @@
/* #include <framework/tcdistribution/PUSDistributorIF.h>
* CommandingServiceBase.cpp #include <framework/tmtcservices/AcceptsTelemetryIF.h>
* #include <framework/objectmanager/ObjectManagerIF.h>
* Created on: 28.08.2019
* Author: gaisser
*/
#include <framework/tmtcservices/CommandingServiceBase.h> #include <framework/tmtcservices/CommandingServiceBase.h>
#include <framework/tmtcservices/TmTcMessage.h>
#include <framework/ipc/QueueFactory.h>
#include <framework/tmtcpacket/pus/TcPacketStored.h>
#include <framework/tmtcpacket/pus/TmPacketStored.h>
CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId,
uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands, uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeout_seconds, object_id_t setPacketSource, uint16_t commandTimeoutSeconds, object_id_t setPacketSource,
object_id_t setPacketDestination, size_t queueDepth) : object_id_t setPacketDestination, size_t queueDepth) :
SystemObject(setObjectId), apid(apid), service(service), timeout_seconds( SystemObject(setObjectId), apid(apid), service(service),
commandTimeout_seconds), tmPacketCounter(0), IPCStore(NULL), TCStore( timeoutSeconds(commandTimeoutSeconds),
NULL), commandQueue(NULL), requestQueue(NULL), commandMap( commandMap(numberOfParallelCommands), packetSource(setPacketSource),
numberOfParallelCommands), failureParameter1(0), failureParameter2( packetDestination(setPacketDestination) {
0), packetSource(setPacketSource), packetDestination(
setPacketDestination),executingTask(NULL) {
commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth);
requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth); requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth);
} }
@ -57,7 +56,7 @@ ReturnValue_t CommandingServiceBase::initialize() {
objectManager->get<AcceptsTelemetryIF>(packetDestination); objectManager->get<AcceptsTelemetryIF>(packetDestination);
PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>( PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>(
packetSource); packetSource);
if ((packetForwarding == NULL) && (distributor == NULL)) { if (packetForwarding == nullptr or distributor == nullptr) {
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -68,7 +67,7 @@ ReturnValue_t CommandingServiceBase::initialize() {
IPCStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE); IPCStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
TCStore = objectManager->get<StorageManagerIF>(objects::TC_STORE); TCStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
if ((IPCStore == NULL) || (TCStore == NULL)) { if (IPCStore == nullptr or TCStore == nullptr) {
return RETURN_FAILED; return RETURN_FAILED;
} }
@ -77,97 +76,118 @@ ReturnValue_t CommandingServiceBase::initialize() {
} }
void CommandingServiceBase::handleCommandQueue() { void CommandingServiceBase::handleCommandQueue() {
CommandMessage reply, nextCommand; MessageQueueMessage message;
ReturnValue_t result, sendResult = RETURN_OK; CommandMessage reply(&message);
bool isStep = false; ReturnValue_t result = RETURN_FAILED;
for (result = commandQueue->receiveMessage(&reply); result == RETURN_OK; for (result = commandQueue->receiveMessage(&reply); result == RETURN_OK;
result = commandQueue->receiveMessage(&reply)) { result = commandQueue->receiveMessage(&reply)) {
isStep = false; handleCommandMessage(reply);
typename FixedMap<MessageQueueId_t,
CommandingServiceBase::CommandInfo>::Iterator iter;
if (reply.getSender() == MessageQueueIF::NO_QUEUE) {
handleUnrequestedReply(&reply);
continue;
}
if ((iter = commandMap.find(reply.getSender())) == commandMap.end()) {
handleUnrequestedReply(&reply);
continue;
}
nextCommand.setCommand(CommandMessage::CMD_NONE);
result = handleReply(&reply, iter->command, &iter->state, &nextCommand,
iter->objectId, &isStep);
switch (result) {
case EXECUTION_COMPLETE:
case RETURN_OK:
case NO_STEP_MESSAGE:
iter->command = nextCommand.getCommand();
if (nextCommand.getCommand() != CommandMessage::CMD_NONE) {
sendResult = commandQueue->sendMessage(reply.getSender(),
&nextCommand);
}
if (sendResult == RETURN_OK) {
if (isStep) {
if (result != NO_STEP_MESSAGE) {
verificationReporter.sendSuccessReport(
TC_VERIFY::PROGRESS_SUCCESS,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, ++iter->step);
}
} else {
verificationReporter.sendSuccessReport(
TC_VERIFY::COMPLETION_SUCCESS,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, 0);
checkAndExecuteFifo(&iter);
}
} else {
if (isStep) {
nextCommand.clearCommandMessage();
verificationReporter.sendFailureReport(
TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, sendResult,
++iter->step, failureParameter1, failureParameter2);
} else {
nextCommand.clearCommandMessage();
verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, sendResult, 0,
failureParameter1, failureParameter2);
}
failureParameter1 = 0;
failureParameter2 = 0;
checkAndExecuteFifo(&iter);
}
break;
case INVALID_REPLY:
//might be just an unrequested reply at a bad moment
handleUnrequestedReply(&reply);
break;
default:
if (isStep) {
verificationReporter.sendFailureReport(
TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
result, ++iter->step, failureParameter1,
failureParameter2);
} else {
verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
result, 0, failureParameter1, failureParameter2);
}
failureParameter1 = 0;
failureParameter2 = 0;
checkAndExecuteFifo(&iter);
break;
}
} }
} }
void CommandingServiceBase::handleCommandMessage(CommandMessage& reply) {
bool isStep = false;
MessageQueueMessage message;
CommandMessage nextCommand(&message);
CommandMapIter iter;
if (reply.getSender() == MessageQueueIF::NO_QUEUE) {
handleUnrequestedReply(&reply);
return;
}
if ((iter = commandMap.find(reply.getSender())) == commandMap.end()) {
handleUnrequestedReply(&reply);
return;
}
nextCommand.setCommand(CommandMessage::CMD_NONE);
// Implemented by child class, specifies what to do with reply.
ReturnValue_t result = handleReply(&reply, iter->command, &iter->state,
&nextCommand, iter->objectId, &isStep);
switch (result) {
case EXECUTION_COMPLETE:
case RETURN_OK:
case NO_STEP_MESSAGE:
// handle result of reply handler implemented by developer.
handleReplyHandlerResult(result, iter, nextCommand, reply, isStep);
break;
case INVALID_REPLY:
//might be just an unrequested reply at a bad moment
handleUnrequestedReply(&reply);
break;
default:
if (isStep) {
verificationReporter.sendFailureReport(
TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
result, ++iter->step, failureParameter1,
failureParameter2);
} else {
verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
result, 0, failureParameter1, failureParameter2);
}
failureParameter1 = 0;
failureParameter2 = 0;
checkAndExecuteFifo(iter);
break;
}
}
void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result,
CommandMapIter iter, CommandMessage& nextCommand, CommandMessage& reply,
bool& isStep) {
iter->command = nextCommand.getCommand();
// In case a new command is to be sent immediately, this is performed here.
// If no new command is sent, only analyse reply result by initializing
// sendResult as RETURN_OK
ReturnValue_t sendResult = RETURN_OK;
if (nextCommand.getCommand() != CommandMessage::CMD_NONE) {
sendResult = commandQueue->sendMessage(reply.getSender(),
&nextCommand);
}
if (sendResult == RETURN_OK) {
if (isStep and result != NO_STEP_MESSAGE) {
verificationReporter.sendSuccessReport(
TC_VERIFY::PROGRESS_SUCCESS,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, ++iter->step);
}
else {
verificationReporter.sendSuccessReport(
TC_VERIFY::COMPLETION_SUCCESS,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, 0);
checkAndExecuteFifo(iter);
}
}
else {
if (isStep) {
nextCommand.clearCommandMessage();
verificationReporter.sendFailureReport(
TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, sendResult,
++iter->step, failureParameter1, failureParameter2);
} else {
nextCommand.clearCommandMessage();
verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, sendResult, 0,
failureParameter1, failureParameter2);
}
failureParameter1 = 0;
failureParameter2 = 0;
checkAndExecuteFifo(iter);
}
}
void CommandingServiceBase::handleRequestQueue() { void CommandingServiceBase::handleRequestQueue() {
TmTcMessage message; TmTcMessage message;
ReturnValue_t result; ReturnValue_t result;
@ -180,8 +200,8 @@ void CommandingServiceBase::handleRequestQueue() {
address = message.getStorageId(); address = message.getStorageId();
packet.setStoreAddress(address); packet.setStoreAddress(address);
if ((packet.getSubService() == 0) if (packet.getSubService() == 0
|| (isValidSubservice(packet.getSubService()) != RETURN_OK)) { or isValidSubservice(packet.getSubService()) != RETURN_OK) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, INVALID_SUBSERVICE); rejectPacket(TC_VERIFY::START_FAILURE, &packet, INVALID_SUBSERVICE);
continue; continue;
} }
@ -194,8 +214,7 @@ void CommandingServiceBase::handleRequestQueue() {
} }
//Is a command already active for the target object? //Is a command already active for the target object?
typename FixedMap<MessageQueueId_t, CommandMapIter iter;
CommandingServiceBase::CommandInfo>::Iterator iter;
iter = commandMap.find(queue); iter = commandMap.find(queue);
if (iter != commandMap.end()) { if (iter != commandMap.end()) {
@ -210,7 +229,7 @@ void CommandingServiceBase::handleRequestQueue() {
if (result != RETURN_OK) { if (result != RETURN_OK) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, BUSY); rejectPacket(TC_VERIFY::START_FAILURE, &packet, BUSY);
} else { } else {
startExecution(&packet, &iter); startExecution(&packet, iter);
} }
} }
@ -263,45 +282,44 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
} }
void CommandingServiceBase::startExecution( void CommandingServiceBase::startExecution(TcPacketStored *storedPacket,
TcPacketStored *storedPacket, CommandMapIter iter) {
typename FixedMap<MessageQueueId_t, ReturnValue_t result = RETURN_OK;
CommandingServiceBase::CommandInfo>::Iterator *iter) { MessageQueueMessage message;
ReturnValue_t result, sendResult = RETURN_OK; CommandMessage command(&message);
CommandMessage message; iter->subservice = storedPacket->getSubService();
(*iter)->subservice = storedPacket->getSubService(); result = prepareCommand(&command, iter->subservice,
result = prepareCommand(&message, (*iter)->subservice, storedPacket->getApplicationData(),
storedPacket->getApplicationData(), storedPacket->getApplicationDataSize(), &iter->state,
storedPacket->getApplicationDataSize(), &(*iter)->state, iter->objectId);
(*iter)->objectId);
ReturnValue_t sendResult = RETURN_OK;
switch (result) { switch (result) {
case RETURN_OK: case RETURN_OK:
if (message.getCommand() != CommandMessage::CMD_NONE) { if (command.getCommand() != CommandMessage::CMD_NONE) {
sendResult = commandQueue->sendMessage((*iter).value->first, sendResult = commandQueue->sendMessage(iter.value->first,
&message); &message);
} }
if (sendResult == RETURN_OK) { if (sendResult == RETURN_OK) {
Clock::getUptime(&(*iter)->uptimeOfStart); Clock::getUptime(&iter->uptimeOfStart);
(*iter)->step = 0; iter->step = 0;
// (*iter)->state = 0; iter->subservice = storedPacket->getSubService();
(*iter)->subservice = storedPacket->getSubService(); iter->command = command.getCommand();
(*iter)->command = message.getCommand(); iter->tcInfo.ackFlags = storedPacket->getAcknowledgeFlags();
(*iter)->tcInfo.ackFlags = storedPacket->getAcknowledgeFlags(); iter->tcInfo.tcPacketId = storedPacket->getPacketId();
(*iter)->tcInfo.tcPacketId = storedPacket->getPacketId(); iter->tcInfo.tcSequenceControl =
(*iter)->tcInfo.tcSequenceControl =
storedPacket->getPacketSequenceControl(); storedPacket->getPacketSequenceControl();
acceptPacket(TC_VERIFY::START_SUCCESS, storedPacket); acceptPacket(TC_VERIFY::START_SUCCESS, storedPacket);
} else { } else {
message.clearCommandMessage(); command.clearCommandMessage();
rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult); rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} }
break; break;
case EXECUTION_COMPLETE: case EXECUTION_COMPLETE:
if (message.getCommand() != CommandMessage::CMD_NONE) { if (command.getCommand() != CommandMessage::CMD_NONE) {
//Fire-and-forget command. //Fire-and-forget command.
sendResult = commandQueue->sendMessage((*iter).value->first, sendResult = commandQueue->sendMessage(iter.value->first,
&message); &message);
} }
if (sendResult == RETURN_OK) { if (sendResult == RETURN_OK) {
@ -310,7 +328,7 @@ void CommandingServiceBase::startExecution(
acceptPacket(TC_VERIFY::COMPLETION_SUCCESS, storedPacket); acceptPacket(TC_VERIFY::COMPLETION_SUCCESS, storedPacket);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} else { } else {
message.clearCommandMessage(); command.clearCommandMessage();
rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult); rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} }
@ -337,12 +355,10 @@ void CommandingServiceBase::acceptPacket(uint8_t reportId,
} }
void CommandingServiceBase::checkAndExecuteFifo( void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter iter) {
typename FixedMap<MessageQueueId_t,
CommandingServiceBase::CommandInfo>::Iterator *iter) {
store_address_t address; store_address_t address;
if ((*iter)->fifo.retrieve(&address) != RETURN_OK) { if (iter->fifo.retrieve(&address) != RETURN_OK) {
commandMap.erase(iter); commandMap.erase(&iter);
} else { } else {
TcPacketStored newPacket(address); TcPacketStored newPacket(address);
startExecution(&newPacket, iter); startExecution(&newPacket, iter);
@ -366,15 +382,14 @@ MessageQueueId_t CommandingServiceBase::getCommandQueue() {
void CommandingServiceBase::checkTimeout() { void CommandingServiceBase::checkTimeout() {
uint32_t uptime; uint32_t uptime;
Clock::getUptime(&uptime); Clock::getUptime(&uptime);
typename FixedMap<MessageQueueId_t, CommandMapIter iter;
CommandingServiceBase::CommandInfo>::Iterator iter;
for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) { for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) {
if ((iter->uptimeOfStart + (timeout_seconds * 1000)) < uptime) { if ((iter->uptimeOfStart + (timeoutSeconds * 1000)) < uptime) {
verificationReporter.sendFailureReport( verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags, TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl, iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
TIMEOUT); TIMEOUT);
checkAndExecuteFifo(&iter); checkAndExecuteFifo(iter);
} }
} }
} }

View File

@ -1,35 +1,33 @@
#ifndef COMMANDINGSERVICEBASE_H_ #ifndef FRAMEWORK_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
#define COMMANDINGSERVICEBASE_H_ #define FRAMEWORK_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
#include <framework/container/FixedMap.h>
#include <framework/container/FIFO.h>
#include <framework/ipc/CommandMessage.h>
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/objectmanager/SystemObject.h> #include <framework/objectmanager/SystemObject.h>
#include <framework/serialize/SerializeAdapter.h>
#include <framework/storagemanager/StorageManagerIF.h> #include <framework/storagemanager/StorageManagerIF.h>
#include <framework/tasks/ExecutableObjectIF.h> #include <framework/tasks/ExecutableObjectIF.h>
#include <framework/tcdistribution/PUSDistributorIF.h> #include <framework/ipc/MessageQueueIF.h>
#include <framework/tmtcpacket/pus/TcPacketStored.h>
#include <framework/tmtcpacket/pus/TmPacketStored.h>
#include <framework/tmtcservices/AcceptsTelecommandsIF.h> #include <framework/tmtcservices/AcceptsTelecommandsIF.h>
#include <framework/tmtcservices/AcceptsTelemetryIF.h>
#include <framework/tmtcservices/TmTcMessage.h>
#include <framework/tmtcservices/VerificationReporter.h> #include <framework/tmtcservices/VerificationReporter.h>
#include <framework/internalError/InternalErrorReporterIF.h> #include <framework/ipc/CommandMessage.h>
#include <framework/ipc/QueueFactory.h> #include <framework/container/FixedMap.h>
#include <framework/timemanager/Clock.h> #include <framework/container/FIFO.h>
#include <framework/serialize/SerializeIF.h>
class TcPacketStored;
/** /**
* \brief This class is the basis for all PUS Services, which have to relay Telecommands to software bus. * @brief This class is the basis for all PUS Services, which have to
* relay Telecommands to software bus.
* *
* It manages Telecommand reception and the generation of Verification Reports like PUSServiceBase. * It manages Telecommand reception and the generation of Verification Reports
* Every class that inherits from this abstract class has to implement four adaption points: * similar to PusServiceBase. This class is used if a telecommand can't be
* handled immediately and must be relayed to the internal software bus.
* - isValidSubservice * - isValidSubservice
* - getMessageQueueAndObject * - getMessageQueueAndObject
* - prepareCommand * - prepareCommand
* - handleReply * - handleReply
* \ingroup pus_services * @author gaisser
* @ingroup pus_services
*/ */
class CommandingServiceBase: public SystemObject, class CommandingServiceBase: public SystemObject,
public AcceptsTelecommandsIF, public AcceptsTelecommandsIF,
@ -59,7 +57,7 @@ public:
*/ */
CommandingServiceBase(object_id_t setObjectId, uint16_t apid, CommandingServiceBase(object_id_t setObjectId, uint16_t apid,
uint8_t service, uint8_t numberOfParallelCommands, uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeout_seconds, object_id_t setPacketSource, uint16_t commandTimeoutSeconds, object_id_t setPacketSource,
object_id_t setPacketDestination, size_t queueDepth = 20); object_id_t setPacketDestination, size_t queueDepth = 20);
virtual ~CommandingServiceBase(); virtual ~CommandingServiceBase();
@ -113,8 +111,9 @@ protected:
virtual ReturnValue_t isValidSubservice(uint8_t subservice) = 0; virtual ReturnValue_t isValidSubservice(uint8_t subservice) = 0;
/** /**
* Once a TC Request is valid, the existence of the destination and its target interface is checked and retrieved. * Once a TC Request is valid, the existence of the destination and its
* The target message queue ID can then be acquired by using the target interface. * target interface is checked and retrieved. The target message queue ID
* can then be acquired by using the target interface.
* @param subservice * @param subservice
* @param tcData Application Data of TC Packet * @param tcData Application Data of TC Packet
* @param tcDataLen * @param tcDataLen
@ -129,15 +128,16 @@ protected:
object_id_t *objectId) = 0; object_id_t *objectId) = 0;
/** /**
* After the Message Queue and Object ID are determined, * After the Message Queue and Object ID are determined, the command is
* the command is prepared by using an implementation specific CommandMessage type * prepared by using an implementation specific CommandMessage type
* which is sent to the target object. * which is sent to the target object. It contains all necessary information
* It contains all necessary information for the device to execute telecommands. * for the device to execute telecommands.
* @param message * @param message [out] message which can be set and is sent to the object
* @param subservice * @param subservice Subservice of the current communication
* @param tcData * @param tcData Application data of command
* @param tcDataLen * @param tcDataLen Application data length
* @param state * @param state [out/in] Setable state of the communication.
* communication
* @param objectId Target object ID * @param objectId Target object ID
* @return * @return
*/ */
@ -146,25 +146,40 @@ protected:
uint32_t *state, object_id_t objectId) = 0; uint32_t *state, object_id_t objectId) = 0;
/** /**
* This function is responsible for the communication between the Command Service Base * This function is implemented by child services to specify how replies
* and the respective PUS Commanding Service once the execution has started. * to a command from another software component are handled
* The PUS Commanding Service receives replies from the target device and forwards them by calling this function. * @param reply
* There are different translations of these replies to specify how the Command Service proceeds. * This is the reply in form of a command message.
* @param reply[out] Command Message which contains information about the command * @param previousCommand
* @param previousCommand [out] * Command_t of related command
* @param state * @param state [out/in]
* @param optionalNextCommand * Additional parameter which can be used to pass state information.
* State of the communication
* @param optionalNextCommand [out]
* An optional next command which can be set in this function
* @param objectId Source object ID * @param objectId Source object ID
* @param isStep Flag value to mark steps of command execution * @param isStep Flag value to mark steps of command execution
* @return - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to generate TC verification success * @return
* - @c INVALID_REPLY can handle unrequested replies * - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to
* - Anything else triggers a TC verification failure * generate TC verification success
* - @c INVALID_REPLY calls handleUnrequestedReply
* - Anything else triggers a TC verification failure
*/ */
virtual ReturnValue_t handleReply(const CommandMessage *reply, virtual ReturnValue_t handleReply(const CommandMessage *reply,
Command_t previousCommand, uint32_t *state, Command_t previousCommand, uint32_t *state,
CommandMessage *optionalNextCommand, object_id_t objectId, CommandMessage *optionalNextCommand, object_id_t objectId,
bool *isStep) = 0; bool *isStep) = 0;
/**
* This function can be overidden to handle unrequested reply,
* when the reply sender ID is unknown or is not found is the command map.
* @param reply
*/
virtual void handleUnrequestedReply(CommandMessage *reply);
virtual void doPeriodicOperation();
struct CommandInfo { struct CommandInfo {
struct tcInfo { struct tcInfo {
uint8_t ackFlags; uint8_t ackFlags;
@ -180,37 +195,42 @@ protected:
FIFO<store_address_t, 3> fifo; FIFO<store_address_t, 3> fifo;
}; };
using CommandMapIter = FixedMap<MessageQueueId_t,
CommandingServiceBase::CommandInfo>::Iterator;
const uint16_t apid; const uint16_t apid;
const uint8_t service; const uint8_t service;
const uint16_t timeout_seconds; const uint16_t timeoutSeconds;
uint8_t tmPacketCounter; uint8_t tmPacketCounter = 0;
StorageManagerIF *IPCStore; StorageManagerIF *IPCStore = nullptr;
StorageManagerIF *TCStore; StorageManagerIF *TCStore = nullptr;
MessageQueueIF* commandQueue; MessageQueueIF* commandQueue = nullptr;
MessageQueueIF* requestQueue; MessageQueueIF* requestQueue = nullptr;
VerificationReporter verificationReporter; VerificationReporter verificationReporter;
FixedMap<MessageQueueId_t, CommandInfo> commandMap; FixedMap<MessageQueueId_t, CommandInfo> commandMap;
uint32_t failureParameter1; //!< May be set be children to return a more precise failure condition. /* May be set be children to return a more precise failure condition. */
uint32_t failureParameter2; //!< May be set be children to return a more precise failure condition. uint32_t failureParameter1 = 0;
uint32_t failureParameter2 = 0;
object_id_t packetSource; object_id_t packetSource;
object_id_t packetDestination; object_id_t packetDestination;
/** /**
* Pointer to the task which executes this component, is invalid before setTaskIF was called. * Pointer to the task which executes this component,
* is invalid before setTaskIF was called.
*/ */
PeriodicTaskIF* executingTask; PeriodicTaskIF* executingTask = nullptr;
/** /**
* @brief Send TM data from pointer to data. * @brief Send TM data from pointer to data.
@ -246,22 +266,21 @@ protected:
ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content, ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content,
SerializeIF* header = nullptr); SerializeIF* header = nullptr);
virtual void handleUnrequestedReply(CommandMessage *reply); void checkAndExecuteFifo(CommandMapIter iter);
virtual void doPeriodicOperation();
void checkAndExecuteFifo(
typename FixedMap<MessageQueueId_t, CommandInfo>::Iterator *iter);
private: private:
/** /**
* This method handles internal execution of a command, * This method handles internal execution of a command,
* once it has been started by @sa{startExecution()} in the Request Queue handler. * once it has been started by @sa{startExecution()} in the request
* It handles replies generated by the devices and relayed by the specific service implementation. * queue handler.
* This means that it determines further course of action depending on the return values specified * It handles replies generated by the devices and relayed by the specific
* in the service implementation. * service implementation. This means that it determines further course of
* action depending on the return values specified in the service
* implementation.
* This includes the generation of TC verification messages. Note that * This includes the generation of TC verification messages. Note that
* the static framework object ID @c VerificationReporter::messageReceiver needs to be set. * the static framework object ID @c VerificationReporter::messageReceiver
* needs to be set.
* - TM[1,5] Step Successs * - TM[1,5] Step Successs
* - TM[1,6] Step Failure * - TM[1,6] Step Failure
* - TM[1,7] Completion Success * - TM[1,7] Completion Success
@ -282,8 +301,11 @@ private:
void acceptPacket(uint8_t reportId, TcPacketStored* packet); void acceptPacket(uint8_t reportId, TcPacketStored* packet);
void startExecution(TcPacketStored *storedPacket, void startExecution(TcPacketStored *storedPacket, CommandMapIter iter);
typename FixedMap<MessageQueueId_t, CommandInfo>::Iterator *iter);
void handleCommandMessage(CommandMessage& reply);
void handleReplyHandlerResult(ReturnValue_t result, CommandMapIter iter,
CommandMessage& nextCommand,CommandMessage& reply, bool& isStep);
void checkTimeout(); void checkTimeout();
}; };

View File

@ -9,10 +9,11 @@
object_id_t PusServiceBase::packetSource = 0; object_id_t PusServiceBase::packetSource = 0;
object_id_t PusServiceBase::packetDestination = 0; object_id_t PusServiceBase::packetDestination = 0;
PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId) : PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid,
SystemObject(setObjectId), apid(setApid), serviceId(setServiceId), errorParameter1( uint8_t setServiceId) :
0), errorParameter2(0), requestQueue(NULL) { SystemObject(setObjectId), apid(setApid), serviceId(setServiceId) {
requestQueue = QueueFactory::instance()->createMessageQueue(PUS_SERVICE_MAX_RECEPTION); requestQueue = QueueFactory::instance()->
createMessageQueue(PUS_SERVICE_MAX_RECEPTION);
} }
PusServiceBase::~PusServiceBase() { PusServiceBase::~PusServiceBase() {
@ -20,51 +21,60 @@ PusServiceBase::~PusServiceBase() {
} }
ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) {
handleRequestQueue();
ReturnValue_t result = this->performService();
if (result != RETURN_OK) {
sif::error << "PusService " << (uint16_t) this->serviceId
<< ": performService returned with " << (int16_t) result
<< std::endl;
return RETURN_FAILED;
}
return RETURN_OK;
}
void PusServiceBase::handleRequestQueue() {
TmTcMessage message; TmTcMessage message;
ReturnValue_t result = RETURN_FAILED;
for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) { for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) {
ReturnValue_t status = this->requestQueue->receiveMessage(&message); ReturnValue_t status = this->requestQueue->receiveMessage(&message);
// debug << "PusServiceBase::performOperation: Receiving from MQ ID: " << std::hex << this->requestQueue.getId() // debug << "PusServiceBase::performOperation: Receiving from MQ ID: "
// << std::dec << " returned: " << status << std::endl; // << std::hex << this->requestQueue.getId()
// << std::dec << " returned: " << status << std::endl;
if (status == RETURN_OK) { if (status == RETURN_OK) {
this->currentPacket.setStoreAddress(message.getStorageId()); this->currentPacket.setStoreAddress(message.getStorageId());
// info << "Service " << (uint16_t) this->serviceId << ": new packet!" << std::endl; //info << "Service " << (uint16_t) this->serviceId <<
// ": new packet!" << std::endl;
ReturnValue_t return_code = this->handleRequest(currentPacket.getSubService()); result = this->handleRequest(currentPacket.getSubService());
// debug << "Service " << (uint16_t)this->serviceId << ": handleRequest returned: " << (int)return_code << std::endl; // debug << "Service " << (uint16_t)this->serviceId <<
if (return_code == RETURN_OK) { // ": handleRequest returned: " << (int)return_code << std::endl;
if (result == RETURN_OK) {
this->verifyReporter.sendSuccessReport( this->verifyReporter.sendSuccessReport(
TC_VERIFY::COMPLETION_SUCCESS, &this->currentPacket); TC_VERIFY::COMPLETION_SUCCESS, &this->currentPacket);
} else { }
else {
this->verifyReporter.sendFailureReport( this->verifyReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, &this->currentPacket, TC_VERIFY::COMPLETION_FAILURE, &this->currentPacket,
return_code, 0, errorParameter1, errorParameter2); result, 0, errorParameter1, errorParameter2);
} }
this->currentPacket.deletePacket(); this->currentPacket.deletePacket();
errorParameter1 = 0; errorParameter1 = 0;
errorParameter2 = 0; errorParameter2 = 0;
} else if (status == MessageQueueIF::EMPTY) { }
else if (status == MessageQueueIF::EMPTY) {
status = RETURN_OK; status = RETURN_OK;
// debug << "PusService " << (uint16_t)this->serviceId << ": no new packet." << std::endl; // debug << "PusService " << (uint16_t)this->serviceId <<
// ": no new packet." << std::endl;
break; break;
} else { }
else {
sif::error << "PusServiceBase::performOperation: Service " sif::error << "PusServiceBase::performOperation: Service "
<< (uint16_t) this->serviceId << (uint16_t) this->serviceId
<< ": Error receiving packet. Code: " << std::hex << status << ": Error receiving packet. Code: " << std::hex << status
<< std::dec << std::endl; << std::dec << std::endl;
} }
} }
ReturnValue_t return_code = this->performService();
if (return_code == RETURN_OK) {
return RETURN_OK;
} else {
sif::error << "PusService " << (uint16_t) this->serviceId
<< ": performService returned with " << (int16_t) return_code
<< std::endl;
return RETURN_FAILED;
}
} }
uint16_t PusServiceBase::getIdentifier() { uint16_t PusServiceBase::getIdentifier() {
@ -80,19 +90,21 @@ ReturnValue_t PusServiceBase::initialize() {
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
AcceptsTelemetryIF* dest_service = objectManager->get<AcceptsTelemetryIF>( AcceptsTelemetryIF* destService = objectManager->get<AcceptsTelemetryIF>(
packetDestination); packetDestination);
PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>( PUSDistributorIF* distributor = objectManager->get<PUSDistributorIF>(
packetSource); packetSource);
if ((dest_service != NULL) && (distributor != NULL)) { if ((destService != nullptr) && (distributor != nullptr)) {
this->requestQueue->setDefaultDestination( this->requestQueue->setDefaultDestination(
dest_service->getReportReceptionQueue()); destService->getReportReceptionQueue());
distributor->registerService(this); distributor->registerService(this);
return RETURN_OK; return RETURN_OK;
} else { }
else {
sif::error << "PusServiceBase::PusServiceBase: Service " sif::error << "PusServiceBase::PusServiceBase: Service "
<< (uint32_t) this->serviceId << ": Configuration error." << (uint32_t) this->serviceId << ": Configuration error."
<< " Make sure packetSource and packetDestination are defined correctly" << std::endl; << " Make sure packetSource and packetDestination are defined "
"correctly" << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} }
} }

View File

@ -1,5 +1,5 @@
#ifndef PUSSERVICEBASE_H_ #ifndef FRAMEWORK_TMTCSERVICES_PUSSERVICEBASE_H_
#define PUSSERVICEBASE_H_ #define FRAMEWORK_TMTCSERVICES_PUSSERVICEBASE_H_
#include <framework/objectmanager/ObjectManagerIF.h> #include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/objectmanager/SystemObject.h> #include <framework/objectmanager/SystemObject.h>
@ -9,7 +9,6 @@
#include <framework/tmtcservices/AcceptsTelecommandsIF.h> #include <framework/tmtcservices/AcceptsTelecommandsIF.h>
#include <framework/tmtcservices/VerificationCodes.h> #include <framework/tmtcservices/VerificationCodes.h>
#include <framework/tmtcservices/VerificationReporter.h> #include <framework/tmtcservices/VerificationReporter.h>
#include <framework/internalError/InternalErrorReporterIF.h>
#include <framework/ipc/MessageQueueIF.h> #include <framework/ipc/MessageQueueIF.h>
namespace Factory{ namespace Factory{
@ -17,18 +16,22 @@ void setStaticFrameworkObjectIds();
} }
/** /**
* \defgroup pus_services PUS Service Framework * @defgroup pus_services PUS Service Framework
* These group contains all implementations of PUS Services in the OBSW. * These group contains all implementations of PUS Services in the OBSW.
* Most of the Services are directly taken from the ECSS PUS Standard. * Most of the Services are directly taken from the ECSS PUS Standard.
*/ */
/** /**
* \brief This class is the basis for all PUS Services, which can immediately process Telecommand Packets. * @brief This class is the basis for all PUS Services,
* It manages Telecommand reception and the generation of Verification Reports. Every class that inherits * which can immediately process Telecommand Packets.
* from this abstract class has to implement handleRequest and performService. Services that are created with this * @details
* It manages Telecommand reception and the generation of Verification Reports.
* Every class that inherits from this abstract class has to implement
* handleRequest and performService. Services that are created with this
* Base class have to handle any kind of request immediately on reception. * Base class have to handle any kind of request immediately on reception.
* All PUS Services are System Objects, so an Object ID needs to be specified on construction. * All PUS Services are System Objects, so an Object ID needs to be specified
* \ingroup pus_services * on construction.
* @ingroup pus_services
*/ */
class PusServiceBase : public ExecutableObjectIF, class PusServiceBase : public ExecutableObjectIF,
public AcceptsTelecommandsIF, public AcceptsTelecommandsIF,
@ -37,49 +40,61 @@ class PusServiceBase : public ExecutableObjectIF,
friend void (Factory::setStaticFrameworkObjectIds)(); friend void (Factory::setStaticFrameworkObjectIds)();
public: public:
/** /**
* The constructor for the class. * @brief The passed values are set, but inter-object initialization is
* The passed values are set, but inter-object initialization is done in the initialize method. * done in the initialize method.
* @param setObjectId The system object identifier of this Service instance. * @param setObjectId
* @param set_apid The APID the Service is instantiated for. * The system object identifier of this Service instance.
* @param set_service_id The Service Identifier as specified in ECSS PUS. * @param setApid
* The APID the Service is instantiated for.
* @param setServiceId
* The Service Identifier as specified in ECSS PUS.
*/ */
PusServiceBase( object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId); PusServiceBase( object_id_t setObjectId, uint16_t setApid,
uint8_t setServiceId);
/** /**
* The destructor is empty. * The destructor is empty.
*/ */
virtual ~PusServiceBase(); virtual ~PusServiceBase();
/** /**
* @brief The handleRequest method shall handle any kind of Telecommand Request immediately. * @brief The handleRequest method shall handle any kind of Telecommand
* Request immediately.
* @details * @details
* Implemetations can take the Telecommand in currentPacket and perform any kind of operation. * Implemetations can take the Telecommand in currentPacket and perform
* They may send additional "Start Success (1,3)" messages with the verifyReporter, but Completion * any kind of operation.
* Success or Failure Reports are generated automatically after execution of this method. * They may send additional "Start Success (1,3)" messages with the
* verifyReporter, but Completion Success or Failure Reports are generated
* automatically after execution of this method.
* *
* If a Telecommand can not be executed within one call cycle, * If a Telecommand can not be executed within one call cycle,
* this Base class is not the right parent. * this Base class is not the right parent.
* *
* The child class may add additional error information by setting #errorParameters which are * The child class may add additional error information by setting
* attached to the generated verification message. * #errorParameters which aren attached to the generated verification
* message.
* *
* Subservice checking should be implemented in this method. * Subservice checking should be implemented in this method.
* *
* @return The returned status_code is directly taken as main error code in the Verification Report. * @return The returned status_code is directly taken as main error code
* in the Verification Report.
* On success, RETURN_OK shall be returned. * On success, RETURN_OK shall be returned.
*/ */
virtual ReturnValue_t handleRequest(uint8_t subservice) = 0; virtual ReturnValue_t handleRequest(uint8_t subservice) = 0;
/** /**
* In performService, implementations can handle periodic, non-TC-triggered activities. * In performService, implementations can handle periodic,
* non-TC-triggered activities.
* The performService method is always called. * The performService method is always called.
* @return A success or failure code that does not trigger any kind of verification message. * @return Currently, everything other that RETURN_OK only triggers
* diagnostic output.
*/ */
virtual ReturnValue_t performService() = 0; virtual ReturnValue_t performService() = 0;
/** /**
* This method implements the typical activity of a simple PUS Service. * This method implements the typical activity of a simple PUS Service.
* It checks for new requests, and, if found, calls handleRequest, sends completion verification messages and deletes * It checks for new requests, and, if found, calls handleRequest, sends
* completion verification messages and deletes
* the TC requests afterwards. * the TC requests afterwards.
* performService is always executed afterwards. * performService is always executed afterwards.
* @return \c RETURN_OK if the periodic performService was successful. * @return @c RETURN_OK if the periodic performService was successful.
* \c RETURN_FAILED else. * @c RETURN_FAILED else.
*/ */
ReturnValue_t performOperation(uint8_t opCode); ReturnValue_t performOperation(uint8_t opCode);
virtual uint16_t getIdentifier(); virtual uint16_t getIdentifier();
@ -97,19 +112,19 @@ protected:
/** /**
* One of two error parameters for additional error information. * One of two error parameters for additional error information.
*/ */
uint32_t errorParameter1; uint32_t errorParameter1 = 0;
/** /**
* One of two error parameters for additional error information. * One of two error parameters for additional error information.
*/ */
uint32_t errorParameter2; uint32_t errorParameter2 = 0;
/** /**
* This is a complete instance of the Telecommand reception queue of the class. * This is a complete instance of the telecommand reception queue
* It is initialized on construction of the class. * of the class. It is initialized on construction of the class.
*/ */
MessageQueueIF* requestQueue; MessageQueueIF* requestQueue = nullptr;
/** /**
* An instance of the VerificationReporter class, that simplifies sending any kind of * An instance of the VerificationReporter class, that simplifies
* Verification Message to the TC Verification Service. * sending any kind of verification message to the TC Verification Service.
*/ */
VerificationReporter verifyReporter; VerificationReporter verifyReporter;
/** /**
@ -124,9 +139,12 @@ protected:
private: private:
/** /**
* This constant sets the maximum number of packets accepted per call. * This constant sets the maximum number of packets accepted per call.
* Remember that one packet must be completely handled in one #handleRequest call. * Remember that one packet must be completely handled in one
* #handleRequest call.
*/ */
static const uint8_t PUS_SERVICE_MAX_RECEPTION = 10; static const uint8_t PUS_SERVICE_MAX_RECEPTION = 10;
void handleRequestQueue();
}; };
#endif /* PUSSERVICEBASE_H_ */ #endif /* PUSSERVICEBASE_H_ */