From 2c64ba9bbaa58b70efa0d89351e45256170e3c89 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Tue, 23 Jun 2020 08:27:45 -0500 Subject: [PATCH] First round of rigs switched over to new rig_flush function When done this will allow all rigs to use network connections and stil flush properly https://github.com/Hamlib/Hamlib/issues/307 --- dummy/flrig.c | 2 +- dummy/netrigctl.c | 10 +--------- dummy/netrotctl.c | 10 +--------- include/hamlib/rig.h | 2 +- src/misc.c | 16 ++++++++++------ 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/dummy/flrig.c b/dummy/flrig.c index 8d9a6b8f9..49af67f9e 100644 --- a/dummy/flrig.c +++ b/dummy/flrig.c @@ -494,7 +494,7 @@ static int write_transaction(RIG *rig, char *xml, int xml_len) // appears we can lose sync if we don't clear things out // shouldn't be anything for us now anyways - network_flush(&rig->state.rigport); + rig_flush(&rig->state.rigport); while (try-- >= 0 && retval != RIG_OK) { diff --git a/dummy/netrigctl.c b/dummy/netrigctl.c index cf5f28180..dad7d0756 100644 --- a/dummy/netrigctl.c +++ b/dummy/netrigctl.c @@ -68,15 +68,7 @@ static int netrigctl_transaction(RIG *rig, char *cmd, int len, char *buf) rig_debug(RIG_DEBUG_VERBOSE, "%s: called len=%d\n", __func__, len); /* flush anything in the read buffer before command is sent */ - if (rig->state.rigport.type.rig == RIG_PORT_NETWORK - || rig->state.rigport.type.rig == RIG_PORT_UDP_NETWORK) - { - network_flush(&rig->state.rigport); - } - else - { - serial_flush(&rig->state.rigport); - } + rig_flush(&rig->state.rigport); ret = write_block(&rig->state.rigport, cmd, len); diff --git a/dummy/netrotctl.c b/dummy/netrotctl.c index d99e0fe33..76c074338 100644 --- a/dummy/netrotctl.c +++ b/dummy/netrotctl.c @@ -48,15 +48,7 @@ static int netrotctl_transaction(ROT *rot, char *cmd, int len, char *buf) int ret; /* flush anything in the read buffer before command is sent */ - if (rot->state.rotport.type.rig == RIG_PORT_NETWORK - || rot->state.rotport.type.rig == RIG_PORT_UDP_NETWORK) - { - network_flush(&rot->state.rotport); - } - else - { - serial_flush(&rot->state.rotport); - } + rig_flush(&rot->state.rotport); ret = write_block(&rot->state.rotport, cmd, len); diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index d8bc4df54..86f2cbdbc 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2113,7 +2113,7 @@ extern HAMLIB_EXPORT(int) rig_open HAMLIB_PARAMS((RIG *rig)); */ extern HAMLIB_EXPORT(int) -rig_flush(RIG *rig); +rig_flush(hamlib_port_t *port); extern HAMLIB_EXPORT(int) rig_set_freq HAMLIB_PARAMS((RIG *rig, diff --git a/src/misc.c b/src/misc.c index 0dae9c3d9..b8f90c8d9 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1480,17 +1480,21 @@ int HAMLIB_API parse_hoststr(char *hoststr, char host[256], char port[6]) return -1; } -int HAMLIB_API rig_flush(RIG *rig) +int HAMLIB_API rig_flush(hamlib_port_t *port) { - if (rig->state.rigport.type.rig == RIG_PORT_NETWORK - || rig->state.rigport.type.rig == RIG_PORT_UDP_NETWORK) + rig_debug(RIG_DEBUG_TRACE, "%s: called for %s device\n", __func__, + port->type.rig == RIG_PORT_SERIAL ? "serial" : "network"); + + if (port->type.rig == RIG_PORT_NETWORK + || port->type.rig == RIG_PORT_UDP_NETWORK) { - network_flush(&rig->state.rigport); + network_flush(port); return RIG_OK; } - return serial_flush(&rig->state.rigport); + + return serial_flush(port); } //! @endcond - /** @} */ +/** @} */