From 238344b0ce3db6d50b8647c54de7d56355a37f64 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Wed, 6 Nov 2024 16:47:19 -0500 Subject: [PATCH 1/3] Update TS-890S and TS-990S RIT/XIT handling Use dedicated commands that make setting much simpler. Replaces usage of deprecated IF command. See issue #1380 --- rigs/kenwood/kenwood.c | 48 +++++++++++++++++++++++++++++++++++++++++- rigs/kenwood/kenwood.h | 6 ++++-- rigs/kenwood/ts890s.c | 8 +++---- rigs/kenwood/ts990s.c | 8 +++---- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index 7fd811422..9d37c46ff 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -1885,7 +1885,6 @@ int kenwood_get_vfo_if(RIG *rig, vfo_t *vfo) RETURNFUNC(RIG_OK); } - /* * kenwood_set_freq */ @@ -2156,6 +2155,29 @@ int kenwood_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) RETURNFUNC(RIG_OK); } +/* RF + * kenwood_get_rit_new (also usable as kenwood_get_xit_new) + * Gets the RIT or XIT value using dedicated command + * and without using IF. + */ +int kenwood_get_rit_new(RIG *rig, vfo_t vfo, shortfreq_t *rit) +{ + int retval, tempf; + char rfbuf[10]; + + ENTERFUNC; + if (!rit) { RETURNFUNC(-RIG_EINVAL); } + retval = kenwood_safe_transaction(rig, "RF", rfbuf, sizeof rfbuf, 7); + if (retval != RIG_OK) {RETURNFUNC(retval); } + tempf = atoi(rfbuf + 3); + if (rfbuf[2] == '1') + { + tempf = -tempf; + } + *rit = tempf; + RETURNFUNC(RIG_OK); +} + /* * rit can only move up/down by 10 Hz, so we use a loop... */ @@ -2252,6 +2274,30 @@ int kenwood_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) RETURNFUNC2(retval); } +/* RU/RD + * Set the RIT/XIT frequency offset + * using dedicated commands (not IF) + */ +int kenwood_set_rit_new(RIG *rig, vfo_t vfo, shortfreq_t rit) +{ + int retval, diff; + shortfreq_t oldrit; + char rdbuf[10]; + + ENTERFUNC; + if (abs(rit) > 9999) { RETURNFUNC(-RIG_EINVAL); } + retval = kenwood_get_rit_new(rig, vfo, &oldrit); + if (retval != RIG_OK) { RETURNFUNC(retval); } + if (rit == oldrit) // if the new value is the same + { + RETURNFUNC(RIG_OK); // Nothing to do + } + diff = rit - oldrit; + SNPRINTF(rdbuf, sizeof rdbuf, "R%c%05d;", diff < 0 ? 'D' : 'U', abs(diff)); + retval = kenwood_transaction(rig, rdbuf, NULL, 0); + RETURNFUNC(retval); +} + /* * rit and xit are the same */ diff --git a/rigs/kenwood/kenwood.h b/rigs/kenwood/kenwood.h index 0989f722f..4e363d533 100644 --- a/rigs/kenwood/kenwood.h +++ b/rigs/kenwood/kenwood.h @@ -223,9 +223,11 @@ int kenwood_set_freq(RIG *rig, vfo_t vfo, freq_t freq); int kenwood_get_freq(RIG *rig, vfo_t vfo, freq_t *freq); int kenwood_get_freq_if(RIG *rig, vfo_t vfo, freq_t *freq); int kenwood_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit); +int kenwood_set_rit_new(RIG *rig, vfo_t vfo, shortfreq_t rit); // Also use this for xit int kenwood_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit); -int kenwood_set_xit(RIG *rig, vfo_t vfo, shortfreq_t rit); -int kenwood_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *rit); +int kenwood_get_rit_new(RIG *rig, vfo_t vfo, shortfreq_t *rit); // Also use this for xit +int kenwood_set_xit(RIG *rig, vfo_t vfo, shortfreq_t xit); +int kenwood_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit); int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width); int kenwood_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width); int kenwood_get_mode_if(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width); diff --git a/rigs/kenwood/ts890s.c b/rigs/kenwood/ts890s.c index 5ae39970d..ec71d0a9f 100644 --- a/rigs/kenwood/ts890s.c +++ b/rigs/kenwood/ts890s.c @@ -617,10 +617,10 @@ struct rig_caps ts890s_caps = .rig_cleanup = kenwood_cleanup, .set_freq = kenwood_set_freq, .get_freq = kenwood_get_freq, - .set_rit = kenwood_set_rit, - .get_rit = kenwood_get_rit, - .set_xit = kenwood_set_xit, - .get_xit = kenwood_get_xit, + .set_rit = kenwood_set_rit_new, + .get_rit = kenwood_get_rit_new, + .set_xit = kenwood_set_rit_new, // Same routines as for RIT + .get_xit = kenwood_get_rit_new, // Same .set_mode = kenwood_set_mode, .get_mode = kenwood_get_mode, .set_vfo = kenwood_set_vfo, diff --git a/rigs/kenwood/ts990s.c b/rigs/kenwood/ts990s.c index 6933581be..4c8d97a2e 100644 --- a/rigs/kenwood/ts990s.c +++ b/rigs/kenwood/ts990s.c @@ -343,10 +343,10 @@ struct rig_caps ts990s_caps = .rig_cleanup = kenwood_cleanup, .set_freq = kenwood_set_freq, .get_freq = kenwood_get_freq, - .set_rit = kenwood_set_rit, - .get_rit = kenwood_get_rit, - .set_xit = kenwood_set_xit, - .get_xit = kenwood_get_xit, + .set_rit = kenwood_set_rit_new, + .get_rit = kenwood_get_rit_new, + .set_xit = kenwood_set_rit_new, // Use same routines as for rit + .get_xit = kenwood_get_rit_new, // Same .set_mode = kenwood_set_mode, .get_mode = kenwood_get_mode, .set_vfo = kenwood_set_vfo_main_sub, From c080ba7b829e0d1427edd066ff39a1a4f88b8fb5 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Wed, 20 Nov 2024 16:35:15 -0500 Subject: [PATCH 2/3] Factor out TS-890S and TS-990S from kenwood_get_split_vfo_if() Fix TS-890S to return correct VFO More of issue #1380 --- rigs/kenwood/kenwood.c | 26 +----------------------- rigs/kenwood/ts890s.c | 46 +++++++++++++++++++++++++++++++++++++++++- rigs/kenwood/ts990s.c | 34 ++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 27 deletions(-) diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index 9d37c46ff..e0bad2505 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -1675,7 +1675,7 @@ int kenwood_set_split(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) } -/* IF TB +/* IF * Gets split VFO status from kenwood_get_if() * */ @@ -1694,30 +1694,6 @@ int kenwood_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, RETURNFUNC(-RIG_EINVAL); } - if (RIG_IS_TS990S || RIG_IS_TS890S) - { - char buf[4]; - - if (RIG_OK == (retval = kenwood_safe_transaction(rig, "TB", buf, sizeof(buf), - 3))) - { - if ('1' == buf[2]) - { - *split = RIG_SPLIT_ON; - *txvfo = RIG_VFO_SUB; - priv->tx_vfo = rs->tx_vfo = *txvfo; - } - else - { - *split = RIG_SPLIT_OFF; - *txvfo = RIG_VFO_MAIN; - priv->tx_vfo = rs->tx_vfo = *txvfo; - } - } - - RETURNFUNC(retval); - } - retval = kenwood_get_if(rig); if (retval != RIG_OK) diff --git a/rigs/kenwood/ts890s.c b/rigs/kenwood/ts890s.c index ec71d0a9f..c5906f6dc 100644 --- a/rigs/kenwood/ts890s.c +++ b/rigs/kenwood/ts890s.c @@ -466,6 +466,50 @@ static int ts890_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) return RIG_OK; } +/* + * Gets split VFO status + * + */ +static int ts890s_get_split_vfo(RIG *rig, vfo_t rxvfo, split_t *split, + vfo_t *txvfo) +{ + char buf[4]; + int retval; + vfo_t tvfo; + struct rig_state *rs = STATE(rig); + struct kenwood_priv_data *priv = rs->priv; + + if (RIG_OK == (retval = kenwood_safe_transaction(rig, "FT", buf, sizeof(buf), + 3))) + { + if ('0' == buf[2]) + { + tvfo = RIG_VFO_A; + } + else if ('1' == buf[2]) + { + tvfo = RIG_VFO_B; + } + else if ('3' == buf[2]) + { + tvfo = RIG_VFO_MEM; + } + else + { + rig_debug(RIG_DEBUG_ERR, "%s: Unknown VFO - %s\n", __func__, buf); + return -RIG_EPROTO; + } + + *txvfo = priv->tx_vfo = rs->tx_vfo = tvfo; + // Now get split status + retval = kenwood_safe_transaction(rig, "TB", buf, sizeof buf, 3); + if (RIG_OK != retval) {return retval;} + *split = priv->split = buf[2] == '1'; + } + + return retval; +} + static struct kenwood_priv_caps ts890s_priv_caps = { @@ -626,7 +670,7 @@ struct rig_caps ts890s_caps = .set_vfo = kenwood_set_vfo, .get_vfo = kenwood_get_vfo_if, .set_split_vfo = kenwood_set_split_vfo, - .get_split_vfo = kenwood_get_split_vfo_if, + .get_split_vfo = ts890s_get_split_vfo, .set_ctcss_tone = kenwood_set_ctcss_tone_tn, .get_ctcss_tone = kenwood_get_ctcss_tone, .set_ctcss_sql = kenwood_set_ctcss_sql, diff --git a/rigs/kenwood/ts990s.c b/rigs/kenwood/ts990s.c index 4c8d97a2e..0deda6bed 100644 --- a/rigs/kenwood/ts990s.c +++ b/rigs/kenwood/ts990s.c @@ -88,6 +88,7 @@ /* prototypes */ static int ts990s_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); +static int ts990s_get_split_vfo(RIG *rig, vfo_t rxvfo, split_t *split, vfo_t *txvfo); static rmode_t ts990s_mode_table[KENWOOD_MODE_TABLE_MAX] = { @@ -352,7 +353,7 @@ struct rig_caps ts990s_caps = .set_vfo = kenwood_set_vfo_main_sub, .get_vfo = kenwood_get_vfo_main_sub, .set_split_vfo = kenwood_set_split_vfo, - .get_split_vfo = kenwood_get_split_vfo_if, + .get_split_vfo = ts990s_get_split_vfo, .set_ctcss_tone = kenwood_set_ctcss_tone_tn, .get_ctcss_tone = kenwood_get_ctcss_tone, .set_ctcss_sql = kenwood_set_ctcss_sql, @@ -761,3 +762,34 @@ int ts990s_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return retval; } + +/* + * Gets split VFO status + * + */ +static int ts990s_get_split_vfo(RIG *rig, vfo_t rxvfo, split_t *split, + vfo_t *txvfo) +{ + char buf[4]; + int retval; + struct rig_state *rs = STATE(rig); + struct kenwood_priv_data *priv = rs->priv; + + if (RIG_OK == (retval = kenwood_safe_transaction(rig, "TB", buf, sizeof(buf), + 3))) + { + if ('1' == buf[2]) + { + *split = RIG_SPLIT_ON; + *txvfo = RIG_VFO_SUB; + } + else + { + *split = RIG_SPLIT_OFF; + *txvfo = RIG_VFO_MAIN; + } + priv->tx_vfo = rs->tx_vfo = *txvfo; + } + + return retval; +} From 11acef5d3bc4645ad70881759b2aeaf0de443cfe Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Thu, 21 Nov 2024 19:21:41 -0500 Subject: [PATCH 3/3] MACROize new code. --- rigs/dummy/flrig.c | 2 +- rigs/yaesu/ft1000mp.c | 2 +- rigs/yaesu/ft817.c | 2 +- src/rig.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rigs/dummy/flrig.c b/rigs/dummy/flrig.c index 58b6e8692..bfabc388b 100644 --- a/rigs/dummy/flrig.c +++ b/rigs/dummy/flrig.c @@ -853,7 +853,7 @@ static int flrig_open(RIG *rig) char model_name[256]; snprintf(model_name,sizeof(model_name), "%.248s(%s)", value, "FLRig"); rig->caps->model_name = strdup(model_name); - rig->state.model_name = strdup(model_name); + STATE(rig)->model_name = strdup(model_name); /* see if get_pwrmeter_scale is available */ retval = flrig_transaction(rig, "rig.get_pwrmeter_scale", NULL, value, diff --git a/rigs/yaesu/ft1000mp.c b/rigs/yaesu/ft1000mp.c index 9a6db6b78..d134c2b3a 100644 --- a/rigs/yaesu/ft1000mp.c +++ b/rigs/yaesu/ft1000mp.c @@ -945,7 +945,7 @@ static int ft1000mp_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) RETURNFUNC(retval); } - priv = (struct ft1000mp_priv_data *)rig->state.priv; + priv = (struct ft1000mp_priv_data *)STATE(rig)->priv; if (vfo == RIG_VFO_B) { diff --git a/rigs/yaesu/ft817.c b/rigs/yaesu/ft817.c index 68a28bf73..301e0e44f 100644 --- a/rigs/yaesu/ft817.c +++ b/rigs/yaesu/ft817.c @@ -1711,7 +1711,7 @@ static int ft817_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) // check if we're already in the mode and return if so // the memory check was failing when in FM mode -- still showing digmode - if (rig->state.current_mode == mode) + if (STATE(rig)->current_mode == mode) { if (digmode[0] == 0x00 && mode == RIG_MODE_RTTY) { return RIG_OK; } else if (digmode[0] == 0x01 && mode == RIG_MODE_PSKR) { return RIG_OK; } diff --git a/src/rig.c b/src/rig.c index a6cd5f2f3..bf233f360 100644 --- a/src/rig.c +++ b/src/rig.c @@ -7979,7 +7979,7 @@ int HAMLIB_API rig_get_rig_info(RIG *rig, char *response, int max_response_len) "VFO=%s Freq=%.0f Mode=%s Width=%d RX=%d TX=%d\nVFO=%s Freq=%.0f Mode=%s Width=%d RX=%d TX=%d\nSplit=%d SatMode=%d\nRig=%s\nApp=%s\nVersion=20241103 1.1.0\nModel=%u\n", rig_strvfo(vfoA), freqA, modeAstr, (int)widthA, rxa, txa, rig_strvfo(vfoB), freqB, modeBstr, (int)widthB, rxb, txb, split, satmode, rig->caps->model_name, - rig->state.client_version, rig->caps->rig_model); + STATE(rig)->client_version, rig->caps->rig_model); unsigned long crc = CRC32_function((unsigned char *)response, strlen(response)); char tmpstr[32]; SNPRINTF(tmpstr, sizeof(tmpstr), "CRC=0x%08lx\n", crc);