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 */ diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index 63873ad1f..03f52f581 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -1446,6 +1446,7 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, /* only for rotctld */ if (interactive && !prompt) { + rot_debug(RIG_DEBUG_TRACE, "%s: NETROTCTL_RET %d\n", __func__, retcode); fprintf(fout, NETROTCTL_RET "%d\n", retcode); // ext_resp = 0; // not used ? resp_sep = '\n'; @@ -1466,12 +1467,14 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, /* netrotctl RIG_OK */ if (!(cmd_entry->flags & ARG_OUT) && !ext_resp) { + rot_debug(RIG_DEBUG_TRACE, "%s: NETROTCTL_RET 0\n", __func__); fprintf(fout, NETROTCTL_RET "0\n"); } /* Extended Response protocol */ else if (ext_resp && cmd != 0xf0) { + rot_debug(RIG_DEBUG_TRACE, "%s: NETROTCTL_RET 0\n", __func__); fprintf(fout, NETROTCTL_RET "0\n"); resp_sep = '\n'; }