Skip to content

Commit 65e350e

Browse files
Vudentznashif
authored andcommitted
Shell: Introduce shell_hexdump
This introduces shell_hexdump API which can be used to print an array such as a network buffer. Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 3ad96bf commit 65e350e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

include/shell/shell.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,15 @@ int shell_stop(const struct shell *shell);
624624
void shell_fprintf(const struct shell *shell, enum shell_vt100_color color,
625625
const char *fmt, ...);
626626

627+
/**
628+
* @brief Print data in hexadecimal format.
629+
*
630+
* @param[in] shell Pointer to the shell instance.
631+
* @param[in] data Pointer to data.
632+
* @param[in] len Length of data.
633+
*/
634+
void shell_hexdump(const struct shell *shell, const u8_t *data, size_t len);
635+
627636
/**
628637
* @brief Print info message to the shell.
629638
*

subsys/shell/shell.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,28 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color,
13551355
k_mutex_unlock(&shell->ctx->wr_mtx);
13561356
}
13571357

1358+
void shell_hexdump(const struct shell *shell, const u8_t *data, size_t len)
1359+
{
1360+
int n = 0;
1361+
1362+
while (len--) {
1363+
if (n % 16 == 0) {
1364+
shell_fprintf(shell, SHELL_NORMAL, "%08X: ", n);
1365+
}
1366+
1367+
shell_fprintf(shell, SHELL_NORMAL, "%02X ", *data++);
1368+
1369+
n++;
1370+
if (n % 16 == 0) {
1371+
shell_print(shell, "");
1372+
}
1373+
}
1374+
1375+
if (n % 16) {
1376+
shell_print(shell, "");
1377+
}
1378+
}
1379+
13581380
int shell_prompt_change(const struct shell *shell, const char *prompt)
13591381
{
13601382
__ASSERT_NO_MSG(shell);

0 commit comments

Comments
 (0)