summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-05-26 01:45:37 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-05-26 01:45:37 +0000
commit1df6fde5271ed4a829b16214710eba79dbecdd83 (patch)
tree0264934a5e12a173199c637b8c8b0193e074c432 /apps
parent2f9e7c17ae5a9e7ada93021a9d1ed2ee9835d969 (diff)
Now have to press enter 3 times to start with USB NSH console
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4772 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'apps')
-rwxr-xr-xapps/ChangeLog.txt3
-rw-r--r--apps/nshlib/nsh_usbdev.c48
2 files changed, 44 insertions, 7 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index 825b1e50f3..acdd387af5 100755
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -234,3 +234,6 @@
* apps/nshlib/nsh_usbdev.c: Add the capability to use an arbitrary USB
device as the console (not necessarily /dev/console). This is a useful
option because then you can still use the serial console to debug with.
+ * apps/nshlib/nsh_usbdev.c: User now has to press ENTER 3 times before
+ USB console will start. Otherwise, the USB console starts before there
+ is anyone at the other end to listen.
diff --git a/apps/nshlib/nsh_usbdev.c b/apps/nshlib/nsh_usbdev.c
index 2b31a1a141..87689d5a2c 100644
--- a/apps/nshlib/nsh_usbdev.c
+++ b/apps/nshlib/nsh_usbdev.c
@@ -92,6 +92,9 @@
#ifdef HAVE_USB_CONSOLE
int nsh_usbconsole(void)
{
+ char inch;
+ ssize_t nbytes;
+ int nlc;
int fd;
int ret;
@@ -116,13 +119,7 @@ int nsh_usbconsole(void)
DEBUGASSERT(ret == OK);
#endif
- /* Make sure the stdin, stdout, and stderr are closed */
-
- (void)fclose(stdin);
- (void)fclose(stdout);
- (void)fclose(stderr);
-
- /* Open the USB serial device for writing */
+ /* Open the USB serial device for read/write access */
do
{
@@ -146,6 +143,43 @@ int nsh_usbconsole(void)
}
while (fd < 0);
+ /* Now waiting until we successfully read a carriage return a few times.
+ * That is a sure way of know that there is something at the other end of
+ * the USB serial connection that is ready to talk with us. The user needs
+ * to hit ENTER a few times to get things started.
+ */
+
+ nlc = 0;
+ do
+ {
+ /* Read one byte */
+
+ inch = 0;
+ nbytes = read(fd, &inch, 1);
+
+ /* Is it a carriage return (or maybe a newline)? */
+
+ if (nbytes == 1 && (inch == '\n' || inch == '\r'))
+ {
+ /* Yes.. increment the count */
+
+ nlc++;
+ }
+ else
+ {
+ /* No.. Reset the count. We need to see 3 in a row to continue. */
+
+ nlc = 0;
+ }
+ }
+ while (nlc < 3);
+
+ /* Make sure the stdin, stdout, and stderr are closed */
+
+ (void)fclose(stdin);
+ (void)fclose(stdout);
+ (void)fclose(stderr);
+
/* Dup the fd to create standard fd 0-2 */
(void)dup2(fd, 0);