2
0

messaging.h 2.0 KB

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