state_machine.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #include "esp_wifi.h"
  6. #include "esp_wifi_types.h"
  7. #define STA_POLLING_MIN (15 * 1000)
  8. #define STA_POLLING_MAX (10 * 60 * 1000)
  9. //enum class state { idle, stopped, started, running };
  10. //enum class trigger { start, stop, set_speed, halt };
  11. typedef enum {
  12. t_link_up,
  13. t_link_down,
  14. t_configure,
  15. t_got_ip,
  16. t_disconnect,
  17. t_next,
  18. t_start,
  19. t_scan,
  20. t_fail,
  21. t_success,
  22. t_scan_done,
  23. t_connect,
  24. t_reboot,
  25. t_reboot_url,
  26. t_lost_connection,
  27. t_update_status
  28. } trig_t;
  29. typedef enum {
  30. instantiated,
  31. initializing,
  32. global,
  33. eth_starting,
  34. eth_active,
  35. eth_active_linkup,
  36. eth_active_connected,
  37. eth_active_linkdown,
  38. wifi_up,
  39. wifi_initializing,
  40. wifi_connecting_scanning,
  41. wifi_connecting,
  42. wifi_connected,
  43. wifi_disconnecting,
  44. wifi_user_disconnected,
  45. wifi_connected_waiting_for_ip,
  46. wifi_connected_scanning,
  47. wifi_lost_connection,
  48. wifi_ap_mode,
  49. wifi_ap_mode_scanning,
  50. wifi_ap_mode_scan_done,
  51. wifi_ap_mode_connecting,
  52. wifi_ap_mode_connected,
  53. system_rebooting
  54. } state_t;
  55. typedef enum {
  56. OTA,
  57. RECOVERY,
  58. RESTART,
  59. } reboot_type_t;
  60. typedef struct {
  61. trig_t trigger;
  62. union
  63. {
  64. wifi_config_t* wifi_config;
  65. reboot_type_t rtype;
  66. char * strval;
  67. wifi_event_sta_disconnected_t * disconnected_event;
  68. } ;
  69. } queue_message;
  70. bool network_manager_event_simple(trig_t trigger);
  71. bool network_manager_event(trig_t trigger, void* param);
  72. bool network_t_connect_event(wifi_config_t* wifi_config);
  73. bool network_t_link_event(bool link_up);
  74. bool network_manager_async_event(trig_t trigger, void* param);
  75. bool network_manager_async(trig_t trigger);
  76. bool network_manager_async_fail();
  77. bool network_manager_async_success();
  78. bool network_manager_async_link_up();
  79. bool network_manager_async_link_down();
  80. bool network_manager_async_configure();
  81. bool network_manager_async_got_ip();
  82. bool network_manager_async_next();
  83. bool network_manager_async_start();
  84. bool network_manager_async_scan();
  85. bool network_manager_async_scan_done();
  86. bool network_manager_async_connect(wifi_config_t* wifi_config);
  87. bool network_manager_async_lost_connection(wifi_event_sta_disconnected_t * disconnected_event);
  88. bool network_manager_async_reboot(reboot_type_t rtype);
  89. void network_manager_reboot_ota(char* url);
  90. bool network_manager_async_disconnect();
  91. bool network_manager_async_update_status();
  92. /**
  93. * Allocate heap memory for the wifi manager and start the wifi_manager RTOS task
  94. */
  95. void network_manager_start();
  96. #ifdef __cplusplus
  97. }
  98. #endif