diff --git a/bsp_hosted/GlobalConfigHandler.cpp b/bsp_hosted/GlobalConfigHandler.cpp index 93fcad10..a2c8ff56 100644 --- a/bsp_hosted/GlobalConfigHandler.cpp +++ b/bsp_hosted/GlobalConfigHandler.cpp @@ -8,9 +8,16 @@ #include "GlobalConfigHandler.h" #include #include "fsfw/serviceinterface/ServiceInterface.h" +#include +#include MutexIF* GlobalConfigHandler::configLock = nullptr; -GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath): SystemObject(objectId), NVMParameterBase(configFilePath){ +GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath): + SystemObject(objectId), + NVMParameterBase(configFilePath), + parameterHelper(this), + commandQueue(QueueFactory::instance()->createMessageQueue(20)), + actionHelper(this, commandQueue){ if (configLock == nullptr) { configLock = MutexFactory::instance()->createMutex(); } @@ -22,6 +29,12 @@ ReturnValue_t GlobalConfigHandler::initialize(){ if (result != RETURN_OK) { return result; } + + result = actionHelper.initialize(commandQueue); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = ReadConfigFile(); if(result!=RETURN_OK){ #if OBSW_VERBOSE_LEVEL >= 1 @@ -32,6 +45,15 @@ ReturnValue_t GlobalConfigHandler::initialize(){ return result; } } + + result = parameterHelper.initialize(); + if (result != HasReturnvaluesIF::RETURN_OK) { +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::initialize: parameterHelper init failed with " << result << std::endl; +#endif + return result; + } + #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::initialize success " << std::endl; #endif @@ -44,9 +66,23 @@ GlobalConfigHandler::~GlobalConfigHandler() { ReturnValue_t GlobalConfigHandler::performOperation(uint8_t operationCode) { ReturnValue_t result = RETURN_OK; sif::debug<<"GlobalConfigHandler::performOperation"<receiveMessage(&command); + if (result != RETURN_OK) { + return; + } + + result = parameterHelper.handleParameterMessage(&command); + if (result == RETURN_OK) { + return; + } +} + ReturnValue_t GlobalConfigHandler::lockConfigFile(){ ReturnValue_t result = RETURN_OK; result = configLock->lockMutex(MutexIF::TimeoutType::WAITING, 0); @@ -244,3 +280,78 @@ std::string GlobalConfigHandler::getConfigFileName(){ return getFullName(); } + +ReturnValue_t GlobalConfigHandler::getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper* parameterWrapper, + const ParameterWrapper* newValues, + uint16_t startAtIndex) { + + ReturnValue_t result = RETURN_OK; + switch(uniqueId){ + + case(ParamIds::PARAM0):{ + result=handleDoubleParamUpdate(PARAM_KEY_MAP[static_cast(uniqueId)], + parameterWrapper, newValues); + break; + } + case(ParamIds::PARAM1):{ + result=handleIntParamUpdate(PARAM_KEY_MAP[static_cast(uniqueId)], + parameterWrapper, newValues); + break; + } + default:{ + result=RETURN_FAILED; + break; + } + } + return result; + +} + +//Taken from payloadPCDU Handler Definition +ReturnValue_t GlobalConfigHandler::handleDoubleParamUpdate(std::string key, + ParameterWrapper* parameterWrapper, + const ParameterWrapper* newValues) { + double newValue = 0.0; + ReturnValue_t result = newValues->getElement(&newValue, 0, 0); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result=setConfigFileValue(key, newValue); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + // Do this so the dumping and loading with the framework works as well + doubleDummy = newValue; + parameterWrapper->set(doubleDummy); + return WriteConfigFile(); +} + +ReturnValue_t GlobalConfigHandler::handleIntParamUpdate(std::string key, + ParameterWrapper* parameterWrapper, + const ParameterWrapper* newValues) { + int newValue = 0; + ReturnValue_t result = newValues->getElement(&newValue, 0, 0); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result=setConfigFileValue(key, newValue); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + // Do this so the dumping and loading with the framework works as well + intDummy = newValue; + parameterWrapper->set(intDummy); + return WriteConfigFile(); +} + +MessageQueueId_t GlobalConfigHandler::getCommandQueue() const{ + return commandQueue->getId(); +} + +ReturnValue_t GlobalConfigHandler::executeAction(ActionId_t actionId, + MessageQueueId_t commandedBy, const uint8_t* data, + size_t size) { + + return RETURN_FAILED; +} diff --git a/bsp_hosted/GlobalConfigHandler.h b/bsp_hosted/GlobalConfigHandler.h index 31652f4b..2beffa67 100644 --- a/bsp_hosted/GlobalConfigHandler.h +++ b/bsp_hosted/GlobalConfigHandler.h @@ -16,9 +16,13 @@ #include #include "mission/memory/NVMParameterBase.h" #include "OBSWConfig.h" +#include "fsfw/parameters/HasParametersIF.h" +#include "fsfw/parameters/ParameterHelper.h" +#include +#include static constexpr double PARAM0_DEFAULT = 5.0; -static constexpr double PARAM1_DEFAULT = 905.0; +static constexpr int PARAM1_DEFAULT = 905; enum ParamIds : uint8_t { PARAM0 = 0, @@ -35,7 +39,11 @@ static std::map PARAM_KEY_MAP = { * Its tasks is managing a configuration JSON file containing config values important for various object. * If some function to read or write a config value is called, a mutex should be used so only one call is done at a time. */ -class GlobalConfigHandler: public SystemObject, public ExecutableObjectIF, public NVMParameterBase{ +class GlobalConfigHandler: public SystemObject, + public ExecutableObjectIF, + public NVMParameterBase, + public ReceivesParameterMessagesIF, + public HasActionsIF{ public: GlobalConfigHandler(object_id_t objectId, std::string configFilePath); virtual ~GlobalConfigHandler(); @@ -49,6 +57,7 @@ public: static constexpr Event READ_CONFIGFILE_FAILED = MAKE_EVENT(5, severity::MEDIUM); ReturnValue_t performOperation(uint8_t operationCode); + void readCommandQueue(); ReturnValue_t initialize(); ReturnValue_t lockConfigFile(); @@ -64,11 +73,30 @@ public: ReturnValue_t setConfigFileName(std::string configFileName); std::string getConfigFileName(); + ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper* parameterWrapper, + const ParameterWrapper* newValues, + uint16_t startAtIndex); + + ReturnValue_t handleDoubleParamUpdate(std::string key, + ParameterWrapper* parameterWrapper, + const ParameterWrapper* newValues); + ReturnValue_t handleIntParamUpdate(std::string key, + ParameterWrapper* parameterWrapper, + const ParameterWrapper* newValues) ; + MessageQueueId_t getCommandQueue() const override; + ReturnValue_t executeAction(ActionId_t actionId, + MessageQueueId_t commandedBy, const uint8_t* data, + size_t size) override; private: static MutexIF* configLock ; + ParameterHelper parameterHelper; + MessageQueueIF* commandQueue; + ActionHelper actionHelper; - + double doubleDummy = 0.0; + int intDummy = 0; }; #endif /* BSP_LINUX_GLOBALCONFIGHANDLER_H_ */