2016-06-15 23:48:41 +02:00
|
|
|
#include <framework/objectmanager/ObjectManagerIF.h>
|
|
|
|
#include <framework/parameters/ParameterHelper.h>
|
|
|
|
#include <framework/parameters/ParameterMessage.h>
|
|
|
|
|
|
|
|
ParameterHelper::ParameterHelper(ReceivesParameterMessagesIF* owner) :
|
|
|
|
owner(owner), storage(NULL) {
|
|
|
|
ownerQueueId = owner->getCommandQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
ParameterHelper::~ParameterHelper() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
|
|
|
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
switch (message->getCommand()) {
|
|
|
|
case ParameterMessage::CMD_PARAMETER_DUMP: {
|
|
|
|
ParameterWrapper description;
|
|
|
|
uint8_t domain = HasParametersIF::getDomain(
|
|
|
|
ParameterMessage::getParameterId(message));
|
|
|
|
uint16_t parameterId = HasParametersIF::getMatrixId(
|
|
|
|
ParameterMessage::getParameterId(message));
|
2018-07-12 16:29:32 +02:00
|
|
|
result = owner->getParameter(domain, parameterId,
|
2016-06-15 23:48:41 +02:00
|
|
|
&description, &description, 0);
|
|
|
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
result = sendParameter(message->getSender(),
|
|
|
|
ParameterMessage::getParameterId(message), &description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ParameterMessage::CMD_PARAMETER_LOAD: {
|
|
|
|
|
|
|
|
uint8_t domain = HasParametersIF::getDomain(
|
|
|
|
ParameterMessage::getParameterId(message));
|
|
|
|
uint16_t parameterId = HasParametersIF::getMatrixId(
|
|
|
|
ParameterMessage::getParameterId(message));
|
|
|
|
uint8_t index = HasParametersIF::getIndex(
|
|
|
|
ParameterMessage::getParameterId(message));
|
|
|
|
|
|
|
|
const uint8_t *storedStream;
|
|
|
|
uint32_t storedStreamSize;
|
2018-07-12 16:29:32 +02:00
|
|
|
result = storage->getData(
|
2016-06-15 23:48:41 +02:00
|
|
|
ParameterMessage::getStoreId(message), &storedStream,
|
|
|
|
&storedStreamSize);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParameterWrapper streamWrapper;
|
|
|
|
result = streamWrapper.set(storedStream, storedStreamSize);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
storage->deleteData(ParameterMessage::getStoreId(message));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParameterWrapper ownerWrapper;
|
|
|
|
result = owner->getParameter(domain, parameterId, &ownerWrapper,
|
|
|
|
&streamWrapper, index);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
storage->deleteData(ParameterMessage::getStoreId(message));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = ownerWrapper.copyFrom(&streamWrapper, index);
|
|
|
|
|
|
|
|
storage->deleteData(ParameterMessage::getStoreId(message));
|
|
|
|
|
|
|
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
result = sendParameter(message->getSender(),
|
|
|
|
ParameterMessage::getParameterId(message), &ownerWrapper);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
rejectCommand(message->getSender(), result, message->getCommand());
|
|
|
|
}
|
|
|
|
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t ParameterHelper::sendParameter(MessageQueueId_t to, uint32_t id,
|
|
|
|
const ParameterWrapper* description) {
|
|
|
|
uint32_t serializedSize = description->getSerializedSize();
|
|
|
|
|
|
|
|
uint8_t *storeElement;
|
|
|
|
store_address_t address;
|
|
|
|
|
|
|
|
ReturnValue_t result = storage->getFreeElement(&address, serializedSize,
|
|
|
|
&storeElement);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t storeElementSize = 0;
|
|
|
|
|
|
|
|
result = description->serialize(&storeElement, &storeElementSize,
|
|
|
|
serializedSize, true);
|
|
|
|
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
storage->deleteData(address);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandMessage reply;
|
|
|
|
|
|
|
|
ParameterMessage::setParameterDumpReply(&reply, id, address);
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t ParameterHelper::initialize() {
|
|
|
|
storage = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
|
|
|
if (storage == NULL) {
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
} else {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParameterHelper::rejectCommand(MessageQueueId_t to, ReturnValue_t reason, Command_t initialCommand) {
|
|
|
|
CommandMessage reply;
|
|
|
|
reply.setReplyRejected(reason, initialCommand);
|
2018-07-12 16:29:32 +02:00
|
|
|
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|