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.

67 lines
1.7 KiB

  1. #include "config.h"
  2. #include <lwip/sockets.h>
  3. #include "lwip/api.h"
  4. #include "lwip/opt.h"
  5. #include "lwip/sys.h"
  6. #include "zflash.h"
  7. #include "zboard.h"
  8. #define CONFIG_SIZE ((sizeof(config_t) / 4) + ((sizeof(config_t) % 4) > 0 ? 1 : 0))
  9. static config_t s_config;
  10. static bool s_is_first_init = false;
  11. void config_init(void)
  12. {
  13. #if 1
  14. IP4_ADDR((ip4_addr_t *)&s_config.ip, 192, 168, 8, 10);
  15. IP4_ADDR((ip4_addr_t *)&s_config.gw, 192, 168, 8, 1);
  16. IP4_ADDR((ip4_addr_t *)&s_config.netmask, 255, 255, 255, 0);
  17. s_config.localport = SERVICE_PORT;
  18. s_config.obtaining_ip_mode = OBTAINING_IP_MODE_DHCP; // dhcp
  19. s_config.mask = 1; //
  20. #endif
  21. // if (stmflash_write(FLASH_START_ADDRESS, (uint32_t *)&s_config, CONFIG_SIZE) < 0)
  22. // {
  23. // printf("flash write config error\r\n");
  24. // }
  25. // config_flash_read();
  26. /*dumpconfig*/
  27. config_dump_config();
  28. }
  29. bool config_is_first_init(void) { return s_is_first_init; }
  30. void config_dump_config(void)
  31. {
  32. printf("=================config================\r\n");
  33. printf("= config obtaining_ip_mode %u\r\n", s_config.obtaining_ip_mode);
  34. printf("= config ip %s\r\n", inet_ntoa(s_config.ip));
  35. printf("= config gw: %s\r\n", inet_ntoa(s_config.gw));
  36. printf("= config netmask: %s\r\n", inet_ntoa(s_config.netmask));
  37. printf("= config localport: %u\r\n", s_config.localport);
  38. }
  39. bool config_update(void)
  40. {
  41. // if (stmflash_write(FLASH_SAVE_ADDR, (uint32_t *)&s_config, CONFIG_SIZE) < 0)
  42. // {
  43. // printf("flash write config error\r\n");
  44. // return false;
  45. // }
  46. // config_dump_config();
  47. return true;
  48. }
  49. void config_flash_read(void)
  50. {
  51. //
  52. // stmflash_read(FLASH_SAVE_ADDR, (uint32_t *)&s_config, CONFIG_SIZE);
  53. }
  54. config_t *config_get(void) { return &s_config; }