local parameter handler wip
This commit is contained in:
@ -51,6 +51,8 @@
|
||||
#include "mission/system/tree/comModeTree.h"
|
||||
#include "mission/system/tree/payloadModeTree.h"
|
||||
#include "mission/system/tree/tcsModeTree.h"
|
||||
#include "mission/utility/GlobalConfigHandler.h"
|
||||
#include "mission/config/configfile.h"
|
||||
#include "tmtc/pusIds.h"
|
||||
#if OBSW_TEST_LIBGPIOD == 1
|
||||
#include "linux/boardtest/LibgpiodTest.h"
|
||||
@ -966,3 +968,7 @@ void ObjectFactory::testAcsBrdAss(AcsBoardAssembly* acsAss) {
|
||||
sif::warning << "Sending mode command failed" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectFactory::createGlobalConfigHandler() {
|
||||
new GlobalConfigHandler(objects::GLOBAL_JSON_CFG, configfile::sdrelative);
|
||||
}
|
||||
|
@ -48,6 +48,8 @@ void createTestComponents(LinuxLibgpioIF* gpioComIF);
|
||||
|
||||
void testAcsBrdAss(AcsBoardAssembly* assAss);
|
||||
|
||||
void createGlobalConfigHandler();
|
||||
|
||||
}; // namespace ObjectFactory
|
||||
|
||||
#endif /* BSP_Q7S_OBJECTFACTORY_H_ */
|
||||
|
@ -86,6 +86,8 @@ void ObjectFactory::produce(void* args) {
|
||||
createTestComponents(gpioComIF);
|
||||
#endif /* OBSW_ADD_TEST_CODE == 1 */
|
||||
|
||||
createGlobalConfigHandler();
|
||||
|
||||
createMiscComponents();
|
||||
createThermalController();
|
||||
createAcsController(true);
|
||||
|
@ -1 +1 @@
|
||||
target_sources(${OBSW_NAME} PRIVATE scratchApi.cpp)
|
||||
target_sources(${OBSW_NAME} PRIVATE scratchApi.cpp LocalParameterHandler.cpp)
|
||||
|
22
bsp_q7s/memory/LocalParameterHandler.cpp
Normal file
22
bsp_q7s/memory/LocalParameterHandler.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "LocalParameterHandler.h"
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
|
||||
LocalParameterHandler::LocalParameterHandler(std::string sdRelativeName, SdCardMountedIF* sdcMan)
|
||||
: sdRelativeName(sdRelativeName), sdcMan(sdcMan) {}
|
||||
|
||||
LocalParameterHandler::~LocalParameterHandler() {
|
||||
}
|
||||
|
||||
ReturnValue_t LocalParameterHandler::initialize() {
|
||||
std::string mountPrefix = sdcMan->getCurrentMountPrefix();
|
||||
std::string fullname = mountPrefix + "/" + sdRelativeName;
|
||||
setFullName(fullname);
|
||||
ReturnValue_t result = readJsonFile();
|
||||
if (result != returnvalue::OK) {
|
||||
sif::warning << "LocalParameterHandler::initialize: Failed to read json file"
|
||||
<< getFullName() << std::endl;
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
66
bsp_q7s/memory/LocalParameterHandler.h
Normal file
66
bsp_q7s/memory/LocalParameterHandler.h
Normal file
@ -0,0 +1,66 @@
|
||||
#ifndef BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_
|
||||
#define BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <mission/memory/NVMParameterBase.h>
|
||||
#include <mission/memory/SdCardMountedIF.h>
|
||||
|
||||
/**
|
||||
* @brief Class to handle persistent parameters
|
||||
*
|
||||
* @details Use the insertValue function to add parameters
|
||||
*/
|
||||
class LocalParameterHandler : public NVMParameterBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param sdRelativeName Absolute name of json file relative to mount
|
||||
* directory of SD card. E.g. conf/example.json
|
||||
* @param sdcMan Pointer to SD card manager
|
||||
*/
|
||||
LocalParameterHandler(std::string sdRelativeName, SdCardMountedIF* sdcMan);
|
||||
virtual ~LocalParameterHandler();
|
||||
|
||||
/**
|
||||
* @brief Will initialize the local parameter handler
|
||||
*
|
||||
* @return OK if successful, otherwise error return value
|
||||
*/
|
||||
ReturnValue_t initialize();
|
||||
|
||||
/**
|
||||
* @brief Function to add parameter to json file
|
||||
*
|
||||
* @param key The string to identify the parameter
|
||||
* @param value The value to set for this parameter
|
||||
*
|
||||
* @return OK if successful, otherwise error return value
|
||||
*
|
||||
* @details The function will add the parameter only if it is not already
|
||||
* present in the json file
|
||||
*/
|
||||
template<typename T> ReturnValue_t addParameter(std::string key, T value);
|
||||
|
||||
private:
|
||||
|
||||
// Name relative to mount point of SD card where parameters will be stored
|
||||
std::string sdRelativeName;
|
||||
|
||||
SdCardMountedIF* sdcMan;
|
||||
};
|
||||
|
||||
template<typename T> inline ReturnValue_t LocalParameterHandler::addParameter(std::string key, T value) {
|
||||
ReturnValue_t result = insertValue(key, value);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = writeJsonFile();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
#endif /* BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_ */
|
Reference in New Issue
Block a user