WIP: somethings wrong.. #19

Closed
muellerr wants to merge 808 commits from source/master into master
5 changed files with 74 additions and 70 deletions
Showing only changes of commit af24cc7d04 - Show all commits

View File

@ -3,57 +3,57 @@
#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, 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(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, MessageQueueMessage::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(MessageQueueMessage::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, MessageQueueMessage::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(MessageQueueMessage::getData() + sizeof(uint32_t), &parameter2, std::memcpy(this->getData() + sizeof(uint32_t), &parameter2,
sizeof(parameter2)); sizeof(parameter2));
} }
size_t CommandMessage::getMinimumMessageSize() const { size_t CommandMessage::getMinimumMessageSize() const {
return MINIMUM_COMMAND_MESSAGE_SIZE; return MINIMUM_COMMAND_MESSAGE_SIZE;
} }
void CommandMessage::clear() { void CommandMessage::clear() {
@ -61,29 +61,37 @@ void CommandMessage::clear() {
} }
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) {
std::memcpy(getData(), &reason, sizeof(reason)); std::memcpy(getData(), &reason, sizeof(reason));
std::memcpy(getData() + sizeof(reason), &initialCommand, std::memcpy(getData() + sizeof(reason), &initialCommand,
sizeof(initialCommand)); sizeof(initialCommand));
} }
ReturnValue_t CommandMessage::getReplyRejectedReason( ReturnValue_t CommandMessage::getReplyRejectedReason(
Command_t *initialCommand) const { Command_t *initialCommand) const {
ReturnValue_t reason = HasReturnvaluesIF::RETURN_FAILED; ReturnValue_t reason = HasReturnvaluesIF::RETURN_FAILED;
std::memcpy(&reason, getData(), sizeof(reason)); std::memcpy(&reason, getData(), sizeof(reason));
if(initialCommand != nullptr) { if(initialCommand != nullptr) {
std::memcpy(initialCommand, getData() + sizeof(reason), std::memcpy(initialCommand, getData() + sizeof(reason),
sizeof(Command_t)); sizeof(Command_t));
} }
return reason; return reason;
}
uint8_t* CommandMessage::getData() {
return MessageQueueMessage::getData() + sizeof(Command_t);
}
const uint8_t* CommandMessage::getData() const {
return MessageQueueMessage::getData() + sizeof(Command_t);
} }

View File

@ -50,6 +50,22 @@ public:
*/ */
virtual ~CommandMessage() {} virtual ~CommandMessage() {}
/**
* Read the DeviceHandlerCommand_t that is stored in the message,
* usually used after receiving.
*
* @return the Command stored in the Message
*/
virtual Command_t getCommand() const override;
/**
* Set the command type of the message. Default implementation also
* sets the message type, which will be the first byte of the command ID.
* @param the Command to be sent
*/
virtual void setCommand(Command_t command);
virtual uint8_t* getData() override;
virtual const uint8_t* getData() const override;
/** /**
* Get the first parameter of the message * Get the first parameter of the message
* @return the first Parameter of the message * @return the first Parameter of the message
@ -105,20 +121,6 @@ public:
virtual void clear() override; virtual void clear() override;
/**
* Read the DeviceHandlerCommand_t that is stored in the message,
* usually used after receiving.
*
* @return the Command stored in the Message
*/
virtual Command_t getCommand() const override;
/**
* Set the command type of the message. Default implementation also
* sets the message type, which will be the first byte of the command ID.
* @param the Command to be sent
*/
virtual void setCommand(Command_t command);
/** /**
* Extract message ID, which is the first byte of the command ID for the * Extract message ID, which is the first byte of the command ID for the
* default implementation. * default implementation.

View File

@ -9,34 +9,34 @@
#include <framework/tmstorage/TmStoreMessage.h> #include <framework/tmstorage/TmStoreMessage.h>
#include <framework/parameters/ParameterMessage.h> #include <framework/parameters/ParameterMessage.h>
void CommandMessageCleaner::clearCommandMessage(CommandMessageIF* message) { void CommandMessageCleaner::clearCommandMessage(CommandMessage* message) {
switch(message->getMessageType()){ switch(message->getMessageType()){
case messagetypes::MODE_COMMAND: case messagetypes::MODE_COMMAND:
ModeMessage::clear(dynamic_cast<CommandMessage*>(message)); ModeMessage::clear(message);
break; break;
case messagetypes::HEALTH_COMMAND: case messagetypes::HEALTH_COMMAND:
HealthMessage::clear(dynamic_cast<CommandMessage*>(message)); HealthMessage::clear(message);
break; break;
case messagetypes::MODE_SEQUENCE: case messagetypes::MODE_SEQUENCE:
ModeSequenceMessage::clear(dynamic_cast<CommandMessage*>(message)); ModeSequenceMessage::clear(message);
break; break;
case messagetypes::ACTION: case messagetypes::ACTION:
ActionMessage::clear(dynamic_cast<CommandMessage*>(message)); ActionMessage::clear(message);
break; break;
case messagetypes::DEVICE_HANDLER_COMMAND: case messagetypes::DEVICE_HANDLER_COMMAND:
DeviceHandlerMessage::clear(dynamic_cast<CommandMessage*>(message)); DeviceHandlerMessage::clear(message);
break; break;
case messagetypes::MEMORY: case messagetypes::MEMORY:
MemoryMessage::clear(dynamic_cast<CommandMessage*>(message)); MemoryMessage::clear(message);
break; break;
case messagetypes::MONITORING: case messagetypes::MONITORING:
MonitoringMessage::clear(dynamic_cast<CommandMessage*>(message)); MonitoringMessage::clear(message);
break; break;
case messagetypes::TM_STORE: case messagetypes::TM_STORE:
TmStoreMessage::clear(dynamic_cast<CommandMessage*>(message)); TmStoreMessage::clear(message);
break; break;
case messagetypes::PARAMETER: case messagetypes::PARAMETER:
ParameterMessage::clear(dynamic_cast<CommandMessage*>(message)); ParameterMessage::clear(message);
break; break;
default: default:
messagetypes::clearMissionMessage(message); messagetypes::clearMissionMessage(message);

View File

@ -1,15 +1,15 @@
#ifndef FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_ #ifndef FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_
#define FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_ #define FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_
#include <framework/ipc/CommandMessageIF.h> #include <framework/ipc/CommandMessage.h>
namespace messagetypes { namespace messagetypes {
// Implemented in config. // Implemented in config.
void clearMissionMessage(CommandMessageIF* message); void clearMissionMessage(CommandMessage* message);
} }
class CommandMessageCleaner { class CommandMessageCleaner {
public: public:
static void clearCommandMessage(CommandMessageIF* message); static void clearCommandMessage(CommandMessage* message);
}; };

View File

@ -80,12 +80,6 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message,
} }
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) { ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
if(message->getMessageSize() < maxMessageSize) {
sif::error << "MessageQueue::receiveMessage: Message size "
<< message->getMessageSize() <<
" too small to receive data!" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
BaseType_t result = xQueueReceive(handle,reinterpret_cast<void*>( BaseType_t result = xQueueReceive(handle,reinterpret_cast<void*>(
message->getBuffer()), 0); message->getBuffer()), 0);
if (result == pdPASS){ if (result == pdPASS){