@@ -66,19 +66,24 @@ extern "C"
66
66
#define ARDUHAL_LOG_COLOR_I ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_GREEN)
67
67
#define ARDUHAL_LOG_COLOR_D ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_CYAN)
68
68
#define ARDUHAL_LOG_COLOR_V ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_GRAY)
69
+ #define ARDUHAL_LOG_COLOR_PRINT (letter ) log_printf(ARDUHAL_LOG_COLOR_ ## letter)
70
+ #define ARDUHAL_LOG_COLOR_PRINT_END log_printf(ARDUHAL_LOG_RESET_COLOR)
69
71
#else
70
72
#define ARDUHAL_LOG_COLOR_E
71
73
#define ARDUHAL_LOG_COLOR_W
72
74
#define ARDUHAL_LOG_COLOR_I
73
75
#define ARDUHAL_LOG_COLOR_D
74
76
#define ARDUHAL_LOG_COLOR_V
75
77
#define ARDUHAL_LOG_RESET_COLOR
78
+ #define ARDUHAL_LOG_COLOR_PRINT (letter )
79
+ #define ARDUHAL_LOG_COLOR_PRINT_END
76
80
#endif
77
81
78
82
79
83
80
84
const char * pathToFileName (const char * path );
81
85
int log_printf (const char * fmt , ...);
86
+ void log_print_buf (const uint8_t * b , size_t len );
82
87
83
88
#define ARDUHAL_SHORT_LOG_FORMAT (letter , format ) ARDUHAL_LOG_COLOR_ ## letter format ARDUHAL_LOG_RESET_COLOR "\r\n"
84
89
#define ARDUHAL_LOG_FORMAT (letter , format ) ARDUHAL_LOG_COLOR_ ## letter "[%6u][" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", (unsigned long) (esp_timer_get_time() / 1000ULL), pathToFileName(__FILE__), __LINE__, __FUNCTION__
@@ -87,78 +92,96 @@ int log_printf(const char *fmt, ...);
87
92
#ifndef USE_ESP_IDF_LOG
88
93
#define log_v (format , ...) log_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__)
89
94
#define isr_log_v (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__)
95
+ #define log_buf_v (b ,l ) do{ARDUHAL_LOG_COLOR_PRINT(V);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0)
90
96
#else
91
97
#define log_v (format , ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, TAG, format, ##__VA_ARGS__);}while(0)
92
98
#define isr_log_v (format , ...) do {ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
99
+ #define log_buf_v (b ,l ) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_VERBOSE);}while(0)
93
100
#endif
94
101
#else
95
102
#define log_v (format , ...)
96
103
#define isr_log_v (format , ...)
104
+ #define log_buf_v (b ,l )
97
105
#endif
98
106
99
107
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
100
108
#ifndef USE_ESP_IDF_LOG
101
109
#define log_d (format , ...) log_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__)
102
110
#define isr_log_d (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__)
111
+ #define log_buf_d (b ,l ) do{ARDUHAL_LOG_COLOR_PRINT(D);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0)
103
112
#else
104
113
#define log_d (format , ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, TAG, format, ##__VA_ARGS__);}while(0)
105
114
#define isr_log_d (format , ...) do {ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
115
+ #define log_buf_d (b ,l ) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_DEBUG);}while(0)
106
116
#endif
107
117
#else
108
118
#define log_d (format , ...)
109
119
#define isr_log_d (format , ...)
120
+ #define log_buf_d (b ,l )
110
121
#endif
111
122
112
123
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
113
124
#ifndef USE_ESP_IDF_LOG
114
125
#define log_i (format , ...) log_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__)
115
126
#define isr_log_i (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__)
127
+ #define log_buf_i (b ,l ) do{ARDUHAL_LOG_COLOR_PRINT(I);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0)
116
128
#else
117
129
#define log_i (format , ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, TAG, format, ##__VA_ARGS__);}while(0)
118
130
#define isr_log_i (format , ...) do {ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
131
+ #define log_buf_i (b ,l ) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_INFO);}while(0)
119
132
#endif
120
133
#else
121
134
#define log_i (format , ...)
122
135
#define isr_log_i (format , ...)
136
+ #define log_buf_i (b ,l )
123
137
#endif
124
138
125
139
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN
126
140
#ifndef USE_ESP_IDF_LOG
127
141
#define log_w (format , ...) log_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__)
128
142
#define isr_log_w (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__)
143
+ #define log_buf_w (b ,l ) do{ARDUHAL_LOG_COLOR_PRINT(W);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0)
129
144
#else
130
145
#define log_w (format , ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, TAG, format, ##__VA_ARGS__);}while(0)
131
146
#define isr_log_w (format , ...) do {ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
147
+ #define log_buf_w (b ,l ) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_WARN);}while(0)
132
148
#endif
133
149
#else
134
150
#define log_w (format , ...)
135
151
#define isr_log_w (format , ...)
152
+ #define log_buf_w (b ,l )
136
153
#endif
137
154
138
155
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
139
156
#ifndef USE_ESP_IDF_LOG
140
157
#define log_e (format , ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
141
158
#define isr_log_e (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
159
+ #define log_buf_e (b ,l ) do{ARDUHAL_LOG_COLOR_PRINT(E);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0)
142
160
#else
143
161
#define log_e (format , ...) do {log_to_esp(TAG, ESP_LOG_ERROR, format, ##__VA_ARGS__);}while(0)
144
162
#define isr_log_e (format , ...) do {ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
163
+ #define log_buf_e (b ,l ) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR);}while(0)
145
164
#endif
146
165
#else
147
166
#define log_e (format , ...)
148
167
#define isr_log_e (format , ...)
168
+ #define log_buf_e (b ,l )
149
169
#endif
150
170
151
171
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_NONE
152
172
#ifndef USE_ESP_IDF_LOG
153
173
#define log_n (format , ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
154
174
#define isr_log_n (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
175
+ #define log_buf_n (b ,l ) do{ARDUHAL_LOG_COLOR_PRINT(E);log_print_buf(b,l);ARDUHAL_LOG_COLOR_PRINT_END;}while(0)
155
176
#else
156
177
#define log_n (format , ...) do {ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__);}while(0)
157
178
#define isr_log_n (format , ...) do {ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
179
+ #define log_buf_n (b ,l ) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR);}while(0)
158
180
#endif
159
181
#else
160
182
#define log_n (format , ...)
161
183
#define isr_log_n (format , ...)
184
+ #define log_buf_n (b ,l )
162
185
#endif
163
186
164
187
#include "esp_log.h"
0 commit comments