From c413d90b88f48425c32294f48acf654b6a29ec88 Mon Sep 17 00:00:00 2001 From: petriVM18 Date: Tue, 3 May 2022 08:10:07 +0200 Subject: [PATCH 01/23] Minor adaption ti filesystem include and removed arcsect submodule to make it work on my local machine --- .gitmodules | 3 --- mission/devices/devicedefinitions/payloadPcduDefinitions.h | 2 +- mission/memory/NVMParameterBase.cpp | 4 ++-- mission/memory/NVMParameterBase.h | 2 +- thirdparty/arcsec_star_tracker | 1 - 5 files changed, 4 insertions(+), 8 deletions(-) delete mode 160000 thirdparty/arcsec_star_tracker diff --git a/.gitmodules b/.gitmodules index d309e0f5..d9a11687 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,9 +13,6 @@ [submodule "generators/fsfwgen"] path = generators/fsfwgen url = https://egit.irs.uni-stuttgart.de/fsfw/fsfw-gen.git -[submodule "thirdparty/arcsec_star_tracker"] - path = thirdparty/arcsec_star_tracker - url = https://egit.irs.uni-stuttgart.de/eive/arcsec_star_tracker.git [submodule "thirdparty/json"] path = thirdparty/json url = https://github.com/nlohmann/json.git diff --git a/mission/devices/devicedefinitions/payloadPcduDefinitions.h b/mission/devices/devicedefinitions/payloadPcduDefinitions.h index ab387fc7..c4dc2aa1 100644 --- a/mission/devices/devicedefinitions/payloadPcduDefinitions.h +++ b/mission/devices/devicedefinitions/payloadPcduDefinitions.h @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include "OBSWConfig.h" diff --git a/mission/memory/NVMParameterBase.cpp b/mission/memory/NVMParameterBase.cpp index 78f40525..865c561b 100644 --- a/mission/memory/NVMParameterBase.cpp +++ b/mission/memory/NVMParameterBase.cpp @@ -8,7 +8,7 @@ NVMParameterBase::NVMParameterBase(std::string fullName) : fullName(fullName) {} ReturnValue_t NVMParameterBase::readJsonFile() { - if (std::filesystem::exists(fullName)) { + if (std::experimental::filesystem::exists(fullName)) { // Read JSON file content into object std::ifstream i(fullName); try { @@ -37,7 +37,7 @@ void NVMParameterBase::setFullName(std::string fullName) { this->fullName = full std::string NVMParameterBase::getFullName() const { return fullName; } -bool NVMParameterBase::getJsonFileExists() { return std::filesystem::exists(fullName); } +bool NVMParameterBase::getJsonFileExists() { return std::experimental::filesystem::exists(fullName); } void NVMParameterBase::printKeys() const { sif::info << "Printing keys for JSON file " << fullName << std::endl; diff --git a/mission/memory/NVMParameterBase.h b/mission/memory/NVMParameterBase.h index eb839905..16d9824c 100644 --- a/mission/memory/NVMParameterBase.h +++ b/mission/memory/NVMParameterBase.h @@ -1,7 +1,7 @@ #ifndef BSP_Q7S_CORE_NVMPARAMS_NVMPARAMIF_H_ #define BSP_Q7S_CORE_NVMPARAMS_NVMPARAMIF_H_ -#include +#include #include #include diff --git a/thirdparty/arcsec_star_tracker b/thirdparty/arcsec_star_tracker deleted file mode 160000 index 93e93965..00000000 --- a/thirdparty/arcsec_star_tracker +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 93e93965e2c6405170b62c523dea1990db02d2ad -- 2.43.0 From 74b38a6d06e6bf7186f95c880e0a75cc2455100b Mon Sep 17 00:00:00 2001 From: petriVM18 Date: Tue, 7 Jun 2022 09:54:52 +0200 Subject: [PATCH 02/23] Worked on config file handler, added all functions --- bsp_hosted/CMakeLists.txt | 1 + bsp_hosted/GlobalConfigHandler.cpp | 156 ++++++++++++++++++ bsp_hosted/GlobalConfigHandler.h | 63 +++++++ bsp_hosted/InitMission.cpp | 10 ++ bsp_hosted/ObjectFactory.cpp | 3 + .../fsfwconfig/objects/systemObjectList.h | 1 + bsp_hosted/main.cpp | 1 + linux/fsfwconfig/objects/systemObjectList.h | 1 + 8 files changed, 236 insertions(+) create mode 100644 bsp_hosted/GlobalConfigHandler.cpp create mode 100644 bsp_hosted/GlobalConfigHandler.h diff --git a/bsp_hosted/CMakeLists.txt b/bsp_hosted/CMakeLists.txt index 7787cf7e..88710bd1 100644 --- a/bsp_hosted/CMakeLists.txt +++ b/bsp_hosted/CMakeLists.txt @@ -2,6 +2,7 @@ target_sources(${OBSW_NAME} PUBLIC InitMission.cpp main.cpp ObjectFactory.cpp + GlobalConfigHandler.cpp ) add_subdirectory(fsfwconfig) diff --git a/bsp_hosted/GlobalConfigHandler.cpp b/bsp_hosted/GlobalConfigHandler.cpp new file mode 100644 index 00000000..b450bfa9 --- /dev/null +++ b/bsp_hosted/GlobalConfigHandler.cpp @@ -0,0 +1,156 @@ +/* + * GlobalConfigHandler.cpp + * + * Created on: May 3, 2022 + * Author: metobs + */ + +#include "GlobalConfigHandler.h" +#include +#include "fsfw/serviceinterface/ServiceInterface.h" + +MutexIF* GlobalConfigHandler::configLock = nullptr; +GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath): SystemObject(objectId), NVMParameterBase(configFilePath){ + if (configLock == nullptr) { + configLock = MutexFactory::instance()->createMutex(); + } + +} +ReturnValue_t GlobalConfigHandler::initialize(){ + + ReturnValue_t result = SystemObject::initialize(); + if (result != RETURN_OK) { + return result; + } + result = ReadConfigFile(); + if(result!=RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::initialize: Creating JSON file at " << getFullName() << std::endl; +#endif + result=ResetConfigFile(); + if (result != RETURN_OK) { + return result; + } + } +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::initialize success " << std::endl; +#endif + return result; +} +GlobalConfigHandler::~GlobalConfigHandler() { + +} + +ReturnValue_t GlobalConfigHandler::performOperation(uint8_t operationCode) { + ReturnValue_t result = RETURN_OK; + sif::debug<<"GlobalConfigHandler::performOperation"<lockMutex(MutexIF::TimeoutType::WAITING, 0); + return result; +} +ReturnValue_t GlobalConfigHandler::unlockConfigFile(){ + ReturnValue_t result = RETURN_OK; + result=configLock->unlockMutex(); + return result; +} + +//TBD for set/get/insert: Mutx lock, set/get/insert, Mutex unlock +//Use template functions for different data types +ReturnValue_t GlobalConfigHandler::setConfigFileValue(){ + ReturnValue_t result = RETURN_OK; + return result; +} +ReturnValue_t GlobalConfigHandler::getConfigFileValue(){ + ReturnValue_t result = RETURN_OK; + return result; +} +ReturnValue_t GlobalConfigHandler::insertConfigFileValue(){ + ReturnValue_t result = RETURN_OK; + return result; +} +ReturnValue_t GlobalConfigHandler::resetConfigFileValues(){ + ReturnValue_t result = RETURN_OK; + result=lockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::resetConfigFileValues lock mutex failed with " << result << std::endl; +#endif + return result; + } + 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 + sif::info << "GlobalConfigHandler::resetConfigFileValues unlock mutex failed with " << result << std::endl; +#endif + return result; + } + return result; +} +ReturnValue_t GlobalConfigHandler::WriteConfigFile(){ + ReturnValue_t result = RETURN_OK; + ReturnValue_t resultWrite = RETURN_OK; + result=lockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::WriteConfigFile lock mutex failed with " << result << std::endl; +#endif + return result; + } + + resultWrite =writeJsonFile(); + if(resultWrite!=RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::WriteConfigFile write json failed with " << result << std::endl; +#endif + } + + + result=unlockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::WriteConfigFile unlock mutex failed with " << result << std::endl; +#endif + return result; + } + return resultWrite; +} +ReturnValue_t GlobalConfigHandler::ReadConfigFile(){ + ReturnValue_t result = RETURN_OK; + ReturnValue_t resultRead = RETURN_OK; + result=lockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::ReadConfigFile lock mutex failed with " << result << std::endl; +#endif + return result; + } + + resultRead=readJsonFile(); + if(resultRead!=RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::ReadConfigFile read json failed with " << result << std::endl; +#endif + } + + result=unlockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::ReadConfigFile unlock mutex failed with " << result << std::endl; +#endif + return result; + } + + return resultRead; +} +ReturnValue_t GlobalConfigHandler::ResetConfigFile(){ + ReturnValue_t result = RETURN_OK; + resetConfigFileValues(); + result =writeJsonFile(); + return result; +} diff --git a/bsp_hosted/GlobalConfigHandler.h b/bsp_hosted/GlobalConfigHandler.h new file mode 100644 index 00000000..9db594a3 --- /dev/null +++ b/bsp_hosted/GlobalConfigHandler.h @@ -0,0 +1,63 @@ +/* + * GlobalConfigHandler.h + * + * Created on: May 3, 2022 + * Author: metobs + */ + +#ifndef BSP_LINUX_GLOBALCONFIGHANDLER_H_ +#define BSP_LINUX_GLOBALCONFIGHANDLER_H_ + +#include +#include +#include +#include +#include +#include +#include "mission/memory/NVMParameterBase.h" +#include "OBSWConfig.h" + +static constexpr double PARAM0_DEFAULT = 5.0; +static constexpr double PARAM1_DEFAULT = 905.0; + +enum ParamIds : uint8_t { + PARAM0 = 0, + PARAM1 = 1, + +}; + +static std::map PARAM_KEY_MAP = { + {PARAM0, "Parameter0"}, + {PARAM1, "Parameter1"}, +}; +/* + * Idea: This class is intended to be used as a subclass for the Core Controller. + * 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{ +public: + GlobalConfigHandler(object_id_t objectId, std::string configFilePath); + virtual ~GlobalConfigHandler(); + ReturnValue_t performOperation(uint8_t operationCode); + ReturnValue_t initialize(); + + ReturnValue_t lockConfigFile(); + ReturnValue_t unlockConfigFile(); + ReturnValue_t setConfigFileValue(); + ReturnValue_t getConfigFileValue(); + ReturnValue_t insertConfigFileValue(); + ReturnValue_t resetConfigFileValues(); + ReturnValue_t WriteConfigFile(); + ReturnValue_t ReadConfigFile(); + ReturnValue_t ResetConfigFile(); + +private: + std::string configFilePath; + static MutexIF* configLock ; + + + +}; + +#endif /* BSP_LINUX_GLOBALCONFIGHANDLER_H_ */ diff --git a/bsp_hosted/InitMission.cpp b/bsp_hosted/InitMission.cpp index 0ca59db5..b1463967 100644 --- a/bsp_hosted/InitMission.cpp +++ b/bsp_hosted/InitMission.cpp @@ -138,6 +138,15 @@ void initmission::initTasks() { } #endif /* OBSW_ADD_TEST_CODE == 1 */ + PeriodicTaskIF* configTask = factory->createPeriodicTask( + "CONFIG_TASK", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc); + + result = configTask->addComponent(objects::CONFIG_TEST); + if (result != HasReturnvaluesIF::RETURN_OK) { + initmission::printAddObjectError("CONFIG_TASK", objects::CONFIG_TEST); + } + + sif::info << "Starting tasks.." << std::endl; tmTcDistributor->startTask(); tmtcBridgeTask->startTask(); @@ -148,6 +157,7 @@ void initmission::initTasks() { pusHighPrio->startTask(); pusMedPrio->startTask(); pusLowPrio->startTask(); + configTask->startTask(); #if OBSW_ADD_TEST_CODE == 1 testTask->startTask(); diff --git a/bsp_hosted/ObjectFactory.cpp b/bsp_hosted/ObjectFactory.cpp index e1be7588..91fbb509 100644 --- a/bsp_hosted/ObjectFactory.cpp +++ b/bsp_hosted/ObjectFactory.cpp @@ -24,6 +24,8 @@ #include #endif +#include "GlobalConfigHandler.h" + void Factory::setStaticFrameworkObjectIds() { PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR; PusServiceBase::packetDestination = objects::TM_FUNNEL; @@ -44,4 +46,5 @@ void ObjectFactory::produce(void* args) { ObjectFactory::produceGenericObjects(); new TestTask(objects::TEST_TASK); + new GlobalConfigHandler(objects::CONFIG_TEST,"/path/to/JSON.config"); } diff --git a/bsp_hosted/fsfwconfig/objects/systemObjectList.h b/bsp_hosted/fsfwconfig/objects/systemObjectList.h index 91bd2bed..8eddfc4f 100644 --- a/bsp_hosted/fsfwconfig/objects/systemObjectList.h +++ b/bsp_hosted/fsfwconfig/objects/systemObjectList.h @@ -21,6 +21,7 @@ enum sourceObjects : uint32_t { /* Test Task */ TEST_TASK = 0x42694269, + CONFIG_TEST = 0x42694270, DUMMY_INTERFACE = 0xCAFECAFE, DUMMY_HANDLER = 0x4400AFFE, diff --git a/bsp_hosted/main.cpp b/bsp_hosted/main.cpp index 938adb76..cdf1bdb4 100644 --- a/bsp_hosted/main.cpp +++ b/bsp_hosted/main.cpp @@ -23,6 +23,7 @@ int main(void) { << " v" << common::OBSW_VERSION << " | FSFW v" << fsfw::FSFW_VERSION << " --" << std::endl; std::cout << "-- " << __DATE__ << " " << __TIME__ << " --" << std::endl; + std::cout << "-- " <<" BSP HOSTED"<< " --" << std::endl; initmission::initMission(); diff --git a/linux/fsfwconfig/objects/systemObjectList.h b/linux/fsfwconfig/objects/systemObjectList.h index a03e4d38..ec711711 100644 --- a/linux/fsfwconfig/objects/systemObjectList.h +++ b/linux/fsfwconfig/objects/systemObjectList.h @@ -59,6 +59,7 @@ enum sourceObjects : uint32_t { /* 0x54 ('T') for test handlers */ TEST_TASK = 0x54694269, + CONFIG_TEST = 0x54694270, LIBGPIOD_TEST = 0x54123456, SPI_TEST = 0x54000010, UART_TEST = 0x54000020, -- 2.43.0 From 0fb620b2903940e571ac204e6720a1088392b418 Mon Sep 17 00:00:00 2001 From: petriVM18 Date: Wed, 8 Jun 2022 08:27:45 +0200 Subject: [PATCH 03/23] Implemented set/get/insert functions for config file handler --- bsp_hosted/GlobalConfigHandler.cpp | 90 +++++++++++++++++++++++++++--- bsp_hosted/GlobalConfigHandler.h | 6 +- 2 files changed, 86 insertions(+), 10 deletions(-) diff --git a/bsp_hosted/GlobalConfigHandler.cpp b/bsp_hosted/GlobalConfigHandler.cpp index b450bfa9..470eba4c 100644 --- a/bsp_hosted/GlobalConfigHandler.cpp +++ b/bsp_hosted/GlobalConfigHandler.cpp @@ -60,17 +60,93 @@ ReturnValue_t GlobalConfigHandler::unlockConfigFile(){ //TBD for set/get/insert: Mutx lock, set/get/insert, Mutex unlock //Use template functions for different data types -ReturnValue_t GlobalConfigHandler::setConfigFileValue(){ +//Trigger Event, if set/get/insert/write/Read fails +template ReturnValue_t GlobalConfigHandler::setConfigFileValue(std::string key, T data){ ReturnValue_t result = RETURN_OK; + ReturnValue_t resultSet = RETURN_OK; + + result=lockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::setConfigFileValue lock mutex failed with " << result << std::endl; +#endif + return result; + } + + resultSet=setValue(key, data); + if(resultSet!=RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::setConfigFileValue set json failed with " << result << std::endl; +#endif + } + + + result=unlockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::setConfigFileValue unlock mutex failed with " << result << std::endl; +#endif + return result; + } + + return resultSet; +} +template ReturnValue_t GlobalConfigHandler::getConfigFileValue(std::string key, T& data){ + ReturnValue_t result = RETURN_OK; + ReturnValue_t resultGet = RETURN_OK; + + result=lockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::getConfigFileValue lock mutex failed with " << result << std::endl; +#endif + return result; + } + + resultGet=getValue(key, data); + if (resultGet!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::getConfigFileValue lock mutex failed with " << result << std::endl; +#endif + } + result=unlockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::getConfigFileValue unlock mutex failed with " << result << std::endl; +#endif + return result; + } + return result; } -ReturnValue_t GlobalConfigHandler::getConfigFileValue(){ +template ReturnValue_t GlobalConfigHandler::insertConfigFileValue(std::string key, T data){ ReturnValue_t result = RETURN_OK; - return result; -} -ReturnValue_t GlobalConfigHandler::insertConfigFileValue(){ - ReturnValue_t result = RETURN_OK; - return result; + ReturnValue_t resultInsert = RETURN_OK; + + result=lockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::insertConfigFileValue lock mutex failed with " << result << std::endl; +#endif + return result; + } + + resultInsert=insertValue(key, data);//Should never fail + if(resultInsert!=RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::insertConfigFileValue insert failed with " << result << std::endl; +#endif + } + + result=unlockConfigFile(); + if (result!= RETURN_OK){ +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::insertConfigFileValue unlock mutex failed with " << result << std::endl; +#endif + return result; + } + + return resultInsert; } ReturnValue_t GlobalConfigHandler::resetConfigFileValues(){ ReturnValue_t result = RETURN_OK; diff --git a/bsp_hosted/GlobalConfigHandler.h b/bsp_hosted/GlobalConfigHandler.h index 9db594a3..5a9d0c30 100644 --- a/bsp_hosted/GlobalConfigHandler.h +++ b/bsp_hosted/GlobalConfigHandler.h @@ -44,9 +44,9 @@ public: ReturnValue_t lockConfigFile(); ReturnValue_t unlockConfigFile(); - ReturnValue_t setConfigFileValue(); - ReturnValue_t getConfigFileValue(); - ReturnValue_t insertConfigFileValue(); + template ReturnValue_t setConfigFileValue(std::string key, T data); + template ReturnValue_t getConfigFileValue(std::string key, T& data); + template ReturnValue_t insertConfigFileValue(std::string key, T data); ReturnValue_t resetConfigFileValues(); ReturnValue_t WriteConfigFile(); ReturnValue_t ReadConfigFile(); -- 2.43.0 From 7cd048b03ff95af2451dd43dba488eaa3e478310 Mon Sep 17 00:00:00 2001 From: petriVM18 Date: Wed, 8 Jun 2022 09:18:17 +0200 Subject: [PATCH 04/23] Added events for failure of config file handler functions --- bsp_hosted/GlobalConfigHandler.cpp | 20 +++++++++++++++++--- bsp_hosted/GlobalConfigHandler.h | 13 ++++++++++++- common/config/commonSubsystemIds.h | 1 + 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/bsp_hosted/GlobalConfigHandler.cpp b/bsp_hosted/GlobalConfigHandler.cpp index 470eba4c..93fcad10 100644 --- a/bsp_hosted/GlobalConfigHandler.cpp +++ b/bsp_hosted/GlobalConfigHandler.cpp @@ -58,9 +58,6 @@ ReturnValue_t GlobalConfigHandler::unlockConfigFile(){ return result; } -//TBD for set/get/insert: Mutx lock, set/get/insert, Mutex unlock -//Use template functions for different data types -//Trigger Event, if set/get/insert/write/Read fails template ReturnValue_t GlobalConfigHandler::setConfigFileValue(std::string key, T data){ ReturnValue_t result = RETURN_OK; ReturnValue_t resultSet = RETURN_OK; @@ -75,6 +72,7 @@ template ReturnValue_t GlobalConfigHandler::setConfigFileValue(std: resultSet=setValue(key, 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; #endif @@ -105,6 +103,7 @@ template ReturnValue_t GlobalConfigHandler::getConfigFileValue(std: resultGet=getValue(key, data); 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; #endif @@ -133,6 +132,7 @@ template ReturnValue_t GlobalConfigHandler::insertConfigFileValue(s resultInsert=insertValue(key, data);//Should never fail if(resultInsert!=RETURN_OK){ + triggerEvent(INSERT_CONFIGFILEVALUE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::insertConfigFileValue insert failed with " << result << std::endl; #endif @@ -181,6 +181,7 @@ ReturnValue_t GlobalConfigHandler::WriteConfigFile(){ resultWrite =writeJsonFile(); 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; #endif @@ -209,6 +210,7 @@ ReturnValue_t GlobalConfigHandler::ReadConfigFile(){ resultRead=readJsonFile(); 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; #endif @@ -230,3 +232,15 @@ ReturnValue_t GlobalConfigHandler::ResetConfigFile(){ result =writeJsonFile(); return result; } + + +ReturnValue_t GlobalConfigHandler::setConfigFileName(std::string configFileName){ + ReturnValue_t result = RETURN_OK; + setFullName(configFileName); + result=ResetConfigFile(); + return result; +} +std::string GlobalConfigHandler::getConfigFileName(){ + + return getFullName(); +} diff --git a/bsp_hosted/GlobalConfigHandler.h b/bsp_hosted/GlobalConfigHandler.h index 5a9d0c30..31652f4b 100644 --- a/bsp_hosted/GlobalConfigHandler.h +++ b/bsp_hosted/GlobalConfigHandler.h @@ -39,6 +39,15 @@ class GlobalConfigHandler: public SystemObject, public ExecutableObjectIF, publi public: GlobalConfigHandler(object_id_t objectId, std::string configFilePath); virtual ~GlobalConfigHandler(); + + static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CONFIGHANDLER; + + static constexpr Event SET_CONFIGFILEVALUE_FAILED = MAKE_EVENT(1, severity::MEDIUM); + static constexpr Event GET_CONFIGFILEVALUE_FAILED = MAKE_EVENT(2, severity::MEDIUM); + static constexpr Event INSERT_CONFIGFILEVALUE_FAILED = MAKE_EVENT(3, severity::MEDIUM); + static constexpr Event WRITE_CONFIGFILE_FAILED = MAKE_EVENT(4, severity::MEDIUM); + static constexpr Event READ_CONFIGFILE_FAILED = MAKE_EVENT(5, severity::MEDIUM); + ReturnValue_t performOperation(uint8_t operationCode); ReturnValue_t initialize(); @@ -52,8 +61,10 @@ public: ReturnValue_t ReadConfigFile(); ReturnValue_t ResetConfigFile(); + ReturnValue_t setConfigFileName(std::string configFileName); + std::string getConfigFileName(); + private: - std::string configFilePath; static MutexIF* configLock ; diff --git a/common/config/commonSubsystemIds.h b/common/config/commonSubsystemIds.h index c3e6c5a2..ef0ce7c2 100644 --- a/common/config/commonSubsystemIds.h +++ b/common/config/commonSubsystemIds.h @@ -31,6 +31,7 @@ enum: uint8_t { PDU2_HANDLER = 134, ACU_HANDLER = 135, SYRLINKS = 136, + CONFIGHANDLER=137, COMMON_SUBSYSTEM_ID_END }; } -- 2.43.0 From 8b6992df6d7c1d3783b873d3af8a517330437357 Mon Sep 17 00:00:00 2001 From: petriVM18 Date: Wed, 8 Jun 2022 11:08:19 +0200 Subject: [PATCH 05/23] Added parameter interface to config file handler --- bsp_hosted/GlobalConfigHandler.cpp | 113 ++++++++++++++++++++++++++++- bsp_hosted/GlobalConfigHandler.h | 34 ++++++++- 2 files changed, 143 insertions(+), 4 deletions(-) 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_ */ -- 2.43.0 From 61257dfdd2988f51016899d52216791f8597046f Mon Sep 17 00:00:00 2001 From: petriVM18 Date: Wed, 8 Jun 2022 12:53:41 +0200 Subject: [PATCH 06/23] Minor refactoring config file handler --- bsp_hosted/GlobalConfigHandler.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bsp_hosted/GlobalConfigHandler.cpp b/bsp_hosted/GlobalConfigHandler.cpp index a2c8ff56..7a995aa3 100644 --- a/bsp_hosted/GlobalConfigHandler.cpp +++ b/bsp_hosted/GlobalConfigHandler.cpp @@ -81,11 +81,18 @@ void GlobalConfigHandler::readCommandQueue(){ if (result == RETURN_OK) { return; } + + result = actionHelper.handleActionMessage(&command); + if (result == HasReturnvaluesIF::RETURN_OK) { + sif::debug<<"GlobalConfigHandler::readCommandQueue handleActionMessage success"<lockMutex(MutexIF::TimeoutType::WAITING, 0); + result = configLock->lockMutex(MutexIF::TimeoutType::WAITING, 10); return result; } ReturnValue_t GlobalConfigHandler::unlockConfigFile(){ @@ -353,5 +360,6 @@ ReturnValue_t GlobalConfigHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, const uint8_t* data, size_t size) { + //Currently, no commands are used return RETURN_FAILED; } -- 2.43.0 From d9060734b05dd29cf2f0849040bdb2506789f968 Mon Sep 17 00:00:00 2001 From: petriVM18 Date: Tue, 5 Jul 2022 12:57:50 +0200 Subject: [PATCH 07/23] Removed insert function in config handler, not needed. Added more tests for config handler --- mission/utility/GlobalConfigFileDefinitions.h | 23 ++++ mission/utility/GlobalConfigHandler.cpp | 103 ++---------------- mission/utility/GlobalConfigHandler.h | 53 ++++----- unittest/controller/testConfigFileHandler.cpp | 44 +++++++- 4 files changed, 95 insertions(+), 128 deletions(-) create mode 100644 mission/utility/GlobalConfigFileDefinitions.h diff --git a/mission/utility/GlobalConfigFileDefinitions.h b/mission/utility/GlobalConfigFileDefinitions.h new file mode 100644 index 00000000..7a48c095 --- /dev/null +++ b/mission/utility/GlobalConfigFileDefinitions.h @@ -0,0 +1,23 @@ +/* + * GlobalConfigFileDefinitions.h + * + * Created on: July 05, 2022 + * Author: Jona Petri (IRS) + */ + +#ifndef MISSION_UTILITY_GLOBALCONFIGFILEDEFINITIONS_H_ +#define MISSION_UTILITY_GLOBALCONFIGFILEDEFINITIONS_H_ + + +static constexpr double PARAM0_DEFAULT = 5.0; +static constexpr int PARAM1_DEFAULT = 905; + +enum ParamIds : uint8_t { + PARAM0 = 0, + PARAM1 = 1, + +}; + + + +#endif /* MISSION_UTILITY_GLOBALCONFIGFILEDEFINITIONS_H_ */ diff --git a/mission/utility/GlobalConfigHandler.cpp b/mission/utility/GlobalConfigHandler.cpp index 109fbfa6..c76af5d1 100644 --- a/mission/utility/GlobalConfigHandler.cpp +++ b/mission/utility/GlobalConfigHandler.cpp @@ -2,7 +2,7 @@ * GlobalConfigHandler.cpp * * Created on: May 3, 2022 - * Author: metobs + * Author: Jona Petri (IRS) */ #include "GlobalConfigHandler.h" @@ -11,6 +11,7 @@ #include #include + MutexIF* GlobalConfigHandler::configLock = nullptr; GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath): SystemObject(objectId), @@ -73,7 +74,7 @@ ReturnValue_t GlobalConfigHandler::unlockConfigFile(){ return result; } -template ReturnValue_t GlobalConfigHandler::setConfigFileValue(std::string key, T data){ +template ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data){ ReturnValue_t result = RETURN_OK; ReturnValue_t resultSet = RETURN_OK; @@ -85,7 +86,7 @@ template ReturnValue_t GlobalConfigHandler::setConfigFileValue(std: return result; } - resultSet=setValue(key, data); + resultSet=setValue(PARAM_KEY_MAP[paramID], data); if(resultSet!=RETURN_OK){ triggerEvent(SET_CONFIGFILEVALUE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 @@ -104,7 +105,7 @@ template ReturnValue_t GlobalConfigHandler::setConfigFileValue(std: return resultSet; } -template ReturnValue_t GlobalConfigHandler::getConfigFileValue(std::string key, T& data){ +template ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, T& data){ ReturnValue_t result = RETURN_OK; ReturnValue_t resultGet = RETURN_OK; @@ -116,7 +117,7 @@ template ReturnValue_t GlobalConfigHandler::getConfigFileValue(std: return result; } - resultGet=getValue(key, data); + resultGet=getValue(PARAM_KEY_MAP[paramID], data); if (resultGet!= RETURN_OK){ triggerEvent(GET_CONFIGFILEVALUE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 @@ -133,36 +134,7 @@ template ReturnValue_t GlobalConfigHandler::getConfigFileValue(std: return result; } -template ReturnValue_t GlobalConfigHandler::insertConfigFileValue(std::string key, T data){ - ReturnValue_t result = RETURN_OK; - ReturnValue_t resultInsert = RETURN_OK; - result=lockConfigFile(); - if (result!= RETURN_OK){ -#if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::insertConfigFileValue lock mutex failed with " << result << std::endl; -#endif - return result; - } - - resultInsert=insertValue(key, data);//Should never fail - if(resultInsert!=RETURN_OK){ - triggerEvent(INSERT_CONFIGFILEVALUE_FAILED, 0, 0); -#if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::insertConfigFileValue insert failed with " << result << std::endl; -#endif - } - - result=unlockConfigFile(); - if (result!= RETURN_OK){ -#if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::insertConfigFileValue unlock mutex failed with " << result << std::endl; -#endif - return result; - } - - return resultInsert; -} ReturnValue_t GlobalConfigHandler::resetConfigFileValues(){ ReturnValue_t result = RETURN_OK; result=lockConfigFile(); @@ -260,65 +232,10 @@ 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 - - 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; - } - - return WriteConfigFile(); -} +template ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, double& data); +template ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, int32_t& data); +template ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, double data); +template ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, int32_t data); diff --git a/mission/utility/GlobalConfigHandler.h b/mission/utility/GlobalConfigHandler.h index 14e20b28..7869aaf0 100644 --- a/mission/utility/GlobalConfigHandler.h +++ b/mission/utility/GlobalConfigHandler.h @@ -2,11 +2,11 @@ * GlobalConfigHandler.h * * Created on: May 3, 2022 - * Author: metobs + * Author: Jona Petri (IRS) */ -#ifndef BSP_LINUX_GLOBALCONFIGHANDLER_H_ -#define BSP_LINUX_GLOBALCONFIGHANDLER_H_ +#ifndef MISSION_UTILITY_GLOBALCONFIGHANDLER_H_ +#define MISSION_UTILITY_GLOBALCONFIGHANDLER_H_ #include #include @@ -21,14 +21,7 @@ #include #include -static constexpr double PARAM0_DEFAULT = 5.0; -static constexpr int PARAM1_DEFAULT = 905; - -enum ParamIds : uint8_t { - PARAM0 = 0, - PARAM1 = 1, - -}; +#include "GlobalConfigFileDefinitions.h" static std::map PARAM_KEY_MAP = { {PARAM0, "Parameter0"}, @@ -58,34 +51,26 @@ public: ReturnValue_t initialize(); - ReturnValue_t lockConfigFile(); - ReturnValue_t unlockConfigFile(); - template ReturnValue_t setConfigFileValue(std::string key, T data); - template ReturnValue_t getConfigFileValue(std::string key, T& data); - template ReturnValue_t insertConfigFileValue(std::string key, T data); + + template ReturnValue_t setConfigFileValue(ParamIds paramID, T data); + template ReturnValue_t getConfigFileValue(ParamIds paramID, T& data); + ReturnValue_t resetConfigFileValues(); ReturnValue_t WriteConfigFile(); + std::string getConfigFileName(); + +private: + static MutexIF* configLock ; + + ReturnValue_t lockConfigFile(); + ReturnValue_t unlockConfigFile(); + + + ReturnValue_t ReadConfigFile(); ReturnValue_t ResetConfigFile(); 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) ; - - -private: - static MutexIF* configLock ; MessageQueueIF* commandQueue; @@ -94,4 +79,4 @@ private: }; -#endif /* BSP_LINUX_GLOBALCONFIGHANDLER_H_ */ +#endif /* MISSION_UTILITY_GLOBALCONFIGHANDLER_H_ */ diff --git a/unittest/controller/testConfigFileHandler.cpp b/unittest/controller/testConfigFileHandler.cpp index a76a9efe..30365863 100644 --- a/unittest/controller/testConfigFileHandler.cpp +++ b/unittest/controller/testConfigFileHandler.cpp @@ -11,9 +11,51 @@ TEST_CASE("Configfile Handler", "[ConfigHandler]") { - GlobalConfigHandler confighandler= GlobalConfigHandler(objects::CONFIG_TEST,"JSON.config"); sif::debug<<"Testcase config file handler"< Date: Tue, 5 Jul 2022 14:56:31 +0200 Subject: [PATCH 08/23] Code refactoring and bug fixes for config file handler. Added new test cases for config file handler --- mission/utility/GlobalConfigFileDefinitions.h | 2 +- mission/utility/GlobalConfigHandler.cpp | 32 +++++++++++++++---- mission/utility/GlobalConfigHandler.h | 10 +++--- unittest/controller/testConfigFileHandler.cpp | 10 ++++-- 4 files changed, 38 insertions(+), 16 deletions(-) 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"< Date: Wed, 13 Jul 2022 09:26:22 +0200 Subject: [PATCH 09/23] Removed obsolete stuff --- bsp_hosted/InitMission.cpp | 8 -------- bsp_hosted/ObjectFactory.cpp | 3 +-- bsp_hosted/fsfwconfig/objects/systemObjectList.h | 1 - common/config/commonSubsystemIds.h | 1 - linux/fsfwconfig/objects/systemObjectList.h | 1 - 5 files changed, 1 insertion(+), 13 deletions(-) diff --git a/bsp_hosted/InitMission.cpp b/bsp_hosted/InitMission.cpp index 0d40cbd7..3a89098b 100644 --- a/bsp_hosted/InitMission.cpp +++ b/bsp_hosted/InitMission.cpp @@ -139,13 +139,6 @@ void initmission::initTasks() { } #endif /* OBSW_ADD_TEST_CODE == 1 */ - PeriodicTaskIF* configTask = factory->createPeriodicTask( - "CONFIG_TASK", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc); - - result = configTask->addComponent(objects::CONFIG_TEST); - if (result != HasReturnvaluesIF::RETURN_OK) { - initmission::printAddObjectError("CONFIG_TASK", objects::CONFIG_TEST); - } sif::info << "Starting tasks.." << std::endl; @@ -158,7 +151,6 @@ void initmission::initTasks() { pusHighPrio->startTask(); pusMedPrio->startTask(); pusLowPrio->startTask(); - configTask->startTask(); #if OBSW_ADD_TEST_CODE == 1 testTask->startTask(); diff --git a/bsp_hosted/ObjectFactory.cpp b/bsp_hosted/ObjectFactory.cpp index ec668cd6..12b30c04 100644 --- a/bsp_hosted/ObjectFactory.cpp +++ b/bsp_hosted/ObjectFactory.cpp @@ -47,5 +47,4 @@ void ObjectFactory::produce(void* args) { ObjectFactory::produceGenericObjects(); new TestTask(objects::TEST_TASK); - new GlobalConfigHandler(objects::CONFIG_TEST,"/path/to/JSON.config"); -} + } diff --git a/bsp_hosted/fsfwconfig/objects/systemObjectList.h b/bsp_hosted/fsfwconfig/objects/systemObjectList.h index 8eddfc4f..91bd2bed 100644 --- a/bsp_hosted/fsfwconfig/objects/systemObjectList.h +++ b/bsp_hosted/fsfwconfig/objects/systemObjectList.h @@ -21,7 +21,6 @@ enum sourceObjects : uint32_t { /* Test Task */ TEST_TASK = 0x42694269, - CONFIG_TEST = 0x42694270, DUMMY_INTERFACE = 0xCAFECAFE, DUMMY_HANDLER = 0x4400AFFE, diff --git a/common/config/commonSubsystemIds.h b/common/config/commonSubsystemIds.h index a56db7db..222325ac 100644 --- a/common/config/commonSubsystemIds.h +++ b/common/config/commonSubsystemIds.h @@ -33,7 +33,6 @@ enum : uint8_t { ACU_HANDLER = 135, PLOC_SUPV_HELPER = 136, SYRLINKS = 137, - CONFIGHANDLER=138, COMMON_SUBSYSTEM_ID_END }; diff --git a/linux/fsfwconfig/objects/systemObjectList.h b/linux/fsfwconfig/objects/systemObjectList.h index 2463837d..28c87d3c 100644 --- a/linux/fsfwconfig/objects/systemObjectList.h +++ b/linux/fsfwconfig/objects/systemObjectList.h @@ -54,7 +54,6 @@ enum sourceObjects : uint32_t { /* 0x54 ('T') for test handlers */ TEST_TASK = 0x54694269, - CONFIG_TEST = 0x54694270, LIBGPIOD_TEST = 0x54123456, SPI_TEST = 0x54000010, UART_TEST = 0x54000020, -- 2.43.0 From 3bad503694c6dbf29f5493e9310af756179adefb Mon Sep 17 00:00:00 2001 From: petriVM18 Date: Wed, 13 Jul 2022 09:34:27 +0200 Subject: [PATCH 10/23] Fixed submodules file --- .gitmodules | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 13fed4d1..ac6824b8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -11,8 +11,11 @@ path = thirdparty/lwgps url = https://github.com/rmspacefish/lwgps.git [submodule "generators/fsfwgen"] - path = generators/fsfwgen + path = generators/deps/fsfwgen url = https://egit.irs.uni-stuttgart.de/fsfw/fsfw-gen.git +[submodule "thirdparty/arcsec_star_tracker"] + path = thirdparty/arcsec_star_tracker + url = https://egit.irs.uni-stuttgart.de/eive/arcsec_star_tracker.git [submodule "thirdparty/json"] path = thirdparty/json url = https://github.com/nlohmann/json.git -- 2.43.0 From b4bb46726cf35511249638cb2e04c2131bf14ac9 Mon Sep 17 00:00:00 2001 From: petriVM18 Date: Wed, 13 Jul 2022 09:38:42 +0200 Subject: [PATCH 11/23] Changed filesystem include to new version --- mission/devices/devicedefinitions/payloadPcduDefinitions.h | 2 +- mission/memory/NVMParameterBase.cpp | 4 ++-- mission/memory/NVMParameterBase.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mission/devices/devicedefinitions/payloadPcduDefinitions.h b/mission/devices/devicedefinitions/payloadPcduDefinitions.h index c4dc2aa1..ab387fc7 100644 --- a/mission/devices/devicedefinitions/payloadPcduDefinitions.h +++ b/mission/devices/devicedefinitions/payloadPcduDefinitions.h @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include "OBSWConfig.h" diff --git a/mission/memory/NVMParameterBase.cpp b/mission/memory/NVMParameterBase.cpp index 865c561b..78f40525 100644 --- a/mission/memory/NVMParameterBase.cpp +++ b/mission/memory/NVMParameterBase.cpp @@ -8,7 +8,7 @@ NVMParameterBase::NVMParameterBase(std::string fullName) : fullName(fullName) {} ReturnValue_t NVMParameterBase::readJsonFile() { - if (std::experimental::filesystem::exists(fullName)) { + if (std::filesystem::exists(fullName)) { // Read JSON file content into object std::ifstream i(fullName); try { @@ -37,7 +37,7 @@ void NVMParameterBase::setFullName(std::string fullName) { this->fullName = full std::string NVMParameterBase::getFullName() const { return fullName; } -bool NVMParameterBase::getJsonFileExists() { return std::experimental::filesystem::exists(fullName); } +bool NVMParameterBase::getJsonFileExists() { return std::filesystem::exists(fullName); } void NVMParameterBase::printKeys() const { sif::info << "Printing keys for JSON file " << fullName << std::endl; diff --git a/mission/memory/NVMParameterBase.h b/mission/memory/NVMParameterBase.h index 16d9824c..eb839905 100644 --- a/mission/memory/NVMParameterBase.h +++ b/mission/memory/NVMParameterBase.h @@ -1,7 +1,7 @@ #ifndef BSP_Q7S_CORE_NVMPARAMS_NVMPARAMIF_H_ #define BSP_Q7S_CORE_NVMPARAMS_NVMPARAMIF_H_ -#include +#include #include #include -- 2.43.0 From 3ca11b589437300a6b8f649ec33a517c3a9d3558 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 14 Jul 2022 17:35:49 +0200 Subject: [PATCH 12/23] run auto-formatter --- bsp_hosted/CMakeLists.txt | 1 - bsp_hosted/InitMission.cpp | 2 - bsp_hosted/ObjectFactory.cpp | 5 +- bsp_hosted/main.cpp | 4 +- mission/controller/CMakeLists.txt | 2 +- mission/tmtc/CMakeLists.txt | 7 +- mission/utility/CMakeLists.txt | 5 +- mission/utility/GlobalConfigFileDefinitions.h | 3 - mission/utility/GlobalConfigHandler.cpp | 347 +++++++++--------- mission/utility/GlobalConfigHandler.h | 83 +++-- unittest/controller/testConfigFileHandler.cpp | 78 ++-- 11 files changed, 268 insertions(+), 269 deletions(-) diff --git a/bsp_hosted/CMakeLists.txt b/bsp_hosted/CMakeLists.txt index 79383a2e..2804977d 100644 --- a/bsp_hosted/CMakeLists.txt +++ b/bsp_hosted/CMakeLists.txt @@ -1,5 +1,4 @@ target_sources(${OBSW_NAME} PUBLIC InitMission.cpp main.cpp ObjectFactory.cpp) - add_subdirectory(fsfwconfig) add_subdirectory(boardconfig) diff --git a/bsp_hosted/InitMission.cpp b/bsp_hosted/InitMission.cpp index 0200e575..6ec0ed35 100644 --- a/bsp_hosted/InitMission.cpp +++ b/bsp_hosted/InitMission.cpp @@ -173,8 +173,6 @@ void initmission::initTasks() { } #endif /* OBSW_ADD_TEST_CODE == 1 */ - - sif::info << "Starting tasks.." << std::endl; tmTcDistributor->startTask(); tmtcBridgeTask->startTask(); diff --git a/bsp_hosted/ObjectFactory.cpp b/bsp_hosted/ObjectFactory.cpp index 693ec63c..2c3b20d2 100644 --- a/bsp_hosted/ObjectFactory.cpp +++ b/bsp_hosted/ObjectFactory.cpp @@ -26,7 +26,6 @@ #include #endif -#include "mission/utility/GlobalConfigHandler.h" #include #include #include @@ -45,6 +44,8 @@ #include #include +#include "mission/utility/GlobalConfigHandler.h" + void Factory::setStaticFrameworkObjectIds() { PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR; PusServiceBase::packetDestination = objects::TM_FUNNEL; @@ -90,6 +91,4 @@ void ObjectFactory::produce(void* args) { new SusDummy(); new ThermalController(objects::THERMAL_CONTROLLER, objects::NO_OBJECT); new TestTask(objects::TEST_TASK); - } - diff --git a/bsp_hosted/main.cpp b/bsp_hosted/main.cpp index 50dc582f..e493c1c9 100644 --- a/bsp_hosted/main.cpp +++ b/bsp_hosted/main.cpp @@ -31,7 +31,9 @@ int main(void) { << "v" << common::OBSW_VERSION << " | FSFW v" << fsfw::FSFW_VERSION << " --" << std::endl; std::cout << "-- " << __DATE__ << " " << __TIME__ << " --" << std::endl; - std::cout << "-- " <<" BSP HOSTED"<< " --" << std::endl; + std::cout << "-- " + << " BSP HOSTED" + << " --" << std::endl; initmission::initMission(); diff --git a/mission/controller/CMakeLists.txt b/mission/controller/CMakeLists.txt index 816a560a..8ecdb1a0 100644 --- a/mission/controller/CMakeLists.txt +++ b/mission/controller/CMakeLists.txt @@ -1,3 +1,3 @@ if(TGT_BSP MATCHES "arm/q7s" OR TGT_BSP MATCHES "") - target_sources(${LIB_EIVE_MISSION} PRIVATE ThermalController.cpp) + target_sources(${LIB_EIVE_MISSION} PRIVATE ThermalController.cpp) endif() diff --git a/mission/tmtc/CMakeLists.txt b/mission/tmtc/CMakeLists.txt index a952629a..0a931d0f 100644 --- a/mission/tmtc/CMakeLists.txt +++ b/mission/tmtc/CMakeLists.txt @@ -1,5 +1,2 @@ -target_sources(${LIB_EIVE_MISSION} PRIVATE - CCSDSHandler.cpp - VirtualChannel.cpp - TmFunnel.cpp -) +target_sources(${LIB_EIVE_MISSION} PRIVATE CCSDSHandler.cpp VirtualChannel.cpp + TmFunnel.cpp) diff --git a/mission/utility/CMakeLists.txt b/mission/utility/CMakeLists.txt index 6e862138..09baae92 100644 --- a/mission/utility/CMakeLists.txt +++ b/mission/utility/CMakeLists.txt @@ -1,2 +1,3 @@ -target_sources(${LIB_EIVE_MISSION} PRIVATE TmFunnel.cpp Timestamp.cpp - ProgressPrinter.cpp Filenaming.cpp GlobalConfigHandler.cpp) +target_sources( + ${LIB_EIVE_MISSION} PRIVATE TmFunnel.cpp Timestamp.cpp ProgressPrinter.cpp + Filenaming.cpp GlobalConfigHandler.cpp) diff --git a/mission/utility/GlobalConfigFileDefinitions.h b/mission/utility/GlobalConfigFileDefinitions.h index b4f5f394..2e7d133a 100644 --- a/mission/utility/GlobalConfigFileDefinitions.h +++ b/mission/utility/GlobalConfigFileDefinitions.h @@ -8,7 +8,6 @@ #ifndef MISSION_UTILITY_GLOBALCONFIGFILEDEFINITIONS_H_ #define MISSION_UTILITY_GLOBALCONFIGFILEDEFINITIONS_H_ - static constexpr double PARAM0_DEFAULT = 5.0; static constexpr int PARAM1_DEFAULT = 905; @@ -18,6 +17,4 @@ enum ParamIds : uint8_t { PARAM2 = 2, }; - - #endif /* MISSION_UTILITY_GLOBALCONFIGFILEDEFINITIONS_H_ */ diff --git a/mission/utility/GlobalConfigHandler.cpp b/mission/utility/GlobalConfigHandler.cpp index df0b4566..36d1bafa 100644 --- a/mission/utility/GlobalConfigHandler.cpp +++ b/mission/utility/GlobalConfigHandler.cpp @@ -6,256 +6,263 @@ */ #include "GlobalConfigHandler.h" -#include -#include "fsfw/serviceinterface/ServiceInterface.h" + #include +#include #include +#include "fsfw/serviceinterface/ServiceInterface.h" MutexIF* GlobalConfigHandler::configLock = nullptr; -GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath): - SystemObject(objectId), - NVMParameterBase(configFilePath), - commandQueue(QueueFactory::instance()->createMessageQueue(20)) - { - if (configLock == nullptr) { - configLock = MutexFactory::instance()->createMutex(); - } - +GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath) + : SystemObject(objectId), + NVMParameterBase(configFilePath), + commandQueue(QueueFactory::instance()->createMessageQueue(20)) { + if (configLock == nullptr) { + configLock = MutexFactory::instance()->createMutex(); + } } -ReturnValue_t GlobalConfigHandler::initialize(){ - - ReturnValue_t result = SystemObject::initialize(); - if (result != RETURN_OK) { +ReturnValue_t GlobalConfigHandler::initialize() { + ReturnValue_t result = SystemObject::initialize(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::initialize: SystemObject::initialize() failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::initialize: SystemObject::initialize() failed with " + << result << std::endl; #endif - return result; - } + return result; + } - - result = ReadConfigFile(); - if(result!=RETURN_OK){ + result = ReadConfigFile(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::initialize: Creating JSON file at " << getFullName() << std::endl; + sif::info << "GlobalConfigHandler::initialize: Creating JSON file at " << getFullName() + << std::endl; #endif - result=ResetConfigFile(); - if (result != RETURN_OK) { - return result; - } - } - + result = ResetConfigFile(); + if (result != RETURN_OK) { + return result; + } + } #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::initialize success " << std::endl; + sif::info << "GlobalConfigHandler::initialize success " << std::endl; #endif - return result; -} -GlobalConfigHandler::~GlobalConfigHandler() { - + return result; } +GlobalConfigHandler::~GlobalConfigHandler() {} ReturnValue_t GlobalConfigHandler::performOperation(uint8_t operationCode) { ReturnValue_t result = RETURN_OK; - sif::debug<<"GlobalConfigHandler::performOperation"<lockMutex(MutexIF::TimeoutType::WAITING, 10); - return result; -} -ReturnValue_t GlobalConfigHandler::unlockConfigFile(){ +ReturnValue_t GlobalConfigHandler::lockConfigFile() { ReturnValue_t result = RETURN_OK; - result=configLock->unlockMutex(); + result = configLock->lockMutex(MutexIF::TimeoutType::WAITING, 10); + return result; +} +ReturnValue_t GlobalConfigHandler::unlockConfigFile() { + ReturnValue_t result = RETURN_OK; + result = configLock->unlockMutex(); return result; } -template ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data){ - ReturnValue_t result = RETURN_OK; - ReturnValue_t resultSet = RETURN_OK; +template +ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data) { + ReturnValue_t result = RETURN_OK; + ReturnValue_t resultSet = RETURN_OK; - result=lockConfigFile(); - if (result!= RETURN_OK){ + result = lockConfigFile(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::setConfigFileValue lock mutex failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::setConfigFileValue lock mutex failed with " << result + << std::endl; #endif - return result; - } + return result; + } - std:: string paramString; - paramString=PARAM_KEY_MAP[paramID]; + 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) { + // 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; + sif::info << "GlobalConfigHandler::setConfigFileValue ParamId " << PARAM_KEY_MAP[paramID] + << " not found!" << std::endl; #endif - triggerEvent(SET_CONFIGFILEVALUE_FAILED, 1, 0); - return RETURN_FAILED; - } + 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); + 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 " << resultSet << std::endl; + sif::info << "GlobalConfigHandler::setConfigFileValue set json failed with " << resultSet + << std::endl; #endif - } + } - - result=unlockConfigFile(); - if (result!= RETURN_OK){ + result = unlockConfigFile(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::setConfigFileValue unlock mutex failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::setConfigFileValue unlock mutex failed with " << result + << std::endl; #endif - return result; - } + return result; + } - return resultSet; + return resultSet; } -template ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, T& data){ - ReturnValue_t result = RETURN_OK; - ReturnValue_t resultGet = RETURN_OK; +template +ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, T& data) { + ReturnValue_t result = RETURN_OK; + ReturnValue_t resultGet = RETURN_OK; - result=lockConfigFile(); - if (result!= RETURN_OK){ + result = lockConfigFile(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::getConfigFileValue lock mutex failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::getConfigFileValue lock mutex failed with " << result + << std::endl; #endif - return result; - } + return result; + } - resultGet=getValue(PARAM_KEY_MAP[paramID], data); - if (resultGet!= RETURN_OK){ - triggerEvent(GET_CONFIGFILEVALUE_FAILED, 0, 0); + resultGet = getValue(PARAM_KEY_MAP[paramID], data); + if (resultGet != RETURN_OK) { + triggerEvent(GET_CONFIGFILEVALUE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::getConfigFileValue getValue failed with " << resultGet << std::endl; + sif::info << "GlobalConfigHandler::getConfigFileValue getValue failed with " << resultGet + << std::endl; #endif - } - result=unlockConfigFile(); - if (result!= RETURN_OK){ + } + result = unlockConfigFile(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::getConfigFileValue unlock mutex failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::getConfigFileValue unlock mutex failed with " << result + << std::endl; #endif - return result; - } + return result; + } - return resultGet; + return resultGet; } -ReturnValue_t GlobalConfigHandler::resetConfigFileValues(){ - ReturnValue_t result = RETURN_OK; - result=lockConfigFile(); - if (result!= RETURN_OK){ +ReturnValue_t GlobalConfigHandler::resetConfigFileValues() { + ReturnValue_t result = RETURN_OK; + result = lockConfigFile(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::resetConfigFileValues lock mutex failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::resetConfigFileValues lock mutex failed with " << result + << std::endl; #endif - return result; - } - insertValue(PARAM_KEY_MAP[PARAM0], PARAM0_DEFAULT); - insertValue(PARAM_KEY_MAP[PARAM1], PARAM1_DEFAULT); + return result; + } + insertValue(PARAM_KEY_MAP[PARAM0], PARAM0_DEFAULT); + insertValue(PARAM_KEY_MAP[PARAM1], PARAM1_DEFAULT); - - result=unlockConfigFile(); - if (result!= RETURN_OK){ + result = unlockConfigFile(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::resetConfigFileValues unlock mutex failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::resetConfigFileValues unlock mutex failed with " << result + << std::endl; #endif - return result; - } - return result; + return result; + } + return result; } -ReturnValue_t GlobalConfigHandler::WriteConfigFile(){ - ReturnValue_t result = RETURN_OK; - ReturnValue_t resultWrite = RETURN_OK; - result=lockConfigFile(); - if (result!= RETURN_OK){ +ReturnValue_t GlobalConfigHandler::WriteConfigFile() { + ReturnValue_t result = RETURN_OK; + ReturnValue_t resultWrite = RETURN_OK; + result = lockConfigFile(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::WriteConfigFile lock mutex failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::WriteConfigFile lock mutex failed with " << result + << std::endl; #endif - return result; - } + return result; + } - resultWrite =writeJsonFile(); - if(resultWrite!=RETURN_OK){ - triggerEvent(WRITE_CONFIGFILE_FAILED, 0, 0); + resultWrite = writeJsonFile(); + if (resultWrite != RETURN_OK) { + triggerEvent(WRITE_CONFIGFILE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::WriteConfigFile write json failed with " << resultWrite << std::endl; + sif::info << "GlobalConfigHandler::WriteConfigFile write json failed with " << resultWrite + << std::endl; #endif - } + } - - result=unlockConfigFile(); - if (result!= RETURN_OK){ + result = unlockConfigFile(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::WriteConfigFile unlock mutex failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::WriteConfigFile unlock mutex failed with " << result + << std::endl; #endif - return result; - } - return resultWrite; + return result; + } + return resultWrite; } -ReturnValue_t GlobalConfigHandler::ReadConfigFile(){ - ReturnValue_t result = RETURN_OK; - ReturnValue_t resultRead = RETURN_OK; - result=lockConfigFile(); - if (result!= RETURN_OK){ +ReturnValue_t GlobalConfigHandler::ReadConfigFile() { + ReturnValue_t result = RETURN_OK; + ReturnValue_t resultRead = RETURN_OK; + result = lockConfigFile(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::ReadConfigFile lock mutex failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::ReadConfigFile lock mutex failed with " << result + << std::endl; #endif - return result; - } + return result; + } - resultRead=readJsonFile(); - if(resultRead!=RETURN_OK){ - triggerEvent(READ_CONFIGFILE_FAILED, 0, 0); + resultRead = readJsonFile(); + if (resultRead != RETURN_OK) { + triggerEvent(READ_CONFIGFILE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::ReadConfigFile read json failed with " << resultRead << std::endl; + sif::info << "GlobalConfigHandler::ReadConfigFile read json failed with " << resultRead + << std::endl; #endif - } + } - result=unlockConfigFile(); - if (result!= RETURN_OK){ + result = unlockConfigFile(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::ReadConfigFile unlock mutex failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::ReadConfigFile unlock mutex failed with " << result + << std::endl; #endif - return result; - } + return result; + } - return resultRead; + return resultRead; } -ReturnValue_t GlobalConfigHandler::ResetConfigFile(){ - ReturnValue_t result = RETURN_OK; - result=resetConfigFileValues(); - if (result!= RETURN_OK){ +ReturnValue_t GlobalConfigHandler::ResetConfigFile() { + ReturnValue_t result = RETURN_OK; + result = resetConfigFileValues(); + if (result != RETURN_OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::ResetConfigFile failed with " << result << std::endl; + sif::info << "GlobalConfigHandler::ResetConfigFile failed with " << result << std::endl; #endif - return result; - } - result =writeJsonFile(); - return result; + return result; + } + result = writeJsonFile(); + return result; } - -ReturnValue_t GlobalConfigHandler::setConfigFileName(std::string configFileName){ - ReturnValue_t result = RETURN_OK; - setFullName(configFileName); - result=ResetConfigFile(); - return result; +ReturnValue_t GlobalConfigHandler::setConfigFileName(std::string configFileName) { + ReturnValue_t result = RETURN_OK; + setFullName(configFileName); + result = ResetConfigFile(); + return result; } -std::string GlobalConfigHandler::getConfigFileName(){ +std::string GlobalConfigHandler::getConfigFileName() { return getFullName(); } - return getFullName(); -} - - -template ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, double& data); -template ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, int32_t& data); - -template ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, double data); -template ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, int32_t data); +template ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, + double& data); +template ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, + int32_t& data); +template ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, + double data); +template ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, + int32_t data); diff --git a/mission/utility/GlobalConfigHandler.h b/mission/utility/GlobalConfigHandler.h index cbb65d20..18a6ec60 100644 --- a/mission/utility/GlobalConfigHandler.h +++ b/mission/utility/GlobalConfigHandler.h @@ -8,73 +8,72 @@ #ifndef MISSION_UTILITY_GLOBALCONFIGHANDLER_H_ #define MISSION_UTILITY_GLOBALCONFIGHANDLER_H_ +#include +#include #include +#include #include #include + #include #include -#include -#include "mission/memory/NVMParameterBase.h" + +#include "GlobalConfigFileDefinitions.h" #include "OBSWConfig.h" #include "fsfw/parameters/HasParametersIF.h" #include "fsfw/parameters/ParameterHelper.h" -#include -#include - -#include "GlobalConfigFileDefinitions.h" +#include "mission/memory/NVMParameterBase.h" static std::map PARAM_KEY_MAP = { - {PARAM0, "Parameter0"}, - {PARAM1, "Parameter1"}, + {PARAM0, "Parameter0"}, + {PARAM1, "Parameter1"}, }; /* * Idea: This class is intended to be used as a subclass for the Core Controller. - * 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. + * 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{ -public: - GlobalConfigHandler(object_id_t objectId, std::string configFilePath); - virtual ~GlobalConfigHandler(); +class GlobalConfigHandler : public SystemObject, + public ExecutableObjectIF, + public NVMParameterBase { + public: + GlobalConfigHandler(object_id_t objectId, std::string configFilePath); + virtual ~GlobalConfigHandler(); - static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CONFIGHANDLER; + static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CONFIGHANDLER; - static constexpr Event SET_CONFIGFILEVALUE_FAILED = MAKE_EVENT(1, severity::MEDIUM); - static constexpr Event GET_CONFIGFILEVALUE_FAILED = MAKE_EVENT(2, severity::MEDIUM); - static constexpr Event INSERT_CONFIGFILEVALUE_FAILED = MAKE_EVENT(3, severity::MEDIUM); - static constexpr Event WRITE_CONFIGFILE_FAILED = MAKE_EVENT(4, severity::MEDIUM); - static constexpr Event READ_CONFIGFILE_FAILED = MAKE_EVENT(5, severity::MEDIUM); + static constexpr Event SET_CONFIGFILEVALUE_FAILED = MAKE_EVENT(1, severity::MEDIUM); + static constexpr Event GET_CONFIGFILEVALUE_FAILED = MAKE_EVENT(2, severity::MEDIUM); + static constexpr Event INSERT_CONFIGFILEVALUE_FAILED = MAKE_EVENT(3, severity::MEDIUM); + static constexpr Event WRITE_CONFIGFILE_FAILED = MAKE_EVENT(4, severity::MEDIUM); + static constexpr Event READ_CONFIGFILE_FAILED = MAKE_EVENT(5, severity::MEDIUM); - ReturnValue_t performOperation(uint8_t operationCode); + ReturnValue_t performOperation(uint8_t operationCode); - ReturnValue_t initialize(); + ReturnValue_t initialize(); + template + ReturnValue_t setConfigFileValue(ParamIds paramID, T data); + template + ReturnValue_t getConfigFileValue(ParamIds paramID, T& data); - template ReturnValue_t setConfigFileValue(ParamIds paramID, T data); - template ReturnValue_t getConfigFileValue(ParamIds paramID, T& data); + ReturnValue_t ResetConfigFile(); + ReturnValue_t WriteConfigFile(); + std::string getConfigFileName(); + private: + static MutexIF* configLock; - ReturnValue_t ResetConfigFile(); - ReturnValue_t WriteConfigFile(); - std::string getConfigFileName(); - -private: - static MutexIF* configLock ; - - ReturnValue_t lockConfigFile(); - ReturnValue_t unlockConfigFile(); - ReturnValue_t resetConfigFileValues(); - - ReturnValue_t setConfigFileName(std::string configFileName); - - ReturnValue_t ReadConfigFile(); - - MessageQueueIF* commandQueue; + ReturnValue_t lockConfigFile(); + ReturnValue_t unlockConfigFile(); + ReturnValue_t resetConfigFileValues(); + ReturnValue_t setConfigFileName(std::string configFileName); + ReturnValue_t ReadConfigFile(); + MessageQueueIF* commandQueue; }; #endif /* MISSION_UTILITY_GLOBALCONFIGHANDLER_H_ */ diff --git a/unittest/controller/testConfigFileHandler.cpp b/unittest/controller/testConfigFileHandler.cpp index cbfd24b6..0f994fba 100644 --- a/unittest/controller/testConfigFileHandler.cpp +++ b/unittest/controller/testConfigFileHandler.cpp @@ -1,65 +1,65 @@ #include +#include + #include #include #include #include #include "../testEnvironment.h" -#include TEST_CASE("Configfile Handler", "[ConfigHandler]") { + sif::debug << "Testcase config file handler" << std::endl; + testEnvironment::initialize(); + // Init handler + GlobalConfigHandler confighandler = GlobalConfigHandler(objects::CONFIG_TEST, "JSON.config"); + REQUIRE(confighandler.initialize() == HasReturnvaluesIF::RETURN_OK); - sif::debug<<"Testcase config file handler"< Date: Mon, 8 Aug 2022 17:12:22 +0200 Subject: [PATCH 13/23] re-point tmtc --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 6cb629c3..df4824af 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 6cb629c3c3ef0b109bc973e4b5b89ad176d373b3 +Subproject commit df4824af8da32951185976ef25ec1038e52e7446 -- 2.43.0 From c0157ca506a5df740cc963699326e07dd6cda3f6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 12 Aug 2022 13:09:58 +0200 Subject: [PATCH 14/23] remove etl submodule --- thirdparty/etl | 1 - 1 file changed, 1 deletion(-) delete mode 160000 thirdparty/etl diff --git a/thirdparty/etl b/thirdparty/etl deleted file mode 160000 index 5468eb65..00000000 --- a/thirdparty/etl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5468eb659c8b4ecdb3d08e8b8f0442c5a2549a48 -- 2.43.0 From e6da1824df3e2b36854e844a109a45ca74ba31c6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 12 Aug 2022 13:11:15 +0200 Subject: [PATCH 15/23] something went wrong here --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index ac6824b8..6ddc3978 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,9 +13,6 @@ [submodule "generators/fsfwgen"] path = generators/deps/fsfwgen url = https://egit.irs.uni-stuttgart.de/fsfw/fsfw-gen.git -[submodule "thirdparty/arcsec_star_tracker"] - path = thirdparty/arcsec_star_tracker - url = https://egit.irs.uni-stuttgart.de/eive/arcsec_star_tracker.git [submodule "thirdparty/json"] path = thirdparty/json url = https://github.com/nlohmann/json.git -- 2.43.0 From 2eac346e41cd3ab257337d9a99ee0d1078b79597 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 12 Aug 2022 13:11:34 +0200 Subject: [PATCH 16/23] re-add arcsec submodule --- .gitmodules | 3 +++ thirdparty/arcsec_star_tracker | 1 + 2 files changed, 4 insertions(+) create mode 160000 thirdparty/arcsec_star_tracker diff --git a/.gitmodules b/.gitmodules index 6ddc3978..c1b4332f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,6 @@ [submodule "thirdparty/rapidcsv"] path = thirdparty/rapidcsv url = https://github.com/d99kris/rapidcsv.git +[submodule "thirdparty/arcsec_star_tracker"] + path = thirdparty/arcsec_star_tracker + url = https://egit.irs.uni-stuttgart.de/eive/arcsec_star_tracker.git diff --git a/thirdparty/arcsec_star_tracker b/thirdparty/arcsec_star_tracker new file mode 160000 index 00000000..93e93965 --- /dev/null +++ b/thirdparty/arcsec_star_tracker @@ -0,0 +1 @@ +Subproject commit 93e93965e2c6405170b62c523dea1990db02d2ad -- 2.43.0 From ed6c90b106ea32df7087acfb9fe364bece9351a4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 12 Aug 2022 13:12:58 +0200 Subject: [PATCH 17/23] retain old order --- .gitmodules | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index c1b4332f..ac6824b8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,12 +13,12 @@ [submodule "generators/fsfwgen"] path = generators/deps/fsfwgen url = https://egit.irs.uni-stuttgart.de/fsfw/fsfw-gen.git +[submodule "thirdparty/arcsec_star_tracker"] + path = thirdparty/arcsec_star_tracker + url = https://egit.irs.uni-stuttgart.de/eive/arcsec_star_tracker.git [submodule "thirdparty/json"] path = thirdparty/json url = https://github.com/nlohmann/json.git [submodule "thirdparty/rapidcsv"] path = thirdparty/rapidcsv url = https://github.com/d99kris/rapidcsv.git -[submodule "thirdparty/arcsec_star_tracker"] - path = thirdparty/arcsec_star_tracker - url = https://egit.irs.uni-stuttgart.de/eive/arcsec_star_tracker.git -- 2.43.0 From 79f5077a2522c952f9a377f4c845f753b689098b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 16 Aug 2022 18:46:10 +0200 Subject: [PATCH 18/23] some issues --- mission/utility/CMakeLists.txt | 2 +- tmtc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mission/utility/CMakeLists.txt b/mission/utility/CMakeLists.txt index 09baae92..8a58630d 100644 --- a/mission/utility/CMakeLists.txt +++ b/mission/utility/CMakeLists.txt @@ -1,3 +1,3 @@ target_sources( - ${LIB_EIVE_MISSION} PRIVATE TmFunnel.cpp Timestamp.cpp ProgressPrinter.cpp + ${LIB_EIVE_MISSION} PRIVATE Timestamp.cpp ProgressPrinter.cpp Filenaming.cpp GlobalConfigHandler.cpp) diff --git a/tmtc b/tmtc index 3fa70080..ca9f85de 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 3fa700804e0592db4e9a5667de2a81323cac5dc7 +Subproject commit ca9f85de1b51e29e3c0cccd527d736083e374f7f -- 2.43.0 From 745551479721877d4869edbdc105820d633cbe33 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 17 Aug 2022 09:05:58 +0200 Subject: [PATCH 19/23] it compiles now --- common/config/commonSubsystemIds.h | 1 + 1 file changed, 1 insertion(+) diff --git a/common/config/commonSubsystemIds.h b/common/config/commonSubsystemIds.h index 222325ac..55c55e88 100644 --- a/common/config/commonSubsystemIds.h +++ b/common/config/commonSubsystemIds.h @@ -33,6 +33,7 @@ enum : uint8_t { ACU_HANDLER = 135, PLOC_SUPV_HELPER = 136, SYRLINKS = 137, + CONFIGHANDLER = 138, COMMON_SUBSYSTEM_ID_END }; -- 2.43.0 From 26dc4ba56e53ae49bd657342e040229f2fc8a545 Mon Sep 17 00:00:00 2001 From: Irini Kosmidou Date: Tue, 27 Sep 2022 19:38:35 +0200 Subject: [PATCH 20/23] fixes for compilation --- mission/utility/GlobalConfigHandler.cpp | 66 ++++++++++++------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/mission/utility/GlobalConfigHandler.cpp b/mission/utility/GlobalConfigHandler.cpp index 36d1bafa..fc92714e 100644 --- a/mission/utility/GlobalConfigHandler.cpp +++ b/mission/utility/GlobalConfigHandler.cpp @@ -24,7 +24,7 @@ GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string confi } ReturnValue_t GlobalConfigHandler::initialize() { ReturnValue_t result = SystemObject::initialize(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::initialize: SystemObject::initialize() failed with " << result << std::endl; @@ -33,13 +33,13 @@ ReturnValue_t GlobalConfigHandler::initialize() { } result = ReadConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::initialize: Creating JSON file at " << getFullName() << std::endl; #endif result = ResetConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { return result; } } @@ -52,29 +52,29 @@ ReturnValue_t GlobalConfigHandler::initialize() { GlobalConfigHandler::~GlobalConfigHandler() {} ReturnValue_t GlobalConfigHandler::performOperation(uint8_t operationCode) { - ReturnValue_t result = RETURN_OK; + ReturnValue_t result = returnvalue::OK; sif::debug << "GlobalConfigHandler::performOperation" << std::endl; return result; } ReturnValue_t GlobalConfigHandler::lockConfigFile() { - ReturnValue_t result = RETURN_OK; + ReturnValue_t result = returnvalue::OK; result = configLock->lockMutex(MutexIF::TimeoutType::WAITING, 10); return result; } ReturnValue_t GlobalConfigHandler::unlockConfigFile() { - ReturnValue_t result = RETURN_OK; + ReturnValue_t result = returnvalue::OK; result = configLock->unlockMutex(); return result; } template ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data) { - ReturnValue_t result = RETURN_OK; - ReturnValue_t resultSet = RETURN_OK; + ReturnValue_t result = returnvalue::OK; + ReturnValue_t resultSet = returnvalue::OK; result = lockConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::setConfigFileValue lock mutex failed with " << result << std::endl; @@ -93,11 +93,11 @@ ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data) << " not found!" << std::endl; #endif triggerEvent(SET_CONFIGFILEVALUE_FAILED, 1, 0); - return RETURN_FAILED; + return returnvalue::FAILED; } resultSet = setValue(PARAM_KEY_MAP[paramID], data); - if (resultSet != RETURN_OK) { + if (resultSet != returnvalue::OK) { triggerEvent(SET_CONFIGFILEVALUE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::setConfigFileValue set json failed with " << resultSet @@ -106,7 +106,7 @@ ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data) } result = unlockConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::setConfigFileValue unlock mutex failed with " << result << std::endl; @@ -118,11 +118,11 @@ ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data) } template ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, T& data) { - ReturnValue_t result = RETURN_OK; - ReturnValue_t resultGet = RETURN_OK; + ReturnValue_t result = returnvalue::OK; + ReturnValue_t resultGet = returnvalue::OK; result = lockConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::getConfigFileValue lock mutex failed with " << result << std::endl; @@ -131,7 +131,7 @@ ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, T& data) } resultGet = getValue(PARAM_KEY_MAP[paramID], data); - if (resultGet != RETURN_OK) { + if (resultGet != returnvalue::OK) { triggerEvent(GET_CONFIGFILEVALUE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::getConfigFileValue getValue failed with " << resultGet @@ -139,7 +139,7 @@ ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, T& data) #endif } result = unlockConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::getConfigFileValue unlock mutex failed with " << result << std::endl; @@ -151,9 +151,9 @@ ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, T& data) } ReturnValue_t GlobalConfigHandler::resetConfigFileValues() { - ReturnValue_t result = RETURN_OK; + ReturnValue_t result = returnvalue::OK; result = lockConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::resetConfigFileValues lock mutex failed with " << result << std::endl; @@ -164,7 +164,7 @@ ReturnValue_t GlobalConfigHandler::resetConfigFileValues() { insertValue(PARAM_KEY_MAP[PARAM1], PARAM1_DEFAULT); result = unlockConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::resetConfigFileValues unlock mutex failed with " << result << std::endl; @@ -174,10 +174,10 @@ ReturnValue_t GlobalConfigHandler::resetConfigFileValues() { return result; } ReturnValue_t GlobalConfigHandler::WriteConfigFile() { - ReturnValue_t result = RETURN_OK; - ReturnValue_t resultWrite = RETURN_OK; + ReturnValue_t result = returnvalue::OK; + ReturnValue_t resultWrite = returnvalue::OK; result = lockConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::WriteConfigFile lock mutex failed with " << result << std::endl; @@ -186,7 +186,7 @@ ReturnValue_t GlobalConfigHandler::WriteConfigFile() { } resultWrite = writeJsonFile(); - if (resultWrite != RETURN_OK) { + if (resultWrite != returnvalue::OK) { triggerEvent(WRITE_CONFIGFILE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::WriteConfigFile write json failed with " << resultWrite @@ -195,7 +195,7 @@ ReturnValue_t GlobalConfigHandler::WriteConfigFile() { } result = unlockConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::WriteConfigFile unlock mutex failed with " << result << std::endl; @@ -205,10 +205,10 @@ ReturnValue_t GlobalConfigHandler::WriteConfigFile() { return resultWrite; } ReturnValue_t GlobalConfigHandler::ReadConfigFile() { - ReturnValue_t result = RETURN_OK; - ReturnValue_t resultRead = RETURN_OK; + ReturnValue_t result = returnvalue::OK; + ReturnValue_t resultRead = returnvalue::OK; result = lockConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::ReadConfigFile lock mutex failed with " << result << std::endl; @@ -217,7 +217,7 @@ ReturnValue_t GlobalConfigHandler::ReadConfigFile() { } resultRead = readJsonFile(); - if (resultRead != RETURN_OK) { + if (resultRead != returnvalue::OK) { triggerEvent(READ_CONFIGFILE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::ReadConfigFile read json failed with " << resultRead @@ -226,7 +226,7 @@ ReturnValue_t GlobalConfigHandler::ReadConfigFile() { } result = unlockConfigFile(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::ReadConfigFile unlock mutex failed with " << result << std::endl; @@ -237,9 +237,9 @@ ReturnValue_t GlobalConfigHandler::ReadConfigFile() { return resultRead; } ReturnValue_t GlobalConfigHandler::ResetConfigFile() { - ReturnValue_t result = RETURN_OK; + ReturnValue_t result = returnvalue::OK; result = resetConfigFileValues(); - if (result != RETURN_OK) { + if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::ResetConfigFile failed with " << result << std::endl; #endif @@ -250,7 +250,7 @@ ReturnValue_t GlobalConfigHandler::ResetConfigFile() { } ReturnValue_t GlobalConfigHandler::setConfigFileName(std::string configFileName) { - ReturnValue_t result = RETURN_OK; + ReturnValue_t result = returnvalue::OK; setFullName(configFileName); result = ResetConfigFile(); return result; -- 2.43.0 From 14639635328eaee09bffa1fbcae3412bb8681718 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 29 Sep 2022 13:20:05 +0200 Subject: [PATCH 21/23] unittest builds now --- common/config/commonObjects.h | 1 + linux/obc/PtmeConfig.h | 2 +- mission/devices/SusHandler.h | 3 +- mission/utility/CMakeLists.txt | 5 ++-- mission/utility/GlobalConfigHandler.cpp | 11 +++---- mission/utility/GlobalConfigHandler.h | 2 +- tmtc | 2 +- unittest/controller/testConfigFileHandler.cpp | 30 +++++++++---------- 8 files changed, 29 insertions(+), 27 deletions(-) diff --git a/common/config/commonObjects.h b/common/config/commonObjects.h index e0efbce7..0e69a581 100644 --- a/common/config/commonObjects.h +++ b/common/config/commonObjects.h @@ -20,6 +20,7 @@ enum commonObjects : uint32_t { THERMAL_CONTROLLER = 0x43400001, ACS_CONTROLLER = 0x43000002, CORE_CONTROLLER = 0x43000003, + GLOBAL_JSON_CFG = 0x43000006, /* 0x44 ('D') for device handlers */ MGM_0_LIS3_HANDLER = 0x44120006, diff --git a/linux/obc/PtmeConfig.h b/linux/obc/PtmeConfig.h index aa5c663a..9c5a85af 100644 --- a/linux/obc/PtmeConfig.h +++ b/linux/obc/PtmeConfig.h @@ -4,8 +4,8 @@ #include "AxiPtmeConfig.h" #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/returnvalues/returnvalue.h" -#include "returnvalues/classIds.h" #include "linux/obc/PtmeConfig.h" +#include "returnvalues/classIds.h" /** * @brief Class to configure donwlink specific parameters in the PTME IP core. diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 94673c40..5645c47d 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -4,10 +4,9 @@ #include #include "devicedefinitions/SusDefinitions.h" +#include "events/subsystemIdRanges.h" #include "fsfw/globalfunctions/PeriodicOperationDivider.h" #include "mission/devices/max1227.h" - -#include "events/subsystemIdRanges.h" #include "returnvalues/classIds.h" /** diff --git a/mission/utility/CMakeLists.txt b/mission/utility/CMakeLists.txt index cdda4407..e2459ed1 100644 --- a/mission/utility/CMakeLists.txt +++ b/mission/utility/CMakeLists.txt @@ -1,2 +1,3 @@ -target_sources(${LIB_EIVE_MISSION} PRIVATE Timestamp.cpp ProgressPrinter.cpp - Filenaming.cpp GlobalConfigHandler.cpp) +target_sources( + ${LIB_EIVE_MISSION} PRIVATE Timestamp.cpp ProgressPrinter.cpp Filenaming.cpp + GlobalConfigHandler.cpp) diff --git a/mission/utility/GlobalConfigHandler.cpp b/mission/utility/GlobalConfigHandler.cpp index fc92714e..bb4b3d7d 100644 --- a/mission/utility/GlobalConfigHandler.cpp +++ b/mission/utility/GlobalConfigHandler.cpp @@ -13,13 +13,14 @@ #include "fsfw/serviceinterface/ServiceInterface.h" -MutexIF* GlobalConfigHandler::configLock = nullptr; +MutexIF* GlobalConfigHandler::CONFIG_LOCK = nullptr; + GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath) : SystemObject(objectId), NVMParameterBase(configFilePath), commandQueue(QueueFactory::instance()->createMessageQueue(20)) { - if (configLock == nullptr) { - configLock = MutexFactory::instance()->createMutex(); + if (CONFIG_LOCK == nullptr) { + CONFIG_LOCK = MutexFactory::instance()->createMutex(); } } ReturnValue_t GlobalConfigHandler::initialize() { @@ -59,12 +60,12 @@ ReturnValue_t GlobalConfigHandler::performOperation(uint8_t operationCode) { ReturnValue_t GlobalConfigHandler::lockConfigFile() { ReturnValue_t result = returnvalue::OK; - result = configLock->lockMutex(MutexIF::TimeoutType::WAITING, 10); + result = CONFIG_LOCK->lockMutex(MutexIF::TimeoutType::WAITING, 10); return result; } ReturnValue_t GlobalConfigHandler::unlockConfigFile() { ReturnValue_t result = returnvalue::OK; - result = configLock->unlockMutex(); + result = CONFIG_LOCK->unlockMutex(); return result; } diff --git a/mission/utility/GlobalConfigHandler.h b/mission/utility/GlobalConfigHandler.h index 18a6ec60..80e141c6 100644 --- a/mission/utility/GlobalConfigHandler.h +++ b/mission/utility/GlobalConfigHandler.h @@ -63,7 +63,7 @@ class GlobalConfigHandler : public SystemObject, std::string getConfigFileName(); private: - static MutexIF* configLock; + static MutexIF* CONFIG_LOCK; ReturnValue_t lockConfigFile(); ReturnValue_t unlockConfigFile(); diff --git a/tmtc b/tmtc index 603b7e85..debbe981 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 603b7e8574d74ba60692115133cde3cd8b8bd423 +Subproject commit debbe9813b1ff0d395cccabad84ee4afe10f64e5 diff --git a/unittest/controller/testConfigFileHandler.cpp b/unittest/controller/testConfigFileHandler.cpp index 0f994fba..5445a558 100644 --- a/unittest/controller/testConfigFileHandler.cpp +++ b/unittest/controller/testConfigFileHandler.cpp @@ -14,52 +14,52 @@ TEST_CASE("Configfile Handler", "[ConfigHandler]") { sif::debug << "Testcase config file handler" << std::endl; testEnvironment::initialize(); // Init handler - GlobalConfigHandler confighandler = GlobalConfigHandler(objects::CONFIG_TEST, "JSON.config"); - REQUIRE(confighandler.initialize() == HasReturnvaluesIF::RETURN_OK); + GlobalConfigHandler confighandler = GlobalConfigHandler(objects::GLOBAL_JSON_CFG, "JSON.config"); + REQUIRE(confighandler.initialize() == returnvalue::OK); // Reset handler - REQUIRE(confighandler.ResetConfigFile() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(confighandler.ResetConfigFile() == returnvalue::OK); // Get and set double as well as int values double doubleData = 0.0; - REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == returnvalue::OK); REQUIRE(doubleData == 5.0); doubleData = 55.9; double doubleDataRead = 0; - REQUIRE(confighandler.setConfigFileValue(PARAM0, doubleData) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(confighandler.setConfigFileValue(PARAM0, doubleData) == returnvalue::OK); - REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleDataRead) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleDataRead) == returnvalue::OK); REQUIRE(doubleDataRead == doubleData); - REQUIRE(confighandler.WriteConfigFile() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(confighandler.WriteConfigFile() == returnvalue::OK); int intData = 0; - REQUIRE(confighandler.getConfigFileValue(PARAM1, intData) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(confighandler.getConfigFileValue(PARAM1, intData) == returnvalue::OK); REQUIRE(intData == 905); intData = 1337; int intDataRead = 0; - REQUIRE(confighandler.setConfigFileValue(PARAM1, intData) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(confighandler.setConfigFileValue(PARAM1, intData) == returnvalue::OK); - REQUIRE(confighandler.getConfigFileValue(PARAM1, intDataRead) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(confighandler.getConfigFileValue(PARAM1, intDataRead) == returnvalue::OK); REQUIRE(intDataRead == intData); - REQUIRE(confighandler.WriteConfigFile() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(confighandler.WriteConfigFile() == returnvalue::OK); // Check file name REQUIRE(confighandler.getConfigFileName() == "JSON.config"); // Reset and check if it worked - REQUIRE(confighandler.ResetConfigFile() == HasReturnvaluesIF::RETURN_OK); + REQUIRE(confighandler.ResetConfigFile() == returnvalue::OK); doubleData = 0.0; - REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == returnvalue::OK); REQUIRE(doubleData == 5.0); // Test invalid Parameter REQUIRE(confighandler.getConfigFileValue(PARAM2, doubleData) != - HasReturnvaluesIF::RETURN_OK); // NVMParameterBase::KEY_NOT_EXISTS is private, why? - REQUIRE(confighandler.setConfigFileValue(PARAM2, doubleData) != HasReturnvaluesIF::RETURN_OK); + returnvalue::OK); // NVMParameterBase::KEY_NOT_EXISTS is private, why? + REQUIRE(confighandler.setConfigFileValue(PARAM2, doubleData) != returnvalue::OK); } -- 2.43.0 From fcef7e42a545d1b9c49fde297cb9e941b6fa4e14 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 29 Sep 2022 13:23:55 +0200 Subject: [PATCH 22/23] some unittest fixes --- unittest/controller/testConfigFileHandler.cpp | 2 +- unittest/controller/testThermalController.cpp | 2 +- unittest/main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/unittest/controller/testConfigFileHandler.cpp b/unittest/controller/testConfigFileHandler.cpp index 5445a558..b8147e29 100644 --- a/unittest/controller/testConfigFileHandler.cpp +++ b/unittest/controller/testConfigFileHandler.cpp @@ -12,7 +12,6 @@ TEST_CASE("Configfile Handler", "[ConfigHandler]") { sif::debug << "Testcase config file handler" << std::endl; - testEnvironment::initialize(); // Init handler GlobalConfigHandler confighandler = GlobalConfigHandler(objects::GLOBAL_JSON_CFG, "JSON.config"); REQUIRE(confighandler.initialize() == returnvalue::OK); @@ -62,4 +61,5 @@ TEST_CASE("Configfile Handler", "[ConfigHandler]") { REQUIRE(confighandler.getConfigFileValue(PARAM2, doubleData) != returnvalue::OK); // NVMParameterBase::KEY_NOT_EXISTS is private, why? REQUIRE(confighandler.setConfigFileValue(PARAM2, doubleData) != returnvalue::OK); + std::filesystem::remove("JSON.config"); } diff --git a/unittest/controller/testThermalController.cpp b/unittest/controller/testThermalController.cpp index a65ec69b..908ef1bb 100644 --- a/unittest/controller/testThermalController.cpp +++ b/unittest/controller/testThermalController.cpp @@ -15,7 +15,7 @@ TEST_CASE("Thermal Controller", "[ThermalController]") { new TemperatureSensorsDummy(); new SusDummy(); - testEnvironment::initialize(); + //testEnvironment::initialize(); ThermalController controller(THERMAL_CONTROLLER_ID, objects::NO_OBJECT); ReturnValue_t result = controller.initialize(); diff --git a/unittest/main.cpp b/unittest/main.cpp index 6438577c..760ff156 100644 --- a/unittest/main.cpp +++ b/unittest/main.cpp @@ -4,7 +4,7 @@ int main(int argc, char* argv[]) { testEnvironment::setup(); - + testEnvironment::initialize(); // Catch internal function call int result = Catch::Session().run(argc, argv); -- 2.43.0 From 0f081e52bdb74592baa459a3c4613057ba598d39 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 29 Sep 2022 14:20:44 +0200 Subject: [PATCH 23/23] bump tmtc --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index a19b6599..648779e8 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit a19b6599396707850a15c7b6c3d15a4884aede1e +Subproject commit 648779e8b6ea8e377e77d6afa85d9e6b06664975 -- 2.43.0