2020-08-13 20:53:35 +02:00
|
|
|
#include "ParameterHelper.h"
|
|
|
|
#include "ParameterMessage.h"
|
2020-08-28 18:46:47 +02:00
|
|
|
#include "../objectmanager/ObjectManagerIF.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:15:42 +01:00
|
|
|
ParameterHelper::ParameterHelper(ReceivesParameterMessagesIF* owner):
|
|
|
|
owner(owner) {}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
ParameterHelper::~ParameterHelper() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
|
2020-10-29 17:57:27 +01:00
|
|
|
if(storage == nullptr) {
|
|
|
|
// ParameterHelper was not initialized
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
switch (message->getCommand()) {
|
|
|
|
case ParameterMessage::CMD_PARAMETER_DUMP: {
|
|
|
|
ParameterWrapper description;
|
|
|
|
uint8_t domain = HasParametersIF::getDomain(
|
|
|
|
ParameterMessage::getParameterId(message));
|
|
|
|
uint8_t uniqueIdentifier = HasParametersIF::getUniqueIdentifierId(
|
|
|
|
ParameterMessage::getParameterId(message));
|
|
|
|
result = owner->getParameter(domain, uniqueIdentifier,
|
|
|
|
&description, &description, 0);
|
|
|
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
result = sendParameter(message->getSender(),
|
|
|
|
ParameterMessage::getParameterId(message), &description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ParameterMessage::CMD_PARAMETER_LOAD: {
|
|
|
|
ParameterId_t parameterId = 0;
|
|
|
|
uint8_t ptc = 0;
|
|
|
|
uint8_t pfc = 0;
|
|
|
|
uint8_t rows = 0;
|
|
|
|
uint8_t columns = 0;
|
|
|
|
store_address_t storeId = ParameterMessage::getParameterLoadCommand(
|
|
|
|
message, ¶meterId, &ptc, &pfc, &rows, &columns);
|
|
|
|
Type type(Type::getActualType(ptc, pfc));
|
|
|
|
|
|
|
|
uint8_t domain = HasParametersIF::getDomain(parameterId);
|
|
|
|
uint8_t uniqueIdentifier = HasParametersIF::getUniqueIdentifierId(
|
|
|
|
parameterId);
|
|
|
|
uint16_t linearIndex = HasParametersIF::getIndex(parameterId);
|
|
|
|
|
|
|
|
ConstStorageAccessor accessor(storeId);
|
|
|
|
result = storage->getData(storeId, accessor);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
2021-01-03 13:58:18 +01:00
|
|
|
#if CPP_OSTREAM_ENABLED == 1
|
2020-11-10 11:14:07 +01:00
|
|
|
sif::error << "ParameterHelper::handleParameterMessage: Getting"
|
|
|
|
<< " store data failed for load command." << std::endl;
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2020-11-10 11:14:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParameterWrapper streamWrapper;
|
|
|
|
result = streamWrapper.set(type, rows, columns, accessor.data(),
|
|
|
|
accessor.size());
|
|
|
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParameterWrapper ownerWrapper;
|
|
|
|
result = owner->getParameter(domain, uniqueIdentifier, &ownerWrapper,
|
|
|
|
&streamWrapper, linearIndex);
|
|
|
|
|
|
|
|
result = ownerWrapper.copyFrom(&streamWrapper, linearIndex);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-10-29 17:57:27 +01:00
|
|
|
result = sendParameter(message->getSender(),
|
|
|
|
ParameterMessage::getParameterId(message), &ownerWrapper);
|
2020-11-10 11:14:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
rejectCommand(message->getSender(), result, message->getCommand());
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t ParameterHelper::sendParameter(MessageQueueId_t to, uint32_t id,
|
2020-11-10 11:14:07 +01:00
|
|
|
const ParameterWrapper* description) {
|
|
|
|
size_t serializedSize = description->getSerializedSize();
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
uint8_t *storeElement;
|
|
|
|
store_address_t address;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
ReturnValue_t result = storage->getFreeElement(&address, serializedSize,
|
|
|
|
&storeElement);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
size_t storeElementSize = 0;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
result = description->serialize(&storeElement, &storeElementSize,
|
|
|
|
serializedSize, SerializeIF::Endianness::BIG);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
storage->deleteData(address);
|
|
|
|
return result;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
CommandMessage reply;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
ParameterMessage::setParameterDumpReply(&reply, id, address);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-11-10 11:14:07 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t ParameterHelper::initialize() {
|
2020-10-29 17:57:27 +01:00
|
|
|
ownerQueueId = owner->getCommandQueue();
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2020-10-29 17:57:27 +01:00
|
|
|
storage = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
|
|
|
if (storage == nullptr) {
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2020-08-28 18:46:47 +02:00
|
|
|
void ParameterHelper::rejectCommand(MessageQueueId_t to, ReturnValue_t reason,
|
2020-11-10 11:14:07 +01:00
|
|
|
Command_t initialCommand) {
|
|
|
|
CommandMessage reply;
|
|
|
|
reply.setReplyRejected(reason, initialCommand);
|
|
|
|
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|