From 8827f081ddfd2fbc0d6fa5bf75bf5f2cf9d9760e Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Wed, 25 Nov 2020 08:40:24 -0600 Subject: [PATCH] Add flushx option for MicroHam devices to allow flushing by read instead of tcflush. The special name of uh-rig only works on Linux and has other purposes apparently for ptt use https://github.com/Hamlib/Hamlib/issues/446 --- include/hamlib/rig.h | 1 + src/conf.c | 13 +++++++++++++ src/serial.c | 10 ++++++---- src/token.h | 2 ++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index ba916435d..da8e5638d 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -1901,6 +1901,7 @@ typedef struct hamlib_port { int value; /*!< Toggle PTT ON or OFF */ } gpio; /*!< GPIO attributes */ } parm; /*!< Port parameter union */ + int flushx; /*!< If true flush is done with read instead of TCFLUSH - MicroHam */ } hamlib_port_t; //! @endcond diff --git a/src/conf.c b/src/conf.c index cb7fc25f4..a018d3043 100644 --- a/src/conf.c +++ b/src/conf.c @@ -143,6 +143,11 @@ static const struct confparams frontend_cfg_params[] = "True enables ptt port to be shared with other apps", "0", RIG_CONF_CHECKBUTTON, { } }, + { + TOK_FLUSHX, "flushx", "Flush with read instead of TCFLUSH", + "True enables flushing serial port with read instead of TCFLUSH -- MicroHam", + "0", RIG_CONF_CHECKBUTTON, { } + }, { RIG_CONF_END, NULL, } }; @@ -594,6 +599,14 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) rs->ptt_share = val_i ? 1 : 0; break; + case TOK_FLUSHX: + if (1 != sscanf(val, "%d", &val_i)) + { + return -RIG_EINVAL; //value format error + } + + rs->rigport.flushx = val_i ? 1 : 0; + break; default: return -RIG_EINVAL; diff --git a/src/serial.c b/src/serial.c index d053ff956..7c8f89f22 100644 --- a/src/serial.c +++ b/src/serial.c @@ -607,7 +607,7 @@ int HAMLIB_API serial_flush(hamlib_port_t *p) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (p->fd == uh_ptt_fd || p->fd == uh_radio_fd) + if (p->fd == uh_ptt_fd || p->fd == uh_radio_fd || p->flushx) { unsigned char buf[32]; /* @@ -615,24 +615,26 @@ int HAMLIB_API serial_flush(hamlib_port_t *p) * if fd corresponds to a microHam device drain the line * (which is a socket) by reading until it is empty. */ - int n; + int n, nbytes=0; - rig_debug(RIG_DEBUG_TRACE, "%s: flushing: ", __func__); + rig_debug(RIG_DEBUG_TRACE, "%s: flushing\n", __func__); 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); return RIG_OK; } - rig_debug(RIG_DEBUG_VERBOSE, "%s: tcflush\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "tcflush%s\n", ""); tcflush(p->fd, TCIFLUSH); return RIG_OK; } diff --git a/src/token.h b/src/token.h index 62a5cc113..4d85e2fb4 100644 --- a/src/token.h +++ b/src/token.h @@ -89,6 +89,8 @@ #define TOK_PTT_BITNUM TOKEN_FRONTEND(34) /** \brief PTT share with other applications */ #define TOK_PTT_SHARE TOKEN_FRONTEND(35) +/** \brief PTT share with other applications */ +#define TOK_FLUSHX TOKEN_FRONTEND(36) /* * rig specific tokens */