2020-06-12 20:23:39 +02:00
|
|
|
#include <framework/ipc/CommandMessage.h>
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
#include <framework/devicehandlers/DeviceHandlerMessage.h>
|
|
|
|
#include <framework/health/HealthMessage.h>
|
|
|
|
#include <framework/memory/MemoryMessage.h>
|
|
|
|
#include <framework/modes/ModeMessage.h>
|
|
|
|
#include <framework/monitoring/MonitoringMessage.h>
|
|
|
|
#include <framework/subsystem/modes/ModeSequenceMessage.h>
|
|
|
|
#include <framework/tmstorage/TmStoreMessage.h>
|
2018-07-12 16:29:32 +02:00
|
|
|
#include <framework/parameters/ParameterMessage.h>
|
|
|
|
|
2020-06-13 17:37:48 +02:00
|
|
|
CommandMessage::CommandMessage(MessageQueueMessageIF* receiverMessage):
|
2020-06-12 20:23:39 +02:00
|
|
|
CommandMessageBase(receiverMessage) {
|
2020-06-09 02:18:39 +02:00
|
|
|
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;
|
2020-06-13 17:37:48 +02:00
|
|
|
return;
|
2020-06-09 02:18:39 +02:00
|
|
|
}
|
2020-06-13 17:37:48 +02:00
|
|
|
if(receiverMessage->getMaximumMessageSize() <
|
|
|
|
MINIMUM_COMMAND_MESSAGE_SIZE) {
|
|
|
|
sif::error << "CommandMessage::ComandMessage: Passed message buffer"
|
|
|
|
" can not hold minimum "<< MINIMUM_COMMAND_MESSAGE_SIZE
|
|
|
|
<< " bytes!" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
internalMessage->setMessageSize(MINIMUM_COMMAND_MESSAGE_SIZE);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2020-06-13 17:37:48 +02:00
|
|
|
CommandMessage::CommandMessage(MessageQueueMessageIF* messageToSet,
|
2020-06-09 02:18:39 +02:00
|
|
|
Command_t command, uint32_t parameter1, uint32_t parameter2):
|
2020-06-12 20:23:39 +02:00
|
|
|
CommandMessageBase(messageToSet) {
|
2020-06-09 02:18:39 +02:00
|
|
|
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;
|
|
|
|
}
|
2020-06-13 17:37:48 +02:00
|
|
|
if(messageToSet->getMaximumMessageSize() <
|
|
|
|
MINIMUM_COMMAND_MESSAGE_SIZE) {
|
|
|
|
sif::error << "CommandMessage::ComandMessage: Passed message buffer"
|
|
|
|
" can not hold minimum "<< MINIMUM_COMMAND_MESSAGE_SIZE
|
|
|
|
<< " bytes!" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
internalMessage->setMessageSize(MINIMUM_COMMAND_MESSAGE_SIZE);
|
2016-06-15 23:48:41 +02:00
|
|
|
setCommand(command);
|
|
|
|
setParameter(parameter1);
|
|
|
|
setParameter2(parameter2);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CommandMessage::getParameter() const {
|
|
|
|
uint32_t parameter1;
|
2020-06-12 20:23:39 +02:00
|
|
|
memcpy(¶meter1, CommandMessageBase::getData(), sizeof(parameter1));
|
2016-06-15 23:48:41 +02:00
|
|
|
return parameter1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setParameter(uint32_t parameter1) {
|
2020-06-12 20:23:39 +02:00
|
|
|
memcpy(CommandMessageBase::getData(), ¶meter1, sizeof(parameter1));
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CommandMessage::getParameter2() const {
|
|
|
|
uint32_t parameter2;
|
2020-06-12 20:23:39 +02:00
|
|
|
memcpy(¶meter2, CommandMessageBase::getData() + sizeof(uint32_t),
|
|
|
|
sizeof(parameter2));
|
2016-06-15 23:48:41 +02:00
|
|
|
return parameter2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setParameter2(uint32_t parameter2) {
|
2020-06-12 20:23:39 +02:00
|
|
|
memcpy(CommandMessageBase::getData() + sizeof(uint32_t), ¶meter2,
|
|
|
|
sizeof(parameter2));
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CommandMessage::getMinimumMessageSize() const {
|
2020-06-13 17:37:48 +02:00
|
|
|
return MINIMUM_COMMAND_MESSAGE_SIZE;
|
2020-06-12 20:23:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t CommandMessage::getMaximumMessageSize() const {
|
|
|
|
return MessageQueueMessage::MAX_MESSAGE_SIZE;
|
2020-06-09 02:18:39 +02:00
|
|
|
}
|
|
|
|
|
2020-06-12 20:23:39 +02:00
|
|
|
bool CommandMessage::isClearedCommandMessage() {
|
|
|
|
return getCommand() == CMD_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setToUnknownCommand() {
|
|
|
|
Command_t initialCommand = getCommand();
|
|
|
|
clearCommandMessage();
|
|
|
|
setReplyRejected(UNKNOWN_COMMAND, initialCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setReplyRejected(ReturnValue_t reason,
|
|
|
|
Command_t initialCommand) {
|
|
|
|
setCommand(REPLY_REJECTED);
|
|
|
|
setParameter(reason);
|
|
|
|
setParameter2(initialCommand);
|
|
|
|
}
|
|
|
|
|
2020-06-13 17:37:48 +02:00
|
|
|
ReturnValue_t CommandMessage::getRejectedReplyReason(
|
|
|
|
Command_t* initialCommand) const {
|
|
|
|
if(initialCommand != nullptr) {
|
|
|
|
*initialCommand = getParameter2();
|
|
|
|
}
|
|
|
|
return getParameter();
|
|
|
|
}
|
2020-06-12 20:23:39 +02:00
|
|
|
|
2020-06-09 02:18:39 +02:00
|
|
|
void CommandMessage::clear() {
|
|
|
|
clearCommandMessage();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::clearCommandMessage() {
|
2020-06-12 20:23:39 +02:00
|
|
|
switch(this->getMessageType()){
|
|
|
|
case messagetypes::MODE_COMMAND:
|
2016-06-15 23:48:41 +02:00
|
|
|
ModeMessage::clear(this);
|
|
|
|
break;
|
2020-06-08 12:25:20 +02:00
|
|
|
case messagetypes::HEALTH_COMMAND:
|
2016-06-15 23:48:41 +02:00
|
|
|
HealthMessage::clear(this);
|
|
|
|
break;
|
2020-06-08 12:25:20 +02:00
|
|
|
case messagetypes::MODE_SEQUENCE:
|
2016-06-15 23:48:41 +02:00
|
|
|
ModeSequenceMessage::clear(this);
|
|
|
|
break;
|
2020-06-08 12:25:20 +02:00
|
|
|
case messagetypes::ACTION:
|
2016-06-15 23:48:41 +02:00
|
|
|
ActionMessage::clear(this);
|
|
|
|
break;
|
2020-06-08 12:25:20 +02:00
|
|
|
case messagetypes::DEVICE_HANDLER_COMMAND:
|
2016-06-15 23:48:41 +02:00
|
|
|
DeviceHandlerMessage::clear(this);
|
|
|
|
break;
|
2020-06-08 12:25:20 +02:00
|
|
|
case messagetypes::MEMORY:
|
2016-06-15 23:48:41 +02:00
|
|
|
MemoryMessage::clear(this);
|
|
|
|
break;
|
2020-06-08 12:25:20 +02:00
|
|
|
case messagetypes::MONITORING:
|
2016-06-15 23:48:41 +02:00
|
|
|
MonitoringMessage::clear(this);
|
|
|
|
break;
|
2020-06-08 12:25:20 +02:00
|
|
|
case messagetypes::TM_STORE:
|
2016-06-15 23:48:41 +02:00
|
|
|
TmStoreMessage::clear(this);
|
|
|
|
break;
|
2020-06-08 12:25:20 +02:00
|
|
|
case messagetypes::PARAMETER:
|
2018-07-12 16:29:32 +02:00
|
|
|
ParameterMessage::clear(this);
|
|
|
|
break;
|
2016-06-15 23:48:41 +02:00
|
|
|
default:
|
2020-06-08 12:25:20 +02:00
|
|
|
messagetypes::clearMissionMessage(this);
|
2016-06-15 23:48:41 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|