messaging.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_CLASS_BT
  17. } messaging_classes;
  18. typedef struct messaging_list_t *messaging_handle_t;
  19. typedef struct {
  20. time_t sent_time;
  21. messaging_types type;
  22. messaging_classes msg_class;
  23. size_t msg_size;
  24. char message[];
  25. } single_message_t;
  26. cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle);
  27. messaging_handle_t messaging_register_subscriber(uint8_t max_count, char * name);
  28. esp_err_t messaging_post_to_queue(messaging_handle_t subscriber_handle, single_message_t * message, size_t message_size);
  29. void messaging_post_message(messaging_types type,messaging_classes msg_class, const char * fmt, ...);
  30. cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle);
  31. single_message_t * messaging_retrieve_message(RingbufHandle_t buf_handle);
  32. void log_send_messaging(messaging_types msgtype,const char *fmt, ...);
  33. void cmd_send_messaging(const char * cmdname,messaging_types msgtype, const char *fmt, ...);
  34. esp_err_t messaging_type_to_err_type(messaging_types type);
  35. void messaging_service_init();
  36. #define REALLOC_CAT(e,n) e=realloc(e,strlen(n)); e=strcat(e,n)
  37. #define LOG_SEND(y, ...) \
  38. { \
  39. ESP_LOG_LEVEL_LOCAL(messaging_type_to_err_type(y),TAG, ##__VA_ARGS__); \
  40. messaging_post_message(y, MESSAGING_CLASS_SYSTEM, ##__VA_ARGS__); }
  41. #define LOG_SEND_ERROR( ...) LOG_SEND(MESSAGING_ERROR,##__VA_ARGS__)
  42. #define LOG_SEND_INFO( ...) LOG_SEND(MESSAGING_INFO,##__VA_ARGS__)
  43. #define LOG_SEND_WARN( ...) LOG_SEND(MESSAGING_WARNING,##__VA_ARGS__)