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.

82 lines
2.0 KiB

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