fsfw/parameters/ParameterHelper.cpp

141 lines
4.7 KiB
C++
Raw Permalink Normal View History

2020-08-13 20:53:35 +02:00
#include "ParameterHelper.h"
#include "ParameterMessage.h"
2021-06-05 19:52:38 +02:00
#include "../objectmanager/ObjectManager.h"
2020-11-10 11:15:42 +01:00
ParameterHelper::ParameterHelper(ReceivesParameterMessagesIF* owner):
owner(owner) {}
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, &parameterId, &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 14:16:52 +01:00
#if FSFW_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;
#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);
2021-04-26 14:17:57 +02:00
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
2020-11-10 11:14:07 +01:00
result = ownerWrapper.copyFrom(&streamWrapper, linearIndex);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
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;
}
2020-11-10 11:14:07 +01:00
if (result != HasReturnvaluesIF::RETURN_OK) {
rejectCommand(message->getSender(), result, message->getCommand());
}
2020-11-10 11:14:07 +01:00
return HasReturnvaluesIF::RETURN_OK;
}
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();
2021-01-31 20:53:25 +01:00
uint8_t *storeElement = nullptr;
2020-11-10 11:14:07 +01:00
store_address_t address;
2020-11-10 11:14:07 +01:00
ReturnValue_t result = storage->getFreeElement(&address, serializedSize,
&storeElement);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
2020-11-10 11:14:07 +01:00
size_t storeElementSize = 0;
2020-11-10 11:14:07 +01:00
result = description->serialize(&storeElement, &storeElementSize,
serializedSize, SerializeIF::Endianness::BIG);
2020-11-10 11:14:07 +01:00
if (result != HasReturnvaluesIF::RETURN_OK) {
storage->deleteData(address);
return result;
}
2020-11-10 11:14:07 +01:00
CommandMessage reply;
2020-11-10 11:14:07 +01:00
ParameterMessage::setParameterDumpReply(&reply, id, address);
2020-11-10 11:14:07 +01:00
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
2020-11-10 11:14:07 +01:00
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t ParameterHelper::initialize() {
2020-10-29 17:57:27 +01:00
ownerQueueId = owner->getCommandQueue();
2018-07-13 18:28:26 +02:00
2021-06-05 19:52:38 +02:00
storage = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
2020-10-29 17:57:27 +01:00
if (storage == nullptr) {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
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);
}