2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/parameters/ParameterHelper.h"
|
2021-06-05 19:52:38 +02:00
|
|
|
|
2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/objectmanager/ObjectManager.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/parameters/ParameterMessage.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ParameterHelper::ParameterHelper(ReceivesParameterMessagesIF* owner) : owner(owner) {}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ParameterHelper::~ParameterHelper() {}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage* message) {
|
|
|
|
if (storage == nullptr) {
|
|
|
|
// ParameterHelper was not initialized
|
2022-08-15 20:28:16 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
2020-10-29 17:57:27 +01:00
|
|
|
|
2022-08-15 20:28:16 +02:00
|
|
|
ReturnValue_t result = returnvalue::FAILED;
|
2022-02-02 10:29:30 +01:00
|
|
|
switch (message->getCommand()) {
|
2020-11-10 11:14:07 +01:00
|
|
|
case ParameterMessage::CMD_PARAMETER_DUMP: {
|
2022-02-02 10:29:30 +01:00
|
|
|
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);
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result == returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
result = sendParameter(message->getSender(), ParameterMessage::getParameterId(message),
|
|
|
|
&description);
|
|
|
|
}
|
|
|
|
} break;
|
2020-11-10 11:14:07 +01:00
|
|
|
case ParameterMessage::CMD_PARAMETER_LOAD: {
|
2022-02-02 10:29:30 +01:00
|
|
|
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);
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +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;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ParameterWrapper streamWrapper;
|
|
|
|
result = streamWrapper.set(type, rows, columns, accessor.data(), accessor.size());
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParameterWrapper ownerWrapper;
|
|
|
|
result =
|
|
|
|
owner->getParameter(domain, uniqueIdentifier, &ownerWrapper, &streamWrapper, linearIndex);
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = ownerWrapper.copyFrom(&streamWrapper, linearIndex);
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = sendParameter(message->getSender(), ParameterMessage::getParameterId(message),
|
|
|
|
&ownerWrapper);
|
|
|
|
break;
|
2020-11-10 11:14:07 +01:00
|
|
|
}
|
|
|
|
default:
|
2022-08-15 20:28:16 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
rejectCommand(message->getSender(), result, message->getCommand());
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-08-15 20:28:16 +02:00
|
|
|
return returnvalue::OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t ParameterHelper::sendParameter(MessageQueueId_t to, uint32_t id,
|
2022-02-02 10:29:30 +01:00
|
|
|
const ParameterWrapper* description) {
|
|
|
|
size_t serializedSize = description->getSerializedSize();
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
uint8_t* storeElement = nullptr;
|
|
|
|
store_address_t address;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t result = storage->getFreeElement(&address, serializedSize, &storeElement);
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return result;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
size_t storeElementSize = 0;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
result = description->serialize(&storeElement, &storeElementSize, serializedSize,
|
|
|
|
SerializeIF::Endianness::BIG);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
storage->deleteData(address);
|
|
|
|
return result;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
CommandMessage reply;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ParameterMessage::setParameterDumpReply(&reply, id, address);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2022-08-15 20:28:16 +02:00
|
|
|
return returnvalue::OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t ParameterHelper::initialize() {
|
2022-02-02 10:29:30 +01:00
|
|
|
ownerQueueId = owner->getCommandQueue();
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
storage = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
|
|
|
|
if (storage == nullptr) {
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
2022-08-15 20:28:16 +02:00
|
|
|
return returnvalue::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,
|
2022-02-02 10:29:30 +01:00
|
|
|
Command_t initialCommand) {
|
|
|
|
CommandMessage reply;
|
|
|
|
reply.setReplyRejected(reason, initialCommand);
|
|
|
|
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|