This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new ae7765449 flash_test: Show printable characters along when read
ae7765449 is described below
commit ae7765449f7dfdb806a587bca403f4c0ea3e308c
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Wed Jun 26 23:58:34 2024 +0200
flash_test: Show printable characters along when read
So far flash read displayed data in hexadecimal format only.
Now additional ascii values are shown for printable
characters, which is common practice
Old format:
compat> flash 0 read 0x1d110100 0x20
Read 0x1d110100 + 32
0x1d110100: 0x09 0x0f 0x00 0x6c 0x6f 0x67 0x2d 0x73
0x1d110108: 0x74 0x6f 0x72 0x61 0x67 0x65 0x20 0xff
New format:
compat> flash 0 read 0x1d110100 0x20
Read 0x1d110100 + 32
0x1d110100: 0x09 0x0f 0x00 0x6c 0x6f 0x67 0x2d 0x73 ...log-s
0x1d110108: 0x74 0x6f 0x72 0x61 0x67 0x65 0x20 0xff torage .
Signed-off-by: Jerzy Kasenberg <[email protected]>
Signed-off-by: Jerzy Kasenberg <[email protected]>
---
test/flash_test/src/flash_test.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/test/flash_test/src/flash_test.c b/test/flash_test/src/flash_test.c
index ef5fa8303..f1b975072 100644
--- a/test/flash_test/src/flash_test.c
+++ b/test/flash_test/src/flash_test.c
@@ -26,6 +26,7 @@
#include <shell/shell.h>
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
static int flash_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv,
struct streamer *streamer);
@@ -48,7 +49,6 @@ flash_cli_cmd(const struct shell_cmd *cmd, int argc, char
**argv,
int sec_cnt;
int i;
int devid;
- int soff;
char *eptr;
char tmp_buf[32];
char pr_str[80];
@@ -157,21 +157,20 @@ flash_cli_cmd(const struct shell_cmd *cmd, int argc, char
**argv,
(long unsigned int) off);
break;
}
- for (i = 0, soff = 0; i < sec_cnt; i++) {
- soff += snprintf(pr_str + soff, sizeof(pr_str) - soff,
- "0x%02x ", tmp_buf[i] & 0xff);
- if (i % 8 == 7) {
- streamer_printf(streamer, " 0x%lx: %s\n",
- (long unsigned int) off, pr_str);
- soff = 0;
- off += 8;
+ for (i = 0; i < sec_cnt; i++) {
+ int n = i & 7;
+ if (n == 0) {
+ streamer_printf(streamer, " 0x%lx: ", (long unsigned
int)off + i);
+ }
+ snprintf(pr_str + n * 5, 6, "0x%02x ", tmp_buf[i] & 0xff);
+ pr_str[41 + n] = isprint((uint8_t)tmp_buf[i]) ? tmp_buf[i] :
'.';
+ if (n == 7 || i + 1 == sec_cnt) {
+ pr_str[41 + n + 1] = '\0';
+ memset(pr_str + (5 * n + 5), ' ', 5 * (7 - n) + 1);
+ streamer_printf(streamer, "%s\n", pr_str);
}
}
- if (i % 8) {
- streamer_printf(streamer, " 0x%lx: %s\n",
- (long unsigned int) off, pr_str);
- off += i;
- }
+ off += sec_cnt;
}
} else if (!strcmp(argv[2], "write")) {
streamer_printf(streamer, "Write 0x%lx + %lx\n",