From e178a984ca693750f2b8a45f3e6b1e516faed281 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Sat, 6 Jan 2024 10:55:49 -0500 Subject: [PATCH] Add cache to the MACRO/porting list Update comments And port my favorite PoC target, rigs/kenwood/kenwood.c --- include/hamlib/rig.h | 20 +++++++++++++------- rigs/kenwood/kenwood.c | 14 +++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 010f46d34..e01a9b291 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ - +/* SPDX-License-Identifier: LGPL-2.1-or-later */ #ifndef _RIG_H #define _RIG_H 1 @@ -2463,10 +2463,14 @@ typedef hamlib_port_t_deprecated port_t_deprecated; typedef hamlib_port_t port_t; #endif -/* Macros to access port structures/pointers +/* Macros to access data structures/pointers * Make it easier to change location in preparation * for moving them out of rig->state. * See https://github.com/Hamlib/Hamlib/issues/1445 + * https://github.com/Hamlib/Hamlib/issues/1452 + * https://github.com/Hamlib/Hamlib/issues/1420 + * https://github.com/Hamlib/Hamlib/issues/536 + * https://github.com/Hamlib/Hamlib/issues/487 */ // Note: Experimental, and subject to change!! #if defined(IN_HAMLIB) @@ -2474,18 +2478,20 @@ typedef hamlib_port_t port_t; #define RIGPORT(r) (&r->state.rigport) #define PTTPORT(r) (&r->state.pttport) #define DCDPORT(r) (&r->state.dcdport) +#define CACHE(r) (&r->state.cache) +/* Then when the rigport address is stored as a pointer somewhere else(say, + * in the rig structure itself), the definition could be changed to + * #define RIGPORT(r) r->somewhereelse + * and every reference is updated. + */ #else /* Define external unique names */ /* These will be changed to a function call before release */ #define HAMLIB_RIGPORT(r) (&r->state.rigport) #define HAMLIB_PTTPORT(r) (&r->state.pttport) #define HAMLIB_DCDPORT(r) (&r->state.dcdport) +//#define HAMLIB_CACHE(r) (&r->state.cache) #endif -/* Then when the rigport address is stored as a pointer somewhere else(say, - * in the rig structure itself), the definition could be changed to - * #define RIGPORT(r) r->somewhereelse - * and every reference is updated. - */ #define HAMLIB_ELAPSED_GET 0 #define HAMLIB_ELAPSED_SET 1 diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index bedda275b..501277d96 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -1576,9 +1576,9 @@ int kenwood_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) tsplit = RIG_SPLIT_OFF; // default in case rig does not set split status retval = rig_get_split_vfo(rig, vfo, &tsplit, &tx_vfo); - priv->split = rig->state.cache.split = split; - rig->state.cache.split_vfo = txvfo; - elapsed_ms(&rig->state.cache.time_split, HAMLIB_ELAPSED_SET); + priv->split = CACHE(rig)->split = split; + CACHE(rig)->split_vfo = txvfo; + elapsed_ms(&CACHE(rig)->time_split, HAMLIB_ELAPSED_SET); // and it should be OK to do a SPLIT_OFF at any time so we won's skip that if (retval == RIG_OK && split == RIG_SPLIT_ON && tsplit == RIG_SPLIT_ON) @@ -1598,7 +1598,7 @@ int kenwood_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) || rig->caps->rig_model == RIG_MODEL_KX2 || rig->caps->rig_model == RIG_MODEL_KX3) { - rig_set_freq(rig, RIG_VFO_B, rig->state.cache.freqMainA); + rig_set_freq(rig, RIG_VFO_B, CACHE(rig)->freqMainA); } if (retval != RIG_OK) @@ -1607,8 +1607,8 @@ int kenwood_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) } /* Remember whether split is on, for kenwood_set_vfo */ - priv->split = rig->state.cache.split = split; - elapsed_ms(&rig->state.cache.time_split, HAMLIB_ELAPSED_SET); + priv->split = CACHE(rig)->split = split; + elapsed_ms(&CACHE(rig)->time_split, HAMLIB_ELAPSED_SET); RETURNFUNC2(RIG_OK); } @@ -2964,7 +2964,7 @@ static int kenwood_get_power_minmax(RIG *rig, int *power_now, int *power_min, } // Don't do this if PTT is on...don't want to max out power!! - if (rs->cache.ptt == RIG_PTT_ON) + if (CACHE(rig)->ptt == RIG_PTT_ON) { rig_debug(RIG_DEBUG_TRACE, "%s: ptt on so not checking min/max power levels\n", __func__);