Now have to press enter 3 times to start with USB NSH console
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4772 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
66eeafb87a
commit
d2ef14cc47
@ -234,3 +234,6 @@
|
|||||||
* apps/nshlib/nsh_usbdev.c: Add the capability to use an arbitrary USB
|
* 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
|
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.
|
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.
|
||||||
|
@ -92,6 +92,9 @@
|
|||||||
#ifdef HAVE_USB_CONSOLE
|
#ifdef HAVE_USB_CONSOLE
|
||||||
int nsh_usbconsole(void)
|
int nsh_usbconsole(void)
|
||||||
{
|
{
|
||||||
|
char inch;
|
||||||
|
ssize_t nbytes;
|
||||||
|
int nlc;
|
||||||
int fd;
|
int fd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -116,13 +119,7 @@ int nsh_usbconsole(void)
|
|||||||
DEBUGASSERT(ret == OK);
|
DEBUGASSERT(ret == OK);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Make sure the stdin, stdout, and stderr are closed */
|
/* Open the USB serial device for read/write access */
|
||||||
|
|
||||||
(void)fclose(stdin);
|
|
||||||
(void)fclose(stdout);
|
|
||||||
(void)fclose(stderr);
|
|
||||||
|
|
||||||
/* Open the USB serial device for writing */
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -146,6 +143,43 @@ int nsh_usbconsole(void)
|
|||||||
}
|
}
|
||||||
while (fd < 0);
|
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 */
|
/* Dup the fd to create standard fd 0-2 */
|
||||||
|
|
||||||
(void)dup2(fd, 0);
|
(void)dup2(fd, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user