diff options
author | px4dev <px4@purgatory.org> | 2013-01-11 02:32:05 -0800 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2013-01-11 02:32:05 -0800 |
commit | 0267782782f083c53bcf49b28e4ba2ed8c28105a (patch) | |
tree | 07bae5bd37604b0af274163bd210a338bf408d54 /apps/nshlib/nsh_dbgcmds.c | |
parent | 919d53766acb1fa6acfb9e38074666167de772e9 (diff) | |
download | px4-firmware-0267782782f083c53bcf49b28e4ba2ed8c28105a.tar.gz px4-firmware-0267782782f083c53bcf49b28e4ba2ed8c28105a.tar.bz2 px4-firmware-0267782782f083c53bcf49b28e4ba2ed8c28105a.zip |
Recover changes lost to bad merging.
Diffstat (limited to 'apps/nshlib/nsh_dbgcmds.c')
-rw-r--r-- | apps/nshlib/nsh_dbgcmds.c | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/apps/nshlib/nsh_dbgcmds.c b/apps/nshlib/nsh_dbgcmds.c index eb081fe9f..85a4ccb9c 100644 --- a/apps/nshlib/nsh_dbgcmds.c +++ b/apps/nshlib/nsh_dbgcmds.c @@ -46,6 +46,10 @@ #include <string.h> #include <errno.h> +#if CONFIG_NFILE_DESCRIPTORS > 0 +# include <fcntl.h> +#endif + #include "nsh.h" #include "nsh_console.h" @@ -328,7 +332,7 @@ void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg, } /**************************************************************************** - * Name: cmd_xd + * Name: cmd_xd, hex dump of memory ****************************************************************************/ #ifndef CONFIG_NSH_DISABLE_XD @@ -354,3 +358,58 @@ int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) return OK; } #endif + +/**************************************************************************** + * Name: cmd_hexdump, hex dump of files + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 +#ifndef CONFIG_NSH_DISABLE_HEXDUMP +int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + uint8_t buffer[IOBUFFERSIZE]; + char msg[32]; + int position; + int fd; + int ret = OK; + + /* Open the file for reading */ + + fd = open(argv[1], O_RDONLY); + if (fd < 0) + { + nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "open", NSH_ERRNO); + return ERROR; + } + + position = 0; + for (;;) + { + int nbytesread = read(fd, buffer, IOBUFFERSIZE); + + /* Check for read errors */ + + if (nbytesread < 0) + { + int errval = errno; + nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "read", NSH_ERRNO_OF(errval)); + ret = ERROR; + break; + } + else if (nbytesread > 0) + { + snprintf(msg, sizeof(msg), "%s at %08x", argv[1], position); + nsh_dumpbuffer(vtbl, msg, buffer, nbytesread); + position += nbytesread; + } + else + { + break; // EOF + } + } + + (void)close(fd); + return ret; +} +#endif +#endif |