local parameter handler wip
This commit is contained in:
@ -15,6 +15,8 @@ enum ParamIds : uint8_t {
|
||||
PARAM0 = 0,
|
||||
PARAM1 = 1,
|
||||
PARAM2 = 2,
|
||||
PDEC_PW = 3,
|
||||
PDEC_NW = 4
|
||||
};
|
||||
|
||||
#endif /* MISSION_UTILITY_GLOBALCONFIGFILEDEFINITIONS_H_ */
|
||||
|
@ -23,23 +23,24 @@ GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string confi
|
||||
CONFIG_LOCK = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t GlobalConfigHandler::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != returnvalue::OK) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
sif::info << "GlobalConfigHandler::initialize: SystemObject::initialize() failed with "
|
||||
sif::info << "GlobalConfigHandler::initialize: SystemObject::initialize failed with "
|
||||
<< result << std::endl;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
result = ReadConfigFile();
|
||||
result = readConfigFile();
|
||||
if (result != returnvalue::OK) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
sif::info << "GlobalConfigHandler::initialize: Creating JSON file at " << getFullName()
|
||||
<< std::endl;
|
||||
#endif
|
||||
result = ResetConfigFile();
|
||||
result = resetConfigFile();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
@ -63,6 +64,7 @@ ReturnValue_t GlobalConfigHandler::lockConfigFile() {
|
||||
result = CONFIG_LOCK->lockMutex(MutexIF::TimeoutType::WAITING, 10);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t GlobalConfigHandler::unlockConfigFile() {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
result = CONFIG_LOCK->unlockMutex();
|
||||
@ -70,34 +72,21 @@ ReturnValue_t GlobalConfigHandler::unlockConfigFile() {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data) {
|
||||
ReturnValue_t GlobalConfigHandler::setConfigFileValue(std::string paramName, T data) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
ReturnValue_t resultSet = returnvalue::OK;
|
||||
|
||||
result = lockConfigFile();
|
||||
if (result != returnvalue::OK) {
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
sif::info << "GlobalConfigHandler::setConfigFileValue lock mutex failed with " << result
|
||||
sif::info << "GlobalConfigHandler::setConfigFileValue: Lock mutex failed with " << result
|
||||
<< std::endl;
|
||||
#endif
|
||||
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 returnvalue::FAILED;
|
||||
}
|
||||
|
||||
resultSet = setValue(PARAM_KEY_MAP[paramID], data);
|
||||
// If value exists it is updated otherwise a new entry will be created
|
||||
resultSet = insertValue(paramName, data);
|
||||
if (resultSet != returnvalue::OK) {
|
||||
triggerEvent(SET_CONFIGFILEVALUE_FAILED, 0, 0);
|
||||
#if OBSW_VERBOSE_LEVEL >= 1
|
||||
@ -117,6 +106,7 @@ ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data)
|
||||
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, T& data) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
@ -161,8 +151,10 @@ ReturnValue_t GlobalConfigHandler::resetConfigFileValues() {
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
insertValue(PARAM_KEY_MAP[PARAM0], PARAM0_DEFAULT);
|
||||
insertValue(PARAM_KEY_MAP[PARAM1], PARAM1_DEFAULT);
|
||||
|
||||
for(const auto& keyMap: PARAM_KEY_MAP) {
|
||||
insertValue(keyMap.second, PARAM0_DEFAULT);
|
||||
}
|
||||
|
||||
result = unlockConfigFile();
|
||||
if (result != returnvalue::OK) {
|
||||
@ -174,7 +166,8 @@ ReturnValue_t GlobalConfigHandler::resetConfigFileValues() {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
ReturnValue_t GlobalConfigHandler::WriteConfigFile() {
|
||||
|
||||
ReturnValue_t GlobalConfigHandler::writeConfigFile() {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
ReturnValue_t resultWrite = returnvalue::OK;
|
||||
result = lockConfigFile();
|
||||
@ -205,7 +198,8 @@ ReturnValue_t GlobalConfigHandler::WriteConfigFile() {
|
||||
}
|
||||
return resultWrite;
|
||||
}
|
||||
ReturnValue_t GlobalConfigHandler::ReadConfigFile() {
|
||||
|
||||
ReturnValue_t GlobalConfigHandler::readConfigFile() {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
ReturnValue_t resultRead = returnvalue::OK;
|
||||
result = lockConfigFile();
|
||||
@ -237,7 +231,8 @@ ReturnValue_t GlobalConfigHandler::ReadConfigFile() {
|
||||
|
||||
return resultRead;
|
||||
}
|
||||
ReturnValue_t GlobalConfigHandler::ResetConfigFile() {
|
||||
|
||||
ReturnValue_t GlobalConfigHandler::resetConfigFile() {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
result = resetConfigFileValues();
|
||||
if (result != returnvalue::OK) {
|
||||
@ -253,7 +248,7 @@ ReturnValue_t GlobalConfigHandler::ResetConfigFile() {
|
||||
ReturnValue_t GlobalConfigHandler::setConfigFileName(std::string configFileName) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
setFullName(configFileName);
|
||||
result = ResetConfigFile();
|
||||
result = resetConfigFile();
|
||||
return result;
|
||||
}
|
||||
std::string GlobalConfigHandler::getConfigFileName() { return getFullName(); }
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <fsfw/storagemanager/StorageManagerIF.h>
|
||||
#include <fsfw/tasks/ExecutableObjectIF.h>
|
||||
|
||||
#include <utility>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
@ -24,10 +25,6 @@
|
||||
#include "fsfw/parameters/ParameterHelper.h"
|
||||
#include "mission/memory/NVMParameterBase.h"
|
||||
|
||||
static std::map<ParamIds, std::string> 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
|
||||
@ -54,12 +51,12 @@ class GlobalConfigHandler : public SystemObject,
|
||||
ReturnValue_t initialize();
|
||||
|
||||
template <typename T>
|
||||
ReturnValue_t setConfigFileValue(ParamIds paramID, T data);
|
||||
ReturnValue_t setConfigFileValue(std::string paramName, T data);
|
||||
template <typename T>
|
||||
ReturnValue_t getConfigFileValue(ParamIds paramID, T& data);
|
||||
ReturnValue_t getConfigFileValue(std::string paramName, T& data);
|
||||
|
||||
ReturnValue_t ResetConfigFile();
|
||||
ReturnValue_t WriteConfigFile();
|
||||
ReturnValue_t resetConfigFile();
|
||||
ReturnValue_t writeConfigFile();
|
||||
std::string getConfigFileName();
|
||||
|
||||
private:
|
||||
@ -71,7 +68,7 @@ class GlobalConfigHandler : public SystemObject,
|
||||
|
||||
ReturnValue_t setConfigFileName(std::string configFileName);
|
||||
|
||||
ReturnValue_t ReadConfigFile();
|
||||
ReturnValue_t readConfigFile();
|
||||
|
||||
MessageQueueIF* commandQueue;
|
||||
};
|
||||
|
Reference in New Issue
Block a user