From 8928672e2cf89eb796f65b2dfd3d3a12f5272811 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Wed, 24 Nov 2021 09:03:26 -0600 Subject: [PATCH] Rigs with non-targetable set_mode will now use cached values to determine if mode needs to be changed Hamlib 5.0 plans are to start using transceive mode and AI2 mode to detect rig changes so eventually users on these types of rigs will be able to twiddle knobs and hamlib will follow. But for now we are avoiding the VFO flashing and relay chattering on non-targetable rigs https://github.com/Hamlib/Hamlib/issues/872 --- rigs/dummy/netrigctl.c | 5 +++-- rigs/kenwood/kenwood.c | 2 +- rigs/kenwood/kenwood.h | 2 +- src/rig.c | 39 ++++++++++++++++++++++++++++++++++----- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/rigs/dummy/netrigctl.c b/rigs/dummy/netrigctl.c index 7dd92e248..8502f4311 100644 --- a/rigs/dummy/netrigctl.c +++ b/rigs/dummy/netrigctl.c @@ -274,6 +274,7 @@ static int netrigctl_open(RIG *rig) if (sscanf(buf, "CHKVFO %d", &priv->rigctld_vfo_mode) == 1) { + rig->state.vfo_opt = 1; rig_debug(RIG_DEBUG_TRACE, "%s: chkvfo=%d\n", __func__, priv->rigctld_vfo_mode); } else if (ret == 2) @@ -1595,7 +1596,7 @@ static int netrigctl_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, char buf[BUF_MAX]; char vfostr[16] = ""; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s called vfo=%s, vfotx=%s, split=%d\n", __func__, rig_strvfo(vfo), rig_strvfo(tx_vfo), split); ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); @@ -2584,7 +2585,7 @@ struct rig_caps netrigctl_caps = RIG_MODEL(RIG_MODEL_NETRIGCTL), .model_name = "NET rigctl", .mfg_name = "Hamlib", - .version = "20211120.0", + .version = "20211123.0", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_OTHER, diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index 84741ce5a..c5cd1df01 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -1312,7 +1312,7 @@ int kenwood_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) } rig_get_split(rig, vfo, &tsplit); - + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): tsplit=%d, split=%d\n", __func__, __LINE__, tsplit, split); if (tsplit == split) { rig_debug(RIG_DEBUG_TRACE, "%s: split already set\n", __func__); diff --git a/rigs/kenwood/kenwood.h b/rigs/kenwood/kenwood.h index 0a972b450..9ce45ab68 100644 --- a/rigs/kenwood/kenwood.h +++ b/rigs/kenwood/kenwood.h @@ -28,7 +28,7 @@ #include "token.h" #include "misc.h" -#define BACKEND_VER "20211122.2" +#define BACKEND_VER "20211124" #define EOM_KEN ';' #define EOM_TH '\r' diff --git a/src/rig.c b/src/rig.c index df636ca03..c8dde30cd 100644 --- a/src/rig.c +++ b/src/rig.c @@ -2208,6 +2208,7 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) RETURNFUNC(-RIG_ENAVAIL); } + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): vfo_opt=%d, model=%d\n", __func__, __LINE__, rig->state.vfo_opt, rig->caps->rig_model); // If we're in vfo_mode then rigctld will do any VFO swapping we need if ((caps->targetable_vfo & RIG_TARGETABLE_FREQ) || vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo @@ -4295,7 +4296,8 @@ int HAMLIB_API rig_set_split_mode(RIG *rig, if (caps->set_split_mode && (vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX - || vfo == rig->state.current_vfo)) + || vfo == rig->state.current_vfo + || rig->caps->rig_model == RIG_MODEL_NETRIGCTL)) { TRACE; retcode = caps->set_split_mode(rig, vfo, tx_mode, tx_width); @@ -4307,7 +4309,7 @@ int HAMLIB_API rig_set_split_mode(RIG *rig, curr_vfo = rig->state.current_vfo; /* Use previously setup TxVFO */ - if (vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX) + if (vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX || rig->state.tx_vfo != RIG_VFO_NONE) { TRACE; tx_vfo = rig->state.tx_vfo; @@ -4319,7 +4321,7 @@ int HAMLIB_API rig_set_split_mode(RIG *rig, } rig_debug(RIG_DEBUG_VERBOSE, "%s: curr_vfo=%s, tx_vfo=%s\n", __func__, rig_strvfo(curr_vfo), rig_strvfo(tx_vfo)); - if (caps->set_mode && (caps->targetable_vfo & RIG_TARGETABLE_MODE)) + if (caps->set_mode && ((caps->targetable_vfo & RIG_TARGETABLE_MODE) || (rig->caps->rig_model == RIG_MODEL_NETRIGCTL))) { TRACE; retcode = caps->set_mode(rig, tx_vfo, tx_mode, tx_width); @@ -4334,7 +4336,28 @@ int HAMLIB_API rig_set_split_mode(RIG *rig, else if (vfo == RIG_VFO_CURR && tx_vfo == RIG_VFO_A) rx_vfo = RIG_VFO_B; else if (vfo == RIG_VFO_CURR && tx_vfo == RIG_VFO_MAIN) rx_vfo = RIG_VFO_SUB; else if (vfo == RIG_VFO_CURR && tx_vfo == RIG_VFO_SUB) rx_vfo = RIG_VFO_MAIN; - rig_debug(RIG_DEBUG_VERBOSE, "%s: rx_vfo=%s, tx_vfo=%s\n", __func__, rig_strvfo(rx_vfo), rig_strvfo(tx_vfo)); + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): rx_vfo=%s, tx_vfo=%s\n", __func__, __LINE__, rig_strvfo(rx_vfo), rig_strvfo(tx_vfo)); + // we will reuse cached mode instead of trying to set mode again + if ((tx_vfo & (RIG_VFO_A|RIG_VFO_MAIN|RIG_VFO_MAIN_A|RIG_VFO_SUB_A)) && (tx_mode == rig->state.cache.modeMainA)) + { + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): VFOA mode=%s already set...ignoring\n", __func__, __LINE__, rig_strrmode(tx_mode)); + ELAPSED2; + RETURNFUNC(RIG_OK); + } + else if ((tx_vfo & (RIG_VFO_B|RIG_VFO_SUB|RIG_VFO_MAIN_B|RIG_VFO_SUB_B)) && (tx_mode == rig->state.cache.modeMainB)) + { + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): VFOB mode=%s already set...ignoring\n", __func__, __LINE__, rig_strrmode(tx_mode)); + ELAPSED2; + RETURNFUNC(RIG_OK); + } + rig_debug(RIG_DEBUG_WARN, "%s(%d): Unhandled VFO=%s, tx_mode=%s\n", __func__, __LINE__, rig_strvfo(tx_vfo), rig_strrmode(tx_mode)); + + // code below here should be dead code now -- but maybe we have VFO situatiuon we need to handle + if (caps->rig_model == RIG_MODEL_NETRIGCTL) + { // special handlingt for netrigctl to avoid set_vfo + retcode = caps->set_split_mode(rig, vfo, tx_mode, tx_width); + RETURNFUNC(retcode); + } rig_set_split_vfo(rig,rx_vfo, RIG_SPLIT_OFF, rx_vfo); if (caps->set_vfo) { @@ -4785,7 +4808,7 @@ int HAMLIB_API rig_set_split_vfo(RIG *rig, // set rig to the the requested RX VFO TRACE; - if (!(caps->targetable_vfo & RIG_TARGETABLE_FREQ)) + if ((!(caps->targetable_vfo & RIG_TARGETABLE_FREQ)) && (!(rig->caps->rig_model == RIG_MODEL_NETRIGCTL))) #if BUILTINFUNC rig_set_vfo(rig, rx_vfo == RIG_VFO_B ? RIG_VFO_B : RIG_VFO_A, __builtin_FUNCTION()); @@ -4797,6 +4820,12 @@ int HAMLIB_API rig_set_split_vfo(RIG *rig, if (rx_vfo == RIG_VFO_CURR || rx_vfo == rig->state.current_vfo) { + // for non-targetable VFOs we will not set split again + if (rig->state.cache.split == split && rig->state.cache.split_vfo == tx_vfo) + { + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): split already set...ignoring\n", __func__, __LINE__); + RETURNFUNC(RIG_OK); + } TRACE; retcode = caps->set_split_vfo(rig, rx_vfo, split, tx_vfo);