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.

54 lines
1.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include "config_service.h"
  2. #include "project_dep.h"
  3. static config_t _config;
  4. static config_t _default_val_config;
  5. #define TAG "config"
  6. static void dump_config(config_t *pcfg) {
  7. ZLOGI(TAG, "=============== config ===============");
  8. ZLOGI(TAG, "obtaining_ip_mode : %s", obtaining_ip_mode_to_string(pcfg->obtaining_ip_mode));
  9. ZLOGI(TAG, "ip : %s", inet_ntoa(pcfg->ip));
  10. ZLOGI(TAG, "gw : %s", inet_ntoa(pcfg->gw));
  11. ZLOGI(TAG, "netmask : %s", inet_ntoa(pcfg->netmask));
  12. ZLOGI(TAG, "mac : %02x:%02x:%02x:%02x:%02x:%02x", pcfg->mac[0], pcfg->mac[1], pcfg->mac[2], pcfg->mac[3], pcfg->mac[4], pcfg->mac[5]);
  13. ZLOGI(TAG, "======================================");
  14. }
  15. static void create_default_config() { //
  16. _default_val_config.config_mark = FLASH_MASK_VAL;
  17. IP4_ADDR((ip4_addr_t *)&_default_val_config.ip, 192, 168, 8, 10);
  18. IP4_ADDR((ip4_addr_t *)&_default_val_config.gw, 192, 168, 8, 1);
  19. IP4_ADDR((ip4_addr_t *)&_default_val_config.netmask, 255, 255, 255, 0);
  20. _default_val_config.obtaining_ip_mode = obtaining_ip_mode_type_static; // dhcp
  21. static mac_t mac;
  22. xs_id_generate_random_mac(&mac);
  23. memcpy(&_default_val_config.mac[0], mac.mac, 6);
  24. // ZLOGD(TAG, "random mac is %02x:%02x:%02x:%02x:%02x:%02x", mac.mac[0], mac.mac[1], mac.mac[2], mac.mac[3], mac.mac[4], mac.mac[5]);
  25. // dump_config(&_default_val_config);
  26. }
  27. void config_init(void) {
  28. ZLOGI(TAG, "config_init");
  29. /**
  30. * @brief Ĭ
  31. */
  32. create_default_config();
  33. /**
  34. * @brief flashʼ
  35. */
  36. xs_flash_init(&_config, &_default_val_config, sizeof(config_t) / 4);
  37. // ZLOGI(TAG, "xs_flash_is_first_run: %d", xs_flash_is_first_run());
  38. // ZLOGI(TAG, "");
  39. /**
  40. * @brief ӡϢ
  41. */
  42. dump_config(&_config);
  43. }
  44. config_t *config_get(void) { return &_config; }
  45. void config_flush(void) { return xs_flash_flush(); }
  46. void config_factory_reset(void) { xs_flash_factory_reset(); }