renormalization

This commit is contained in:
Robin Müller 2020-09-04 14:58:36 +02:00
parent 4da21d2c38
commit a6b2b4dd93

View File

@ -1,111 +1,111 @@
#include "CommandMessage.h" #include "CommandMessage.h"
#include "CommandMessageCleaner.h" #include "CommandMessageCleaner.h"
#include <cstring> #include <cstring>
CommandMessage::CommandMessage() { CommandMessage::CommandMessage() {
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE); MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
setCommand(CMD_NONE); setCommand(CMD_NONE);
} }
CommandMessage::CommandMessage(Command_t command, uint32_t parameter1, CommandMessage::CommandMessage(Command_t command, uint32_t parameter1,
uint32_t parameter2) { uint32_t parameter2) {
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE); MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
setCommand(command); setCommand(command);
setParameter(parameter1); setParameter(parameter1);
setParameter2(parameter2); setParameter2(parameter2);
} }
Command_t CommandMessage::getCommand() const { Command_t CommandMessage::getCommand() const {
Command_t command; Command_t command;
std::memcpy(&command, MessageQueueMessage::getData(), sizeof(Command_t)); std::memcpy(&command, MessageQueueMessage::getData(), sizeof(Command_t));
return command; return command;
} }
void CommandMessage::setCommand(Command_t command) { void CommandMessage::setCommand(Command_t command) {
std::memcpy(MessageQueueMessage::getData(), &command, sizeof(Command_t)); std::memcpy(MessageQueueMessage::getData(), &command, sizeof(Command_t));
} }
uint8_t CommandMessage::getMessageType() const { uint8_t CommandMessage::getMessageType() const {
// first byte of command ID. // first byte of command ID.
return getCommand() >> 8 & 0xff; return getCommand() >> 8 & 0xff;
} }
uint32_t CommandMessage::getParameter() const { uint32_t CommandMessage::getParameter() const {
uint32_t parameter1; uint32_t parameter1;
std::memcpy(&parameter1, this->getData(), sizeof(parameter1)); std::memcpy(&parameter1, this->getData(), sizeof(parameter1));
return parameter1; return parameter1;
} }
void CommandMessage::setParameter(uint32_t parameter1) { void CommandMessage::setParameter(uint32_t parameter1) {
std::memcpy(this->getData(), &parameter1, sizeof(parameter1)); std::memcpy(this->getData(), &parameter1, sizeof(parameter1));
} }
uint32_t CommandMessage::getParameter2() const { uint32_t CommandMessage::getParameter2() const {
uint32_t parameter2; uint32_t parameter2;
std::memcpy(&parameter2, this->getData() + sizeof(uint32_t), std::memcpy(&parameter2, this->getData() + sizeof(uint32_t),
sizeof(parameter2)); sizeof(parameter2));
return parameter2; return parameter2;
} }
void CommandMessage::setParameter2(uint32_t parameter2) { void CommandMessage::setParameter2(uint32_t parameter2) {
std::memcpy(this->getData() + sizeof(uint32_t), &parameter2, std::memcpy(this->getData() + sizeof(uint32_t), &parameter2,
sizeof(parameter2)); sizeof(parameter2));
} }
uint32_t CommandMessage::getParameter3() const { uint32_t CommandMessage::getParameter3() const {
uint32_t parameter3; uint32_t parameter3;
std::memcpy(&parameter3, this->getData() + 2 * sizeof(uint32_t), std::memcpy(&parameter3, this->getData() + 2 * sizeof(uint32_t),
sizeof(parameter3)); sizeof(parameter3));
return parameter3; return parameter3;
} }
void CommandMessage::setParameter3(uint32_t parameter3) { void CommandMessage::setParameter3(uint32_t parameter3) {
std::memcpy(this->getData() + 2 * sizeof(uint32_t), &parameter3, std::memcpy(this->getData() + 2 * sizeof(uint32_t), &parameter3,
sizeof(parameter3)); sizeof(parameter3));
} }
size_t CommandMessage::getMinimumMessageSize() const { size_t CommandMessage::getMinimumMessageSize() const {
return MINIMUM_COMMAND_MESSAGE_SIZE; return MINIMUM_COMMAND_MESSAGE_SIZE;
} }
void CommandMessage::clearCommandMessage() { void CommandMessage::clearCommandMessage() {
clear(); clear();
} }
void CommandMessage::clear() { void CommandMessage::clear() {
CommandMessageCleaner::clearCommandMessage(this); CommandMessageCleaner::clearCommandMessage(this);
} }
bool CommandMessage::isClearedCommandMessage() { bool CommandMessage::isClearedCommandMessage() {
return getCommand() == CMD_NONE; return getCommand() == CMD_NONE;
} }
void CommandMessage::setToUnknownCommand() { void CommandMessage::setToUnknownCommand() {
Command_t initialCommand = getCommand(); Command_t initialCommand = getCommand();
this->clear(); this->clear();
setReplyRejected(UNKNOWN_COMMAND, initialCommand); setReplyRejected(UNKNOWN_COMMAND, initialCommand);
} }
void CommandMessage::setReplyRejected(ReturnValue_t reason, void CommandMessage::setReplyRejected(ReturnValue_t reason,
Command_t initialCommand) { Command_t initialCommand) {
setCommand(REPLY_REJECTED); setCommand(REPLY_REJECTED);
setParameter(reason); setParameter(reason);
setParameter2(initialCommand); setParameter2(initialCommand);
} }
ReturnValue_t CommandMessage::getReplyRejectedReason( ReturnValue_t CommandMessage::getReplyRejectedReason(
Command_t *initialCommand) const { Command_t *initialCommand) const {
ReturnValue_t reason = getParameter(); ReturnValue_t reason = getParameter();
if(initialCommand != nullptr) { if(initialCommand != nullptr) {
*initialCommand = getParameter2(); *initialCommand = getParameter2();
} }
return reason; return reason;
} }
uint8_t* CommandMessage::getData() { uint8_t* CommandMessage::getData() {
return MessageQueueMessage::getData() + sizeof(Command_t); return MessageQueueMessage::getData() + sizeof(Command_t);
} }
const uint8_t* CommandMessage::getData() const { const uint8_t* CommandMessage::getData() const {
return MessageQueueMessage::getData() + sizeof(Command_t); return MessageQueueMessage::getData() + sizeof(Command_t);
} }