Add NSH xd command
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@892 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
9edf6200b8
commit
df083ea819
|
@ -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)
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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 }
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue