kopia lustrzana https://github.com/Hamlib/Hamlib
Add flushing of rig port, including async data pipes, after \send_raw and \send_cmd to drain any extra rig responses
rodzic
92215dfd2a
commit
e89687668d
|
@ -2713,6 +2713,9 @@ extern HAMLIB_EXPORT(int) rig_open HAMLIB_PARAMS((RIG *rig));
|
|||
* List Set/Get functions pairs
|
||||
*/
|
||||
|
||||
extern HAMLIB_EXPORT(int)
|
||||
rig_flush_force(hamlib_port_t *port, int flush_async_data);
|
||||
|
||||
extern HAMLIB_EXPORT(int)
|
||||
rig_flush(hamlib_port_t *port);
|
||||
|
||||
|
|
38
src/iofunc.c
38
src/iofunc.c
|
@ -787,6 +787,12 @@ int HAMLIB_API write_block_sync_error(hamlib_port_t *p,
|
|||
return async_pipe_write(p->sync_data_error_pipe, txbuffer, count, p->timeout);
|
||||
}
|
||||
|
||||
int HAMLIB_API port_flush_sync_pipes(hamlib_port_t *p)
|
||||
{
|
||||
// TODO: To be implemented for Windows
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* POSIX */
|
||||
|
@ -970,6 +976,38 @@ int HAMLIB_API write_block_sync_error(hamlib_port_t *p,
|
|||
return (int) write(p->fd_sync_error_write, txbuffer, count);
|
||||
}
|
||||
|
||||
int HAMLIB_API port_flush_sync_pipes(hamlib_port_t *p)
|
||||
{
|
||||
unsigned char buf[1024];
|
||||
int n;
|
||||
int nbytes;
|
||||
|
||||
if (!p->asyncio)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: flushing sync pipes\n", __func__);
|
||||
|
||||
nbytes = 0;
|
||||
while ((n = read(p->fd_sync_read, buf, sizeof(buf))) > 0)
|
||||
{
|
||||
nbytes += n;
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, "read flushed %d bytes from sync read pipe\n", nbytes);
|
||||
|
||||
nbytes = 0;
|
||||
while ((n = read(p->fd_sync_error_read, buf, sizeof(buf))) > 0)
|
||||
{
|
||||
nbytes += n;
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, "read flushed %d bytes from sync error read pipe\n", nbytes);
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,6 +49,8 @@ extern HAMLIB_EXPORT(int) write_block_sync_error(hamlib_port_t *p,
|
|||
const unsigned char *txbuffer,
|
||||
size_t count);
|
||||
|
||||
extern HAMLIB_EXPORT(int) port_flush_sync_pipes(hamlib_port_t *p);
|
||||
|
||||
extern HAMLIB_EXPORT(int) read_string(hamlib_port_t *p,
|
||||
unsigned char *rxbuffer,
|
||||
size_t rxmax,
|
||||
|
|
32
src/misc.c
32
src/misc.c
|
@ -2152,19 +2152,28 @@ int HAMLIB_API parse_hoststr(char *hoststr, int hoststr_len, char host[256],
|
|||
return -1;
|
||||
}
|
||||
|
||||
//K3 was showing stacked command replies so re-enabling this
|
||||
//#define RIG_FLUSH_REMOVE
|
||||
int HAMLIB_API rig_flush(hamlib_port_t *port)
|
||||
|
||||
/**
|
||||
* \brief Force flush of rig communication data buffers.
|
||||
* \param port communication port
|
||||
* \param flush_async_data Flushes also asynchronous I/O pipes if non-zero.
|
||||
* \return status code
|
||||
*
|
||||
* This function should be used only in special cases like after handling raw command data from Hamlib clients.
|
||||
* When asynchronous I/O is enabled, responses to raw commands may disrupt processing of all commands,
|
||||
* because the responses and up in the async I/O pipes.
|
||||
*/
|
||||
int HAMLIB_API rig_flush_force(hamlib_port_t *port, int flush_async_data)
|
||||
{
|
||||
if (port->type.rig == RIG_PORT_NONE)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
// Data should never be flushed when using async I/O
|
||||
if (port->asyncio)
|
||||
// Flush also the async I/O pipes
|
||||
if (port->asyncio && flush_async_data)
|
||||
{
|
||||
return RIG_OK;
|
||||
port_flush_sync_pipes(port);
|
||||
}
|
||||
|
||||
#ifndef RIG_FLUSH_REMOVE
|
||||
|
@ -2190,6 +2199,17 @@ int HAMLIB_API rig_flush(hamlib_port_t *port)
|
|||
#endif
|
||||
}
|
||||
|
||||
int HAMLIB_API rig_flush(hamlib_port_t *port)
|
||||
{
|
||||
// Data should never be flushed when using async I/O
|
||||
if (port->asyncio)
|
||||
{
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
return rig_flush_force(port, 0);
|
||||
}
|
||||
|
||||
|
||||
static const struct
|
||||
{
|
||||
|
|
|
@ -7771,6 +7771,7 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
|
|||
if (retval < RIG_OK)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: read_string, result=%d\n", __func__, retval);
|
||||
rig_flush_force(&rs->rigport, 1);
|
||||
set_transaction_inactive(rig);
|
||||
RETURNFUNC(retval);
|
||||
}
|
||||
|
@ -7781,6 +7782,7 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
|
|||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: reply_len(%d) less than reply from rig(%d)\n",
|
||||
__func__, reply_len, nbytes);
|
||||
rig_flush_force(&rs->rigport, 1);
|
||||
set_transaction_inactive(rig);
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
@ -7790,10 +7792,12 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
|
|||
}
|
||||
else
|
||||
{
|
||||
rig_flush_force(&rs->rigport, 1);
|
||||
set_transaction_inactive(rig);
|
||||
RETURNFUNC(retval);
|
||||
}
|
||||
|
||||
rig_flush_force(&rs->rigport, 1);
|
||||
set_transaction_inactive(rig);
|
||||
|
||||
ELAPSED2;
|
||||
|
|
|
@ -4893,6 +4893,8 @@ declare_proto_rig(send_cmd)
|
|||
rig_debug(RIG_DEBUG_TRACE, "%s: rigport=%d, bufcmd=%s, cmd_len=%d\n", __func__,
|
||||
rs->rigport.fd, hasbinary(bufcmd, cmd_len) ? "BINARY" : bufcmd, cmd_len);
|
||||
|
||||
set_transaction_active(rig);
|
||||
|
||||
if (simulate)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: simulating response for model %s\n",
|
||||
|
@ -4910,6 +4912,8 @@ declare_proto_rig(send_cmd)
|
|||
|
||||
if (retval != RIG_OK)
|
||||
{
|
||||
rig_flush_force(&rs->rigport, 1);
|
||||
set_transaction_inactive(rig);
|
||||
RETURNFUNC(retval);
|
||||
}
|
||||
}
|
||||
|
@ -5002,6 +5006,9 @@ declare_proto_rig(send_cmd)
|
|||
strncat(hexbuf, hex, hexbufbytes - 1);
|
||||
}
|
||||
|
||||
rig_flush_force(&rs->rigport, 1);
|
||||
set_transaction_inactive(rig);
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: binary=%s, retval=%d\n", __func__, hexbuf,
|
||||
retval);
|
||||
fprintf(fout, "%s %d\n", hexbuf, retval);
|
||||
|
@ -5016,6 +5023,9 @@ declare_proto_rig(send_cmd)
|
|||
}
|
||||
while (retval > 0 && rxbytes == BUFSZ);
|
||||
|
||||
rig_flush_force(&rs->rigport, 1);
|
||||
set_transaction_inactive(rig);
|
||||
|
||||
// we use fwrite in case of any nulls in binary return
|
||||
if (binary) { fwrite(buf, 1, retval, fout); }
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue