messaging.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "sdkconfig.h"
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/ringbuf.h"
  4. #include "cJSON.h"
  5. #pragma once
  6. typedef enum {
  7. MESSAGING_INFO,
  8. MESSAGING_WARNING,
  9. MESSAGING_ERROR
  10. } messaging_types;
  11. typedef enum {
  12. MESSAGING_CLASS_OTA,
  13. MESSAGING_CLASS_SYSTEM,
  14. MESSAGING_CLASS_STATS,
  15. MESSAGING_CLASS_CFGCMD
  16. } messaging_classes;
  17. typedef struct messaging_list_t *messaging_handle_t;
  18. typedef struct {
  19. time_t sent_time;
  20. messaging_types type;
  21. messaging_classes msg_class;
  22. size_t msg_size;
  23. char message[];
  24. } single_message_t;
  25. cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle);
  26. messaging_handle_t messaging_register_subscriber(uint8_t max_count, char * name);
  27. esp_err_t messaging_post_to_queue(messaging_handle_t subscriber_handle, single_message_t * message, size_t message_size);
  28. void messaging_post_message(messaging_types type,messaging_classes msg_class, const char * fmt, ...);
  29. cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle);
  30. single_message_t * messaging_retrieve_message(RingbufHandle_t buf_handle);
  31. void log_send_messaging(messaging_types msgtype,const char *fmt, ...);
  32. void cmd_send_messaging(const char * cmdname,messaging_types msgtype, const char *fmt, ...);
  33. esp_err_t messaging_type_to_err_type(messaging_types type);
  34. void messaging_service_init();
  35. #define REALLOC_CAT(e,n) e=realloc(e,strlen(n)); e=strcat(e,n)
  36. #define LOG_SEND(y, ...) \
  37. { \
  38. ESP_LOG_LEVEL_LOCAL(messaging_type_to_err_type(y),TAG, ##__VA_ARGS__); \
  39. messaging_post_message(y, MESSAGING_CLASS_SYSTEM, ##__VA_ARGS__); }
  40. #define LOG_SEND_ERROR( ...) LOG_SEND(MESSAGING_ERROR,##__VA_ARGS__)
  41. #define LOG_SEND_INFO( ...) LOG_SEND(MESSAGING_INFO,##__VA_ARGS__)
  42. #define LOG_SEND_WARN( ...) LOG_SEND(MESSAGING_WARNING,##__VA_ARGS__)