From 17fcf880ebf5f669bc39b1da92fe870e2ed06984 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 4 Mar 2012 17:38:00 +0000 Subject: [PATCH] Several fixes to the PIC32 USB device OUT path logic git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4451 42af7a65-404d-4744-a932-0658087f49c3 --- examples/usbterm/usbterm.h | 2 ++ examples/usbterm/usbterm_main.c | 32 +++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/examples/usbterm/usbterm.h b/examples/usbterm/usbterm.h index a889c886d..2534c2f3c 100644 --- a/examples/usbterm/usbterm.h +++ b/examples/usbterm/usbterm.h @@ -132,6 +132,8 @@ struct usbterm_globals_s FILE *instream; /* Stream for incoming USB data */ FILE *outstream; /* Stream for outgoing USB data */ pthread_t listener; /* USB terminal listener thread */ + bool peer; /* True: A peer is connected to the serial port on + * the remote host */ /* Buffers for incoming and outgoing data */ diff --git a/examples/usbterm/usbterm_main.c b/examples/usbterm/usbterm_main.c index ba723e91b..170585624 100644 --- a/examples/usbterm/usbterm_main.c +++ b/examples/usbterm/usbterm_main.c @@ -127,15 +127,27 @@ FAR void *usbterm_listener(FAR void *parameter) message("usbterm_listener: Waiting for remote input\n"); for (;;) { - /* Display the prompt string on the remote USB serial connection */ + /* Display the prompt string on the remote USB serial connection -- only + * if we know that there is someone listening at the other end. The + * remote side must initiate the the conversation. + */ - fputs("\rusbterm> ", g_usbterm.outstream); - fflush(g_usbterm.outstream); + if (g_usbterm.peer) + { + fputs("\rusbterm> ", g_usbterm.outstream); + fflush(g_usbterm.outstream); + } /* Get the next line of input from the remote USB serial connection */ if (fgets(g_usbterm.inbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, g_usbterm.instream)) { + /* If we receive anything, then we can be assured that there is someone + * with the serial driver open on the remote host. + */ + + g_usbterm.peer = true; + /* Echo the line on the local stdout */ fputs(g_usbterm.inbuffer, stdout); @@ -181,6 +193,10 @@ int MAIN_NAME(int argc, char *argv[]) pthread_attr_t attr; int ret; + /* Initialize global data */ + + memset(&g_usbterm, 0, sizeof(struct usbterm_globals_s)); + /* Initialization of the USB hardware may be performed by logic external to * this test. */ @@ -324,9 +340,11 @@ int MAIN_NAME(int argc, char *argv[]) return 1; } #endif - else + /* Is there anyone listening on the other end? */ + + else if (g_usbterm.peer) { - /* Send the line of input via USB */ + /* Yes.. Send the line of input via USB */ fputs(g_usbterm.outbuffer, g_usbterm.outstream); @@ -335,6 +353,10 @@ int MAIN_NAME(int argc, char *argv[]) fputs("\rusbterm> ", g_usbterm.outstream); fflush(g_usbterm.outstream); } + else + { + printf("Still waiting for remote peer. Please try again later.\n", ret); + } /* If USB tracing is enabled, then dump all collected trace data to stdout */