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.
 
 

50 lines
932 B

#pragma once
#include "project_configs.h"
#include "sdk/os/zos.hpp"
#ifdef IFLYTOP_NVS_CONFIG_FLASH_SECTOR
namespace iflytop {
using namespace std;
class ZNVS {
typedef struct {
const char* name;
uint8_t* defaultval;
size_t len;
} cfg_index_t;
#pragma pack(1)
typedef struct {
uint32_t config_start;
uint32_t data_size;
uint8_t data[];
} config_t;
#pragma pack()
cfg_index_t m_index[20];
int m_index_num = 0;
bool inited = false;
config_t* m_cfgcache = nullptr;
size_t m_cfgcachesize = 0;
public:
static ZNVS& ins();
void initialize();
bool alloc_config(const char* key, uint8_t* data, size_t datalen);
bool init_config();
bool get_config(const char* key, uint8_t* data, size_t len);
bool set_config(const char* key, uint8_t* data, size_t len);
void flush();
private:
void flush_all_to_configcache();
};
#endif
} // namespace iflytop