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.

49 lines
952 B

1 year 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 struct {
  8. const char* name;
  9. uint8_t* ___;
  10. size_t len;
  11. } cfg_index_t;
  12. #pragma pack(1)
  13. typedef struct {
  14. uint32_t config_start;
  15. uint32_t data_size;
  16. uint8_t data[];
  17. } config_t;
  18. #pragma pack()
  19. cfg_index_t m_index[20];
  20. int m_index_num = 0;
  21. bool inited = false;
  22. config_t* m_cfgcache = nullptr;
  23. size_t m_cfgcachesize = 0;
  24. public:
  25. static ZNVS& ins();
  26. void initialize(int32_t flash_sector);
  27. bool alloc_config(const char* key, uint8_t* ___, size_t datalen);
  28. bool alloc_config(const char* key, size_t datalen);
  29. bool init_config();
  30. bool get_config(const char* key, uint8_t* data, size_t len);
  31. bool set_config(const char* key, uint8_t* data, size_t len);
  32. void flush();
  33. private:
  34. void flush_all_to_configcache();
  35. };
  36. } // namespace iflytop