Skip to content

Commit 84163d3

Browse files
hlord2000fabiobaltieri
authored andcommitted
logging: rtt: add dictionary hex logging
Adds hex dictionary logging for RTT backend Signed-off-by: Helmut Lord <kellyhlord@gmail.com>
1 parent 53c5aa3 commit 84163d3

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

subsys/logging/backends/log_backend_rtt.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#define CONFIG_LOG_BACKEND_RTT_RETRY_CNT 10
3333
#endif
3434

35+
#if defined(CONFIG_LOG_BACKEND_RTT_OUTPUT_DICTIONARY)
36+
static const uint8_t LOG_HEX_SEP[10] = "##ZLOGV1##";
37+
#endif
38+
3539
#define DROP_MAX 99
3640

3741
#define DROP_MSG "messages dropped: \r\n"
@@ -247,12 +251,34 @@ static int data_out_overwrite_mode(uint8_t *data, size_t length, void *ctx)
247251
return length;
248252
}
249253

250-
LOG_OUTPUT_DEFINE(log_output_rtt,
251-
IS_ENABLED(CONFIG_LOG_BACKEND_RTT_MODE_BLOCK) ?
252-
data_out_block_mode :
253-
IS_ENABLED(CONFIG_LOG_BACKEND_RTT_MODE_OVERWRITE) ?
254-
data_out_overwrite_mode : data_out_drop_mode,
255-
char_buf, sizeof(char_buf));
254+
static const log_output_func_t logging_func =
255+
IS_ENABLED(CONFIG_LOG_BACKEND_RTT_MODE_BLOCK) ? data_out_block_mode
256+
: IS_ENABLED(CONFIG_LOG_BACKEND_RTT_MODE_OVERWRITE) ? data_out_overwrite_mode
257+
: data_out_drop_mode;
258+
259+
static int data_out(uint8_t *data, size_t length, void *ctx)
260+
{
261+
#if defined(CONFIG_LOG_BACKEND_RTT_OUTPUT_DICTIONARY)
262+
for (size_t i = 0; i < length; i++) {
263+
char c[2];
264+
uint8_t x[2];
265+
266+
/* upper 8-bit */
267+
x[0] = data[i] >> 4;
268+
(void)hex2char(x[0], &c[0]);
269+
270+
/* lower 8-bit */
271+
x[1] = data[i] & 0x0FU;
272+
(void)hex2char(x[1], &c[1]);
273+
logging_func(c, sizeof(c), ctx);
274+
}
275+
return length;
276+
#endif
277+
278+
return logging_func(data, length, ctx);
279+
}
280+
281+
LOG_OUTPUT_DEFINE(log_output_rtt, data_out, char_buf, sizeof(char_buf));
256282

257283
static void log_backend_rtt_cfg(void)
258284
{
@@ -267,6 +293,10 @@ static void log_backend_rtt_init(struct log_backend const *const backend)
267293
log_backend_rtt_cfg();
268294
}
269295

296+
#if defined(CONFIG_LOG_BACKEND_RTT_OUTPUT_DICTIONARY)
297+
logging_func((uint8_t *)LOG_HEX_SEP, sizeof(LOG_HEX_SEP), NULL);
298+
#endif
299+
270300
host_present = true;
271301
line_pos = line_buf;
272302
}

0 commit comments

Comments
 (0)