Change serial_flush to read data instead of TCFLUSH

This is for the future to enable transceive mode on rigs
pull/875/head
Mike Black W9MDB 2021-10-29 11:24:16 -05:00
rodzic 4ad28fd5ab
commit d28f440968
3 zmienionych plików z 24 dodań i 29 usunięć

Wyświetl plik

@ -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.
*/
static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count)
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 */
static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count)
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)
{

Wyświetl plik

@ -26,6 +26,7 @@
#include <hamlib/rig.h>
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);
@ -44,4 +45,5 @@ 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 */

Wyświetl plik

@ -81,6 +81,7 @@
#include <hamlib/rig.h>
#include "serial.h"
#include "misc.h"
#include "iofunc.h"
#ifdef HAVE_SYS_IOCCOM_H
# include <sys/ioccom.h>
@ -639,39 +640,31 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
*/
int HAMLIB_API serial_flush(hamlib_port_t *p)
{
ENTERFUNC;
//ENTERFUNC; // too verbose
if (p->fd == uh_ptt_fd || p->fd == uh_radio_fd || p->flushx)
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)
{
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;
int i;
char pbuf[sizeof(buf)+1];
char hbuf[sizeof(buf)*3+1];
nbytes += n;
rig_debug(RIG_DEBUG_TRACE, "%s: flushing\n", __func__);
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] : '~'); }
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);
/* do nothing */
}
rig_debug(RIG_DEBUG_VERBOSE, "tcflush%s\n", "");
tcflush(p->fd, TCIFLUSH);
RETURNFUNC(RIG_OK);
return RIG_OK;
}