[Hamlib-commits] Hamlib -- Ham radio control libraries branch master updated. 73464a6c2e2453f988dd1
Library to control radio transceivers and receivers
Brought to you by:
n0nb
From: Michael B. <mdb...@us...> - 2021-04-11 16:51:15
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Hamlib -- Ham radio control libraries". The branch, master has been updated via 73464a6c2e2453f988dd12b9ed3e4a737632c85e (commit) via 778758200eec2bf403222484331c817a8e40db32 (commit) via 758e9bc3a7ff9e19da0954166b93683d41ab622c (commit) via 601f0ab1f1c4f05e7771c2cd0401014f8058e7be (commit) from 1d1259545a7074b5b2d4419503abc5caebc67233 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 73464a6c2e2453f988dd12b9ed3e4a737632c85e Author: Mike Black W9MDB <mdb...@ya...> Date: Sun Apr 11 11:49:37 2021 -0500 Fix IC910 behavior with gpredict -- also should fix some Main/Sub behavior elsewhere too https://github.com/Hamlib/Hamlib/issues/657 diff --git a/rigs/icom/ic910.c b/rigs/icom/ic910.c index 66b101d7..bfb50a7a 100644 --- a/rigs/icom/ic910.c +++ b/rigs/icom/ic910.c @@ -65,266 +65,6 @@ static int ic910_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) } #endif /* HAVE_WEIRD_IC910_MODES */ -/* this function compares 2 frequencies - * returns 1 if they are in the same band - * returns 0 if they are in different bands - */ - -static int compareFrequencies(RIG *rig, freq_t freq1, freq_t freq2) -{ - int freq1band = 0, freq2band = 0; - freq_range_t noband = RIG_FRNG_END; - - while (rig->caps->rx_range_list1[freq1band].startf != noband.startf) - { - if (freq1 >= rig->caps->rx_range_list1[freq1band].startf && - freq1 <= rig->caps->rx_range_list1[freq1band].endf) - { - break; - } - - ++freq1band; - //fprintf(stderr, "%i\n", freq1band); - } - - while (rig->caps->rx_range_list1[freq2band].startf != noband.startf) - { - if (freq2 >= rig->caps->rx_range_list1[freq2band].startf && - freq2 <= rig->caps->rx_range_list1[freq2band].endf) - { - break; - } - - ++freq2band; - } - - if (freq2band == freq1band) { return 1; } - else { return 0; } -} - -static int ic910_set_freq(RIG *rig, vfo_t vfo, freq_t freq) -{ - int retval; - freq_t otherfreq; - freq_t origfreq; - - if ((retval = icom_get_freq(rig, RIG_VFO_CURR, &origfreq)) != RIG_OK) { return retval; } - - if (compareFrequencies(rig, freq, origfreq)) - { - /* correct band already */ - if (RIG_VFO_A == vfo || RIG_VFO_B == vfo) - { - /* switch to desired VFO and read its frequency */ - if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; } - - if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) { return retval; } - - retval = icom_set_freq(rig, RIG_VFO_CURR, freq); - - if (otherfreq != origfreq) - { - /* swap VFOs back as original was the other one */ - icom_set_vfo(rig, RIG_VFO_A == vfo ? RIG_VFO_B : RIG_VFO_A); - } - } - else if (RIG_VFO_MAIN == vfo || RIG_VFO_SUB == vfo) - { - /* switch to the desired of MAIN and SUB and read its frequency */ - if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; } - - if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) { return retval; } - - if (otherfreq != origfreq) - { - /* started on a different so band exchange MAIN and SUB */ - if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) { return retval; } - - retval = icom_set_freq(rig, RIG_VFO_CURR, freq); - /* swap MAIN/SUB back as original was the other one */ - icom_set_vfo(rig, RIG_VFO_MAIN == vfo ? RIG_VFO_SUB : RIG_VFO_MAIN); - } - else - { - /* already correct one of MAIN and SUB */ - retval = icom_set_freq(rig, RIG_VFO_CURR, freq); - } - } - else if (RIG_VFO_CURR == vfo) - { - retval = icom_set_freq(rig, RIG_VFO_CURR, freq); - } - else { retval = -RIG_EVFO; } - } - else - { - /* wrong band */ - if (RIG_VFO_A == vfo || RIG_VFO_B == vfo) - { - /* try and set frequency, may fail if band is already on other of MAIN/SUB */ - retval = icom_set_freq(rig, RIG_VFO_CURR, freq); - - if (-RIG_ERJCTED == retval) - { - /* exchange MAIN & SUB */ - if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) { return retval; } - - if ((retval = icom_get_freq(rig, vfo, &origfreq)) != RIG_OK) { return retval; } - - if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; } - - if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) { return retval; } - - retval = icom_set_freq(rig, RIG_VFO_CURR, freq); - - if (-RIG_ERJCTED == retval) - { - /* band not fitted so swap MAIN & SUB back and give up */ - icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG); - return retval; - } - else if (retval != RIG_OK) { return retval; } - - if (otherfreq != origfreq) - { - /* swap VFOs back as original was the other one */ - icom_set_vfo(rig, RIG_VFO_A == vfo ? RIG_VFO_B : RIG_VFO_A); - } - - /* we do not exchange bands back as this is taken to - mean set VFOA/B on MAIN to the specified frequency - as Hamlib does not recognize A on MAIN or B on SUB - etc. This is probably reasonable since we cannot Tx - on SUB */ - return retval; - } - - /* we changed band to the "third band" which always makes - VFO A current so just make the requested one the - specified frequency as well if it is VFO B. There is no - way of going to the "third band" without changing VFO - A */ - if (RIG_VFO_B == vfo) - { - if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; } - - retval = icom_set_freq(rig, RIG_VFO_CURR, freq); - icom_set_vfo(rig, RIG_VFO_A); - } - } - else if (RIG_VFO_MAIN == vfo || RIG_VFO_SUB == vfo) - { - if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; } - - if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) { return retval; } - - retval = icom_set_freq(rig, RIG_VFO_CURR, freq); - - if (-RIG_ERJCTED == retval) - { - /* required band is on other of MAIN or SUB */ - if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) { return retval; } - - retval = icom_set_freq(rig, RIG_VFO_CURR, freq); - } - else if (retval != RIG_OK) { return retval; } - - if (otherfreq != origfreq) - { - /* started on other of MAIN & SUB so switch back */ - icom_set_vfo(rig, - RIG_VFO_MAIN == vfo ? - RIG_VFO_SUB : RIG_VFO_MAIN); - } - } - else if (RIG_VFO_CURR == vfo) - { - retval = icom_set_freq(rig, RIG_VFO_CURR, freq); - - if (-RIG_ERJCTED == retval) - { - /* exchange MAIN & SUB */ - if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) { return retval; } - - retval = icom_set_freq(rig, RIG_VFO_CURR, freq); - - if (-RIG_ERJCTED == retval) - { - /* band not fitted so swap MAIN & SUB back and give up */ - icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG); - return retval; - } - } - } - else { retval = -RIG_EVFO; } - } - - return retval; -} - -static int ic910_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) -{ - int retval; - freq_t origfreq; - vfo_t vfo_save; - struct icom_priv_data *priv = (struct icom_priv_data *) rig->state.priv; - - /* start off by reading the current VFO frequency */ - if ((retval = icom_get_freq(rig, RIG_VFO_CURR, &origfreq)) != RIG_OK) { return retval; } - - vfo_save = rig->state.current_vfo; - rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); - - if (RIG_VFO_A == vfo || RIG_VFO_B == vfo) - { - /* switch to desired VFO and read its frequency */ - if (vfo_save != vfo) - { - if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; } - } - - if ((retval = icom_get_freq(rig, vfo, freq)) != RIG_OK) { return retval; } - - if (vfo_save != vfo) - { - /* swap VFOs back as original was the other one */ - icom_set_vfo(rig, vfo_save); - } - } - else if (RIG_VFO_MAIN == vfo || RIG_VFO_SUB == vfo) - { - /* switch to the desired of MAIN and SUB and read its frequency */ - if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; } - - if ((retval = icom_get_freq(rig, vfo, freq)) != RIG_OK) { return retval; } - - if (*freq != origfreq) - { - /* started on a different so switch back MAIN or SUB */ - icom_set_vfo(rig, RIG_VFO_MAIN == vfo ? RIG_VFO_SUB : RIG_VFO_MAIN); - } - } - else if (RIG_VFO_CURR == vfo) - { - *freq = origfreq; - } - else if (RIG_VFO_TX == vfo) - { - vfo = priv->tx_vfo; - rig_debug(RIG_DEBUG_VERBOSE, "%s: VFO_TX asked for so vfo=%s\n", __func__, - rig_strvfo(vfo)); - } - else if (RIG_VFO_RX == vfo) - { - vfo = priv->rx_vfo; - rig_debug(RIG_DEBUG_VERBOSE, "%s: VFO_RX asked for so vfo=%s\n", __func__, - rig_strvfo(vfo)); - } - else { retval = -RIG_EVFO; } - - return retval; -} - /* * This function does the special bandwidth coding for IC-910 * (1 - normal, 2 - narrow) @@ -464,7 +204,7 @@ const struct rig_caps ic910_caps = RIG_MODEL(RIG_MODEL_IC910), .model_name = "IC-910", .mfg_name = "Icom", - .version = BACKEND_VER ".0", + .version = BACKEND_VER ".1", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, @@ -574,8 +314,8 @@ const struct rig_caps ic910_caps = .set_conf = icom_set_conf, .get_conf = icom_get_conf, - .get_freq = ic910_get_freq, - .set_freq = ic910_set_freq, + .get_freq = icom_get_freq, + .set_freq = icom_set_freq, #ifdef HAVE_WEIRD_IC910_MODES .get_mode = ic910_get_mode, diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index ad83437e..ef5e4519 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -2234,6 +2234,8 @@ int icom_set_vfo(RIG *rig, vfo_t vfo) } else if (vfo == RIG_VFO_TX) { + rig_debug(RIG_DEBUG_TRACE, "%s: vfo line#%d vfo=%s\n", __func__, __LINE__, + rig_strvfo(vfo)); vfo = RIG_VFO_A; if (VFO_HAS_A_B_ONLY && rig->state.cache.satmode) { vfo = RIG_VFO_B; } @@ -2243,13 +2245,17 @@ int icom_set_vfo(RIG *rig, vfo_t vfo) else if ((vfo == RIG_VFO_A || vfo == RIG_VFO_MAIN) && VFO_HAS_DUAL) { + rig_debug(RIG_DEBUG_TRACE, "%s: vfo line#%d vfo=%s, split=%d\n", __func__, + __LINE__, rig_strvfo(vfo), rig->state.cache.split); // If we're being asked for A/Main but we are a MainA/MainB rig change it vfo = RIG_VFO_MAIN; - if (rig->state.cache.split == RIG_SPLIT_ON) { vfo = RIG_VFO_A; } + if (rig->state.cache.split == RIG_SPLIT_ON && !rig->state.cache.satmode) { vfo = RIG_VFO_A; } } else if ((vfo == RIG_VFO_B || vfo == RIG_VFO_SUB) && VFO_HAS_DUAL) { + rig_debug(RIG_DEBUG_TRACE, "%s: vfo line#%d vfo=%s\n", __func__, __LINE__, + rig_strvfo(vfo)); // If we're being asked for B/Sub but we are a MainA/MainB rig change it vfo = RIG_VFO_SUB; @@ -2286,7 +2292,7 @@ int icom_set_vfo(RIG *rig, vfo_t vfo) priv->curr_freq = 0; // reset curr_freq so set_freq works 1st time } - rig_debug(RIG_DEBUG_TRACE, "%s: debug#2\n", __func__); + rig_debug(RIG_DEBUG_TRACE, "%s: line#%d\n", __func__, __LINE__); switch (vfo) { @@ -2439,10 +2445,10 @@ int icom_set_vfo(RIG *rig, vfo_t vfo) RETURNFUNC(-RIG_EINVAL); } - rig_debug(RIG_DEBUG_TRACE, "%s: debug#3\n", __func__); + rig_debug(RIG_DEBUG_TRACE, "%s: line#%d\n", __func__, __LINE__); retval = icom_transaction(rig, C_SET_VFO, icvfo, NULL, 0, ackbuf, &ack_len); - rig_debug(RIG_DEBUG_TRACE, "%s: debug#4\n", __func__); + rig_debug(RIG_DEBUG_TRACE, "%s: line#%d\n", __func__, __LINE__); if (retval != RIG_OK) { @@ -2464,7 +2470,7 @@ int icom_set_vfo(RIG *rig, vfo_t vfo) } rig->state.current_vfo = vfo; - rig_debug(RIG_DEBUG_TRACE, "%s: debug#5 curr_vfo=%s\n", __func__, + rig_debug(RIG_DEBUG_TRACE, "%s: line#%d curr_vfo=%s\n", __func__, __LINE__, rig_strvfo(rig->state.current_vfo)); RETURNFUNC(RIG_OK); } diff --git a/src/rig.c b/src/rig.c index 252b59e1..0acace4e 100644 --- a/src/rig.c +++ b/src/rig.c @@ -2525,7 +2525,7 @@ int HAMLIB_API rig_set_vfo(RIG *rig, vfo_t vfo) if (retcode == RIG_OK) { - rig->state.current_vfo = vfo; + vfo = rig->state.current_vfo; // vfo may change in the rig backend rig->state.cache.vfo = vfo; elapsed_ms(&rig->state.cache.time_vfo, HAMLIB_ELAPSED_SET); rig_debug(RIG_DEBUG_TRACE, "%s: rig->state.current_vfo=%s\n", __func__, @@ -3778,10 +3778,8 @@ int HAMLIB_API rig_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) if (caps->set_vfo) { // If we started with RIG_VFO_CURR we need to choose VFO_A/MAIN as appropriate to return to - if (save_vfo == RIG_VFO_CURR) - { - save_vfo = VFO_HAS_A_B_ONLY ? RIG_VFO_A : RIG_VFO_MAIN; - } + //rig_debug(RIG_DEBUG_TRACE, "%s: save_vfo=%s, hasmainsub=%d\n",__func__, rig_strvfo(save_vfo), VFO_HAS_MAIN_SUB); + save_vfo = VFO_HAS_MAIN_SUB ? RIG_VFO_MAIN : RIG_VFO_A; rig_debug(RIG_DEBUG_TRACE, "%s: restoring vfo=%s\n", __func__, rig_strvfo(save_vfo)); commit 778758200eec2bf403222484331c817a8e40db32 Author: Mike Black W9MDB <mdb...@ya...> Date: Sat Apr 10 14:22:53 2021 -0500 A more robust rigctld that can survive the rig disappearing and coming back again. This means when a rigctld client sees RIG_EIO it can keep polling and will reconnect when the rig reappears. diff --git a/src/rig.c b/src/rig.c index 2821d07d..252b59e1 100644 --- a/src/rig.c +++ b/src/rig.c @@ -767,6 +767,7 @@ int HAMLIB_API rig_open(RIG *rig) if (status < 0) { + rs->comm_state = 0; RETURNFUNC(status); } diff --git a/tests/rigctl.c b/tests/rigctl.c index f1248367..9a57316a 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -604,6 +604,7 @@ int main(int argc, char *argv[]) #endif /* HAVE_LIBREADLINE */ int rig_opened = 1; // our rig is already open + do { if (!rig_opened) @@ -630,7 +631,7 @@ int main(int argc, char *argv[]) hl_usleep(1000 * 1000); rig_debug(RIG_DEBUG_ERR, "%s: rig_close retcode=%d\n", __func__, retcode); retcode = rig_open(my_rig); - if (retcode != RIG_OK) rig_opened = 0; + rig_opened = retcode == RIG_OK ? 1 : 0; rig_debug(RIG_DEBUG_ERR, "%s: rig_open retcode=%d\n", __func__, retcode); } while (retry-- > 0 && retcode != RIG_OK); diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 90049882..c99cfbfe 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -1651,6 +1651,11 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } rig_debug(RIG_DEBUG_TRACE, "%s: vfo_opt=%d\n", __func__, *vfo_opt); + if (my_rig->state.comm_state == 0) + { + rig_debug(RIG_DEBUG_WARN, "%s: rig not open...trying to reopen\n", __func__); + rig_open(my_rig); + } retcode = (*cmd_entry->rig_routine)(my_rig, fout, fin, diff --git a/tests/rigctld.c b/tests/rigctld.c index 93fcbada..41cc030e 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -549,11 +549,13 @@ int main(int argc, char *argv[]) } #if 0 + if (!vfo_mode) { printf("Recommend using --vfo switch for rigctld if client supports it\n"); printf("rigctl and netrigctl will automatically detect vfo mode\n"); } + #endif rig_set_debug(verbose); @@ -1066,15 +1068,32 @@ void *handle_socket(void *arg) #endif + int rig_opened = 1; // our rig is already open + do { - 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, - 1, 0, &handle_data_arg->vfo_mode, send_cmd_term, &ext_resp, &resp_sep); + if (!rig_opened) + { + retcode = rig_open(my_rig); + rig_opened = retcode == RIG_OK ? 1 : 0; + rig_debug(RIG_DEBUG_ERR, "%s: rig_open reopened retcode=%d\n", __func__, + retcode); + } - if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: rigctl_parse retcode=%d\n", __func__, retcode); } + if (rig_opened) // only do this if rig is open + { + 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, + 1, 0, &handle_data_arg->vfo_mode, send_cmd_term, &ext_resp, &resp_sep); + + if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: rigctl_parse retcode=%d\n", __func__, retcode); } + } + else + { + retcode = -RIG_EIO; + } // if we get a hard error we try to reopen the rig again // this should cover short dropouts that can occur @@ -1089,7 +1108,9 @@ void *handle_socket(void *arg) 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); + rig_opened = retcode == RIG_OK ? 1 : 0; + rig_debug(RIG_DEBUG_ERR, "%s: rig_open retcode=%d, opened=%d\n", __func__, + retcode, rig_opened); } while (retry-- > 0 && retcode != RIG_OK); } commit 758e9bc3a7ff9e19da0954166b93683d41ab622c Author: Mike Black W9MDB <mdb...@ya...> Date: Sat Apr 10 11:07:10 2021 -0500 Use different method to detect rigctld port being offline diff --git a/tests/rigctl.c b/tests/rigctl.c index 86e419d3..f1248367 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -603,10 +603,10 @@ int main(int argc, char *argv[]) } #endif /* HAVE_LIBREADLINE */ - + int rig_opened = 1; // our rig is already open do { - if (my_rig->state.comm_state == 0) + if (!rig_opened) { // rig may have closed on us to try once to reopen retcode = rig_open(my_rig); @@ -630,6 +630,7 @@ int main(int argc, char *argv[]) hl_usleep(1000 * 1000); rig_debug(RIG_DEBUG_ERR, "%s: rig_close retcode=%d\n", __func__, retcode); retcode = rig_open(my_rig); + if (retcode != RIG_OK) rig_opened = 0; rig_debug(RIG_DEBUG_ERR, "%s: rig_open retcode=%d\n", __func__, retcode); } while (retry-- > 0 && retcode != RIG_OK); commit 601f0ab1f1c4f05e7771c2cd0401014f8058e7be Author: Mike Black W9MDB <mdb...@ya...> Date: Sat Apr 10 10:43:49 2021 -0500 Allow rigctl to reopen port if it has been closed diff --git a/tests/rigctl.c b/tests/rigctl.c index 126f5275..86e419d3 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -606,6 +606,13 @@ int main(int argc, char *argv[]) do { + if (my_rig->state.comm_state == 0) + { + // rig may have closed on us to try once to reopen + retcode = rig_open(my_rig); + rig_debug(RIG_DEBUG_WARN, "%s: rig_open again retcode=%d\n", __func__, retcode); + } + retcode = rigctl_parse(my_rig, stdin, stdout, argv, argc, NULL, interactive, prompt, &vfo_opt, send_cmd_term, &ext_resp, &resp_sep); ----------------------------------------------------------------------- Summary of changes: rigs/icom/ic910.c | 266 +-------------------------------------------------- rigs/icom/icom.c | 16 +++- src/rig.c | 9 +- tests/rigctl.c | 9 ++ tests/rigctl_parse.c | 5 + tests/rigctld.c | 35 +++++-- 6 files changed, 60 insertions(+), 280 deletions(-) hooks/post-receive -- Hamlib -- Ham radio control libraries |