2020-06-12 20:23:39 +02:00
|
|
|
#include <framework/ipc/CommandMessage.h>
|
2020-06-13 21:01:01 +02:00
|
|
|
#include <cstring>
|
2018-07-12 16:29:32 +02:00
|
|
|
|
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-23 21:03:22 +02:00
|
|
|
// if(receiverMessage->getMessageSize() <
|
|
|
|
// getMinimumMessageSize()) {
|
|
|
|
// sif::error << "CommandMessage::ComandMessage: Passed message buffer"
|
|
|
|
// " can not hold minimum "<< getMinimumMessageSize()
|
|
|
|
// << " bytes!" << std::endl;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// internalMessage->setMessageSize(getMinimumMessageSize());
|
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-15 11:11:42 +02:00
|
|
|
CommandMessage(messageToSet) {
|
2016-06-15 23:48:41 +02:00
|
|
|
setCommand(command);
|
|
|
|
setParameter(parameter1);
|
|
|
|
setParameter2(parameter2);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CommandMessage::getParameter() const {
|
|
|
|
uint32_t parameter1;
|
2020-06-13 21:01:01 +02:00
|
|
|
std::memcpy(¶meter1, CommandMessageBase::getData(), sizeof(parameter1));
|
2016-06-15 23:48:41 +02:00
|
|
|
return parameter1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setParameter(uint32_t parameter1) {
|
2020-06-13 21:01:01 +02:00
|
|
|
std::memcpy(CommandMessageBase::getData(), ¶meter1, sizeof(parameter1));
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CommandMessage::getParameter2() const {
|
|
|
|
uint32_t parameter2;
|
2020-06-13 21:01:01 +02:00
|
|
|
std::memcpy(¶meter2, CommandMessageBase::getData() + sizeof(uint32_t),
|
2020-06-12 20:23:39 +02:00
|
|
|
sizeof(parameter2));
|
2016-06-15 23:48:41 +02:00
|
|
|
return parameter2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setParameter2(uint32_t parameter2) {
|
2020-06-13 21:01:01 +02:00
|
|
|
std::memcpy(CommandMessageBase::getData() + sizeof(uint32_t), ¶meter2,
|
2020-06-12 20:23:39 +02:00
|
|
|
sizeof(parameter2));
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:03:22 +02:00
|
|
|
//size_t CommandMessage::getMinimumMessageSize() const {
|
|
|
|
// return MINIMUM_COMMAND_MESSAGE_SIZE;
|
|
|
|
//}
|
2020-06-12 20:23:39 +02:00
|
|
|
|
|
|
|
bool CommandMessage::isClearedCommandMessage() {
|
|
|
|
return getCommand() == CMD_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandMessage::setToUnknownCommand() {
|
|
|
|
Command_t initialCommand = getCommand();
|
2020-06-13 21:01:01 +02:00
|
|
|
this->clear();
|
2020-06-12 20:23:39 +02:00
|
|
|
setReplyRejected(UNKNOWN_COMMAND, initialCommand);
|
|
|
|
}
|