network_services.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include "esp_netif.h"
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #define ADD_ROOT(name, ...) name,
  7. #define ADD_ROOT_LEAF(name, ...) name,
  8. #define ADD_LEAF(name, ...) name,
  9. #define ALL_NM_STATE \
  10. ADD_ROOT_LEAF(NETWORK_INSTANTIATED_STATE)\
  11. ADD_ROOT_LEAF(NETWORK_INITIALIZING_STATE)\
  12. ADD_ROOT(NETWORK_ETH_ACTIVE_STATE, Eth_Active_State)\
  13. ADD_ROOT(NETWORK_WIFI_ACTIVE_STATE, Wifi_Active_State)\
  14. ADD_ROOT(NETWORK_WIFI_CONFIGURING_ACTIVE_STATE, Wifi_Configuring_State)
  15. #define ALL_ETH_STATE(PARENT, LEVEL)\
  16. ADD_LEAF(ETH_STARTING_STATE,PARENT,LEVEL)\
  17. ADD_LEAF(ETH_ACTIVE_LINKUP_STATE,PARENT,LEVEL)\
  18. ADD_LEAF(ETH_ACTIVE_LINKDOWN_STATE,PARENT,LEVEL)\
  19. ADD_LEAF(ETH_ACTIVE_CONNECTED_STATE,PARENT,LEVEL)\
  20. ADD_LEAF(ETH_CONNECTING_NEW_STATE,PARENT,LEVEL)
  21. #define ALL_WIFI_STATE(PARENT, LEVEL)\
  22. ADD_LEAF(WIFI_INITIALIZING_STATE,PARENT,LEVEL)\
  23. ADD_LEAF(WIFI_CONNECTING_STATE,PARENT,LEVEL)\
  24. ADD_LEAF(WIFI_CONNECTING_NEW_STATE,PARENT,LEVEL)\
  25. ADD_LEAF(WIFI_CONNECTING_NEW_FAILED_STATE,PARENT,LEVEL)\
  26. ADD_LEAF(WIFI_CONNECTED_STATE,PARENT,LEVEL)\
  27. ADD_LEAF(WIFI_USER_DISCONNECTED_STATE,PARENT,LEVEL)\
  28. ADD_LEAF(WIFI_LOST_CONNECTION_STATE,PARENT,LEVEL)
  29. #define ALL_WIFI_CONFIGURING_STATE(PARENT, LEVEL)\
  30. ADD_LEAF(WIFI_CONFIGURING_STATE,PARENT,LEVEL)\
  31. ADD_LEAF(WIFI_CONFIGURING_CONNECT_STATE,PARENT,LEVEL)\
  32. ADD_LEAF(WIFI_CONFIGURING_CONNECT_SUCCESS_STATE,PARENT,LEVEL)
  33. typedef enum {
  34. ALL_NM_STATE
  35. TOTAL_NM_STATE
  36. } nm_state_t;
  37. typedef enum {
  38. ALL_WIFI_STATE(,)
  39. TOTAL_WIFI_ACTIVE_STATE
  40. } mn_wifi_active_state_t;
  41. typedef enum {
  42. ALL_ETH_STATE(,)
  43. TOTAL_ETH_ACTIVE_STATE
  44. } mn_eth_active_state_t;
  45. typedef enum {
  46. ALL_WIFI_CONFIGURING_STATE(,)
  47. TOTAL_WIFI_CONFIGURING_STATE
  48. } mn_wifi_configuring_state_t;
  49. #undef ADD_STATE
  50. #undef ADD_ROOT
  51. #undef ADD_ROOT_LEAF
  52. #undef ADD_LEAF
  53. typedef void (*network_status_reached_cb)(nm_state_t state_id, int sub_state);
  54. esp_err_t network_register_state_callback(nm_state_t state, int sub_state, const char* from, network_status_reached_cb cb);
  55. esp_netif_t * network_get_active_interface();
  56. esp_err_t network_get_hostname(const char **hostname);
  57. esp_err_t network_get_ip_info(tcpip_adapter_ip_info_t* ipInfo);
  58. #ifdef __cplusplus
  59. }
  60. #endif