lib_printf.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Copyright 2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @file lib_printf.c
  16. *
  17. * This file contains library-specific printf functions
  18. * used by WiFi libraries in the `lib` directory.
  19. * These function are used to catch any output which gets printed
  20. * by libraries, and redirect it to ESP_LOG macros.
  21. *
  22. * Eventually WiFi libraries will use ESP_LOG functions internally
  23. * and these definitions will be removed.
  24. */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include "esp_log.h"
  28. #include "esp_attr.h"
  29. #define VPRINTF_STACK_BUFFER_SIZE 80
  30. static int lib_printf(const char* tag, const char* format, va_list arg)
  31. {
  32. char temp[VPRINTF_STACK_BUFFER_SIZE];
  33. int len = vsnprintf(temp, sizeof(temp) - 1, format, arg);
  34. temp[sizeof(temp) - 1] = 0;
  35. int i;
  36. for (i = len - 1; i >= 0; --i) {
  37. if (temp[i] != '\n' && temp[i] != '\r' && temp[i] != ' ') {
  38. break;
  39. }
  40. temp[i] = 0;
  41. }
  42. if (i > 0) {
  43. ESP_EARLY_LOGI(tag, "%s", temp);
  44. }
  45. va_end(arg);
  46. return len;
  47. }
  48. int phy_printf(const char* format, ...)
  49. {
  50. va_list arg;
  51. va_start(arg, format);
  52. int res = lib_printf("phy", format, arg);
  53. va_end(arg);
  54. return res;
  55. }
  56. int rtc_printf(const char* format, ...)
  57. {
  58. va_list arg;
  59. va_start(arg, format);
  60. int res = lib_printf("rtc", format, arg);
  61. va_end(arg);
  62. return res;
  63. }
  64. int wpa_printf(const char* format, ...)
  65. {
  66. va_list arg;
  67. va_start(arg, format);
  68. int res = lib_printf("wpa", format, arg);
  69. va_end(arg);
  70. return res;
  71. }
  72. int wpa2_printf(const char* format, ...)
  73. {
  74. va_list arg;
  75. va_start(arg, format);
  76. int res = lib_printf("wpa2", format, arg);
  77. va_end(arg);
  78. return res;
  79. }
  80. int wps_printf(const char* format, ...)
  81. {
  82. va_list arg;
  83. va_start(arg, format);
  84. int res = lib_printf("wps", format, arg);
  85. va_end(arg);
  86. return res;
  87. }
  88. int pp_printf(const char* format, ...)
  89. {
  90. va_list arg;
  91. va_start(arg, format);
  92. int res = lib_printf("pp", format, arg);
  93. va_end(arg);
  94. return res;
  95. }
  96. int sc_printf(const char* format, ...)
  97. {
  98. va_list arg;
  99. va_start(arg, format);
  100. int res = lib_printf("smartconfig", format, arg);
  101. va_end(arg);
  102. return res;
  103. }
  104. int core_printf(const char* format, ...)
  105. {
  106. va_list arg;
  107. va_start(arg, format);
  108. int res = lib_printf("core", format, arg);
  109. va_end(arg);
  110. return res;
  111. }
  112. int net80211_printf(const char* format, ...)
  113. {
  114. va_list arg;
  115. va_start(arg, format);
  116. int res = lib_printf("net80211", format, arg);
  117. va_end(arg);
  118. return res;
  119. }