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 <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2019-03-19 18:24:34 +02:00 committed by Anas Nashif
commit 65e350e6af
2 changed files with 31 additions and 0 deletions

View file

@ -1355,6 +1355,28 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color,
k_mutex_unlock(&shell->ctx->wr_mtx);
}
void shell_hexdump(const struct shell *shell, const u8_t *data, size_t len)
{
int n = 0;
while (len--) {
if (n % 16 == 0) {
shell_fprintf(shell, SHELL_NORMAL, "%08X: ", n);
}
shell_fprintf(shell, SHELL_NORMAL, "%02X ", *data++);
n++;
if (n % 16 == 0) {
shell_print(shell, "");
}
}
if (n % 16) {
shell_print(shell, "");
}
}
int shell_prompt_change(const struct shell *shell, const char *prompt)
{
__ASSERT_NO_MSG(shell);