From 2be172ac4ecfd5203d6ead8c172ee71343286a67 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Sun, 24 Jan 2021 10:51:19 -0600 Subject: [PATCH 01/17] Improve robustness of rigctld Now retries opening indefinitely Improved client side too Error message should now show timeout if rig disappears --- rigs/dummy/flrig.c | 5 +++ rigs/dummy/flrig.h | 2 +- src/rig.c | 4 +++ tests/rigctl.c | 17 ++++++++++ tests/rigctld.c | 79 +++++++++++++++++++++++++++++++--------------- 5 files changed, 80 insertions(+), 27 deletions(-) diff --git a/rigs/dummy/flrig.c b/rigs/dummy/flrig.c index 5e2d661fd..9c452cc73 100644 --- a/rigs/dummy/flrig.c +++ b/rigs/dummy/flrig.c @@ -541,6 +541,11 @@ static int flrig_transaction(RIG *rig, char *cmd, char *cmd_arg, char *value, if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: write_transaction error=%d\n", __func__, retval); + + // if we get RIG_EIO the socket has probably disappeared + // so bubble up the error so port can re re-opened + if (retval == -RIG_EIO) { return retval; } + hl_usleep(50 * 1000); // 50ms sleep if error } diff --git a/rigs/dummy/flrig.h b/rigs/dummy/flrig.h index 10f2dda13..70c84b0d9 100644 --- a/rigs/dummy/flrig.h +++ b/rigs/dummy/flrig.h @@ -28,7 +28,7 @@ #include #endif -#define BACKEND_VER "20210117" +#define BACKEND_VER "20210123" #define EOM "\r" #define TRUE 1 diff --git a/src/rig.c b/src/rig.c index 451617a48..735ddc8f1 100644 --- a/src/rig.c +++ b/src/rig.c @@ -1653,12 +1653,16 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) rig_debug(RIG_DEBUG_VERBOSE, "%s called vfo=%s\n", __func__, rig_strvfo(vfo)); +#if 0 // don't think we really need this check + if (CHECK_RIG_ARG(rig) || !freq) { rig_debug(RIG_DEBUG_TRACE, "%s: rig or freq ptr invalid\n", __func__); RETURNFUNC(-RIG_EINVAL); } +#endif + curr_vfo = rig->state.current_vfo; // save vfo for restore later vfo = vfo_fixup(rig, vfo); diff --git a/tests/rigctl.c b/tests/rigctl.c index a23d0696a..799e52507 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -615,6 +615,23 @@ int main(int argc, char *argv[]) { exitcode = 2; } + + rig_debug(RIG_DEBUG_ERR, "%s: XXXXXXXXX#1 retcode=%d\n", __func__, retcode); + if (retcode == -RIG_EIO || retcode == 2) + { + rig_debug(RIG_DEBUG_ERR, "%s: i/o error\n", __func__) + + do + { + retcode = rig_close(my_rig); + hl_usleep(1000 * 1000); + rig_debug(RIG_DEBUG_ERR, "%s: rig_close retcode=%d\n", __func__, retcode); + retcode = rig_open(my_rig); + rig_debug(RIG_DEBUG_ERR, "%s: rig_open retcode=%d\n", __func__, retcode); + } + while (retcode != RIG_OK); + + } } while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL); diff --git a/tests/rigctld.c b/tests/rigctld.c index 4739e41bc..7e74f03b3 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -969,6 +969,31 @@ int main(int argc, char *argv[]) return 0; } +static FILE*get_fsockout(struct handle_data *handle_data_arg) +{ +#ifdef __MINGW32__ + return _fdopen(sock_osfhandle, "wb"); +#else + return fdopen(handle_data_arg->sock, "wb"); +#endif +} + +static FILE* get_fsockin(struct handle_data *handle_data_arg) +{ +#ifdef __MINGW32__ + int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY); + + if (sock_osfhandle == -1) + { + rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno)); + goto handle_exit; + } + + return _fdopen(sock_osfhandle, "rb"); +#else + return fdopen(handle_data_arg->sock, "rb"); +#endif +} /* * This is the function run by the threads @@ -985,19 +1010,7 @@ void *handle_socket(void *arg) int ext_resp = 0; char resp_sep = '\n'; -#ifdef __MINGW32__ - int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY); - - if (sock_osfhandle == -1) - { - rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno)); - goto handle_exit; - } - - fsockin = _fdopen(sock_osfhandle, "rb"); -#else - fsockin = fdopen(handle_data_arg->sock, "rb"); -#endif + fsockin = get_fsockin(handle_data_arg); if (!fsockin) { @@ -1006,11 +1019,7 @@ void *handle_socket(void *arg) goto handle_exit; } -#ifdef __MINGW32__ - fsockout = _fdopen(sock_osfhandle, "wb"); -#else - fsockout = fdopen(handle_data_arg->sock, "wb"); -#endif + fsockout = get_fsockout(handle_data_arg); if (!fsockout) { @@ -1055,7 +1064,7 @@ void *handle_socket(void *arg) do { - rig_debug(RIG_DEBUG_TRACE, "%s: vfo_mode=%d\n", __func__, + rig_debug(RIG_DEBUG_TRACE, "%s: doing rigctl_parse vfo_mode=%d\n", __func__, handle_data_arg->vfo_mode); retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0, sync_callback, @@ -1063,24 +1072,42 @@ void *handle_socket(void *arg) if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: rigctl_parse retcode=%d\n", __func__, retcode); } + +#if 0 // disabled -- don't think we need this + + // see https://github.com/Hamlib/Hamlib/issues/516 if (retcode == -1) { //sleep(1); // probably don't need this delay - continue; + //continue; } - if (ferror(fsockin) || ferror(fsockout)) +#endif + + // if socket error or rigctld gets RIG_EIO we'll try to reopen + if (ferror(fsockin)) { + rig_debug(RIG_DEBUG_ERR, "%s: sockin err=%s\n", __func__, strerror(errno)); + RETURNFUNC(NULL); + } + + if (ferror(fsockin) || ferror(fsockout) || retcode == 2) + { + if (ferror(fsockout)) fsockout = get_fsockout(handle_data_arg); rig_debug(RIG_DEBUG_ERR, "%s: socket error in=%d, out=%d\n", __func__, ferror(fsockin), ferror(fsockout)); - retcode = rig_close(my_rig); - rig_debug(RIG_DEBUG_ERR, "%s: rig_close retcode=%d\n", __func__, retcode); - retcode = rig_open(my_rig); - rig_debug(RIG_DEBUG_ERR, "%s: rig_open retcode=%d\n", __func__, retcode); + do + { + retcode = rig_close(my_rig); + hl_usleep(1000 * 1000); + rig_debug(RIG_DEBUG_ERR, "%s: rig_close retcode=%d\n", __func__, retcode); + retcode = rig_open(my_rig); + rig_debug(RIG_DEBUG_ERR, "%s: rig_open retcode=%d\n", __func__, retcode); + } + while (retcode != RIG_OK); } } - while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL); #ifdef HAVE_PTHREAD From f1fd159b9a964328b3811181ea9354773c253686 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Sun, 24 Jan 2021 12:25:29 -0600 Subject: [PATCH 02/17] Prevent ftdx101d from setting frequency on the non-tx vfo when in split mode --- rigs/yaesu/newcat.c | 15 +++++++++++++-- rigs/yaesu/newcat.h | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index 3d9c04ea5..e07733672 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -775,6 +775,15 @@ int newcat_set_freq(RIG *rig, vfo_t vfo, freq_t freq) target_vfo = 'A' == c ? '0' : '1'; + // some rigs like FTDX101D cannot change non-TX vfo freq + // but they can change the TX vfo + if (is_ftdx101 && rig->state.cache.ptt == RIG_PTT_ON) + { + // then we can't change freq on the non-tx VFO + rig_debug(RIG_DEBUG_TRACE, "%s: ftdx101 check vfo OK, vfo=%s, tx_vfo=%s\n", __func__, rig_strvfo(vfo), rig_strvfo(rig->state.tx_vfo)); + if (vfo != rig->state.tx_vfo) return -RIG_ENTARGET; + } + if (rig->state.cache.ptt == RIG_PTT_ON) // we have a few rigs that can't set TX VFO while PTT_ON { @@ -6687,6 +6696,7 @@ ncboolean newcat_is_rig(RIG *rig, rig_model_t model) /* * newcat_set_tx_vfo does not set priv->curr_vfo + * does set rig->state.tx_vfo */ int newcat_set_tx_vfo(RIG *rig, vfo_t tx_vfo) { @@ -6762,9 +6772,10 @@ int newcat_set_tx_vfo(RIG *rig, vfo_t tx_vfo) snprintf(priv->cmd_str, sizeof(priv->cmd_str), "%s%c%c", command, p1, cat_term); - rig_debug(RIG_DEBUG_TRACE, "cmd_str = %s\n", priv->cmd_str); + rig_debug(RIG_DEBUG_TRACE, "cmd_str = %s, vfo=%s\n", priv->cmd_str, rig_strvfo(tx_vfo)); + + rig->state.tx_vfo = tx_vfo; - /* Set TX VFO */ RETURNFUNC(newcat_set_cmd(rig)); } diff --git a/rigs/yaesu/newcat.h b/rigs/yaesu/newcat.h index bf6005aed..ba2e50965 100644 --- a/rigs/yaesu/newcat.h +++ b/rigs/yaesu/newcat.h @@ -50,7 +50,7 @@ typedef char ncboolean; /* shared function version */ -#define NEWCAT_VER "20210123" +#define NEWCAT_VER "20210124" /* Hopefully large enough for future use, 128 chars plus '\0' */ #define NEWCAT_DATA_LEN 129 From 7e6adc6d2a69e6bb41809f59e9103c8cc156fae3 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Sun, 24 Jan 2021 12:25:29 -0600 Subject: [PATCH 03/17] Prevent ftdx101d from setting frequency on the non-tx vfo when in split mode --- rigs/yaesu/newcat.c | 15 +++++++++++++-- rigs/yaesu/newcat.h | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index 3d9c04ea5..e07733672 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -775,6 +775,15 @@ int newcat_set_freq(RIG *rig, vfo_t vfo, freq_t freq) target_vfo = 'A' == c ? '0' : '1'; + // some rigs like FTDX101D cannot change non-TX vfo freq + // but they can change the TX vfo + if (is_ftdx101 && rig->state.cache.ptt == RIG_PTT_ON) + { + // then we can't change freq on the non-tx VFO + rig_debug(RIG_DEBUG_TRACE, "%s: ftdx101 check vfo OK, vfo=%s, tx_vfo=%s\n", __func__, rig_strvfo(vfo), rig_strvfo(rig->state.tx_vfo)); + if (vfo != rig->state.tx_vfo) return -RIG_ENTARGET; + } + if (rig->state.cache.ptt == RIG_PTT_ON) // we have a few rigs that can't set TX VFO while PTT_ON { @@ -6687,6 +6696,7 @@ ncboolean newcat_is_rig(RIG *rig, rig_model_t model) /* * newcat_set_tx_vfo does not set priv->curr_vfo + * does set rig->state.tx_vfo */ int newcat_set_tx_vfo(RIG *rig, vfo_t tx_vfo) { @@ -6762,9 +6772,10 @@ int newcat_set_tx_vfo(RIG *rig, vfo_t tx_vfo) snprintf(priv->cmd_str, sizeof(priv->cmd_str), "%s%c%c", command, p1, cat_term); - rig_debug(RIG_DEBUG_TRACE, "cmd_str = %s\n", priv->cmd_str); + rig_debug(RIG_DEBUG_TRACE, "cmd_str = %s, vfo=%s\n", priv->cmd_str, rig_strvfo(tx_vfo)); + + rig->state.tx_vfo = tx_vfo; - /* Set TX VFO */ RETURNFUNC(newcat_set_cmd(rig)); } diff --git a/rigs/yaesu/newcat.h b/rigs/yaesu/newcat.h index bf6005aed..ba2e50965 100644 --- a/rigs/yaesu/newcat.h +++ b/rigs/yaesu/newcat.h @@ -50,7 +50,7 @@ typedef char ncboolean; /* shared function version */ -#define NEWCAT_VER "20210123" +#define NEWCAT_VER "20210124" /* Hopefully large enough for future use, 128 chars plus '\0' */ #define NEWCAT_DATA_LEN 129 From d75a23d15615a03cf95f11ee5216b893960dcf47 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Sun, 24 Jan 2021 12:52:44 -0600 Subject: [PATCH 04/17] Fix ftdx101d set_freq behavior depending on split mode and VFO requested --- rigs/yaesu/newcat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index e07733672..1edde1b3e 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -779,8 +779,11 @@ int newcat_set_freq(RIG *rig, vfo_t vfo, freq_t freq) // but they can change the TX vfo if (is_ftdx101 && rig->state.cache.ptt == RIG_PTT_ON) { - // then we can't change freq on the non-tx VFO rig_debug(RIG_DEBUG_TRACE, "%s: ftdx101 check vfo OK, vfo=%s, tx_vfo=%s\n", __func__, rig_strvfo(vfo), rig_strvfo(rig->state.tx_vfo)); + // when in split we can change VFOB but not VFOA + if (rig->state.split == RIG_SPLIT_ON && target_vfo == '0') return -RIG_ENTARGET; + // when not in split we can't change VFOA at all + if (rig->state.split == RIG_SPLIT_OFF && target_vfo == '0') return -RIG_ENTARGET; if (vfo != rig->state.tx_vfo) return -RIG_ENTARGET; } From b5c60e50fb83bd9aa80af7f7c7199e5920835dc2 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Sun, 24 Jan 2021 16:01:19 -0600 Subject: [PATCH 05/17] Fix newcat.c compile error --- rigs/yaesu/newcat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index 1edde1b3e..973217a85 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -781,9 +781,9 @@ int newcat_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { rig_debug(RIG_DEBUG_TRACE, "%s: ftdx101 check vfo OK, vfo=%s, tx_vfo=%s\n", __func__, rig_strvfo(vfo), rig_strvfo(rig->state.tx_vfo)); // when in split we can change VFOB but not VFOA - if (rig->state.split == RIG_SPLIT_ON && target_vfo == '0') return -RIG_ENTARGET; + if (rig->state.cache.split == RIG_SPLIT_ON && target_vfo == '0') return -RIG_ENTARGET; // when not in split we can't change VFOA at all - if (rig->state.split == RIG_SPLIT_OFF && target_vfo == '0') return -RIG_ENTARGET; + if (rig->state.cache.split == RIG_SPLIT_OFF && target_vfo == '0') return -RIG_ENTARGET; if (vfo != rig->state.tx_vfo) return -RIG_ENTARGET; } From 1b89407a8d64a6895f935afc8dec8f032336be16 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Sun, 24 Jan 2021 17:19:58 -0600 Subject: [PATCH 06/17] Fix compilation of rigctld.c on mingw --- tests/rigctld.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/rigctld.c b/tests/rigctld.c index 7e74f03b3..bd33cb8fc 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -972,6 +972,7 @@ int main(int argc, char *argv[]) static FILE*get_fsockout(struct handle_data *handle_data_arg) { #ifdef __MINGW32__ + int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY); return _fdopen(sock_osfhandle, "wb"); #else return fdopen(handle_data_arg->sock, "wb"); @@ -986,7 +987,7 @@ static FILE* get_fsockin(struct handle_data *handle_data_arg) if (sock_osfhandle == -1) { rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno)); - goto handle_exit; + return NULL; } return _fdopen(sock_osfhandle, "rb"); From fda709c7af2fee6fe8d09226c8de6b9833613fce Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Sun, 24 Jan 2021 22:43:07 -0600 Subject: [PATCH 07/17] Change FTDX101 to 2 stop bits --- rigs/yaesu/ftdx101.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rigs/yaesu/ftdx101.c b/rigs/yaesu/ftdx101.c index 24a77bd35..173b3ce24 100644 --- a/rigs/yaesu/ftdx101.c +++ b/rigs/yaesu/ftdx101.c @@ -76,7 +76,7 @@ const struct rig_caps ftdx101d_caps = RIG_MODEL(RIG_MODEL_FTDX101D), .model_name = "FTDX-101D", .mfg_name = "Yaesu", - .version = NEWCAT_VER ".7", + .version = NEWCAT_VER ".8z .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, @@ -86,7 +86,7 @@ const struct rig_caps ftdx101d_caps = .serial_rate_min = 4800, .serial_rate_max = 38400, .serial_data_bits = 8, - .serial_stop_bits = 1, + .serial_stop_bits = 2, .serial_parity = RIG_PARITY_NONE, .serial_handshake = RIG_HANDSHAKE_HARDWARE, .write_delay = FTDX101_WRITE_DELAY, From 11be167354c87f6c2914a70d50f947486c332131 Mon Sep 17 00:00:00 2001 From: Nate Bargmann Date: Mon, 25 Jan 2021 07:13:26 -0600 Subject: [PATCH 08/17] Correct typo causing compilation failure --- rigs/yaesu/ftdx101.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rigs/yaesu/ftdx101.c b/rigs/yaesu/ftdx101.c index 173b3ce24..3871e8106 100644 --- a/rigs/yaesu/ftdx101.c +++ b/rigs/yaesu/ftdx101.c @@ -76,7 +76,7 @@ const struct rig_caps ftdx101d_caps = RIG_MODEL(RIG_MODEL_FTDX101D), .model_name = "FTDX-101D", .mfg_name = "Yaesu", - .version = NEWCAT_VER ".8z + .version = NEWCAT_VER ".8z", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, From 9322479117388eb7688992f420760ddf33c03aa7 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Mon, 25 Jan 2021 11:19:32 -0600 Subject: [PATCH 09/17] Fix kx3/kx2 RFPOWER_METER_WATTS and buffer size --- rigs/kenwood/k3.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/rigs/kenwood/k3.c b/rigs/kenwood/k3.c index abe1f4917..1691f7b03 100644 --- a/rigs/kenwood/k3.c +++ b/rigs/kenwood/k3.c @@ -181,7 +181,7 @@ const struct rig_caps k3_caps = RIG_MODEL(RIG_MODEL_K3), .model_name = "K3", .mfg_name = "Elecraft", - .version = BACKEND_VER ".2", + .version = BACKEND_VER ".3", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, @@ -1584,7 +1584,7 @@ static int k3_get_maxpower(RIG *rig) { int retval; int maxpower = 12; // K3 default power level - char levelbuf[16]; + char levelbuf[KENWOOD_MAX_BUF_LEN]; struct kenwood_priv_data *priv = rig->state.priv; // default range is 0-12 if there is no KPA3 installed @@ -2129,6 +2129,23 @@ int kx3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) val->f = pwr; return retval; } + case RIG_LEVEL_RFPOWER_METER_WATTS: + { + struct kenwood_priv_data *priv = rig->state.priv; + char levelbuf[KENWOOD_MAX_BUF_LEN]; + int pwr; + + retval = kenwood_safe_transaction(rig, "PO", levelbuf, sizeof(levelbuf), 5); + + if (retval != RIG_OK) + { + return retval; + } + + sscanf(levelbuf + 2, "%d", &pwr); + val->f = priv->has_kpa100 ? pwr : pwr / 10.0; + return retval; + } } return k3_get_level(rig, vfo, level, val); From e38c69602bdfadf0203ac6788f2e8787a3397c87 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Mon, 25 Jan 2021 11:20:28 -0600 Subject: [PATCH 10/17] astyle k3.c --- rigs/kenwood/k3.c | 1 + 1 file changed, 1 insertion(+) diff --git a/rigs/kenwood/k3.c b/rigs/kenwood/k3.c index 1691f7b03..dc37c67dc 100644 --- a/rigs/kenwood/k3.c +++ b/rigs/kenwood/k3.c @@ -2129,6 +2129,7 @@ int kx3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) val->f = pwr; return retval; } + case RIG_LEVEL_RFPOWER_METER_WATTS: { struct kenwood_priv_data *priv = rig->state.priv; From 54fc0e10f63767dd7e63728cd1715559de761c99 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Mon, 25 Jan 2021 12:23:05 -0600 Subject: [PATCH 11/17] Add clock change to misc.c to allow building hamlib on some mac platforms --- src/misc.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/misc.c b/src/misc.c index a0b31cf87..2aa1ad564 100644 --- a/src/misc.c +++ b/src/misc.c @@ -57,6 +57,46 @@ #include "misc.h" #include "serial.h" #include "network.h" +#ifdef __APPLE__ + +#if !HAVE_CLOCK_GETTIME + +# include +# ifndef __clockid_t_defined + typedef int clockid_t; + #define __clockid_t_defined 1 +# endif /* __clockid_t_defined */ + +# define CLOCK_REALTIME 0 +# define CLOCK_MONOTONIC 6 + +int clock_gettime(clockid_t clock_id, struct timespec* tp) +{ + if (clock_id == CLOCK_REALTIME) { + struct timeval t; + if (gettimeofday(&t, NULL) != 0) + return -1; + tp->tv_sec = t.tv_sec; + tp->tv_nsec = t.tv_usec * 1000; + } + else if (clock_id == CLOCK_MONOTONIC) { + static mach_timebase_info_data_t info = { 0, 0 }; + if (info.denom == 0) + mach_timebase_info(&info); + uint64_t t = mach_absolute_time() * info.numer / info.denom; + tp->tv_sec = t / 1000000000; + tp->tv_nsec = t % 1000000000; + } + else { + errno = EINVAL; + return -1; + } + + return 0; +} +#endif // !HAVE_CLOCK_GETTIME + +#endif // __APPLE__ /** From c717bb5d76939fa355c56dd84d850b1a3b889338 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Mon, 25 Jan 2021 22:24:57 -0600 Subject: [PATCH 12/17] Improve -V version info --- tests/rigctl.c | 5 ++--- tests/rigctld.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/rigctl.c b/tests/rigctl.c index 799e52507..4411a6ead 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -177,7 +177,7 @@ int main(int argc, char *argv[]) exit(0); case 'V': - version(); + printf("rigctl %s\nLast commit was %s\n", hamlib_version, HAMLIBDATETIME); exit(0); case 'm': @@ -433,8 +433,7 @@ int main(int argc, char *argv[]) rig_set_debug(verbose); - rig_debug(RIG_DEBUG_VERBOSE, "rigctl %s\nLast commit was %s\n", hamlib_version, - HAMLIBDATETIME); + rig_debug(RIG_DEBUG_VERBOSE, "rigctl %s\nLast commit was %s\n", hamlib_version,HAMLIBDATETIME); rig_debug(RIG_DEBUG_VERBOSE, "%s", "Report bugs to \n\n"); diff --git a/tests/rigctld.c b/tests/rigctld.c index bd33cb8fc..88cace9a7 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -287,7 +287,7 @@ int main(int argc, char *argv[]) exit(0); case 'V': - version(); + printf("rigctl %s\nLast commit was %s\n", hamlib_version, HAMLIBDATETIME); exit(0); case 'm': From 921220bfa5b04c3737262e9acc7a41b556da0759 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Mon, 25 Jan 2021 23:38:43 -0600 Subject: [PATCH 13/17] Update NEWS --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 4d78c5e00..a3fe9bcb0 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,7 @@ Copyright (C) 2000-2020 Michael Black W9MDB, and others Please send Hamlib bug reports to hamlib-developer@lists.sourceforge.net Version 4.1 + * rigctld and rigs should be more robust for disconnect problemsy * Several fixes for Icom and Yaesu rigs * Nobody should need to use rig->caps or rig->state anymore If you need a variable added please contact us. From 610cd2608593139afcec2658a66ba9ba5dbe6a45 Mon Sep 17 00:00:00 2001 From: Nate Bargmann Date: Tue, 26 Jan 2021 07:12:26 -0600 Subject: [PATCH 14/17] Supply missing rotators/satel/Android.mk The use of 'make discheck' will detect such missing files before pushing out changes. --- rotators/satel/Android.mk | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 rotators/satel/Android.mk diff --git a/rotators/satel/Android.mk b/rotators/satel/Android.mk new file mode 100644 index 000000000..7925dd54e --- /dev/null +++ b/rotators/satel/Android.mk @@ -0,0 +1,12 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := satel.c +LOCAL_MODULE := satel + +LOCAL_CFLAGS := -DHAVE_CONFIG_H +LOCAL_C_INCLUDES := android include src +LOCAL_LDLIBS := -lhamlib -Lobj/local/armeabi + +include $(BUILD_STATIC_LIBRARY) From a81b4db9bebb711681632c7427dd7dc7ec81d446 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Tue, 26 Jan 2021 07:28:55 -0600 Subject: [PATCH 15/17] Fix clock_gettime for Big Sur and hopefully older MacOS too --- src/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/misc.c b/src/misc.c index 2aa1ad564..3206fe67b 100644 --- a/src/misc.c +++ b/src/misc.c @@ -59,11 +59,11 @@ #include "network.h" #ifdef __APPLE__ -#if !HAVE_CLOCK_GETTIME +#ifndef HAVE_CLOCK_GETTIME # include # ifndef __clockid_t_defined - typedef int clockid_t; + typedef enum clockid_t; #define __clockid_t_defined 1 # endif /* __clockid_t_defined */ From 30eca94210ece61603d2d09d88632125c66072b4 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Tue, 26 Jan 2021 15:05:43 -0600 Subject: [PATCH 16/17] Change MacOS detection logic for clock_gettime to hopefully cover all flavors --- src/misc.c | 74 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/src/misc.c b/src/misc.c index 3206fe67b..e5a0a6e76 100644 --- a/src/misc.c +++ b/src/misc.c @@ -57,48 +57,64 @@ #include "misc.h" #include "serial.h" #include "network.h" + #ifdef __APPLE__ -#ifndef HAVE_CLOCK_GETTIME +#include + +#if AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + +#else # include -# ifndef __clockid_t_defined - typedef enum clockid_t; - #define __clockid_t_defined 1 -# endif /* __clockid_t_defined */ +# ifndef __clockid_t_defined +typedef int clockid_t; +#define __clockid_t_defined 1 +# endif /* __clockid_t_defined */ -# define CLOCK_REALTIME 0 -# define CLOCK_MONOTONIC 6 +# define CLOCK_REALTIME 0 +# define CLOCK_MONOTONIC 1 -int clock_gettime(clockid_t clock_id, struct timespec* tp) +int clock_gettime(clockid_t clock_id, struct timespec *tp) { - if (clock_id == CLOCK_REALTIME) { - struct timeval t; - if (gettimeofday(&t, NULL) != 0) - return -1; - tp->tv_sec = t.tv_sec; - tp->tv_nsec = t.tv_usec * 1000; - } - else if (clock_id == CLOCK_MONOTONIC) { - static mach_timebase_info_data_t info = { 0, 0 }; - if (info.denom == 0) - mach_timebase_info(&info); - uint64_t t = mach_absolute_time() * info.numer / info.denom; - tp->tv_sec = t / 1000000000; - tp->tv_nsec = t % 1000000000; - } - else { - errno = EINVAL; - return -1; - } + if (clock_id == CLOCK_REALTIME) + { + struct timeval t; - return 0; + if (gettimeofday(&t, NULL) != 0) + { + return -1; + } + + tp->tv_sec = t.tv_sec; + tp->tv_nsec = t.tv_usec * 1000; + } + else if (clock_id == CLOCK_MONOTONIC) + { + static mach_timebase_info_data_t info = { 0, 0 }; + + if (info.denom == 0) + { + mach_timebase_info(&info); + } + + uint64_t t = mach_absolute_time() * info.numer / info.denom; + tp->tv_sec = t / 1000000000; + tp->tv_nsec = t % 1000000000; + } + else + { + errno = EINVAL; + return -1; + } + + return 0; } + #endif // !HAVE_CLOCK_GETTIME #endif // __APPLE__ - /** * \brief Convert from binary to 4-bit BCD digits, little-endian * \param bcd_data From f2b7893a2b81c00e7a9998b376b846a34bab1205 Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Wed, 27 Jan 2021 11:00:58 -0600 Subject: [PATCH 17/17] Another attempt to get clock_gettime compiling for all Mac flavors --- src/misc.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/misc.c b/src/misc.c index e5a0a6e76..eccb7ba15 100644 --- a/src/misc.c +++ b/src/misc.c @@ -60,22 +60,23 @@ #ifdef __APPLE__ -#include +#include -#if AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER +#if !defined(CLOCK_REALTIME) && !defined(CLOCK_MONOTONIC) +// +// MacOS < 10.12 does not have clock_gettime +// +// Contribution from github user "ra1nb0w" +// -#else - -# include -# ifndef __clockid_t_defined +#define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 6 typedef int clockid_t; -#define __clockid_t_defined 1 -# endif /* __clockid_t_defined */ -# define CLOCK_REALTIME 0 -# define CLOCK_MONOTONIC 1 +#include +#include -int clock_gettime(clockid_t clock_id, struct timespec *tp) +static int clock_gettime(clockid_t clock_id, struct timespec *tp) { if (clock_id == CLOCK_REALTIME) {