network_status.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include "network_manager.h"
  3. #include "cJSON.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. char* network_status_alloc_get_ip_info_json();
  8. /**
  9. * @brief Tries to get access to json buffer mutex.
  10. *
  11. * The HTTP server can try to access the json to serve clients while the wifi manager thread can try
  12. * to update it. These two tasks are synchronized through a mutex.
  13. *
  14. * The mutex is used by both the access point list json and the connection status json.\n
  15. * These two resources should technically have their own mutex but we lose some flexibility to save
  16. * on memory.
  17. *
  18. * This is a simple wrapper around freeRTOS function xSemaphoreTake.
  19. *
  20. * @param xTicksToWait The time in ticks to wait for the semaphore to become available.
  21. * @return true in success, false otherwise.
  22. */
  23. bool network_status_lock_json_buffer(TickType_t xTicksToWait);
  24. /**
  25. * @brief Releases the json buffer mutex.
  26. */
  27. void network_status_unlock_json_buffer();
  28. bool network_status_lock_sta_ip_string(TickType_t xTicksToWait);
  29. void network_status_unlock_sta_ip_string();
  30. /**
  31. * @brief gets the string representation of the STA IP address, e.g.: "192.168.1.69"
  32. */
  33. char* network_status_get_sta_ip_string();
  34. /**
  35. * @brief thread safe char representation of the STA IP update
  36. */
  37. void network_status_safe_update_sta_ip_string(esp_ip4_addr_t * ip4);
  38. /**
  39. * @brief Generates the connection status json: ssid and IP addresses.
  40. * @note This is not thread-safe and should be called only if network_status_lock_json_buffer call is successful.
  41. */
  42. void network_status_update_ip_info(update_reason_code_t update_reason_code);
  43. void init_network_status();
  44. void destroy_network_status();
  45. cJSON* network_status_get_basic_info(cJSON** old);
  46. void network_status_update_basic_info();
  47. void network_status_clear_ip();
  48. void network_status_safe_reset_sta_ip_string();
  49. #ifdef __cplusplus
  50. }
  51. #endif