local parameter handler wip
This commit is contained in:
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