rtthread_bt_log_impl.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <rtthread.h>
  2. #include <rthw.h>
  3. #include "rtthread_bt_log_impl.h"
  4. #include "base/byteorder.h"
  5. #include "logging/bt_log_impl.h"
  6. #include "logging/bt_log.h"
  7. #define H4_CMD 0x01
  8. #define H4_ACL 0x02
  9. #define H4_SCO 0x03
  10. #define H4_EVT 0x04
  11. #define H4_ISO 0x05
  12. #define LOG_FILE_PRINT_BUFFER_MAX_LENGTH (0x100)
  13. __unused
  14. static const char *get_packet_type_str(uint8_t packet_type, uint8_t in)
  15. {
  16. switch (packet_type)
  17. {
  18. case H4_CMD:
  19. return ("CMD => ");
  20. break;
  21. case H4_EVT:
  22. return ("EVT <= ");
  23. break;
  24. case H4_ACL:
  25. if (in)
  26. {
  27. return ("ACL <= ");
  28. }
  29. else
  30. {
  31. return ("ACL => ");
  32. }
  33. break;
  34. case H4_SCO:
  35. if (in)
  36. {
  37. return ("SCO <= ");
  38. }
  39. else
  40. {
  41. return ("SCO => ");
  42. }
  43. break;
  44. case H4_ISO:
  45. if (in)
  46. {
  47. return ("ISO <= ");
  48. }
  49. else
  50. {
  51. return ("ISO => ");
  52. }
  53. break;
  54. default:
  55. return "";
  56. }
  57. }
  58. static void log_printf_dump(uint8_t level, const char *format, va_list argptr)
  59. {
  60. char log_printf_buffer[LOG_FILE_PRINT_BUFFER_MAX_LENGTH];
  61. rt_vsnprintf(log_printf_buffer, sizeof(log_printf_buffer), format,
  62. argptr);
  63. rt_kprintf(log_printf_buffer);
  64. }
  65. static void log_packet_dump(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len)
  66. {
  67. #if 0
  68. char log_printf_buffer[LOG_FILE_PRINT_BUFFER_MAX_LENGTH];
  69. const char *packet_type_str = get_packet_type_str(packet_type, in);
  70. char msg_str[LOG_FILE_PRINT_BUFFER_MAX_LENGTH];
  71. log_hex_dump(msg_str, sizeof(msg_str), packet, len);
  72. rt_snprintf(log_printf_buffer, sizeof(log_printf_buffer), "%s %s\n",
  73. packet_type_str, msg_str);
  74. rt_kprintf(log_printf_buffer);
  75. #endif
  76. }
  77. static void log_point_dump(uint32_t point)
  78. {
  79. }
  80. static void log_init(void)
  81. {
  82. }
  83. static const bt_log_impl_t log_impl = {
  84. log_init,
  85. log_packet_dump,
  86. log_printf_dump,
  87. log_point_dump,
  88. };
  89. const bt_log_impl_t *bt_log_impl_local_instance(void)
  90. {
  91. return &log_impl;
  92. }