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.

77 lines
2.0 KiB

2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #include "project_configs.h"
  3. #include "sdk/os/zos.hpp"
  4. namespace iflytop {
  5. using namespace std;
  6. class ZNVS {
  7. typedef enum {
  8. kcfg_type_int8_t,
  9. kcfg_type_uint8_t,
  10. kcfg_type_int16_t,
  11. kcfg_type_uint16_t,
  12. kcfg_type_int32_t,
  13. kcfg_type_uint32_t,
  14. kcfg_type_float,
  15. kcfg_type_bool,
  16. } type_t;
  17. #pragma pack(1)
  18. typedef struct {
  19. char key[64];
  20. uint8_t val[8];
  21. uint8_t type;
  22. bool is_initialed;
  23. } cfg_t;
  24. typedef struct {
  25. uint32_t config_start;
  26. cfg_t cfgs[IFLYTOP_NVS_CONFIG_MAX_ITEM_NUM];
  27. uint32_t config_end;
  28. } config_t;
  29. #pragma pack()
  30. config_t m_cfg;
  31. public:
  32. static ZNVS& ins();
  33. void initialize();
  34. void factory_reset();
  35. void dumpcfg();
  36. void flush();
  37. int8_t get_config_int8(const char* key, int8_t default_val);
  38. void set_config_int8(const char* key, int8_t val);
  39. uint8_t get_config_uint8(const char* key, uint8_t default_val);
  40. void set_config_uint8(const char* key, uint8_t val);
  41. int16_t get_config_int16(const char* key, int16_t default_val);
  42. void set_config_int16(const char* key, int16_t val);
  43. uint16_t get_config_uint16(const char* key, uint16_t default_val);
  44. void set_config_uint16(const char* key, uint16_t val);
  45. int32_t get_config_int32(const char* key, int32_t default_val);
  46. void set_config_int32(const char* key, int32_t val);
  47. uint32_t get_config_uint32(const char* key, uint32_t default_val);
  48. void set_config_uint32(const char* key, uint32_t val);
  49. float get_config_float(const char* key, float default_val);
  50. void set_config_float(const char* key, float val);
  51. bool get_config_bool(const char* key, bool default_val);
  52. void set_config_bool(const char* key, bool val);
  53. private:
  54. void dumpcfg(cfg_t* cfg);
  55. cfg_t* get_cfg(const char* key);
  56. void allocate_cfg(const char* key, type_t type, uint8_t* default_val, uint8_t len);
  57. cfg_t* get_and_create_cfg(const char* key, type_t type, uint8_t* default_val, uint8_t len);
  58. };
  59. } // namespace iflytop