diff --git a/ChangeLog b/ChangeLog index 55b263e1f88f3e8b44d98d6fa323fe1966fc50f6..8f774358d7bff3b6125140d73415e6018bb2d67e 100644 --- a/ChangeLog +++ b/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/Documentation/NuttShell.html b/Documentation/NuttShell.html index 1b83454b93e9e71394782bea05631cab8b66d90e..bedb624f84fa3be942769174f6ff15f1c48bedd7 100644 --- a/Documentation/NuttShell.html +++ b/Documentation/NuttShell.html @@ -254,6 +254,12 @@ <a href="#cmdusleep">2.30 Wait for Microseconds (usleep)</a> </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> @@ -1411,6 +1417,33 @@ usleep <usec> Pause execution (sleep) of <code><usec></code> microseconds. </p> +<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> @@ -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/Documentation/NuttX.html b/Documentation/NuttX.html index 4674077cc3335f5164cd99cdfe78c6244d56789b..04704af51f27a2358ff1a37c75d751ba2d7383c5 100644 --- a/Documentation/NuttX.html +++ b/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/examples/nsh/README.txt b/examples/nsh/README.txt index c202d7a8ea659caa94696e0ef2860ab023b7dcd9..69187f1a344e628efc5f2165a71a66d04f3b368d 100644 --- a/examples/nsh/README.txt +++ b/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/examples/nsh/nsh.h b/examples/nsh/nsh.h index c69aa2342d303c759278e417fd59996974cc7227..d8d18a72a68fb6552f1a00a1df05feb8f5604b24 100644 --- a/examples/nsh/nsh.h +++ b/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/examples/nsh/nsh_dbgcmds.c b/examples/nsh/nsh_dbgcmds.c index 2f528a657dcc6fc5f4c82ab25d9030bc6e8ef49c..305727dc6971a45c82f86d9227a20ea5ae8c084f 100644 --- a/examples/nsh/nsh_dbgcmds.c +++ b/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/examples/nsh/nsh_fscmds.c b/examples/nsh/nsh_fscmds.c index cd02ca576ee731b4de3370717bb0e540f6594224..f6049e67e0473b9997dac0748b0278009e555c07 100644 --- a/examples/nsh/nsh_fscmds.c +++ b/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/examples/nsh/nsh_main.c b/examples/nsh/nsh_main.c index e58836fccee946551323214b8c2308dc6306fb59..68de8528510804f4f23fcdfe2e7a84b0f3f456a5 100644 --- a/examples/nsh/nsh_main.c +++ b/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/examples/nsh/nsh_telnetd.c b/examples/nsh/nsh_telnetd.c index d3cce997178ed640369f5049eee78d8c130d7fcf..dd679cf39188bad4b38fa960527384cc1344b4ae 100644 --- a/examples/nsh/nsh_telnetd.c +++ b/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 ****************************************************************************/ @@ -171,56 +177,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); } }