diff options
author | YH Lin <yueherngl@google.com> | 2018-05-30 14:02:45 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-06-08 03:15:25 -0700 |
commit | eb88a0f5fa4b2909b430e8a16a54dc0f5f15b90c (patch) | |
tree | 6fac37aed1b6256badd67de7aa1844e7965e3ad7 /util | |
parent | 6857e0b159a63919f374c8b1710c10068e45cf9e (diff) | |
download | chrome-ec-eb88a0f5fa4b2909b430e8a16a54dc0f5f15b90c.tar.gz |
ectool: add "--ascii" option
As suggested in the bug, add an option to print the data in ASCII form.
BUG=b:78240760
TEST=build and test with "ectool --ascii i2cxfer..." command
BRANCH=none
Signed-off-by: YH Lin <yueherngl@chromium.org>
Change-Id: Iaef7c8713ff35287ba934abac8f18362c6636bf5
Reviewed-on: https://chromium-review.googlesource.com/1080009
Commit-Ready: YH Lin <yueherngl@chromium.org>
Tested-by: YH Lin <yueherngl@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'util')
-rw-r--r-- | util/ectool.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/util/ectool.c b/util/ectool.c index 4285e7ce65..3b62effd69 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -35,12 +35,14 @@ enum { OPT_DEV = 1000, OPT_INTERFACE, OPT_NAME, + OPT_ASCII, }; static struct option long_opts[] = { {"dev", 1, 0, OPT_DEV}, {"interface", 1, 0, OPT_INTERFACE}, {"name", 1, 0, OPT_NAME}, + {"ascii", 0, 0, OPT_ASCII}, {NULL, 0, 0, 0} }; @@ -285,6 +287,9 @@ static const char * const led_names[] = { "sysrq debug" }; BUILD_ASSERT(ARRAY_SIZE(led_names) == EC_LED_ID_COUNT); +/* ASCII mode for printing, default off */ +static int ascii_mode = 0; + /* Check SBS numerical value range */ int is_battery_range(int val) { @@ -309,7 +314,8 @@ int parse_bool(const char *s, int *dest) void print_help(const char *prog, int print_cmds) { printf("Usage: %s [--dev=n] [--interface=dev|lpc|i2c] ", prog); - printf("[--name=cros_ec|cros_sh|cros_pd] <command> [params]\n\n"); + printf("[--name=cros_ec|cros_sh|cros_pd] [--ascii] "); + printf("<command> [params]\n\n"); if (print_cmds) puts(help_str); else @@ -5695,9 +5701,15 @@ int cmd_i2c_xfer(int argc, char *argv[]) return rv; if (read_len) { - printf("Read bytes:"); - for (i = 0; i < read_len; i++) - printf(" %#02x", read_buf[i]); + if (ascii_mode) { + for (i = 0; i < read_len; i++) + printf(isprint(read_buf[i]) ? "%c" : "\\x%02x", + read_buf[i]); + } else { + printf("Read bytes:"); + for (i = 0; i < read_len; i++) + printf(" %#02x", read_buf[i]); + } printf("\n"); } else { printf("Write successful.\n"); @@ -8115,6 +8127,9 @@ int main(int argc, char *argv[]) strncpy(device_name, optarg, 40); device_name[40] = '\0'; break; + case OPT_ASCII: + ascii_mode = 1; + break; } } |