summaryrefslogtreecommitdiff
path: root/nuttx/examples/nsh
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-07 13:42:55 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-07 13:42:55 +0000
commit33ebc18c23173530e25b9585010e3411530f4940 (patch)
tree3168654f7c9ee4ffb5124dd9f0990369c5e79852 /nuttx/examples/nsh
parenta5f7cf98731bec3e33558a7805c37463e0d634ae (diff)
downloadpx4-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
Diffstat (limited to 'nuttx/examples/nsh')
-rw-r--r--nuttx/examples/nsh/README.txt16
-rw-r--r--nuttx/examples/nsh/nsh.h6
-rw-r--r--nuttx/examples/nsh/nsh_dbgcmds.c68
-rw-r--r--nuttx/examples/nsh/nsh_fscmds.c2
-rw-r--r--nuttx/examples/nsh/nsh_main.c3
-rw-r--r--nuttx/examples/nsh/nsh_telnetd.c70
6 files changed, 109 insertions, 56 deletions
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);
}
}