Removed insert function in config handler, not needed. Added more tests for config handler
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
This commit is contained in:
parent
c4b8fa5444
commit
d9060734b0
23
mission/utility/GlobalConfigFileDefinitions.h
Normal file
23
mission/utility/GlobalConfigFileDefinitions.h
Normal file
@ -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_ */
|
@ -2,7 +2,7 @@
|
|||||||
* GlobalConfigHandler.cpp
|
* GlobalConfigHandler.cpp
|
||||||
*
|
*
|
||||||
* Created on: May 3, 2022
|
* Created on: May 3, 2022
|
||||||
* Author: metobs
|
* Author: Jona Petri (IRS)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "GlobalConfigHandler.h"
|
#include "GlobalConfigHandler.h"
|
||||||
@ -11,6 +11,7 @@
|
|||||||
#include <fsfw/ipc/MessageQueueIF.h>
|
#include <fsfw/ipc/MessageQueueIF.h>
|
||||||
#include <fsfw/ipc/QueueFactory.h>
|
#include <fsfw/ipc/QueueFactory.h>
|
||||||
|
|
||||||
|
|
||||||
MutexIF* GlobalConfigHandler::configLock = nullptr;
|
MutexIF* GlobalConfigHandler::configLock = nullptr;
|
||||||
GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath):
|
GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string configFilePath):
|
||||||
SystemObject(objectId),
|
SystemObject(objectId),
|
||||||
@ -73,7 +74,7 @@ ReturnValue_t GlobalConfigHandler::unlockConfigFile(){
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> ReturnValue_t GlobalConfigHandler::setConfigFileValue(std::string key, T data){
|
template <typename T> ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data){
|
||||||
ReturnValue_t result = RETURN_OK;
|
ReturnValue_t result = RETURN_OK;
|
||||||
ReturnValue_t resultSet = RETURN_OK;
|
ReturnValue_t resultSet = RETURN_OK;
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ template <typename T> ReturnValue_t GlobalConfigHandler::setConfigFileValue(std:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
resultSet=setValue(key, data);
|
resultSet=setValue(PARAM_KEY_MAP[paramID], data);
|
||||||
if(resultSet!=RETURN_OK){
|
if(resultSet!=RETURN_OK){
|
||||||
triggerEvent(SET_CONFIGFILEVALUE_FAILED, 0, 0);
|
triggerEvent(SET_CONFIGFILEVALUE_FAILED, 0, 0);
|
||||||
#if OBSW_VERBOSE_LEVEL >= 1
|
#if OBSW_VERBOSE_LEVEL >= 1
|
||||||
@ -104,7 +105,7 @@ template <typename T> ReturnValue_t GlobalConfigHandler::setConfigFileValue(std:
|
|||||||
|
|
||||||
return resultSet;
|
return resultSet;
|
||||||
}
|
}
|
||||||
template <typename T> ReturnValue_t GlobalConfigHandler::getConfigFileValue(std::string key, T& data){
|
template <typename T> ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, T& data){
|
||||||
ReturnValue_t result = RETURN_OK;
|
ReturnValue_t result = RETURN_OK;
|
||||||
ReturnValue_t resultGet = RETURN_OK;
|
ReturnValue_t resultGet = RETURN_OK;
|
||||||
|
|
||||||
@ -116,7 +117,7 @@ template <typename T> ReturnValue_t GlobalConfigHandler::getConfigFileValue(std:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
resultGet=getValue(key, data);
|
resultGet=getValue(PARAM_KEY_MAP[paramID], data);
|
||||||
if (resultGet!= RETURN_OK){
|
if (resultGet!= RETURN_OK){
|
||||||
triggerEvent(GET_CONFIGFILEVALUE_FAILED, 0, 0);
|
triggerEvent(GET_CONFIGFILEVALUE_FAILED, 0, 0);
|
||||||
#if OBSW_VERBOSE_LEVEL >= 1
|
#if OBSW_VERBOSE_LEVEL >= 1
|
||||||
@ -133,36 +134,7 @@ template <typename T> ReturnValue_t GlobalConfigHandler::getConfigFileValue(std:
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
template <typename T> 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 GlobalConfigHandler::resetConfigFileValues(){
|
||||||
ReturnValue_t result = RETURN_OK;
|
ReturnValue_t result = RETURN_OK;
|
||||||
result=lockConfigFile();
|
result=lockConfigFile();
|
||||||
@ -260,65 +232,10 @@ std::string GlobalConfigHandler::getConfigFileName(){
|
|||||||
return getFullName();
|
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;
|
template ReturnValue_t GlobalConfigHandler::getConfigFileValue<double>(ParamIds paramID, double& data);
|
||||||
switch(uniqueId){
|
template ReturnValue_t GlobalConfigHandler::getConfigFileValue<int32_t>(ParamIds paramID, int32_t& data);
|
||||||
|
|
||||||
case(ParamIds::PARAM0):{
|
|
||||||
result=handleDoubleParamUpdate(PARAM_KEY_MAP[static_cast<ParamIds>(uniqueId)],
|
|
||||||
parameterWrapper, newValues);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case(ParamIds::PARAM1):{
|
|
||||||
result=handleIntParamUpdate(PARAM_KEY_MAP[static_cast<ParamIds>(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<double>(&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<int>(&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::setConfigFileValue<double>(ParamIds paramID, double data);
|
||||||
|
template ReturnValue_t GlobalConfigHandler::setConfigFileValue<int32_t>(ParamIds paramID, int32_t data);
|
||||||
|
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
* GlobalConfigHandler.h
|
* GlobalConfigHandler.h
|
||||||
*
|
*
|
||||||
* Created on: May 3, 2022
|
* Created on: May 3, 2022
|
||||||
* Author: metobs
|
* Author: Jona Petri (IRS)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef BSP_LINUX_GLOBALCONFIGHANDLER_H_
|
#ifndef MISSION_UTILITY_GLOBALCONFIGHANDLER_H_
|
||||||
#define BSP_LINUX_GLOBALCONFIGHANDLER_H_
|
#define MISSION_UTILITY_GLOBALCONFIGHANDLER_H_
|
||||||
|
|
||||||
#include <fsfw/objectmanager/SystemObject.h>
|
#include <fsfw/objectmanager/SystemObject.h>
|
||||||
#include <fsfw/storagemanager/StorageManagerIF.h>
|
#include <fsfw/storagemanager/StorageManagerIF.h>
|
||||||
@ -21,14 +21,7 @@
|
|||||||
#include <fsfw/action/ActionHelper.h>
|
#include <fsfw/action/ActionHelper.h>
|
||||||
#include <fsfw/action/HasActionsIF.h>
|
#include <fsfw/action/HasActionsIF.h>
|
||||||
|
|
||||||
static constexpr double PARAM0_DEFAULT = 5.0;
|
#include "GlobalConfigFileDefinitions.h"
|
||||||
static constexpr int PARAM1_DEFAULT = 905;
|
|
||||||
|
|
||||||
enum ParamIds : uint8_t {
|
|
||||||
PARAM0 = 0,
|
|
||||||
PARAM1 = 1,
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
static std::map<ParamIds, std::string> PARAM_KEY_MAP = {
|
static std::map<ParamIds, std::string> PARAM_KEY_MAP = {
|
||||||
{PARAM0, "Parameter0"},
|
{PARAM0, "Parameter0"},
|
||||||
@ -58,34 +51,26 @@ public:
|
|||||||
|
|
||||||
ReturnValue_t initialize();
|
ReturnValue_t initialize();
|
||||||
|
|
||||||
ReturnValue_t lockConfigFile();
|
|
||||||
ReturnValue_t unlockConfigFile();
|
template <typename T> ReturnValue_t setConfigFileValue(ParamIds paramID, T data);
|
||||||
template <typename T> ReturnValue_t setConfigFileValue(std::string key, T data);
|
template <typename T> ReturnValue_t getConfigFileValue(ParamIds paramID, T& data);
|
||||||
template <typename T> ReturnValue_t getConfigFileValue(std::string key, T& data);
|
|
||||||
template <typename T> ReturnValue_t insertConfigFileValue(std::string key, T data);
|
|
||||||
ReturnValue_t resetConfigFileValues();
|
ReturnValue_t resetConfigFileValues();
|
||||||
ReturnValue_t WriteConfigFile();
|
ReturnValue_t WriteConfigFile();
|
||||||
|
std::string getConfigFileName();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static MutexIF* configLock ;
|
||||||
|
|
||||||
|
ReturnValue_t lockConfigFile();
|
||||||
|
ReturnValue_t unlockConfigFile();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ReturnValue_t ReadConfigFile();
|
ReturnValue_t ReadConfigFile();
|
||||||
ReturnValue_t ResetConfigFile();
|
ReturnValue_t ResetConfigFile();
|
||||||
|
|
||||||
ReturnValue_t setConfigFileName(std::string configFileName);
|
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;
|
MessageQueueIF* commandQueue;
|
||||||
@ -94,4 +79,4 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* BSP_LINUX_GLOBALCONFIGHANDLER_H_ */
|
#endif /* MISSION_UTILITY_GLOBALCONFIGHANDLER_H_ */
|
||||||
|
@ -11,9 +11,51 @@
|
|||||||
|
|
||||||
TEST_CASE("Configfile Handler", "[ConfigHandler]") {
|
TEST_CASE("Configfile Handler", "[ConfigHandler]") {
|
||||||
|
|
||||||
GlobalConfigHandler confighandler= GlobalConfigHandler(objects::CONFIG_TEST,"JSON.config");
|
|
||||||
sif::debug<<"Testcase config file handler"<<std::endl;
|
sif::debug<<"Testcase config file handler"<<std::endl;
|
||||||
|
|
||||||
|
//Init handler
|
||||||
|
GlobalConfigHandler confighandler= GlobalConfigHandler(objects::CONFIG_TEST,"JSON.config");
|
||||||
REQUIRE(confighandler.initialize() == HasReturnvaluesIF::RETURN_OK);
|
REQUIRE(confighandler.initialize() == HasReturnvaluesIF::RETURN_OK);
|
||||||
|
|
||||||
|
//Reset handler
|
||||||
|
REQUIRE(confighandler.resetConfigFileValues() == HasReturnvaluesIF::RETURN_OK);
|
||||||
|
|
||||||
|
//Get and set double as well as int values
|
||||||
|
double doubleData=0.0;
|
||||||
|
REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == HasReturnvaluesIF::RETURN_OK);
|
||||||
|
REQUIRE(doubleData==5.0);
|
||||||
|
|
||||||
|
doubleData=55.9;
|
||||||
|
double doubleDataRead=0;
|
||||||
|
REQUIRE(confighandler.setConfigFileValue(PARAM0, doubleData) == HasReturnvaluesIF::RETURN_OK);
|
||||||
|
|
||||||
|
REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleDataRead) == HasReturnvaluesIF::RETURN_OK);
|
||||||
|
REQUIRE(doubleDataRead==doubleData);
|
||||||
|
|
||||||
|
REQUIRE(confighandler.WriteConfigFile()==HasReturnvaluesIF::RETURN_OK);
|
||||||
|
|
||||||
|
int intData=0;
|
||||||
|
|
||||||
|
REQUIRE(confighandler.getConfigFileValue(PARAM1, intData) == HasReturnvaluesIF::RETURN_OK);
|
||||||
|
REQUIRE(intData==905);
|
||||||
|
|
||||||
|
intData=1337;
|
||||||
|
int intDataRead=0;
|
||||||
|
REQUIRE(confighandler.setConfigFileValue(PARAM1, intData) == HasReturnvaluesIF::RETURN_OK);
|
||||||
|
|
||||||
|
REQUIRE(confighandler.getConfigFileValue(PARAM1, intDataRead) == HasReturnvaluesIF::RETURN_OK);
|
||||||
|
REQUIRE(intDataRead==intData);
|
||||||
|
|
||||||
|
REQUIRE(confighandler.WriteConfigFile()==HasReturnvaluesIF::RETURN_OK);
|
||||||
|
|
||||||
|
//Check file name
|
||||||
|
REQUIRE(confighandler.getConfigFileName()=="JSON.config");
|
||||||
|
|
||||||
|
//Reset and check if it worked
|
||||||
|
REQUIRE(confighandler.resetConfigFileValues() == HasReturnvaluesIF::RETURN_OK);
|
||||||
|
|
||||||
|
doubleData=0.0;
|
||||||
|
REQUIRE(confighandler.getConfigFileValue(PARAM0, doubleData) == HasReturnvaluesIF::RETURN_OK);
|
||||||
|
REQUIRE(doubleData==5.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user