Merge branch 'jaebird-master'

Flush the buffer for the network protocol used with the PiHPSDR backend.
This commit is contained in:
Nate Bargmann 2017-01-25 20:52:28 -06:00
commit cb9ec24cd3
4 changed files with 34 additions and 3 deletions

View File

@ -33,6 +33,7 @@
#include <ctype.h>
#include "hamlib/rig.h"
#include "network.h"
#include "serial.h"
#include "misc.h"
#include "register.h"
@ -242,7 +243,13 @@ int kenwood_transaction(RIG *rig, const char *cmdstr, char *data, size_t datasiz
len++;
}
serial_flush(&rs->rigport);
/* flush anything in the read buffer before command is sent */
if (rs->rigport.type.rig == RIG_PORT_NETWORK || rs->rigport.type.rig == RIG_PORT_UDP_NETWORK) {
network_flush(&rs->rigport);
} else {
serial_flush(&rs->rigport);
}
retval = write_block(&rs->rigport, cmd, len);
free(cmd);

View File

@ -107,8 +107,8 @@ const struct rig_caps pihpsdr_caps = {
.port_type = RIG_PORT_NETWORK,
.write_delay = 0,
.post_write_delay = 50, /* ms */
.timeout = 200,
.retry = 10,
.timeout = 0,
.retry = 0,
.has_get_func = PIHPSDR_FUNC_ALL,
.has_set_func = PIHPSDR_FUNC_ALL,
.has_get_level = PIHPSDR_LEVEL_ALL,

View File

@ -44,6 +44,7 @@
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/ioctl.h>
#ifdef HAVE_NETINET_IN_H
@ -73,6 +74,8 @@
static int wsstarted;
#endif
#define NET_BUFFER_SIZE 64
static void handle_error (enum rig_debug_level_e lvl, const char *msg)
{
int e;
@ -103,6 +106,26 @@ static void handle_error (enum rig_debug_level_e lvl, const char *msg)
#endif
}
/**
* \brief Clears any data in the read buffer of the socket
*
* \param rp Port data structure
*/
void network_flush(hamlib_port_t* rp)
{
int len = 0;
char buffer[NET_BUFFER_SIZE] = { 0 };
for (;;) {
ioctl(rp->fd, FIONREAD, &len);
if (len > 0) {
len = read(rp->fd, &buffer, len < NET_BUFFER_SIZE ? len : NET_BUFFER_SIZE);
rig_debug(RIG_DEBUG_WARN, "Network data cleared: %s\n", buffer);
} else {
break;
}
}
}
/**
* \brief Open network port using rig.state data
*

View File

@ -30,6 +30,7 @@ __BEGIN_DECLS
/* Hamlib internal use, see rig.c */
int network_open(hamlib_port_t *p, int default_port);
int network_close(hamlib_port_t *rp);
void network_flush(hamlib_port_t *rp);
__END_DECLS