diff --git a/mission/utility/GlobalConfigFileDefinitions.h b/mission/utility/GlobalConfigFileDefinitions.h index 7a48c095..b4f5f394 100644 --- a/mission/utility/GlobalConfigFileDefinitions.h +++ b/mission/utility/GlobalConfigFileDefinitions.h @@ -15,7 +15,7 @@ static constexpr int PARAM1_DEFAULT = 905; enum ParamIds : uint8_t { PARAM0 = 0, PARAM1 = 1, - + PARAM2 = 2, }; diff --git a/mission/utility/GlobalConfigHandler.cpp b/mission/utility/GlobalConfigHandler.cpp index c76af5d1..df0b4566 100644 --- a/mission/utility/GlobalConfigHandler.cpp +++ b/mission/utility/GlobalConfigHandler.cpp @@ -86,11 +86,23 @@ template ReturnValue_t GlobalConfigHandler::setConfigFileValue(Para return result; } + std:: string paramString; + paramString=PARAM_KEY_MAP[paramID]; + + //Check if key exists in map before setting value. No check is done in setValue! Somehow PARAM_KEY_MAP.count(paramID) == 0 does not work + if (paramString.empty() == true) { +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::setConfigFileValue ParamId " << PARAM_KEY_MAP[paramID]<<" not found!" << std::endl; +#endif + triggerEvent(SET_CONFIGFILEVALUE_FAILED, 1, 0); + return RETURN_FAILED; + } + resultSet=setValue(PARAM_KEY_MAP[paramID], data); if(resultSet!=RETURN_OK){ triggerEvent(SET_CONFIGFILEVALUE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::setConfigFileValue set json failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::setConfigFileValue set json failed with " << resultSet << std::endl; #endif } @@ -121,7 +133,7 @@ template ReturnValue_t GlobalConfigHandler::getConfigFileValue(Para if (resultGet!= RETURN_OK){ triggerEvent(GET_CONFIGFILEVALUE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::getConfigFileValue lock mutex failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::getConfigFileValue getValue failed with " << resultGet << std::endl; #endif } result=unlockConfigFile(); @@ -132,7 +144,7 @@ template ReturnValue_t GlobalConfigHandler::getConfigFileValue(Para return result; } - return result; + return resultGet; } ReturnValue_t GlobalConfigHandler::resetConfigFileValues(){ @@ -146,6 +158,8 @@ ReturnValue_t GlobalConfigHandler::resetConfigFileValues(){ } insertValue(PARAM_KEY_MAP[PARAM0], PARAM0_DEFAULT); insertValue(PARAM_KEY_MAP[PARAM1], PARAM1_DEFAULT); + + result=unlockConfigFile(); if (result!= RETURN_OK){ #if OBSW_VERBOSE_LEVEL >= 1 @@ -170,7 +184,7 @@ ReturnValue_t GlobalConfigHandler::WriteConfigFile(){ if(resultWrite!=RETURN_OK){ triggerEvent(WRITE_CONFIGFILE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::WriteConfigFile write json failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::WriteConfigFile write json failed with " << resultWrite << std::endl; #endif } @@ -199,7 +213,7 @@ ReturnValue_t GlobalConfigHandler::ReadConfigFile(){ if(resultRead!=RETURN_OK){ triggerEvent(READ_CONFIGFILE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::ReadConfigFile read json failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::ReadConfigFile read json failed with " << resultRead << std::endl; #endif } @@ -215,7 +229,13 @@ ReturnValue_t GlobalConfigHandler::ReadConfigFile(){ } ReturnValue_t GlobalConfigHandler::ResetConfigFile(){ ReturnValue_t result = RETURN_OK; - resetConfigFileValues(); + result=resetConfigFileValues(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::ResetConfigFile failed with " << result << std::endl; +#endif + return result; + } result =writeJsonFile(); return result; } diff --git a/mission/utility/GlobalConfigHandler.h b/mission/utility/GlobalConfigHandler.h index 7869aaf0..cbb65d20 100644 --- a/mission/utility/GlobalConfigHandler.h +++ b/mission/utility/GlobalConfigHandler.h @@ -55,7 +55,8 @@ public: template ReturnValue_t setConfigFileValue(ParamIds paramID, T data); template ReturnValue_t getConfigFileValue(ParamIds paramID, T& data); - ReturnValue_t resetConfigFileValues(); + + ReturnValue_t ResetConfigFile(); ReturnValue_t WriteConfigFile(); std::string getConfigFileName(); @@ -64,14 +65,11 @@ private: ReturnValue_t lockConfigFile(); ReturnValue_t unlockConfigFile(); - - - - ReturnValue_t ReadConfigFile(); - ReturnValue_t ResetConfigFile(); + ReturnValue_t resetConfigFileValues(); ReturnValue_t setConfigFileName(std::string configFileName); + ReturnValue_t ReadConfigFile(); MessageQueueIF* commandQueue; diff --git a/unittest/controller/testConfigFileHandler.cpp b/unittest/controller/testConfigFileHandler.cpp index 30365863..cbfd24b6 100644 --- a/unittest/controller/testConfigFileHandler.cpp +++ b/unittest/controller/testConfigFileHandler.cpp @@ -12,13 +12,13 @@ TEST_CASE("Configfile Handler", "[ConfigHandler]") { sif::debug<<"Testcase config file handler"<