diff --git a/include/shell/shell.h b/include/shell/shell.h index 99b54eeddd9..c282adaef90 100644 --- a/include/shell/shell.h +++ b/include/shell/shell.h @@ -36,6 +36,8 @@ extern "C" { #define SHELL_CMD_ROOT_LVL (0u) +#define SHELL_HEXDUMP_BYTES_IN_LINE 16 + /** * @brief Flag indicates that optional arguments will be treated as one, * unformatted argument. @@ -783,6 +785,24 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color, void shell_vfprintf(const struct shell *shell, enum shell_vt100_color color, const char *fmt, va_list args); +/** + * @brief Print a line of data in hexadecimal format. + * + * Each line shows the offset, bytes and then ASCII representation. + * + * For example: + * + * 00008010: 20 25 00 20 2f 48 00 08 80 05 00 20 af 46 00 + * | %. /H.. ... .F. | + * + * @param[in] shell Pointer to the shell instance. + * @param[in] offset Offset to show for this line. + * @param[in] data Pointer to data. + * @param[in] len Length of data. + */ +void shell_hexdump_line(const struct shell *shell, unsigned int offset, + const uint8_t *data, size_t len); + /** * @brief Print data in hexadecimal format. * diff --git a/subsys/shell/shell.c b/subsys/shell/shell.c index d29f2dc1b9d..cfd0400a446 100644 --- a/subsys/shell/shell.c +++ b/subsys/shell/shell.c @@ -15,8 +15,6 @@ #include "shell_vt100.h" #include "shell_wildcard.h" -#define HEXDUMP_BYTES_IN_LINE 16 - /* 2 == 1 char for cmd + 1 char for '\0' */ #if (CONFIG_SHELL_CMD_BUFF_SIZE < 2) #error too small CONFIG_SHELL_CMD_BUFF_SIZE @@ -1389,14 +1387,14 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color, va_end(args); } -static void shell_hexdump_line(const struct shell *shell, unsigned int offset, - const uint8_t *data, size_t len) +void shell_hexdump_line(const struct shell *shell, unsigned int offset, + const uint8_t *data, size_t len) { int i; shell_fprintf(shell, SHELL_NORMAL, "%08X: ", offset); - for (i = 0; i < HEXDUMP_BYTES_IN_LINE; i++) { + for (i = 0; i < SHELL_HEXDUMP_BYTES_IN_LINE; i++) { if (i > 0 && !(i % 8)) { shell_fprintf(shell, SHELL_NORMAL, " "); } @@ -1411,7 +1409,7 @@ static void shell_hexdump_line(const struct shell *shell, unsigned int offset, shell_fprintf(shell, SHELL_NORMAL, "|"); - for (i = 0; i < HEXDUMP_BYTES_IN_LINE; i++) { + for (i = 0; i < SHELL_HEXDUMP_BYTES_IN_LINE; i++) { if (i > 0 && !(i % 8)) { shell_fprintf(shell, SHELL_NORMAL, " "); } @@ -1435,7 +1433,7 @@ void shell_hexdump(const struct shell *shell, const uint8_t *data, size_t len) size_t line_len; while (len) { - line_len = MIN(len, HEXDUMP_BYTES_IN_LINE); + line_len = MIN(len, SHELL_HEXDUMP_BYTES_IN_LINE); shell_hexdump_line(shell, p - data, p, line_len);