kopia lustrzana https://github.com/Hamlib/Hamlib
Revert "Change serial_flush to read data instead of TCFLUSH"
Was causing timing problems
This reverts commit d28f440968
.
pull/875/head
rodzic
f071adac8f
commit
1ed398466d
|
@ -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.
|
||||
*/
|
||||
ssize_t port_read(hamlib_port_t *p, void *buf, size_t count)
|
||||
static 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 */
|
||||
|
||||
ssize_t port_read(hamlib_port_t *p, void *buf, size_t count)
|
||||
static 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)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#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);
|
||||
|
||||
|
@ -45,5 +44,4 @@ 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 */
|
||||
|
|
47
src/serial.c
47
src/serial.c
|
@ -81,7 +81,6 @@
|
|||
#include <hamlib/rig.h>
|
||||
#include "serial.h"
|
||||
#include "misc.h"
|
||||
#include "iofunc.h"
|
||||
|
||||
#ifdef HAVE_SYS_IOCCOM_H
|
||||
# include <sys/ioccom.h>
|
||||
|
@ -640,31 +639,39 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp)
|
|||
*/
|
||||
int HAMLIB_API serial_flush(hamlib_port_t *p)
|
||||
{
|
||||
//ENTERFUNC; // too verbose
|
||||
ENTERFUNC;
|
||||
|
||||
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)
|
||||
if (p->fd == uh_ptt_fd || p->fd == uh_radio_fd || p->flushx)
|
||||
{
|
||||
int i;
|
||||
char pbuf[sizeof(buf)+1];
|
||||
char hbuf[sizeof(buf)*3+1];
|
||||
nbytes += n;
|
||||
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;
|
||||
|
||||
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] : '~'); }
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: flushing\n", __func__);
|
||||
|
||||
/* do nothing */
|
||||
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);
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "tcflush%s\n", "");
|
||||
tcflush(p->fd, TCIFLUSH);
|
||||
RETURNFUNC(RIG_OK);
|
||||
}
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue