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.

80 lines
2.0 KiB

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