2020-06-12 20:23:39 +02:00
|
|
|
#include <framework/ipc/CommandMessage.h>
|
2020-06-24 00:24:15 +02:00
|
|
|
#include <framework/ipc/CommandMessageCleaner.h>
|
2020-06-13 21:01:01 +02:00
|
|
|
#include <cstring>
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2020-06-24 00:24:15 +02:00
|
|
|
CommandMessage::CommandMessage() {
|
2020-06-24 00:49:13 +02:00
|
|
|
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
|
2020-06-24 00:24:15 +02:00
|
|
|
setCommand(CMD_NONE);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 00:24:15 +02:00
|
|
|
CommandMessage::CommandMessage(Command_t command, uint32_t parameter1,
|
|
|
|
uint32_t parameter2) {
|
|
|
|
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
|
2020-06-24 00:49:13 +02:00
|
|
|
setCommand(command);
|
|
|
|
setParameter(parameter1);
|
|
|
|
setParameter2(parameter2);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 00:24:15 +02:00
|
|
|
Command_t CommandMessage::getCommand() const {
|
2020-06-24 00:49:13 +02:00
|
|
|
Command_t command;
|
|
|
|
std::memcpy(&command, MessageQueueMessage::getData(), sizeof(Command_t));
|
|
|
|
return command;
|
2020-06-24 00:24:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setCommand(Command_t command) {
|
2020-06-24 00:49:13 +02:00
|
|
|
std::memcpy(MessageQueueMessage::getData(), &command, sizeof(Command_t));
|
2020-06-24 00:24:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t CommandMessage::getMessageType() const {
|
2020-06-24 00:49:13 +02:00
|
|
|
// first byte of command ID.
|
|
|
|
return getCommand() >> 8 & 0xff;
|
2020-06-24 00:24:15 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
uint32_t CommandMessage::getParameter() const {
|
2020-06-24 00:49:13 +02:00
|
|
|
uint32_t parameter1;
|
|
|
|
std::memcpy(¶meter1, this->getData(), sizeof(parameter1));
|
|
|
|
return parameter1;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setParameter(uint32_t parameter1) {
|
2020-06-24 00:49:13 +02:00
|
|
|
std::memcpy(this->getData(), ¶meter1, sizeof(parameter1));
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CommandMessage::getParameter2() const {
|
2020-06-24 00:49:13 +02:00
|
|
|
uint32_t parameter2;
|
|
|
|
std::memcpy(¶meter2, this->getData() + sizeof(uint32_t),
|
|
|
|
sizeof(parameter2));
|
|
|
|
return parameter2;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setParameter2(uint32_t parameter2) {
|
2020-06-24 00:49:13 +02:00
|
|
|
std::memcpy(this->getData() + sizeof(uint32_t), ¶meter2,
|
|
|
|
sizeof(parameter2));
|
2020-06-12 20:23:39 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 02:00:26 +02:00
|
|
|
uint32_t CommandMessage::getParameter3() const {
|
|
|
|
uint32_t parameter3;
|
|
|
|
std::memcpy(¶meter3, this->getData() + 2 * sizeof(uint32_t),
|
|
|
|
sizeof(parameter3));
|
|
|
|
return parameter3;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setParameter3(uint32_t parameter3) {
|
|
|
|
std::memcpy(this->getData() + 2 * sizeof(uint32_t), ¶meter3,
|
|
|
|
sizeof(parameter3));
|
|
|
|
}
|
|
|
|
|
2020-06-24 00:24:15 +02:00
|
|
|
size_t CommandMessage::getMinimumMessageSize() const {
|
2020-06-24 00:49:13 +02:00
|
|
|
return MINIMUM_COMMAND_MESSAGE_SIZE;
|
2020-06-24 00:24:15 +02:00
|
|
|
}
|
|
|
|
|
2020-06-29 16:50:45 +02:00
|
|
|
void CommandMessage::clearCommandMessage() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2020-06-24 00:24:15 +02:00
|
|
|
void CommandMessage::clear() {
|
|
|
|
CommandMessageCleaner::clearCommandMessage(this);
|
|
|
|
}
|
2020-06-12 20:23:39 +02:00
|
|
|
|
|
|
|
bool CommandMessage::isClearedCommandMessage() {
|
2020-06-24 00:49:13 +02:00
|
|
|
return getCommand() == CMD_NONE;
|
2020-06-12 20:23:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setToUnknownCommand() {
|
2020-06-24 00:49:13 +02:00
|
|
|
Command_t initialCommand = getCommand();
|
|
|
|
this->clear();
|
|
|
|
setReplyRejected(UNKNOWN_COMMAND, initialCommand);
|
2020-06-12 20:23:39 +02:00
|
|
|
}
|
2020-06-24 00:24:15 +02:00
|
|
|
|
|
|
|
void CommandMessage::setReplyRejected(ReturnValue_t reason,
|
2020-06-24 00:49:13 +02:00
|
|
|
Command_t initialCommand) {
|
2020-06-29 15:44:18 +02:00
|
|
|
setParameter(reason);
|
|
|
|
setParameter2(initialCommand);
|
2020-06-24 00:24:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t CommandMessage::getReplyRejectedReason(
|
2020-06-24 00:49:13 +02:00
|
|
|
Command_t *initialCommand) const {
|
2020-06-29 15:46:16 +02:00
|
|
|
ReturnValue_t reason = getParameter();
|
2020-06-24 00:49:13 +02:00
|
|
|
if(initialCommand != nullptr) {
|
2020-06-29 15:46:16 +02:00
|
|
|
*initialCommand = getParameter2();
|
2020-06-24 00:49:13 +02:00
|
|
|
}
|
|
|
|
return reason;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* CommandMessage::getData() {
|
|
|
|
return MessageQueueMessage::getData() + sizeof(Command_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t* CommandMessage::getData() const {
|
|
|
|
return MessageQueueMessage::getData() + sizeof(Command_t);
|
2020-06-24 00:24:15 +02:00
|
|
|
}
|