diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-09-07 13:42:55 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-09-07 13:42:55 +0000 |
commit | 33ebc18c23173530e25b9585010e3411530f4940 (patch) | |
tree | 3168654f7c9ee4ffb5124dd9f0990369c5e79852 | |
parent | a5f7cf98731bec3e33558a7805c37463e0d634ae (diff) | |
download | px4-nuttx-33ebc18c23173530e25b9585010e3411530f4940.tar.gz px4-nuttx-33ebc18c23173530e25b9585010e3411530f4940.tar.bz2 px4-nuttx-33ebc18c23173530e25b9585010e3411530f4940.zip |
Add NSH xd command
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@892 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/ChangeLog | 1 | ||||
-rw-r--r-- | nuttx/Documentation/NuttShell.html | 34 | ||||
-rw-r--r-- | nuttx/Documentation/NuttX.html | 3 | ||||
-rw-r--r-- | nuttx/examples/nsh/README.txt | 16 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh.h | 6 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh_dbgcmds.c | 68 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh_fscmds.c | 2 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh_main.c | 3 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh_telnetd.c | 70 |
9 files changed, 146 insertions, 57 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 55b263e1f..8f774358d 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -455,4 +455,5 @@ and mounted. * Corrected a critical bug that prevent recvfrom from receiving packets from any remote UDP port. + * NSH: Add hexadecimal dump command (xd) diff --git a/nuttx/Documentation/NuttShell.html b/nuttx/Documentation/NuttShell.html index 1b83454b9..bedb624f8 100644 --- a/nuttx/Documentation/NuttShell.html +++ b/nuttx/Documentation/NuttShell.html @@ -255,6 +255,12 @@ </td> </tr> <tr> + <td><br></td> + <td> + <a href="#cmdxd">2.31 Hexadecimal Dump (xd)</a> + </td> +</tr> +<tr> <td valign="top" width="22"><img height="20" width="20" src="favicon.ico"></td> <td> <a href="#configuration">3.0 Configuration Settings</a> @@ -1414,6 +1420,33 @@ usleep <usec> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> + <a name="cmdxd"><h2>2.31 Hexadecimal dump (xd)</h2></a> + </td> + </tr> +</table> + +<a <p><b>Command Syntax:</b></p> +<ul><pre> +xd <hex-address> <byte-count> +</pre></ul> +<p> + <b>Synopsis</b>. + Dump <code><byte-count></code> bytes of data from address <code><hex-address></code>. +</p> +<p><b>Example:</b></p> +<ul><pre> +nsh> xd 410e0 512 +Hex dump: +0000: 00 00 00 00 9c 9d 03 00 00 00 00 01 11 01 10 06 ................ +0010: 12 01 11 01 25 08 13 0b 03 08 1b 08 00 00 02 24 ....%..........$ +... +01f0: 08 3a 0b 3b 0b 49 13 00 00 04 13 01 01 13 03 08 .:.;.I.......... +nsh> +</pre></ul> + +<table width ="100%"> + <tr bgcolor="#e4e4e4"> + <td> <a name="configuration"><h1>3.0 Configuration Settings</h1></a> </td> </tr> @@ -1800,6 +1833,7 @@ usleep <usec> <li><a href="#cmdunmount"><code>umount</code></a></li> <li><a href="#cmdunset"><code>unset</code></a></li> <li><a href="#cmdusleep"><code>usleep</code></a></li> + <li><a href="#cmdxd"><code>xd</code></a></li> </ul></td> </tr></table> diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index 4674077cc..04704af51 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -8,7 +8,7 @@ <tr align="center" bgcolor="#e4e4e4"> <td> <h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1> - <p>Last Updated: September 6, 2008</p> + <p>Last Updated: September 7, 2008</p> </td> </tr> </table> @@ -1082,6 +1082,7 @@ nuttx-0.3.14 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> and mounted. * Corrected a critical bug that prevent recvfrom from receiving packets from any remote UDP port. + * NSH: Add hexadecimal dump command (xd) pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/nsh/README.txt b/nuttx/examples/nsh/README.txt index c202d7a8e..69187f1a3 100644 --- a/nuttx/examples/nsh/README.txt +++ b/nuttx/examples/nsh/README.txt @@ -552,6 +552,21 @@ o usleep <usec> Pause execution (sleep) of <usec> microseconds. +o xd <hex-address> <byte-count> + + Dump <byte-count> bytes of data from address <hex-address> + + Example: + ^^^^^^^^ + + nsh> xd 410e0 512 + Hex dump: + 0000: 00 00 00 00 9c 9d 03 00 00 00 00 01 11 01 10 06 ................ + 0010: 12 01 11 01 25 08 13 0b 03 08 1b 08 00 00 02 24 ....%..........$ + ... + 01f0: 08 3a 0b 3b 0b 49 13 00 00 04 13 01 01 13 03 08 .:.;.I.......... + nsh> + NSH Configuration Settings ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -598,6 +613,7 @@ Command Dependencies on Configuration Settings umount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT unset !CONFIG_DISABLE_ENVIRON usleep !CONFIG_DISABLE_SIGNALS + xd --- * NOTES: - Because of hardware padding, the actual required size may be larger. diff --git a/nuttx/examples/nsh/nsh.h b/nuttx/examples/nsh/nsh.h index c69aa2342..d8d18a72a 100644 --- a/nuttx/examples/nsh/nsh.h +++ b/nuttx/examples/nsh/nsh.h @@ -259,6 +259,11 @@ extern char *nsh_getfullpath(FAR struct nsh_vtbl_s *vtbl, const char *relpath); extern void nsh_freefullpath(char *relpath); #endif +/* Debug */ + +extern void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg, + const char *buffer, ssize_t nbytes); + /* Shell command handlers */ extern int cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); @@ -268,6 +273,7 @@ extern int cmd_mh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_mw(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_mem(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +extern int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT extern int cmd_test(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); diff --git a/nuttx/examples/nsh/nsh_dbgcmds.c b/nuttx/examples/nsh/nsh_dbgcmds.c index 2f528a657..305727dc6 100644 --- a/nuttx/examples/nsh/nsh_dbgcmds.c +++ b/nuttx/examples/nsh/nsh_dbgcmds.c @@ -298,3 +298,71 @@ int cmd_mem(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) nsh_output(vtbl, " fordblks: %8x\n", mem.fordblks); return OK; } + +/**************************************************************************** + * Name: nsh_dumpbuffer + ****************************************************************************/ + +void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg, + const char *buffer, ssize_t nbytes) +{ + char line[128]; + int ch; + int i; + int j; + + nsh_output(vtbl, "%s:\n", msg); + for (i = 0; i < nbytes; i += 16) + { + sprintf(line, "%04x: ", i); + + for ( j = 0; j < 16; j++) + { + if (i + j < nbytes) + { + sprintf(&line[strlen(line)], "%02x ", buffer[i+j] ); + } + else + { + strcpy(&line[strlen(line)], " "); + } + } + + for ( j = 0; j < 16; j++) + { + if (i + j < nbytes) + { + ch = buffer[i+j]; + sprintf(&line[strlen(line)], "%c", ch >= 0x20 && ch <= 0x7e ? ch : '.'); + } + } + nsh_output(vtbl, "%s\n", line); + } +} + +/**************************************************************************** + * Name: cmd_xd + ****************************************************************************/ + +int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + char *addr; + char *endptr; + int nbytes; + + addr = (char*)strtol(argv[1], &endptr, 16); + if (argv[0][0] == '\0' || *endptr != '\0') + { + return ERROR; + } + + nbytes = (int)strtol(argv[2], &endptr, 0); + if (argv[0][0] == '\0' || *endptr != '\0' || nbytes < 0) + { + return ERROR; + } + + nsh_dumpbuffer(vtbl, "Hex dump", addr, nbytes); + return OK; +} + diff --git a/nuttx/examples/nsh/nsh_fscmds.c b/nuttx/examples/nsh/nsh_fscmds.c index cd02ca576..f6049e67e 100644 --- a/nuttx/examples/nsh/nsh_fscmds.c +++ b/nuttx/examples/nsh/nsh_fscmds.c @@ -60,6 +60,7 @@ #include <limits.h> #include <libgen.h> #include <errno.h> +#include <debug.h> #include "nsh.h" @@ -851,6 +852,7 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) fmt = g_fmtcmdoutofmemory; goto errout_with_fmt; } + dbg("RAMDISK at %p\n", buffer); /* Then register the ramdisk */ diff --git a/nuttx/examples/nsh/nsh_main.c b/nuttx/examples/nsh/nsh_main.c index e58836fcc..68de85285 100644 --- a/nuttx/examples/nsh/nsh_main.c +++ b/nuttx/examples/nsh/nsh_main.c @@ -210,7 +210,8 @@ static const struct cmdmap_s g_cmdmap[] = #ifndef CONFIG_DISABLE_SIGNALS { "usleep", cmd_usleep, 2, 2, "<usec>" }, #endif /* CONFIG_DISABLE_SIGNALS */ - { NULL, NULL, 1, 1, NULL } + { "xd", cmd_xd, 3, 3, "<hex-address> <byte-count>" }, + { NULL, NULL, 1, 1, NULL } }; /**************************************************************************** diff --git a/nuttx/examples/nsh/nsh_telnetd.c b/nuttx/examples/nsh/nsh_telnetd.c index d3cce9971..dd679cf39 100644 --- a/nuttx/examples/nsh/nsh_telnetd.c +++ b/nuttx/examples/nsh/nsh_telnetd.c @@ -84,6 +84,12 @@ #define TELNET_DO 253 #define TELNET_DONT 254 +#ifdef CONFIG_EXAMPLES_NSH_TELNETD_DUMPBUFFER +# define nsh_telnetdump(vtbl,msg,buf,nb) nsh_dumpbuffer(vtbl,msg,buf,nb) +#else +# define nsh_telnetdump(vtbl,msg,buf,nb) +#endif + /**************************************************************************** * Private Types ****************************************************************************/ @@ -172,56 +178,6 @@ static void tio_semtake(struct telnetio_s *tio) #define tio_semgive(tio) ASSERT(sem_post(&tio->tio_sem) == 0) /**************************************************************************** - * Name: nsh_dumpbuffer - * - * Description: - * Dump a buffer of data (debug only) - * - ****************************************************************************/ - -#ifdef CONFIG_EXAMPLES_NSH_TELNETD_DUMPBUFFER -static void nsh_dumpbuffer(const char *msg, const char *buffer, ssize_t nbytes) -{ -#ifdef CONFIG_DEBUG - char line[128]; - int ch; - int i; - int j; - - dbg("%s:\n", msg); - for (i = 0; i < nbytes; i += 16) - { - sprintf(line, "%04x: ", i); - - for ( j = 0; j < 16; j++) - { - if (i + j < nbytes) - { - sprintf(&line[strlen(line)], "%02x ", buffer[i+j] ); - } - else - { - strcpy(&line[strlen(line)], " "); - } - } - - for ( j = 0; j < 16; j++) - { - if (i + j < nbytes) - { - ch = buffer[i+j]; - sprintf(&line[strlen(line)], "%c", ch >= 0x20 && ch <= 0x7e ? ch : '.'); - } - } - dbg("%s\n", line); - } -#endif -} -#else -# define nsh_dumpbuffer(msg,buffer,nbytes) -#endif - -/**************************************************************************** * Name: nsh_allocstruct ****************************************************************************/ @@ -327,7 +283,8 @@ static void nsh_putchar(struct telnetd_s *pstate, uint8 ch) if (ch == ISO_nl || tio->tio_bufndx == (CONFIG_EXAMPLES_NSH_LINELEN - 1)) { pstate->tn_cmd[tio->tio_bufndx] = '\0'; - nsh_dumpbuffer("TELNET CMD", pstate->tn_cmd, strlen(pstate->tn_cmd)); + nsh_telnetdump(&pstate->tn_vtbl, "TELNET CMD", + pstate->tn_cmd, strlen(pstate->tn_cmd)); nsh_parse(&pstate->tn_vtbl, pstate->tn_cmd); tio->tio_bufndx = 0; } @@ -354,7 +311,7 @@ static void nsh_sendopt(struct telnetd_s *pstate, uint8 option, uint8 value) optbuf[2] = value; optbuf[3] = 0; - nsh_dumpbuffer("Send optbuf", optbuf, 4); + nsh_telnetdump(&pstate->tn_vtbl, "Send optbuf", optbuf, 4); tio_semtake(tio); /* Only one call to send at a time */ if (send(tio->tio_sockfd, optbuf, 4, 0) < 0) { @@ -377,7 +334,8 @@ static void nsh_flush(FAR struct telnetd_s *pstate) if (pstate->tn_sndlen > 0) { - nsh_dumpbuffer("Shell output", pstate->tn_outbuffer, pstate->tn_sndlen); + nsh_telnetdump(&pstate->tn_vtbl, "Shell output", + pstate->tn_outbuffer, pstate->tn_sndlen); tio_semtake(tio); /* Only one call to send at a time */ if (send(tio->tio_sockfd, pstate->tn_outbuffer, pstate->tn_sndlen, 0) < 0) { @@ -531,13 +489,15 @@ static void *nsh_connection(void *arg) /* Read a buffer of data from the TELNET client */ - ret = recv(tio->tio_sockfd, tio->tio_inbuffer, CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE, 0); + ret = recv(tio->tio_sockfd, tio->tio_inbuffer, + CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE, 0); if (ret > 0) { /* Process the received TELNET data */ - nsh_dumpbuffer("Received buffer", tio->tio_inbuffer, ret); + nsh_telnetdump(&pstate->tn_vtbl, "Received buffer", + tio->tio_inbuffer, ret); ret = nsh_receive(pstate, ret); } } |