From 1ed398466d7f5dcb05b4ca695b5bb867b6d95ae3 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Fri, 29 Oct 2021 14:38:40 -0500 Subject: [PATCH] Revert "Change serial_flush to read data instead of TCFLUSH" Was causing timing problems This reverts commit d28f4409683b3dcc34a0ff618714e20f3b43078a. --- src/iofunc.c | 4 ++-- src/iofunc.h | 2 -- src/serial.c | 47 +++++++++++++++++++++++++++-------------------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/iofunc.c b/src/iofunc.c index e4fe4ae77..4114d57ec 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -243,7 +243,7 @@ extern int is_uh_radio_fd(int fd); /* On MinGW32/MSVC/.. the appropriate accessor must be used * depending on the port type, sigh. */ -ssize_t port_read(hamlib_port_t *p, void *buf, size_t count) +static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count) { int i; ssize_t ret; @@ -370,7 +370,7 @@ static int port_select(hamlib_port_t *p, /* POSIX */ -ssize_t port_read(hamlib_port_t *p, void *buf, size_t count) +static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count) { if (p->type.rig == RIG_PORT_SERIAL && p->parm.serial.data_bits == 7) { diff --git a/src/iofunc.h b/src/iofunc.h index 321d3b4e4..efe8b6687 100644 --- a/src/iofunc.h +++ b/src/iofunc.h @@ -26,7 +26,6 @@ #include - extern HAMLIB_EXPORT(int) port_open(hamlib_port_t *p); extern HAMLIB_EXPORT(int) port_close(hamlib_port_t *p, rig_port_t port_type); @@ -45,5 +44,4 @@ extern HAMLIB_EXPORT(int) read_string(hamlib_port_t *p, const char *stopset, int stopset_len); -extern ssize_t port_read(hamlib_port_t *p, void *buf, size_t count); #endif /* _IOFUNC_H */ diff --git a/src/serial.c b/src/serial.c index 1fc46ff58..a9e15a188 100644 --- a/src/serial.c +++ b/src/serial.c @@ -81,7 +81,6 @@ #include #include "serial.h" #include "misc.h" -#include "iofunc.h" #ifdef HAVE_SYS_IOCCOM_H # include @@ -640,31 +639,39 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp) */ int HAMLIB_API serial_flush(hamlib_port_t *p) { - //ENTERFUNC; // too verbose + ENTERFUNC; - unsigned char buf[32]; - int n, nbytes = 0; - - //rig_debug(RIG_DEBUG_TRACE, "%s: flushing\n", __func__); - - while ((n = port_read(p, buf, 32)) > 0) + if (p->fd == uh_ptt_fd || p->fd == uh_radio_fd || p->flushx) { - int i; - char pbuf[sizeof(buf)+1]; - char hbuf[sizeof(buf)*3+1]; - nbytes += n; + unsigned char buf[32]; + /* + * Catch microHam case: + * if fd corresponds to a microHam device drain the line + * (which is a socket) by reading until it is empty. + */ + int n, nbytes = 0; - memset(pbuf,0,sizeof(pbuf)); - memset(hbuf,0,sizeof(hbuf)); - for (i = 0; i < n; ++i) { pbuf[i] = isprint(buf[i]) ? buf[i] : '~'; } - for (i = 0; i < n; ++i) { sprintf(&hbuf[i], "%02X ", buf[i]); } - rig_debug(RIG_DEBUG_VERBOSE, "%s: flushed=%s %s\n",__func__,pbuf,hbuf); - //for (i = 0; i < n; ++i) { printf("0x%02x(%c) ", buf[i], isprint(buf[i]) ? buf[i] : '~'); } + rig_debug(RIG_DEBUG_TRACE, "%s: flushing\n", __func__); - /* do nothing */ + while ((n = read(p->fd, buf, 32)) > 0) + { + nbytes += n; + //int i; + + //for (i = 0; i < n; ++i) { printf("0x%02x(%c) ", buf[i], isprint(buf[i]) ? buf[i] : '~'); } + + /* do nothing */ + } + + rig_debug(RIG_DEBUG_TRACE, "read flushed %d bytes\n", nbytes); + + + RETURNFUNC(RIG_OK); } - return RIG_OK; + rig_debug(RIG_DEBUG_VERBOSE, "tcflush%s\n", ""); + tcflush(p->fd, TCIFLUSH); + RETURNFUNC(RIG_OK); }