You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.0 KiB
78 lines
2.0 KiB
#pragma once
|
|
#include "project_configs.h"
|
|
#include "sdk/os/zos.hpp"
|
|
|
|
namespace iflytop {
|
|
using namespace std;
|
|
|
|
class ZNVS {
|
|
typedef enum {
|
|
kcfg_type_int8_t,
|
|
kcfg_type_uint8_t,
|
|
kcfg_type_int16_t,
|
|
kcfg_type_uint16_t,
|
|
kcfg_type_int32_t,
|
|
kcfg_type_uint32_t,
|
|
kcfg_type_float,
|
|
kcfg_type_bool,
|
|
} type_t;
|
|
|
|
#pragma pack(1)
|
|
typedef struct {
|
|
char key[64];
|
|
uint8_t val[8];
|
|
uint8_t type;
|
|
bool is_initialed;
|
|
} cfg_t;
|
|
|
|
typedef struct {
|
|
uint32_t config_start;
|
|
cfg_t cfgs[IFLYTOP_NVS_CONFIG_MAX_ITEM_NUM];
|
|
uint32_t config_end;
|
|
} config_t;
|
|
#pragma pack()
|
|
|
|
config_t m_cfg;
|
|
|
|
public:
|
|
static ZNVS& ins();
|
|
|
|
void initialize();
|
|
void factory_reset();
|
|
void dumpcfg();
|
|
|
|
void flush();
|
|
|
|
int8_t get_config_int8(const char* key, int8_t default_val);
|
|
void set_config_int8(const char* key, int8_t val);
|
|
|
|
uint8_t get_config_uint8(const char* key, uint8_t default_val);
|
|
void set_config_uint8(const char* key, uint8_t val);
|
|
|
|
int16_t get_config_int16(const char* key, int16_t default_val);
|
|
void set_config_int16(const char* key, int16_t val);
|
|
|
|
uint16_t get_config_uint16(const char* key, uint16_t default_val);
|
|
void set_config_uint16(const char* key, uint16_t val);
|
|
|
|
int32_t get_config_int32(const char* key, int32_t default_val);
|
|
void set_config_int32(const char* key, int32_t val);
|
|
|
|
uint32_t get_config_uint32(const char* key, uint32_t default_val);
|
|
void set_config_uint32(const char* key, uint32_t val);
|
|
|
|
float get_config_float(const char* key, float default_val);
|
|
void set_config_float(const char* key, float val);
|
|
|
|
bool get_config_bool(const char* key, bool default_val);
|
|
void set_config_bool(const char* key, bool val);
|
|
|
|
private:
|
|
void dumpcfg(cfg_t* cfg);
|
|
|
|
cfg_t* get_cfg(const char* key);
|
|
void allocate_cfg(const char* key, type_t type, uint8_t* default_val, uint8_t len);
|
|
cfg_t* get_and_create_cfg(const char* key, type_t type, uint8_t* default_val, uint8_t len);
|
|
};
|
|
|
|
} // namespace iflytop
|