fsfw/ipc/CommandMessage.cpp

65 lines
1.9 KiB
C++
Raw Normal View History

#include <framework/ipc/CommandMessage.h>
2020-06-13 21:01:01 +02:00
#include <cstring>
CommandMessage::CommandMessage(MessageQueueMessageIF* receiverMessage):
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;
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());
}
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) {
setCommand(command);
setParameter(parameter1);
setParameter2(parameter2);
}
uint32_t CommandMessage::getParameter() const {
uint32_t parameter1;
2020-06-13 21:01:01 +02:00
std::memcpy(&parameter1, CommandMessageBase::getData(), sizeof(parameter1));
return parameter1;
}
void CommandMessage::setParameter(uint32_t parameter1) {
2020-06-13 21:01:01 +02:00
std::memcpy(CommandMessageBase::getData(), &parameter1, sizeof(parameter1));
}
uint32_t CommandMessage::getParameter2() const {
uint32_t parameter2;
2020-06-13 21:01:01 +02:00
std::memcpy(&parameter2, CommandMessageBase::getData() + sizeof(uint32_t),
sizeof(parameter2));
return parameter2;
}
void CommandMessage::setParameter2(uint32_t parameter2) {
2020-06-13 21:01:01 +02:00
std::memcpy(CommandMessageBase::getData() + sizeof(uint32_t), &parameter2,
sizeof(parameter2));
}
2020-06-23 21:03:22 +02:00
//size_t CommandMessage::getMinimumMessageSize() const {
// return MINIMUM_COMMAND_MESSAGE_SIZE;
//}
bool CommandMessage::isClearedCommandMessage() {
return getCommand() == CMD_NONE;
}
void CommandMessage::setToUnknownCommand() {
Command_t initialCommand = getCommand();
2020-06-13 21:01:01 +02:00
this->clear();
setReplyRejected(UNKNOWN_COMMAND, initialCommand);
}