2020-06-08 12:25:20 +02:00
|
|
|
#include "MissionMessageTypes.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
#include <framework/devicehandlers/DeviceHandlerMessage.h>
|
|
|
|
#include <framework/health/HealthMessage.h>
|
|
|
|
#include <framework/ipc/CommandMessage.h>
|
|
|
|
#include <framework/memory/MemoryMessage.h>
|
|
|
|
#include <framework/modes/ModeMessage.h>
|
|
|
|
#include <framework/monitoring/MonitoringMessage.h>
|
|
|
|
#include <framework/subsystem/modes/ModeSequenceMessage.h>
|
|
|
|
#include <framework/tmstorage/TmStoreMessage.h>
|
2018-07-12 16:29:32 +02:00
|
|
|
#include <framework/parameters/ParameterMessage.h>
|
|
|
|
|
2020-06-08 12:25:20 +02:00
|
|
|
namespace messagetypes {
|
|
|
|
// Implemented in config.
|
2018-07-12 16:29:32 +02:00
|
|
|
void clearMissionMessage(CommandMessage* message);
|
|
|
|
}
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
CommandMessage::CommandMessage() {
|
|
|
|
this->messageSize = COMMAND_MESSAGE_SIZE;
|
|
|
|
setCommand(CMD_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandMessage::CommandMessage(Command_t command, uint32_t parameter1,
|
|
|
|
uint32_t parameter2) {
|
|
|
|
this->messageSize = COMMAND_MESSAGE_SIZE;
|
|
|
|
setCommand(command);
|
|
|
|
setParameter(parameter1);
|
|
|
|
setParameter2(parameter2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Command_t CommandMessage::getCommand() const {
|
|
|
|
Command_t command;
|
|
|
|
memcpy(&command, getData(), sizeof(Command_t));
|
|
|
|
return command;
|
|
|
|
}
|
|
|
|
|
2020-06-08 12:25:20 +02:00
|
|
|
uint8_t CommandMessage::getMessageType() const {
|
|
|
|
return getCommand() >> 8 & 0xff;
|
|
|
|
}
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
void CommandMessage::setCommand(Command_t command) {
|
|
|
|
memcpy(getData(), &command, sizeof(command));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CommandMessage::getParameter() const {
|
|
|
|
uint32_t parameter1;
|
|
|
|
memcpy(¶meter1, getData() + sizeof(Command_t), sizeof(parameter1));
|
|
|
|
return parameter1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setParameter(uint32_t parameter1) {
|
|
|
|
memcpy(getData() + sizeof(Command_t), ¶meter1, sizeof(parameter1));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CommandMessage::getParameter2() const {
|
|
|
|
uint32_t parameter2;
|
|
|
|
memcpy(¶meter2, getData() + sizeof(Command_t) + sizeof(uint32_t),
|
|
|
|
sizeof(parameter2));
|
|
|
|
return parameter2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setParameter2(uint32_t parameter2) {
|
|
|
|
memcpy(getData() + sizeof(Command_t) + sizeof(uint32_t), ¶meter2,
|
|
|
|
sizeof(parameter2));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::clearCommandMessage() {
|
2020-06-08 12:25:20 +02:00
|
|
|
switch(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CommandMessage::isClearedCommandMessage() {
|
|
|
|
return getCommand() == CMD_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CommandMessage::getMinimumMessageSize() const {
|
|
|
|
return COMMAND_MESSAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
void CommandMessage::setToUnknownCommand() {
|
|
|
|
Command_t initialCommand = getCommand();
|
|
|
|
clearCommandMessage();
|
2016-06-15 23:48:41 +02:00
|
|
|
setReplyRejected(UNKNOW_COMMAND, initialCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setReplyRejected(ReturnValue_t reason,
|
|
|
|
Command_t initialCommand) {
|
|
|
|
setCommand(REPLY_REJECTED);
|
|
|
|
setParameter(reason);
|
|
|
|
setParameter2(initialCommand);
|
|
|
|
}
|