From a8a39d5873ab01c54d531ec4fa1cb236233e7a0e Mon Sep 17 00:00:00 2001
From: TimEverett <tim.everett3@gmail.com>
Date: Tue, 9 Oct 2018 10:16:16 -0600
Subject: [PATCH] - Reduce unnecessary NTRIP connection requests - Add option
 for 460800 baud rate for serial ports

---
 src/stream.c    | 7 +++++--
 src/streamsvr.c | 6 +++---
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/stream.c b/src/stream.c
index 9308c6e..05e5fdc 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -330,7 +330,7 @@ static DWORD WINAPI serialthread(void *arg)
 static serial_t *openserial(const char *path, int mode, char *msg)
 {
     const int br[]={
-        300,600,1200,2400,4800,9600,19200,38400,57600,115200,230400
+        300,600,1200,2400,4800,9600,19200,38400,57600,115200,230400,460800
     };
     serial_t *serial;
     int i,brate=115200,bsize=8,stopb=1,tcp_port=0;
@@ -342,7 +342,7 @@ static serial_t *openserial(const char *path, int mode, char *msg)
     char dcb[64]="";
 #else
     const speed_t bs[]={
-        B300,B600,B1200,B2400,B4800,B9600,B19200,B38400,B57600,B115200,B230400
+        B300,B600,B1200,B2400,B4800,B9600,B19200,B38400,B57600,B115200,B230400,B460800
     };
     struct termios ios={0};
     int rw=0;
@@ -1574,6 +1574,7 @@ static int rspntrip_c(ntrip_t *ntrip, char *msg)
         ntrip->state=2;
         sprintf(msg,"%s/%s",ntrip->tcp->svr.saddr,ntrip->mntpnt);
         tracet(2,"rspntrip_c: response ok nb=%d\n",ntrip->nb);
+        ntrip->tcp->tirecon=ticonnect;
         return 1;
     }
     if ((p=strstr((char *)ntrip->buff,NTRIP_RSP_SRCTBL))) { /* source table */
@@ -1588,6 +1589,8 @@ static int rspntrip_c(ntrip_t *ntrip, char *msg)
         ntrip->nb=0;
         ntrip->buff[0]='\0';
         ntrip->state=0;
+        /* increase subsequent disconnect time to avoid too many reconnect requests */
+        if (ntrip->tcp->tirecon>300000) ntrip->tcp->tirecon=ntrip->tcp->tirecon*5/4;
         discontcp(&ntrip->tcp->svr,ntrip->tcp->tirecon);
     }
     else if ((p=strstr((char *)ntrip->buff,NTRIP_RSP_HTTP))) { /* http response */
diff --git a/src/streamsvr.c b/src/streamsvr.c
index 9564e08..6533e2e 100644
--- a/src/streamsvr.c
+++ b/src/streamsvr.c
@@ -436,9 +436,9 @@ static void *strsvrthread(void *arg)
         }
         for (i=1;i<svr->nstr;i++) {
             
-            /* read message from output stream */
-            while ((n=strread(svr->stream+i,buff,sizeof(buff)))>0) {
-                
+            /* read message from output stream if connected */
+            while (strstat(svr->stream+i,NULL)>=2 &&
+                  (n=strread(svr->stream+i,buff,sizeof(buff)))>0) {
                 /* relay back message from output stream to input stream */
                 if (i==svr->relayback) {
                     strwrite(svr->stream,buff,n);
-- 
GitLab