Disable async processing and move async definitions out of hamlib_port_t

This broke backwards compatibility with DLL/shared libraries
pull/910/head
Mike Black W9MDB 2021-12-26 22:24:09 -06:00
rodzic 65cfbb9760
commit 2fe9117639
4 zmienionych plików z 83 dodań i 15 usunięć

Wyświetl plik

@ -2211,13 +2211,16 @@ typedef struct hamlib_port {
int client_port; /*!< client socket port for tcp connection */ int client_port; /*!< client socket port for tcp connection */
RIG *rig; /*!< our parent RIG device */ RIG *rig; /*!< our parent RIG device */
} hamlib_port_t;
//! @endcond
typedef struct hamlib_async {
int async; /*!< enable asynchronous data handling if true */ int async; /*!< enable asynchronous data handling if true */
int fd_sync_write; /*!< file descriptor for writing synchronous data */ int fd_sync_write; /*!< file descriptor for writing synchronous data */
int fd_sync_read; /*!< file descriptor for reading synchronous data */ int fd_sync_read; /*!< file descriptor for reading synchronous data */
int fd_sync_error_write; /*!< file descriptor for writing synchronous data error codes */ int fd_sync_error_write; /*!< file descriptor for writing synchronous data error codes */
int fd_sync_error_read; /*!< file descriptor for reading synchronous data error codes */ int fd_sync_error_read; /*!< file descriptor for reading synchronous data error codes */
} hamlib_port_t; } hamlib_async_t;
//! @endcond
#if !defined(__APPLE__) || !defined(__cplusplus) #if !defined(__APPLE__) || !defined(__cplusplus)
typedef hamlib_port_t port_t; typedef hamlib_port_t port_t;
@ -2431,6 +2434,7 @@ struct rig_state {
void *async_data_handler_priv_data; void *async_data_handler_priv_data;
volatile int poll_routine_thread_run; volatile int poll_routine_thread_run;
void *poll_routine_priv_data; void *poll_routine_priv_data;
hamlib_async_t asyncport;
}; };
//! @cond Doxygen_Suppress //! @cond Doxygen_Suppress

Wyświetl plik

@ -56,7 +56,8 @@
#include "cm108.h" #include "cm108.h"
#include "gpio.h" #include "gpio.h"
static void close_sync_data_pipe(hamlib_port_t *p) #ifdef ASYNC_BUG
static void close_sync_data_pipe(hamlib_async_t *p)
{ {
if (p->fd_sync_read != -1) { if (p->fd_sync_read != -1) {
close(p->fd_sync_read); close(p->fd_sync_read);
@ -77,6 +78,7 @@ static void close_sync_data_pipe(hamlib_port_t *p)
p->fd_sync_error_write = -1; p->fd_sync_error_write = -1;
} }
} }
#endif
/** /**
* \brief Open a hamlib_port based on its rig port type * \brief Open a hamlib_port based on its rig port type
@ -87,16 +89,19 @@ int HAMLIB_API port_open(hamlib_port_t *p)
{ {
int status; int status;
int want_state_delay = 0; int want_state_delay = 0;
#ifdef ASYNC_BUG
int sync_pipe_fds[2]; int sync_pipe_fds[2];
#endif
ENTERFUNC; ENTERFUNC;
p->fd = -1; p->fd = -1;
p->fd_sync_write = -1; //p->fd_sync_write = -1;
p->fd_sync_read = -1; //p->fd_sync_read = -1;
p->fd_sync_error_write = -1; //p->fd_sync_error_write = -1;
p->fd_sync_error_read = -1; //p->fd_sync_error_read = -1;
#if 0
if (p->async) if (p->async)
{ {
#ifdef HAVE_WINDOWS_H #ifdef HAVE_WINDOWS_H
@ -159,6 +164,7 @@ int HAMLIB_API port_open(hamlib_port_t *p)
rig_debug(RIG_DEBUG_VERBOSE, "%s: created synchronous data pipe\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s: created synchronous data pipe\n", __func__);
} }
#endif
switch (p->type.rig) switch (p->type.rig)
{ {
@ -169,7 +175,9 @@ int HAMLIB_API port_open(hamlib_port_t *p)
{ {
rig_debug(RIG_DEBUG_ERR, "%s: serial_open(%s) status=%d, err=%s\n", __func__, rig_debug(RIG_DEBUG_ERR, "%s: serial_open(%s) status=%d, err=%s\n", __func__,
p->pathname, status, strerror(errno)); p->pathname, status, strerror(errno));
#ifdef ASYNC_BUG
close_sync_data_pipe(p); close_sync_data_pipe(p);
#endif
RETURNFUNC(status); RETURNFUNC(status);
} }
@ -184,7 +192,9 @@ int HAMLIB_API port_open(hamlib_port_t *p)
if (status != 0) if (status != 0)
{ {
rig_debug(RIG_DEBUG_ERR, "%s: set_rts status=%d\n", __func__, status); rig_debug(RIG_DEBUG_ERR, "%s: set_rts status=%d\n", __func__, status);
#ifdef ASYNC_BUG
close_sync_data_pipe(p); close_sync_data_pipe(p);
#endif
RETURNFUNC(status); RETURNFUNC(status);
} }
@ -198,7 +208,9 @@ int HAMLIB_API port_open(hamlib_port_t *p)
if (status != 0) if (status != 0)
{ {
rig_debug(RIG_DEBUG_ERR, "%s: set_dtr status=%d\n", __func__, status); rig_debug(RIG_DEBUG_ERR, "%s: set_dtr status=%d\n", __func__, status);
#ifdef ASYNC_BUG
close_sync_data_pipe(p); close_sync_data_pipe(p);
#endif
RETURNFUNC(status); RETURNFUNC(status);
} }
@ -218,7 +230,9 @@ int HAMLIB_API port_open(hamlib_port_t *p)
if (status < 0) if (status < 0)
{ {
#ifdef ASYNC_BUG
close_sync_data_pipe(p); close_sync_data_pipe(p);
#endif
RETURNFUNC(status); RETURNFUNC(status);
} }
@ -229,7 +243,9 @@ int HAMLIB_API port_open(hamlib_port_t *p)
if (status < 0) if (status < 0)
{ {
#ifdef ASYNC_BUG
close_sync_data_pipe(p); close_sync_data_pipe(p);
#endif
RETURNFUNC(status); RETURNFUNC(status);
} }
@ -240,7 +256,9 @@ int HAMLIB_API port_open(hamlib_port_t *p)
if (status < 0) if (status < 0)
{ {
#ifdef ASYNC_BUG
close_sync_data_pipe(p); close_sync_data_pipe(p);
#endif
RETURNFUNC(-RIG_EIO); RETURNFUNC(-RIG_EIO);
} }
@ -254,7 +272,9 @@ int HAMLIB_API port_open(hamlib_port_t *p)
if (status < 0) if (status < 0)
{ {
#ifdef ASYNC_BUG
close_sync_data_pipe(p); close_sync_data_pipe(p);
#endif
RETURNFUNC(status); RETURNFUNC(status);
} }
@ -272,14 +292,18 @@ int HAMLIB_API port_open(hamlib_port_t *p)
if (status < 0) if (status < 0)
{ {
#ifdef ASYNC_BUG
close_sync_data_pipe(p); close_sync_data_pipe(p);
#endif
RETURNFUNC(status); RETURNFUNC(status);
} }
break; break;
default: default:
#ifdef ASYNC_BUG
close_sync_data_pipe(p); close_sync_data_pipe(p);
#endif
RETURNFUNC(-RIG_EINVAL); RETURNFUNC(-RIG_EINVAL);
} }
@ -331,7 +355,9 @@ int HAMLIB_API port_close(hamlib_port_t *p, rig_port_t port_type)
p->fd = -1; p->fd = -1;
} }
#ifdef ASYNC_BUG
close_sync_data_pipe(p); close_sync_data_pipe(p);
#endif
RETURNFUNC(ret); RETURNFUNC(ret);
} }
@ -473,7 +499,11 @@ static int port_select(hamlib_port_t *p,
static ssize_t port_read_generic(hamlib_port_t *p, void *buf, size_t count, int direct) static ssize_t port_read_generic(hamlib_port_t *p, void *buf, size_t count, int direct)
{ {
#ifdef ASYNC_BUG
int fd = direct ? p->fd : p->fd_sync_read; int fd = direct ? p->fd : p->fd_sync_read;
#else
int fd = p->fd;
#endif
if (p->type.rig == RIG_PORT_SERIAL && p->parm.serial.data_bits == 7) if (p->type.rig == RIG_PORT_SERIAL && p->parm.serial.data_bits == 7)
{ {
@ -629,7 +659,8 @@ int HAMLIB_API write_block(hamlib_port_t *p, const unsigned char *txbuffer, size
return RIG_OK; return RIG_OK;
} }
int HAMLIB_API write_block_sync(hamlib_port_t *p, const unsigned char *txbuffer, size_t count) #ifdef ASYNC_BUG
int HAMLIB_API write_block_sync(async_port_t *p, const unsigned char *txbuffer, size_t count)
{ {
if (!p->async) if (!p->async)
{ {
@ -639,7 +670,7 @@ int HAMLIB_API write_block_sync(hamlib_port_t *p, const unsigned char *txbuffer,
return (int) write(p->fd_sync_write, txbuffer, count); return (int) write(p->fd_sync_write, txbuffer, count);
} }
int HAMLIB_API write_block_sync_error(hamlib_port_t *p, const unsigned char *txbuffer, size_t count) int HAMLIB_API write_block_sync_error(async_port_t *p, const unsigned char *txbuffer, size_t count)
{ {
if (!p->async) if (!p->async)
{ {
@ -648,6 +679,7 @@ int HAMLIB_API write_block_sync_error(hamlib_port_t *p, const unsigned char *txb
return (int) write(p->fd_sync_error_write, txbuffer, count); return (int) write(p->fd_sync_error_write, txbuffer, count);
} }
#endif
static int read_block_generic(hamlib_port_t *p, unsigned char *rxbuffer, size_t count, int direct) static int read_block_generic(hamlib_port_t *p, unsigned char *rxbuffer, size_t count, int direct)
{ {
@ -658,12 +690,20 @@ static int read_block_generic(hamlib_port_t *p, unsigned char *rxbuffer, size_t
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
#ifdef ASYNC_BUG
if (!p->async && !direct) if (!p->async && !direct)
#else
if (!direct)
#endif
{ {
return -RIG_EINTERNAL; return -RIG_EINTERNAL;
} }
#ifdef ASYNC_GBUG
fd = direct ? p->fd : p->fd_sync_read; fd = direct ? p->fd : p->fd_sync_read;
#else
fd = p->fd;
#endif
/* /*
* Wait up to timeout ms. * Wait up to timeout ms.
@ -772,7 +812,11 @@ static int read_block_generic(hamlib_port_t *p, unsigned char *rxbuffer, size_t
int HAMLIB_API read_block(hamlib_port_t *p, unsigned char *rxbuffer, size_t count) int HAMLIB_API read_block(hamlib_port_t *p, unsigned char *rxbuffer, size_t count)
{ {
#ifdef ASYNC_BUG
return read_block_generic(p, rxbuffer, count, !p->async); return read_block_generic(p, rxbuffer, count, !p->async);
#else
return read_block_generic(p, rxbuffer, count, 1);
#endif
} }
/** /**
@ -851,7 +895,11 @@ static int read_string_generic(hamlib_port_t *p,
int i = 0; int i = 0;
static int minlen = 1; // dynamic minimum length of rig response data static int minlen = 1; // dynamic minimum length of rig response data
#ifdef ASYNC_BUG
if (!p->async && !direct) if (!p->async && !direct)
#else
if (!direct)
#endif
{ {
return -RIG_EINTERNAL; return -RIG_EINTERNAL;
} }
@ -871,9 +919,15 @@ static int read_string_generic(hamlib_port_t *p,
return 0; return 0;
} }
#if ASYNC_BUG
fd = direct ? p->fd : p->fd_sync_read; fd = direct ? p->fd : p->fd_sync_read;
errorfd = direct ? -1 : p->fd_sync_error_read; errorfd = direct ? -1 : p->fd_sync_error_read;
maxfd = (fd > errorfd) ? fd : errorfd; maxfd = (fd > errorfd) ? fd : errorfd;
#else
fd = p->fd;
errorfd = -1;
maxfd = (fd > errorfd) ? fd : errorfd;
#endif
/* /*
* Wait up to timeout ms. * Wait up to timeout ms.
@ -1074,7 +1128,11 @@ int HAMLIB_API read_string(hamlib_port_t *p,
int flush_flag, int flush_flag,
int expected_len) int expected_len)
{ {
#ifdef ASYNC_BUG
return read_string_generic(p, rxbuffer, rxmax, stopset, stopset_len, flush_flag, expected_len, !p->async); return read_string_generic(p, rxbuffer, rxmax, stopset, stopset_len, flush_flag, expected_len, !p->async);
#else
return read_string_generic(p, rxbuffer, rxmax, stopset, stopset_len, flush_flag, expected_len, 1);
#endif
} }

Wyświetl plik

@ -41,6 +41,7 @@ extern HAMLIB_EXPORT(int) write_block(hamlib_port_t *p,
const unsigned char *txbuffer, const unsigned char *txbuffer,
size_t count); size_t count);
#ifdef ASYNC_BUG
extern HAMLIB_EXPORT(int) write_block_sync(hamlib_port_t *p, extern HAMLIB_EXPORT(int) write_block_sync(hamlib_port_t *p,
const unsigned char *txbuffer, const unsigned char *txbuffer,
size_t count); size_t count);
@ -48,6 +49,7 @@ extern HAMLIB_EXPORT(int) write_block_sync(hamlib_port_t *p,
extern HAMLIB_EXPORT(int) write_block_sync_error(hamlib_port_t *p, extern HAMLIB_EXPORT(int) write_block_sync_error(hamlib_port_t *p,
const unsigned char *txbuffer, const unsigned char *txbuffer,
size_t count); size_t count);
#endif
extern HAMLIB_EXPORT(int) read_string(hamlib_port_t *p, extern HAMLIB_EXPORT(int) read_string(hamlib_port_t *p,
unsigned char *rxbuffer, unsigned char *rxbuffer,

Wyświetl plik

@ -436,14 +436,14 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model)
rs->comm_state = 0; rs->comm_state = 0;
rs->rigport.type.rig = caps->port_type; /* default from caps */ rs->rigport.type.rig = caps->port_type; /* default from caps */
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
rs->rigport.async = caps->async_data_supported; rs->asyncport.async = caps->async_data_supported;
#else #else
rs->rigport.async = 0; rs->rigport.async = 0;
#endif #endif
rs->rigport.fd_sync_write = -1; rs->asyncport.fd_sync_write = -1;
rs->rigport.fd_sync_read = -1; rs->asyncport.fd_sync_read = -1;
rs->rigport.fd_sync_error_write = -1; rs->asyncport.fd_sync_error_write = -1;
rs->rigport.fd_sync_error_read = -1; rs->asyncport.fd_sync_error_read = -1;
switch (caps->port_type) switch (caps->port_type)
{ {
@ -6903,11 +6903,13 @@ static int async_data_handler_stop(RIG *rig)
void *async_data_handler(void *arg) void *async_data_handler(void *arg)
{ {
#ifdef ASYNC_BUG
struct async_data_handler_args_s *args = (struct async_data_handler_args_s *)arg; struct async_data_handler_args_s *args = (struct async_data_handler_args_s *)arg;
unsigned char frame[MAX_FRAME_LENGTH];
RIG *rig = args->rig; RIG *rig = args->rig;
unsigned char frame[MAX_FRAME_LENGTH];
struct rig_state *rs = &rig->state; struct rig_state *rs = &rig->state;
int result; int result;
#endif
rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Starting async data handler thread\n", __FILE__, rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Starting async data handler thread\n", __FILE__,
__LINE__); __LINE__);
@ -6916,6 +6918,7 @@ void *async_data_handler(void *arg)
// TODO: add initial support for async in Kenwood kenwood_transaction (+one) functions -> add transaction_active flag usage // TODO: add initial support for async in Kenwood kenwood_transaction (+one) functions -> add transaction_active flag usage
// TODO: add initial support for async in Yaesu newcat_get_cmd/set_cmd (+validate) functions -> add transaction_active flag usage // TODO: add initial support for async in Yaesu newcat_get_cmd/set_cmd (+validate) functions -> add transaction_active flag usage
#ifdef ASYNC_BUG
while (rs->async_data_handler_thread_run) while (rs->async_data_handler_thread_run)
{ {
int frame_length; int frame_length;
@ -6967,6 +6970,7 @@ void *async_data_handler(void *arg)
} }
} }
} }
#endif
rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Stopping async data handler thread\n", __FILE__, rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Stopping async data handler thread\n", __FILE__,
__LINE__); __LINE__);