From 53b01d829ed7ebaf1742353117db1646051a9330 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Sun, 10 Mar 2024 15:16:32 -0400 Subject: [PATCH 1/6] Start converting rigs/* to use pointers to state --- rigs/adat/adat.c | 74 ++++++++++++++++++++-------------------- rigs/anytone/anytone.c | 16 ++++----- rigs/aor/aor.c | 20 +++++------ rigs/aor/ar3030.c | 29 ++++++++-------- rigs/aor/ar7030p.c | 32 +++++++++-------- rigs/aor/ar7030p_utils.c | 16 +++++---- rigs/aor/sr2200.c | 4 +-- rigs/barrett/4050.c | 2 +- rigs/barrett/950.c | 6 ++-- rigs/barrett/barrett.c | 26 +++++++------- rigs/codan/codan.c | 16 ++++----- 11 files changed, 122 insertions(+), 119 deletions(-) diff --git a/rigs/adat/adat.c b/rigs/adat/adat.c index b865af42f..ad08b58e4 100644 --- a/rigs/adat/adat.c +++ b/rigs/adat/adat.c @@ -1309,7 +1309,7 @@ int adat_priv_set_cmd(RIG *pRig, char *pcCmd, int nCmdKind) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; memset(pPriv->acCmd, 0, ADAT_PRIV_DATA_CMD_LENGTH + 1); snprintf(pPriv->acCmd, ADAT_PRIV_DATA_CMD_LENGTH + 1, "%s", pcCmd); @@ -1348,7 +1348,7 @@ int adat_priv_set_result(RIG *pRig, char *pcResult) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; memset(pPriv->acResult, 0, ADAT_PRIV_DATA_RESULT_LENGTH + 1); snprintf(pPriv->acResult, ADAT_PRIV_DATA_RESULT_LENGTH + 1, "%s", pcResult); @@ -1390,7 +1390,7 @@ int adat_priv_clear_result(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; memset(pPriv->acResult, 0, ADAT_PRIV_DATA_RESULT_LENGTH + 1); } @@ -1426,7 +1426,7 @@ int adat_get_single_cmd_result(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_send(pRig, pPriv->acCmd); @@ -1561,7 +1561,7 @@ int adat_cmd_recover_from_error(RIG *pRig, int nError) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; // Recover from communication error @@ -1617,7 +1617,7 @@ int adat_cmd_fn_get_callsign(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_priv_set_cmd(pRig, ADAT_CMD_DEF_STRING_GET_CALLSIGN, @@ -1671,7 +1671,7 @@ int adat_cmd_fn_get_serial_nr(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_priv_set_cmd(pRig, ADAT_CMD_DEF_STRING_GET_SERIAL_NR, @@ -1725,7 +1725,7 @@ int adat_cmd_fn_get_fw_version(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_priv_set_cmd(pRig, ADAT_CMD_DEF_STRING_GET_FW_VERSION, @@ -1780,7 +1780,7 @@ int adat_cmd_fn_get_hw_version(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_priv_set_cmd(pRig, ADAT_CMD_DEF_STRING_GET_HW_VERSION, @@ -1834,7 +1834,7 @@ int adat_cmd_fn_get_gui_fw_version(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_priv_set_cmd(pRig, ADAT_CMD_DEF_STRING_GET_GUI_FW_VERSION, @@ -1889,7 +1889,7 @@ int adat_cmd_fn_get_id_code(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_priv_set_cmd(pRig, ADAT_CMD_DEF_STRING_GET_ID_CODE, @@ -1943,7 +1943,7 @@ int adat_cmd_fn_get_options(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_priv_set_cmd(pRig, ADAT_CMD_DEF_STRING_GET_OPTIONS, @@ -1997,7 +1997,7 @@ int adat_cmd_fn_get_mode(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_priv_set_cmd(pRig, ADAT_CMD_DEF_STRING_GET_MODE, @@ -2047,7 +2047,7 @@ int adat_cmd_fn_set_mode(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; // Translate Mode from RIG Mode Nr to ADAT Mode Nr @@ -2109,7 +2109,7 @@ int adat_cmd_fn_get_freq(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_priv_set_cmd(pRig, ADAT_CMD_DEF_STRING_GET_FREQ, @@ -2171,7 +2171,7 @@ int adat_cmd_fn_set_freq(RIG *pRig) else { // cppcheck-suppress constVariablePointer - const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; char acBuf[ ADAT_BUFSZ + 1 ]; // Get frequency of selected VFO @@ -2227,7 +2227,7 @@ int adat_cmd_fn_set_vfo(RIG *pRig) else { // cppcheck-suppress constVariablePointer - const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; char acBuf[ ADAT_BUFSZ + 1 ]; // Switch on VFO @@ -2294,7 +2294,7 @@ int adat_cmd_fn_get_ptt(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_priv_set_cmd(pRig, ADAT_CMD_DEF_STRING_GET_PTT, @@ -2349,7 +2349,7 @@ int adat_cmd_fn_set_ptt(RIG *pRig) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; char *pcPTTStr = NULL; // Switch PTT @@ -2430,7 +2430,7 @@ int adat_transaction(RIG *pRig, { int nI = 0; int nFini = 0; // = 1 -> Stop executing commands - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; rig_debug(RIG_DEBUG_TRACE, "*** ADAT: %d %s (%s:%d): Nr of commands = %d\n", @@ -2552,7 +2552,7 @@ int adat_init(RIG *pRig) // Set Rig Priv data memset(&gsADATPrivData, 0, sizeof(adat_priv_data_t)); - pRig->state.priv = &gsADATPrivData; + STATE(pRig)->priv = &gsADATPrivData; } // Done ! @@ -2586,7 +2586,7 @@ int adat_cleanup(RIG *pRig) } else { - pRig->state.priv = NULL; + STATE(pRig)->priv = NULL; } rig_debug(RIG_DEBUG_TRACE, @@ -2691,7 +2691,7 @@ const char *adat_get_info(RIG *pRig) if (nRC == RIG_OK) { // cppcheck-suppress constVariablePointer - const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; snprintf(acBuf, 2048, "ADAT ADT-200A, Callsign: %s, S/N: %s, ID Code: %s, Options: %s, FW: %s, GUI FW: %s, HW: %s", @@ -2736,7 +2736,7 @@ int adat_set_freq(RIG *pRig, vfo_t vfo, freq_t freq) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; pPriv->nFreq = freq; @@ -2775,7 +2775,7 @@ int adat_get_freq(RIG *pRig, vfo_t vfo, freq_t *freq) else { // cppcheck-suppress constVariablePointer - const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_transaction(pRig, &adat_cmd_list_get_freq); @@ -2813,7 +2813,7 @@ int adat_set_level(RIG *pRig, vfo_t vfo, setting_t level, value_t val) } else { - //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; } @@ -2848,7 +2848,7 @@ int adat_get_level(RIG *pRig, vfo_t vfo, setting_t level, value_t *val) } else { - //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; } @@ -2883,7 +2883,7 @@ int adat_set_mode(RIG *pRig, vfo_t vfo, rmode_t mode, pbwidth_t width) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; pPriv->nRIGMode = mode; adat_vfo_rnr2anr(vfo, &(pPriv->nCurrentVFO)); @@ -2933,7 +2933,7 @@ int adat_get_mode(RIG *pRig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) else { // cppcheck-suppress constVariablePointer - const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_transaction(pRig, &adat_cmd_list_get_mode); @@ -2976,7 +2976,7 @@ int adat_get_vfo(RIG *pRig, vfo_t *vfo) else { // cppcheck-suppress constVariablePointer - const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_transaction(pRig, &adat_cmd_list_get_vfo); @@ -3014,7 +3014,7 @@ int adat_set_vfo(RIG *pRig, vfo_t vfo) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_vfo_rnr2anr(vfo, &(pPriv->nCurrentVFO)); @@ -3056,7 +3056,7 @@ int adat_get_ptt(RIG *pRig, vfo_t vfo, ptt_t *ptt) else { // cppcheck-suppress constVariablePointer - const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; nRC = adat_transaction(pRig, &adat_cmd_list_get_ptt); @@ -3094,7 +3094,7 @@ int adat_set_ptt(RIG *pRig, vfo_t vfo, ptt_t ptt) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; switch (ptt) { @@ -3270,7 +3270,7 @@ int adat_set_conf(RIG *pRig, hamlib_token_t token, const char *val) } else { - adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; switch (token) { @@ -3317,7 +3317,7 @@ int adat_get_conf(RIG *pRig, hamlib_token_t token, char *val) else { // cppcheck-suppress constVariablePointer - const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; switch (token) { @@ -3369,7 +3369,7 @@ int adat_reset(RIG *pRig, reset_t reset) } else { - //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; } @@ -3404,7 +3404,7 @@ int adat_handle_event(RIG *pRig) } else { - //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; + //adat_priv_data_ptr pPriv = (adat_priv_data_ptr) STATE(pRig)->priv; char acBuf[ ADAT_RESPSZ + 1 ]; memset(acBuf, 0, ADAT_RESPSZ + 1); diff --git a/rigs/anytone/anytone.c b/rigs/anytone/anytone.c index 8c4ca1fdf..ddcfcdf5e 100644 --- a/rigs/anytone/anytone.c +++ b/rigs/anytone/anytone.c @@ -98,7 +98,7 @@ void *anytone_thread(void *vrig) { RIG *rig = (RIG *)vrig; hamlib_port_t *rp = RIGPORT(rig); - anytone_priv_data_t *p = rig->state.priv; + anytone_priv_data_t *p = STATE(rig)->priv; rig_debug(RIG_DEBUG_TRACE, "%s: anytone_thread started\n", __func__); p->runflag = 1; @@ -182,7 +182,7 @@ int anytone_transaction(RIG *rig, unsigned char *cmd, int cmd_len, unsigned char *reply, int reply_len, int expected_len) { int retval = RIG_OK; - //anytone_priv_data_t *p = rig->state.priv; + //anytone_priv_data_t *p = STATE(rig)->priv; ENTERFUNC; @@ -221,7 +221,7 @@ int anytone_init(RIG *rig) } else { - rig->state.priv = p; + STATE(rig)->priv = p; p->vfo_curr = RIG_VFO_NONE; #ifdef HAVE_PTHREAD pthread_mutex_init(&p->mutex, NULL); @@ -246,8 +246,8 @@ int anytone_cleanup(RIG *rig) ENTERFUNC; - free(rig->state.priv); - rig->state.priv = NULL; + free(STATE(rig)->priv); + STATE(rig)->priv = NULL; RETURNFUNC(retval); } @@ -312,7 +312,7 @@ int anytone_get_vfo(RIG *rig, vfo_t *vfo) ENTERFUNC; - const anytone_priv_data_ptr p = (anytone_priv_data_ptr) rig->state.priv; + const anytone_priv_data_ptr p = (anytone_priv_data_ptr) STATE(rig)->priv; unsigned char reply[512]; unsigned char cmd[] = { 0x2b, 0x41, 0x44, 0x41, 0x54, 0x41, 0x3a, 0x30, 0x30, 0x2c, 0x30, 0x30, 0x36, 0x0d, 0x0a, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x0a }; anytone_transaction(rig, cmd, sizeof(cmd), reply, sizeof(reply), 114); @@ -348,7 +348,7 @@ int anytone_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) ENTERFUNC; - anytone_priv_data_t *p = rig->state.priv; + anytone_priv_data_t *p = STATE(rig)->priv; *ptt = p->ptt; RETURNFUNC(retval); @@ -373,7 +373,7 @@ int anytone_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) MUTEX_LOCK(p->mutex); anytone_transaction(rig, pttcmd, sizeof(ptton), NULL, 0, 0); - anytone_priv_data_t *p = rig->state.priv; + anytone_priv_data_t *p = STATE(rig)->priv; p->ptt = ptt; MUTEX_UNLOCK(p->mutex); diff --git a/rigs/aor/aor.c b/rigs/aor/aor.c index 9839cd6ce..fd8147791 100644 --- a/rigs/aor/aor.c +++ b/rigs/aor/aor.c @@ -58,7 +58,7 @@ /* * aor_transaction - * We assume that rig!=NULL, rig->state!= NULL, data!=NULL, data_len!=NULL + * We assume that rig!=NULL, STATE(rig)!= NULL, data!=NULL, data_len!=NULL * Otherwise, you'll get a nice seg fault. You've been warned! * return value: RIG_OK if everything's fine, negative value otherwise * TODO: error case handling @@ -605,7 +605,7 @@ int aor_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts) /* * aor_set_level - * Assumes rig!=NULL, rig->state.priv!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL */ int aor_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { @@ -613,7 +613,7 @@ int aor_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) char lvlbuf[BUFSZ]; int agc; - rs = &rig->state; + rs = STATE(rig); switch (level) @@ -670,16 +670,14 @@ int aor_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) /* * aor_get_level - * Assumes rig!=NULL, rig->state.priv!=NULL, val!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL, val!=NULL */ int aor_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - struct rig_state *rs; + struct rig_state *rs = STATE(rig); char lvlbuf[BUFSZ], ackbuf[BUFSZ]; int ack_len, retval; - rs = &rig->state; - switch (level) { case RIG_LEVEL_RAWSTR: @@ -820,7 +818,7 @@ int aor_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) /* * aor_get_dcd - * Assumes rig!=NULL, rig->state.priv!=NULL, val!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL, val!=NULL */ int aor_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) { @@ -847,7 +845,7 @@ int aor_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) /* * aor_set_powerstat - * Assumes rig!=NULL, rig->state.priv!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL */ int aor_set_powerstat(RIG *rig, powerstat_t status) { @@ -891,7 +889,7 @@ int aor_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) /* * aor_scan, scan operation - * Assumes rig!=NULL, rig->state.priv!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL */ int aor_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch) { @@ -1344,7 +1342,7 @@ int aor_get_chan_all_cb(RIG *rig, vfo_t vfo, chan_cb_t chan_cb, rig_ptr_t arg) { const struct aor_priv_caps *priv = (struct aor_priv_caps *)rig->caps->priv; int i, j, retval; - chan_t *chan_list = rig->state.chan_list; + chan_t *chan_list = STATE(rig)->chan_list; channel_t *chan; int chan_count; char aorcmd[BUFSZ]; diff --git a/rigs/aor/ar3030.c b/rigs/aor/ar3030.c index 6d56f0983..ab8c9bdd2 100644 --- a/rigs/aor/ar3030.c +++ b/rigs/aor/ar3030.c @@ -277,15 +277,16 @@ static int ar3030_transaction(RIG *rig, const char *cmd, int cmd_len, int ar3030_init(RIG *rig) { struct ar3030_priv_data *priv; + struct rig_state *rs = STATE(rig); - rig->state.priv = calloc(1, sizeof(struct ar3030_priv_data)); + rs->priv = calloc(1, sizeof(struct ar3030_priv_data)); - if (!rig->state.priv) + if (!rs->priv) { return -RIG_ENOMEM; } - priv = rig->state.priv; + priv = rs->priv; priv->curr_ch = 99; /* huh! FIXME: get_mem in open() ? */ priv->curr_vfo = RIG_VFO_A; @@ -295,7 +296,7 @@ int ar3030_init(RIG *rig) int ar3030_cleanup(RIG *rig) { - struct ar3030_priv_data *priv = rig->state.priv; + struct ar3030_priv_data *priv = STATE(rig)->priv; free(priv); @@ -318,7 +319,7 @@ int ar3030_close(RIG *rig) int ar3030_set_vfo(RIG *rig, vfo_t vfo) { - struct ar3030_priv_data *priv = (struct ar3030_priv_data *)rig->state.priv; + struct ar3030_priv_data *priv = (struct ar3030_priv_data *)STATE(rig)->priv; char *cmd = ""; int retval; @@ -353,7 +354,7 @@ int ar3030_set_vfo(RIG *rig, vfo_t vfo) int ar3030_get_vfo(RIG *rig, vfo_t *vfo) { const struct ar3030_priv_data *priv = (struct ar3030_priv_data *) - rig->state.priv; + STATE(rig)->priv; *vfo = priv->curr_vfo; @@ -367,7 +368,7 @@ int ar3030_get_vfo(RIG *rig, vfo_t *vfo) */ int ar3030_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { - struct ar3030_priv_data *priv = (struct ar3030_priv_data *)rig->state.priv; + struct ar3030_priv_data *priv = (struct ar3030_priv_data *)STATE(rig)->priv; char freqbuf[BUFSZ]; int retval; @@ -391,7 +392,7 @@ int ar3030_set_freq(RIG *rig, vfo_t vfo, freq_t freq) */ int ar3030_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - struct ar3030_priv_data *priv = (struct ar3030_priv_data *)rig->state.priv; + struct ar3030_priv_data *priv = (struct ar3030_priv_data *)STATE(rig)->priv; char *rfp; int freq_len, retval; char freqbuf[BUFSZ]; @@ -491,7 +492,7 @@ int ar3030_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) */ int ar3030_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - struct ar3030_priv_data *priv = (struct ar3030_priv_data *)rig->state.priv; + struct ar3030_priv_data *priv = (struct ar3030_priv_data *)STATE(rig)->priv; int buf_len, retval; char buf[BUFSZ]; @@ -553,7 +554,7 @@ int ar3030_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) int ar3030_set_mem(RIG *rig, vfo_t vfo, int ch) { - struct ar3030_priv_data *priv = (struct ar3030_priv_data *)rig->state.priv; + struct ar3030_priv_data *priv = (struct ar3030_priv_data *)STATE(rig)->priv; int retval = RIG_OK; if (priv->curr_vfo == RIG_VFO_MEM) @@ -573,7 +574,7 @@ int ar3030_set_mem(RIG *rig, vfo_t vfo, int ch) int ar3030_get_mem(RIG *rig, vfo_t vfo, int *ch) { - struct ar3030_priv_data *priv = (struct ar3030_priv_data *)rig->state.priv; + struct ar3030_priv_data *priv = (struct ar3030_priv_data *)STATE(rig)->priv; char infobuf[BUFSZ]; int info_len, retval; @@ -646,7 +647,7 @@ int ar3030_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int ar3030_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - struct ar3030_priv_data *priv = (struct ar3030_priv_data *)rig->state.priv; + struct ar3030_priv_data *priv = (struct ar3030_priv_data *)STATE(rig)->priv; int info_len, retval; char infobuf[BUFSZ], *p; @@ -717,7 +718,7 @@ int ar3030_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int ar3030_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only) { - struct ar3030_priv_data *priv = (struct ar3030_priv_data *)rig->state.priv; + struct ar3030_priv_data *priv = (struct ar3030_priv_data *)STATE(rig)->priv; char cmdbuf[BUFSZ], infobuf[BUFSZ]; int info_len, retval; @@ -814,7 +815,7 @@ int ar3030_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only) int ar3030_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) { - struct ar3030_priv_data *priv = (struct ar3030_priv_data *)rig->state.priv; + struct ar3030_priv_data *priv = (struct ar3030_priv_data *)STATE(rig)->priv; char buf[16]; int retval; diff --git a/rigs/aor/ar7030p.c b/rigs/aor/ar7030p.c index 19874ad1d..2d57b0f17 100644 --- a/rigs/aor/ar7030p.c +++ b/rigs/aor/ar7030p.c @@ -264,7 +264,7 @@ static int ar7030p_init(RIG *rig) { int i; - rig->state.priv = (void *) priv; + STATE(rig)->priv = (void *) priv; RIGPORT(rig)->type.rig = RIG_PORT_SERIAL; @@ -327,7 +327,7 @@ static int ar7030p_init(RIG *rig) static int ar7030p_cleanup(RIG *rig) { - struct ar7030p_priv_data *priv = (struct ar7030p_priv_data *) rig->state.priv; + struct ar7030p_priv_data *priv = (struct ar7030p_priv_data *) STATE(rig)->priv; int rc = RIG_OK; int i; @@ -345,9 +345,9 @@ static int ar7030p_cleanup(RIG *rig) free(priv->ext_parms); - free(rig->state.priv); + free(STATE(rig)->priv); - rig->state.priv = NULL; + STATE(rig)->priv = NULL; return (rc); } @@ -363,8 +363,10 @@ static int ar7030p_open(RIG *rig) { int rc = RIG_OK; unsigned char v; + struct rig_state *rs; assert(NULL != rig); + rs = STATE(rig); rc = lockRx(rig, LOCK_1); @@ -373,9 +375,9 @@ static int ar7030p_open(RIG *rig) int i; /* Load calibration table */ - rig->state.str_cal.size = rig->caps->str_cal.size; + rs->str_cal.size = rig->caps->str_cal.size; - for (i = 0; i < rig->state.str_cal.size; i++) + for (i = 0; i < rs->str_cal.size; i++) { rc = readByte(rig, EEPROM1, SM_CAL + i, &v); @@ -384,12 +386,12 @@ static int ar7030p_open(RIG *rig) break; } - rig->state.str_cal.table[ i ].val = rig->caps->str_cal.table[ i ].val; - rig->state.str_cal.table[ i ].raw = (int) v; + rs->str_cal.table[ i ].val = rig->caps->str_cal.table[ i ].val; + rs->str_cal.table[ i ].raw = (int) v; rig_debug(RIG_DEBUG_VERBOSE, "%s: index %d, val %d, raw %d\n", - __func__, i, rig->state.str_cal.table[ i ].val, - rig->state.str_cal.table[ i ].raw); + __func__, i, rs->str_cal.table[ i ].val, + rs->str_cal.table[ i ].raw); } if (RIG_OK == rc) @@ -1220,7 +1222,7 @@ static int ar7030p_get_level(RIG *rig, vfo_t vfo, setting_t level, static int ar7030p_set_vfo(RIG *rig, vfo_t vfo) { int rc = RIG_OK; - struct ar7030p_priv_data *priv = (struct ar7030p_priv_data *) rig->state.priv; + struct ar7030p_priv_data *priv = (struct ar7030p_priv_data *) STATE(rig)->priv; switch (vfo) { @@ -1265,7 +1267,7 @@ static int ar7030p_get_vfo(RIG *rig, vfo_t *vfo) { int rc = RIG_OK; struct ar7030p_priv_data const *priv = (struct ar7030p_priv_data *) - rig->state.priv; + STATE(rig)->priv; assert(NULL != vfo); @@ -1329,7 +1331,7 @@ static int ar7030p_set_mem(RIG *rig, vfo_t vfo, int ch) { int rc = RIG_OK; - struct ar7030p_priv_data *priv = (struct ar7030p_priv_data *) rig->state.priv; + struct ar7030p_priv_data *priv = (struct ar7030p_priv_data *) STATE(rig)->priv; if (RIG_VFO_MEM == priv->curr_vfo) { @@ -1350,7 +1352,7 @@ static int ar7030p_get_mem(RIG *rig, vfo_t vfo, int *ch) int rc = RIG_OK; struct ar7030p_priv_data const *priv = (struct ar7030p_priv_data *) - rig->state.priv; + STATE(rig)->priv; const channel_t *curr = priv->curr; assert(NULL != ch); @@ -1651,7 +1653,7 @@ static int ar7030p_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, unsigned char *p = NULL; int ch; const struct ar7030p_priv_data *priv = (struct ar7030p_priv_data *) - rig->state.priv; + STATE(rig)->priv; const channel_t *curr = priv->curr; assert(NULL != chan); diff --git a/rigs/aor/ar7030p_utils.c b/rigs/aor/ar7030p_utils.c index 2f15a6a50..adeef7b8b 100644 --- a/rigs/aor/ar7030p_utils.c +++ b/rigs/aor/ar7030p_utils.c @@ -987,27 +987,29 @@ int getCalLevel(RIG *rig, unsigned char rawAgc, int *dbm) int raw = (int) rawAgc; int step; unsigned char v; + struct rig_state *rs; assert(NULL != rig); assert(NULL != dbm); + rs = STATE(rig); rig_debug(RIG_DEBUG_VERBOSE, "%s: raw AGC %03d\n", __func__, rawAgc); - for (i = 0; i < rig->state.str_cal.size; i++) + for (i = 0; i < rs->str_cal.size; i++) { - *dbm = rig->state.str_cal.table[ i ].val; + *dbm = rs->str_cal.table[ i ].val; rig_debug(RIG_DEBUG_VERBOSE, "%s: got cal table[ %d ] dBm value %d\n", __func__, i, *dbm); /* if the remaining difference in the raw value is negative */ - if (0 > (raw - rig->state.str_cal.table[ i ].raw)) + if (0 > (raw - rs->str_cal.table[ i ].raw)) { /* calculate step size */ if (0 < i) { - step = rig->state.str_cal.table[ i ].val - - rig->state.str_cal.table[ i - 1 ].val; + step = rs->str_cal.table[ i ].val - + rs->str_cal.table[ i - 1 ].val; } else { @@ -1018,7 +1020,7 @@ int getCalLevel(RIG *rig, unsigned char rawAgc, int *dbm) /* interpolate the final value */ *dbm -= step; /* HACK - table seems to be off by one index */ - *dbm += (int)(((double) raw / (double) rig->state.str_cal.table[ i ].raw) * + *dbm += (int)(((double) raw / (double) rs->str_cal.table[ i ].raw) * (double) step); rig_debug(RIG_DEBUG_VERBOSE, "%s: interpolated dBm value %d\n", __func__, *dbm); @@ -1029,7 +1031,7 @@ int getCalLevel(RIG *rig, unsigned char rawAgc, int *dbm) else { /* calculate the remaining raw value */ - raw = raw - rig->state.str_cal.table[ i ].raw; + raw = raw - rs->str_cal.table[ i ].raw; rig_debug(RIG_DEBUG_VERBOSE, "%s: residual raw value %d\n", __func__, raw); } diff --git a/rigs/aor/sr2200.c b/rigs/aor/sr2200.c index 244308878..0b092f71f 100644 --- a/rigs/aor/sr2200.c +++ b/rigs/aor/sr2200.c @@ -603,7 +603,7 @@ int sr2200_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int agc; unsigned att = 0; - rs = &rig->state; + rs = STATE(rig); switch (level) { @@ -685,7 +685,7 @@ int sr2200_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) char lvlbuf[BUFSZ], ackbuf[BUFSZ]; int ack_len, retval; - rs = &rig->state; + rs = STATE(rig); switch (level) { diff --git a/rigs/barrett/4050.c b/rigs/barrett/4050.c index 6bd44ef56..a6664a16e 100644 --- a/rigs/barrett/4050.c +++ b/rigs/barrett/4050.c @@ -66,7 +66,7 @@ static int barrett4050_open(RIG *rig) { int retval; char *response; - struct barrett_priv_data *priv = rig->state.priv; + struct barrett_priv_data *priv = STATE(rig)->priv; ENTERFUNC; barrett4050_get_info(rig); retval = barrett_transaction(rig, "IDC9999", 0, &response); diff --git a/rigs/barrett/950.c b/rigs/barrett/950.c index 1c6e40045..8ac8fc769 100644 --- a/rigs/barrett/950.c +++ b/rigs/barrett/950.c @@ -137,7 +137,7 @@ struct rig_caps barrett950_caps = /* * barrett950_set_freq - * assumes rig!=NULL, rig->state.priv!=NULL + * assumes rig!=NULL, STATE(rig)->priv!=NULL */ int barrett950_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { @@ -148,8 +148,8 @@ int barrett950_set_freq(RIG *rig, vfo_t vfo, freq_t freq) freq_t freq_rx, freq_tx; freq_t freq_MHz; char *response = NULL; - const struct barrett_priv_data *priv = rig->state.priv; - //struct barrett_priv_data *priv = rig->state.priv; + const struct barrett_priv_data *priv = STATE(rig)->priv; + //struct barrett_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s freq=%.0f\n", __func__, rig_strvfo(vfo), freq); diff --git a/rigs/barrett/barrett.c b/rigs/barrett/barrett.c index b407322ff..0dad6cd72 100644 --- a/rigs/barrett/barrett.c +++ b/rigs/barrett/barrett.c @@ -58,7 +58,7 @@ DECLARE_INITRIG_BACKEND(barrett) int barrett_transaction2(RIG *rig, char *cmd, int expected, char **result) { char cmd_buf[MAXCMDLEN]; - struct barrett_priv_data *priv = rig->state.priv; + struct barrett_priv_data *priv = STATE(rig)->priv; int retval; SNPRINTF(cmd_buf, sizeof(cmd_buf), "%c%s%s", 0x0a, cmd, EOM); @@ -80,7 +80,7 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result) char xon; char xoff; hamlib_port_t *rp = RIGPORT(rig); - struct barrett_priv_data *priv = rig->state.priv; + struct barrett_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s: cmd=%s\n", __func__, cmd); @@ -200,10 +200,10 @@ int barrett_init(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s version %s\n", __func__, rig->caps->version); // cppcheck claims leak here but it's freed in cleanup - rig->state.priv = (struct barrett_priv_data *)calloc(1, + STATE(rig)->priv = (struct barrett_priv_data *)calloc(1, sizeof(struct barrett_priv_data)); - if (!rig->state.priv) + if (!STATE(rig)->priv) { return -RIG_ENOMEM; } @@ -227,12 +227,12 @@ int barrett_cleanup(RIG *rig) return -RIG_EINVAL; } - if (rig->state.priv) + if (STATE(rig)->priv) { - free(rig->state.priv); + free(STATE(rig)->priv); } - rig->state.priv = NULL; + STATE(rig)->priv = NULL; return RIG_OK; } @@ -240,7 +240,7 @@ int barrett_cleanup(RIG *rig) /* * barrett_get_freq - * Assumes rig!=NULL, rig->state.priv!=NULL, freq!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL, freq!=NULL */ int barrett_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { @@ -280,13 +280,13 @@ int barrett_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) // TC command does not work on 4050 -- not implemented as of 2022-01-12 /* * barrett_set_freq - * assumes rig!=NULL, rig->state.priv!=NULL + * assumes rig!=NULL, STATE(rig)->priv!=NULL */ int barrett_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { char cmd_buf[MAXCMDLEN]; int retval; - const struct barrett_priv_data *priv = rig->state.priv; + const struct barrett_priv_data *priv = STATE(rig)->priv; freq_t tfreq; rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s freq=%.0f\n", __func__, @@ -438,7 +438,7 @@ int barrett_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) rmode_t tmode; pbwidth_t twidth; - //struct tt588_priv_data *priv = (struct tt588_priv_data *) rig->state.priv; + //struct tt588_priv_data *priv = (struct tt588_priv_data *) STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s mode=%s width=%d\n", __func__, rig_strvfo(vfo), rig_strrmode(mode), (int)width); @@ -604,7 +604,7 @@ int barrett_set_split_vfo(RIG *rig, vfo_t rxvfo, split_t split, vfo_t txvfo) { struct barrett_priv_data *priv; - priv = rig->state.priv; + priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called rxvfo=%s, txvfo=%s, split=%d\n", __func__, rig_strvfo(rxvfo), rig_strvfo(txvfo), split); @@ -618,7 +618,7 @@ int barrett_get_split_vfo(RIG *rig, vfo_t rxvfo, split_t *split, vfo_t *txvfo) { struct barrett_priv_data *priv; - priv = rig->state.priv; + priv = STATE(rig)->priv; *split = priv->split; *txvfo = RIG_VFO_B; // constant diff --git a/rigs/codan/codan.c b/rigs/codan/codan.c index f1fe2b51a..692cb4695 100644 --- a/rigs/codan/codan.c +++ b/rigs/codan/codan.c @@ -47,7 +47,7 @@ int codan_transaction(RIG *rig, char *cmd, int expected, char **result) char cmd_buf[MAXCMDLEN]; int retval; hamlib_port_t *rp = RIGPORT(rig); - struct codan_priv_data *priv = rig->state.priv; + struct codan_priv_data *priv = STATE(rig)->priv; //int retry = 3; rig_debug(RIG_DEBUG_VERBOSE, "%s: cmd=%s\n", __func__, cmd); @@ -137,10 +137,10 @@ int codan_init(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s version %s\n", __func__, rig->caps->version); // cppcheck claims leak here but it's freed in cleanup - rig->state.priv = (struct codan_priv_data *)calloc(1, + STATE(rig)->priv = (struct codan_priv_data *)calloc(1, sizeof(struct codan_priv_data)); - if (!rig->state.priv) + if (!STATE(rig)->priv) { return -RIG_ENOMEM; } @@ -184,12 +184,12 @@ int codan_cleanup(RIG *rig) return -RIG_EINVAL; } - if (rig->state.priv) + if (STATE(rig)->priv) { - free(rig->state.priv); + free(STATE(rig)->priv); } - rig->state.priv = NULL; + STATE(rig)->priv = NULL; return RIG_OK; } @@ -286,7 +286,7 @@ int codan_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) /* * codan_set_freq - * assumes rig!=NULL, rig->state.priv!=NULL + * assumes rig!=NULL, STATE(rig)->priv!=NULL */ int codan_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { @@ -313,7 +313,7 @@ int codan_set_freq(RIG *rig, vfo_t vfo, freq_t freq) /* * codan_get_freq - * Assumes rig!=NULL, rig->state.priv!=NULL, freq!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL, freq!=NULL */ int codan_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { From 406b947134502996a1eca14a98b53716b86b5cec Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Mon, 11 Mar 2024 15:49:15 -0400 Subject: [PATCH 2/6] More pointers to state --- rigs/dorji/dra818.c | 46 ++++++++++++------------ rigs/drake/drake.c | 18 +++++----- rigs/elad/elad.c | 80 +++++++++++++++++++++--------------------- rigs/elad/elad.h | 2 +- rigs/flexradio/dttsp.c | 53 ++++++++++++++-------------- rigs/flexradio/sdr1k.c | 19 +++++----- rigs/wj/wj.c | 34 +++++++++--------- 7 files changed, 127 insertions(+), 125 deletions(-) diff --git a/rigs/dorji/dra818.c b/rigs/dorji/dra818.c index 8cf4e93e4..4f684b7ef 100644 --- a/rigs/dorji/dra818.c +++ b/rigs/dorji/dra818.c @@ -100,7 +100,7 @@ static void dra818_subaudio(RIG *rig, char *subaudio, int subaudio_len, static int dra818_setgroup(RIG *rig) { - const struct dra818_priv *priv = rig->state.priv; + const struct dra818_priv *priv = STATE(rig)->priv; char cmd[80]; char subtx[8] = { 0 }; char subrx[8] = { 0 }; @@ -121,7 +121,7 @@ static int dra818_setgroup(RIG *rig) static int dra818_setvolume(RIG *rig) { - const struct dra818_priv *priv = rig->state.priv; + const struct dra818_priv *priv = STATE(rig)->priv; char cmd[80]; SNPRINTF(cmd, sizeof(cmd), "AT+DMOSETVOLUME=%1d\r\n", priv->vol); @@ -136,14 +136,14 @@ int dra818_init(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s: dra818_init called\n", __func__); - rig->state.priv = calloc(sizeof(*priv), 1); + STATE(rig)->priv = calloc(sizeof(*priv), 1); - if (!rig->state.priv) + if (!STATE(rig)->priv) { return -RIG_ENOMEM; } - priv = rig->state.priv; + priv = STATE(rig)->priv; switch (rig->caps->rig_model) { @@ -174,7 +174,7 @@ int dra818_cleanup(RIG *rig) { rig_debug(RIG_DEBUG_VERBOSE, "%s: dra818_cleanup called\n", __func__); - free(rig->state.priv); + free(STATE(rig)->priv); return RIG_OK; } @@ -214,7 +214,7 @@ int dra818_open(RIG *rig) int dra818_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { - struct dra818_priv *priv = rig->state.priv; + struct dra818_priv *priv = STATE(rig)->priv; /* Nearest channel */ shortfreq_t sfreq = ((freq + priv->bw / 2) / priv->bw); @@ -252,7 +252,7 @@ int dra818_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int dra818_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { - struct dra818_priv *priv = rig->state.priv; + struct dra818_priv *priv = STATE(rig)->priv; if (width > 12500) { @@ -270,7 +270,7 @@ int dra818_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) int dra818_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - const struct dra818_priv *priv = rig->state.priv; + const struct dra818_priv *priv = STATE(rig)->priv; *mode = RIG_MODE_FM; *width = priv->bw; @@ -280,7 +280,7 @@ int dra818_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) int dra818_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) { - const struct dra818_priv *priv = rig->state.priv; + const struct dra818_priv *priv = STATE(rig)->priv; hamlib_port_t *rp = RIGPORT(rig); char cmd[80]; char response[8]; @@ -313,7 +313,7 @@ int dra818_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) int dra818_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - const struct dra818_priv *priv = rig->state.priv; + const struct dra818_priv *priv = STATE(rig)->priv; switch (vfo) { @@ -334,7 +334,7 @@ int dra818_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int dra818_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo) { - struct dra818_priv *priv = rig->state.priv; + struct dra818_priv *priv = STATE(rig)->priv; priv->split = split; @@ -348,7 +348,7 @@ int dra818_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo) int dra818_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo) { - const struct dra818_priv *priv = rig->state.priv; + const struct dra818_priv *priv = STATE(rig)->priv; *split = priv->split; @@ -366,7 +366,7 @@ int dra818_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo) int dra818_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - const struct dra818_priv *priv = rig->state.priv; + const struct dra818_priv *priv = STATE(rig)->priv; switch (level) { @@ -389,7 +389,7 @@ int dra818_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int dra818_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { - struct dra818_priv *priv = rig->state.priv; + struct dra818_priv *priv = STATE(rig)->priv; switch (level) { @@ -434,7 +434,7 @@ int dra818_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int dra818_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) { - struct dra818_priv *priv = rig->state.priv; + struct dra818_priv *priv = STATE(rig)->priv; priv->dcs_code = code; @@ -448,7 +448,7 @@ int dra818_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) int dra818_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) { - struct dra818_priv *priv = rig->state.priv; + struct dra818_priv *priv = STATE(rig)->priv; priv->ctcss_tone = tone; @@ -462,7 +462,7 @@ int dra818_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) int dra818_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code) { - struct dra818_priv *priv = rig->state.priv; + struct dra818_priv *priv = STATE(rig)->priv; priv->dcs_sql = code; @@ -476,7 +476,7 @@ int dra818_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code) int dra818_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) { - struct dra818_priv *priv = rig->state.priv; + struct dra818_priv *priv = STATE(rig)->priv; priv->ctcss_sql = tone; @@ -490,7 +490,7 @@ int dra818_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) int dra818_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) { - const struct dra818_priv *priv = rig->state.priv; + const struct dra818_priv *priv = STATE(rig)->priv; *tone = priv->ctcss_sql; return RIG_OK; @@ -498,7 +498,7 @@ int dra818_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) int dra818_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code) { - const struct dra818_priv *priv = rig->state.priv; + const struct dra818_priv *priv = STATE(rig)->priv; *code = priv->dcs_sql; return RIG_OK; @@ -506,7 +506,7 @@ int dra818_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code) int dra818_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) { - const struct dra818_priv *priv = rig->state.priv; + const struct dra818_priv *priv = STATE(rig)->priv; *code = priv->dcs_code; return RIG_OK; @@ -514,7 +514,7 @@ int dra818_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) int dra818_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) { - const struct dra818_priv *priv = rig->state.priv; + const struct dra818_priv *priv = STATE(rig)->priv; *tone = priv->ctcss_tone; return RIG_OK; diff --git a/rigs/drake/drake.c b/rigs/drake/drake.c index f9796ea4e..416c51a77 100644 --- a/rigs/drake/drake.c +++ b/rigs/drake/drake.c @@ -97,14 +97,14 @@ int drake_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int drake_init(RIG *rig) { struct drake_priv_data *priv; - rig->state.priv = calloc(1, sizeof(struct drake_priv_data)); + STATE(rig)->priv = calloc(1, sizeof(struct drake_priv_data)); - if (!rig->state.priv) + if (!STATE(rig)->priv) { return -RIG_ENOMEM; } - priv = rig->state.priv; + priv = STATE(rig)->priv; priv->curr_ch = 0; @@ -113,7 +113,7 @@ int drake_init(RIG *rig) int drake_cleanup(RIG *rig) { - struct drake_priv_data *priv = rig->state.priv; + struct drake_priv_data *priv = STATE(rig)->priv; free(priv); @@ -552,7 +552,7 @@ int drake_set_mem(RIG *rig, vfo_t vfo, int ch) { int ack_len, retval; char buf[16], ackbuf[16]; - struct drake_priv_data *priv = rig->state.priv; + struct drake_priv_data *priv = STATE(rig)->priv; priv->curr_ch = ch; @@ -576,7 +576,7 @@ int drake_set_mem(RIG *rig, vfo_t vfo, int ch) */ int drake_get_mem(RIG *rig, vfo_t vfo, int *ch) { - struct drake_priv_data *priv = rig->state.priv; + struct drake_priv_data *priv = STATE(rig)->priv; int mdbuf_len, retval; char mdbuf[BUFSZ]; int chan; @@ -612,7 +612,7 @@ int drake_get_mem(RIG *rig, vfo_t vfo, int *ch) */ int drake_set_chan(RIG *rig, vfo_t vfo, const channel_t *chan) { - const struct drake_priv_data *priv = rig->state.priv; + const struct drake_priv_data *priv = STATE(rig)->priv; vfo_t old_vfo; int old_chan; char mdbuf[16], ackbuf[16]; @@ -668,7 +668,7 @@ int drake_set_chan(RIG *rig, vfo_t vfo, const channel_t *chan) */ int drake_get_chan(RIG *rig, vfo_t vfo, channel_t *chan, int read_only) { - const struct drake_priv_data *priv = rig->state.priv; + const struct drake_priv_data *priv = STATE(rig)->priv; vfo_t old_vfo; int old_chan; char mdbuf[BUFSZ], freqstr[BUFSZ]; @@ -880,7 +880,7 @@ int drake_get_chan(RIG *rig, vfo_t vfo, channel_t *chan, int read_only) */ int drake_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) { - const struct drake_priv_data *priv = rig->state.priv; + const struct drake_priv_data *priv = STATE(rig)->priv; char buf[16], ackbuf[16]; int len, ack_len, retval; diff --git a/rigs/elad/elad.c b/rigs/elad/elad.c index 8b9245266..953d9f0f3 100644 --- a/rigs/elad/elad.c +++ b/rigs/elad/elad.c @@ -145,7 +145,7 @@ const struct confparams elad_cfg_params[] = /** * elad_transaction - * Assumes rig!=NULL rig->state!=NULL rig->caps!=NULL + * Assumes rig!=NULL STATE(rig)!=NULL rig->caps!=NULL * * Parameters: * cmdstr: Command to be sent to the rig. cmdstr can also be NULL, @@ -164,7 +164,7 @@ const struct confparams elad_cfg_params[] = */ int elad_transaction(RIG *rig, const char *cmdstr, char *data, size_t datasize) { - struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_data *priv = STATE(rig)->priv; const struct elad_priv_caps *caps = elad_caps(rig); struct rig_state *rs; hamlib_port_t *rp = RIGPORT(rig); @@ -185,7 +185,7 @@ int elad_transaction(RIG *rig, const char *cmdstr, char *data, size_t datasize) return -RIG_EINVAL; } - rs = &rig->state; + rs = STATE(rig); rs->transaction_active = 1; @@ -235,13 +235,13 @@ transaction_write: if (!datasize) { - rig->state.transaction_active = 0; + rs->transaction_active = 0; /* no reply expected so we need to write a command that always gives a reply so we can read any error replies from the actual command being sent without blocking */ - if (RIG_OK != (retval = write_block(rp, - (unsigned char *) priv->verify_cmd, strlen(priv->verify_cmd)))) + if (RIG_OK != (retval = write_block(rp, (unsigned char *) priv->verify_cmd, + strlen(priv->verify_cmd)))) { goto transaction_quit; } @@ -515,14 +515,14 @@ int elad_init(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig->state.priv = calloc(1, sizeof(struct elad_priv_data)); + STATE(rig)->priv = calloc(1, sizeof(struct elad_priv_data)); - if (rig->state.priv == NULL) + if (STATE(rig)->priv == NULL) { return -RIG_ENOMEM; } - priv = rig->state.priv; + priv = STATE(rig)->priv; memset(priv, 0x00, sizeof(struct elad_priv_data)); strcpy(priv->verify_cmd, RIG_MODEL_XG3 == rig->caps->rig_model ? ";" : "ID;"); @@ -551,15 +551,15 @@ int elad_cleanup(RIG *rig) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - free(rig->state.priv); - rig->state.priv = NULL; + free(STATE(rig)->priv); + STATE(rig)->priv = NULL; return RIG_OK; } int elad_open(RIG *rig) { - struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_data *priv = STATE(rig)->priv; int err, i; char *idptr; char id[ELAD_MAX_BUF_LEN]; @@ -699,7 +699,7 @@ int elad_open(RIG *rig) int elad_close(RIG *rig) { - const struct elad_priv_data *priv = rig->state.priv; + const struct elad_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -734,7 +734,7 @@ int elad_get_id(RIG *rig, char *buf) */ static int elad_get_if(RIG *rig) { - struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_data *priv = STATE(rig)->priv; const struct elad_priv_caps *caps = elad_caps(rig); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -754,7 +754,7 @@ int elad_set_vfo(RIG *rig, vfo_t vfo) char cmdbuf[6]; int retval; char vfo_function; - const struct elad_priv_data *priv = rig->state.priv; + const struct elad_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -906,7 +906,7 @@ int elad_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { // this is a bogus suppress which complains priv is not used -- but it is 20231012 // cppcheck-suppress unreadVariable - struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_data *priv = STATE(rig)->priv; char cmdbuf[6]; int retval; unsigned char vfo_function; @@ -1004,7 +1004,7 @@ int elad_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) */ int elad_set_split(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { - struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_data *priv = STATE(rig)->priv; char cmdbuf[6]; int retval; @@ -1033,7 +1033,7 @@ int elad_set_split(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) */ int elad_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, vfo_t *txvfo) { - struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_data *priv = STATE(rig)->priv; int retval; int transmitting; @@ -1132,7 +1132,7 @@ int elad_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, vfo_t *txvfo) int elad_get_vfo_if(RIG *rig, vfo_t *vfo) { int retval; - struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_data *priv = STATE(rig)->priv; int split_and_transmitting; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1184,13 +1184,13 @@ int elad_set_freq(RIG *rig, vfo_t vfo, freq_t freq) unsigned char vfo_letter = '\0'; vfo_t tvfo; int err; - const struct elad_priv_data *priv = rig->state.priv; + const struct elad_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); tvfo = (vfo == RIG_VFO_CURR - || vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; + || vfo == RIG_VFO_VFO) ? STATE(rig)->current_vfo : vfo; if (RIG_VFO_CURR == tvfo) { @@ -1270,7 +1270,7 @@ int elad_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int elad_get_freq_if(RIG *rig, vfo_t vfo, freq_t *freq) { - const struct elad_priv_data *priv = rig->state.priv; + const struct elad_priv_data *priv = STATE(rig)->priv; char freqbuf[50]; int retval; @@ -1314,7 +1314,7 @@ int elad_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) } tvfo = (vfo == RIG_VFO_CURR - || vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; + || vfo == RIG_VFO_VFO) ? STATE(rig)->current_vfo : vfo; if (RIG_VFO_CURR == tvfo) { @@ -1370,7 +1370,7 @@ int elad_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { int retval; char buf[6]; - const struct elad_priv_data *priv = rig->state.priv; + const struct elad_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1503,7 +1503,7 @@ static int elad_set_filter(RIG *rig, pbwidth_t width) */ int elad_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { - const struct elad_priv_data *priv = rig->state.priv; + const struct elad_priv_data *priv = STATE(rig)->priv; struct elad_priv_caps *caps = elad_caps(rig); char buf[6]; char kmode; @@ -1705,7 +1705,7 @@ static int elad_get_filter(RIG *rig, pbwidth_t *width) */ int elad_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_data *priv = STATE(rig)->priv; struct elad_priv_caps *caps = elad_caps(rig); char cmd[4]; char modebuf[10]; @@ -1824,7 +1824,7 @@ int elad_get_mode_if(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { int err; struct elad_priv_caps *caps = elad_caps(rig); - const struct elad_priv_data *priv = rig->state.priv; + const struct elad_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1919,9 +1919,9 @@ int elad_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { int foundit = 0; - for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rig->state.attenuator[i]; i++) + for (i = 0; i < HAMLIB_MAXDBLSTSIZ && STATE(rig)->attenuator[i]; i++) { - if (val.i == rig->state.attenuator[i]) + if (val.i == STATE(rig)->attenuator[i]) { SNPRINTF(levelbuf, sizeof(levelbuf), "RA%02d", i + 1); foundit = 1; @@ -1948,9 +1948,9 @@ int elad_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { int foundit = 0; - for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rig->state.preamp[i]; i++) + for (i = 0; i < HAMLIB_MAXDBLSTSIZ && STATE(rig)->preamp[i]; i++) { - if (val.i == rig->state.preamp[i]) + if (val.i == STATE(rig)->preamp[i]) { SNPRINTF(levelbuf, sizeof(levelbuf), "PA%01d", i + 1); foundit = 1; @@ -2133,7 +2133,7 @@ int elad_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { for (i = 0; i < lvl && i < HAMLIB_MAXDBLSTSIZ; i++) { - if (rig->state.attenuator[i] == 0) + if (STATE(rig)->attenuator[i] == 0) { rig_debug(RIG_DEBUG_ERR, "%s: " "unexpected att level %d\n", @@ -2147,7 +2147,7 @@ int elad_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return -RIG_EINTERNAL; } - val->i = rig->state.attenuator[i - 1]; + val->i = STATE(rig)->attenuator[i - 1]; } break; @@ -2170,7 +2170,7 @@ int elad_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) for (i = 0; i < lvl && i < HAMLIB_MAXDBLSTSIZ; i++) { - if (rig->state.preamp[i] == 0) + if (STATE(rig)->preamp[i] == 0) { rig_debug(RIG_DEBUG_ERR, "%s: " "unexpected preamp level %d\n", @@ -2184,7 +2184,7 @@ int elad_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return -RIG_EINTERNAL; } - val->i = rig->state.preamp[i - 1]; + val->i = STATE(rig)->preamp[i - 1]; } else { @@ -2559,11 +2559,11 @@ int elad_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) /* * elad_get_ctcss_tone - * Assumes rig->state.priv != NULL + * Assumes STATE(rig)->priv != NULL */ int elad_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) { - const struct elad_priv_data *priv = rig->state.priv; + const struct elad_priv_data *priv = STATE(rig)->priv; struct rig_caps *caps; char tonebuf[3]; int i, retval; @@ -2908,7 +2908,7 @@ int elad_get_ant(RIG *rig, vfo_t vfo, ant_t dummy, value_t *option, */ int elad_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) { - struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_data *priv = STATE(rig)->priv; int retval; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -3367,7 +3367,7 @@ int elad_get_mem_if(RIG *rig, vfo_t vfo, int *ch) { int err; char buf[4]; - const struct elad_priv_data *priv = rig->state.priv; + const struct elad_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -3614,7 +3614,7 @@ int elad_set_ext_parm(RIG *rig, hamlib_token_t token, value_t val) int elad_get_ext_parm(RIG *rig, hamlib_token_t token, value_t *val) { int err; - struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); diff --git a/rigs/elad/elad.h b/rigs/elad/elad.h index 423ffb93a..4e0da053b 100644 --- a/rigs/elad/elad.h +++ b/rigs/elad/elad.h @@ -170,7 +170,7 @@ extern struct rig_caps fdm_duo_caps; /* use when not interested in the answer, but want to check its len */ static int inline elad_simple_transaction(RIG *rig, const char *cmd, size_t expected) { - struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_data *priv = STATE(rig)->priv; return elad_safe_transaction(rig, cmd, priv->info, ELAD_MAX_BUF_LEN, expected); } #endif diff --git a/rigs/flexradio/dttsp.c b/rigs/flexradio/dttsp.c index 50de1461a..c51e824c4 100644 --- a/rigs/flexradio/dttsp.c +++ b/rigs/flexradio/dttsp.c @@ -335,7 +335,7 @@ static int send_command(RIG *rig, const char *cmdstr, size_t buflen) static int fetch_meter(RIG *rig, int *label, float *data, int npts) { - struct dttsp_priv_data *priv = (struct dttsp_priv_data *)rig->state.priv; + struct dttsp_priv_data *priv = (struct dttsp_priv_data *)STATE(rig)->priv; int ret, buf_len; if (priv->meter_port.type.rig == RIG_PORT_UDP_NETWORK) @@ -398,14 +398,14 @@ static int fetch_meter(RIG *rig, int *label, float *data, int npts) /* - * Assumes rig!=NULL, rig->state.priv!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL */ int dttsp_set_conf(RIG *rig, hamlib_token_t token, const char *val) { struct dttsp_priv_data *priv; struct rig_state *rs; - rs = &rig->state; + rs = STATE(rig); priv = (struct dttsp_priv_data *)rs->priv; switch (token) @@ -436,7 +436,7 @@ int dttsp_set_conf(RIG *rig, hamlib_token_t token, const char *val) /* * assumes rig!=NULL, - * Assumes rig!=NULL, rig->state.priv!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL * and val points to a buffer big enough to hold the conf value. */ int dttsp_get_conf2(RIG *rig, hamlib_token_t token, char *val, int val_len) @@ -444,7 +444,7 @@ int dttsp_get_conf2(RIG *rig, hamlib_token_t token, char *val, int val_len) struct dttsp_priv_data *priv; struct rig_state *rs; - rs = &rig->state; + rs = STATE(rig); priv = (struct dttsp_priv_data *)rs->priv; switch (token) @@ -487,15 +487,15 @@ int dttsp_init(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig->state.priv = (struct dttsp_priv_data *)calloc(1, + STATE(rig)->priv = (struct dttsp_priv_data *)calloc(1, sizeof(struct dttsp_priv_data)); - if (!rig->state.priv) + if (!STATE(rig)->priv) { return -RIG_ENOMEM; } - priv = rig->state.priv; + priv = STATE(rig)->priv; priv->tuner = NULL; priv->tuner_model = RIG_MODEL_DUMMY; @@ -527,11 +527,12 @@ int dttsp_init(RIG *rig) int dttsp_open(RIG *rig) { - struct dttsp_priv_data *priv = (struct dttsp_priv_data *)rig->state.priv; + struct dttsp_priv_data *priv = (struct dttsp_priv_data *)STATE(rig)->priv; int ret; char *p; char *meterpath; hamlib_port_t *rp = RIGPORT(rig); + struct rig_state *rs = STATE(rig); rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); @@ -622,12 +623,12 @@ int dttsp_open(RIG *rig) */ #if 1 - rig->state.has_set_func |= priv->tuner->state.has_set_func; - rig->state.has_get_func |= priv->tuner->state.has_get_func; - rig->state.has_set_level |= priv->tuner->state.has_set_level; - rig->state.has_get_level |= priv->tuner->state.has_get_level; - rig->state.has_set_parm |= priv->tuner->state.has_set_parm; - rig->state.has_get_parm |= priv->tuner->state.has_get_parm; + rs->has_set_func |= STATE(priv->tuner)->has_set_func; + rs->has_get_func |= STATE(priv->tuner)->has_get_func; + rs->has_set_level |= STATE(priv->tuner)->has_set_level; + rs->has_get_level |= STATE(priv->tuner)->has_get_level; + rs->has_set_parm |= STATE(priv->tuner)->has_set_parm; + rs->has_get_parm |= STATE(priv->tuner)->has_get_parm; #endif @@ -645,7 +646,7 @@ int dttsp_open(RIG *rig) int dttsp_close(RIG *rig) { - struct dttsp_priv_data *priv = (struct dttsp_priv_data *)rig->state.priv; + struct dttsp_priv_data *priv = (struct dttsp_priv_data *)STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -657,7 +658,7 @@ int dttsp_close(RIG *rig) int dttsp_cleanup(RIG *rig) { - struct dttsp_priv_data *priv = (struct dttsp_priv_data *)rig->state.priv; + struct dttsp_priv_data *priv = (struct dttsp_priv_data *)STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -667,9 +668,9 @@ int dttsp_cleanup(RIG *rig) priv->tuner = NULL; } - free(rig->state.priv); + free(STATE(rig)->priv); - rig->state.priv = NULL; + STATE(rig)->priv = NULL; return RIG_OK; } @@ -680,7 +681,7 @@ int dttsp_cleanup(RIG *rig) */ int dttsp_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { - struct dttsp_priv_data *priv = (struct dttsp_priv_data *)rig->state.priv; + struct dttsp_priv_data *priv = (struct dttsp_priv_data *)STATE(rig)->priv; freq_t tuner_freq; int ret; char fstr[20]; @@ -740,7 +741,7 @@ int dttsp_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int dttsp_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - struct dttsp_priv_data *priv = (struct dttsp_priv_data *)rig->state.priv; + struct dttsp_priv_data *priv = (struct dttsp_priv_data *)STATE(rig)->priv; freq_t tuner_freq; int ret; @@ -859,7 +860,7 @@ static int agc_level2dttsp(enum agc_level_e agc) */ int dttsp_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { - struct dttsp_priv_data *priv = (struct dttsp_priv_data *)rig->state.priv; + struct dttsp_priv_data *priv = (struct dttsp_priv_data *)STATE(rig)->priv; int ret = RIG_OK; char buf[32]; @@ -882,7 +883,7 @@ int dttsp_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int dttsp_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - struct dttsp_priv_data *priv = (struct dttsp_priv_data *)rig->state.priv; + struct dttsp_priv_data *priv = (struct dttsp_priv_data *)STATE(rig)->priv; int ret = RIG_OK; char buf[32]; float rxm[MAXRX][RXMETERPTS]; @@ -913,7 +914,7 @@ int dttsp_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) if (level == RIG_LEVEL_STRENGTH) { - val->i = (int)rig_raw2val(val->i, &rig->state.str_cal); + val->i = (int)rig_raw2val(val->i, &STATE(rig)->str_cal); } ret = RIG_OK; @@ -930,7 +931,7 @@ int dttsp_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int dttsp_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) { - struct dttsp_priv_data *priv = (struct dttsp_priv_data *)rig->state.priv; + struct dttsp_priv_data *priv = (struct dttsp_priv_data *)STATE(rig)->priv; char buf[32]; const char *cmd; int ret; @@ -991,7 +992,7 @@ int dttsp_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) int dttsp_set_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t option) { - struct dttsp_priv_data *priv = (struct dttsp_priv_data *)rig->state.priv; + struct dttsp_priv_data *priv = (struct dttsp_priv_data *)STATE(rig)->priv; rig_debug(RIG_DEBUG_TRACE, "%s: ant %u, try tuner\n", __func__, ant); diff --git a/rigs/flexradio/sdr1k.c b/rigs/flexradio/sdr1k.c index 3489651d2..1981186af 100644 --- a/rigs/flexradio/sdr1k.c +++ b/rigs/flexradio/sdr1k.c @@ -194,17 +194,18 @@ struct rig_caps sdr1k_rig_caps = int sdr1k_init(RIG *rig) { struct sdr1k_priv_data *priv; + struct rig_state *rs = STATE(rig); - rig->state.priv = (struct sdr1k_priv_data *)calloc(1, sizeof( + rs->priv = (struct sdr1k_priv_data *)calloc(1, sizeof( struct sdr1k_priv_data)); - if (!rig->state.priv) + if (!rs->priv) { /* whoops! memory shortage! */ return -RIG_ENOMEM; } - priv = rig->state.priv; + priv = rs->priv; priv->dds_freq = RIG_FREQ_NONE; priv->xtal = DEFAULT_XTAL; @@ -221,7 +222,7 @@ static void pdelay(RIG *rig) int sdr1k_open(RIG *rig) { - struct sdr1k_priv_data *priv = (struct sdr1k_priv_data *)rig->state.priv; + struct sdr1k_priv_data *priv = (struct sdr1k_priv_data *)STATE(rig)->priv; priv->shadow[0] = 0; priv->shadow[1] = 0; @@ -242,14 +243,14 @@ int sdr1k_close(RIG *rig) int sdr1k_cleanup(RIG *rig) { - struct sdr1k_priv_data *priv = (struct sdr1k_priv_data *)rig->state.priv; + struct sdr1k_priv_data *priv = (struct sdr1k_priv_data *)STATE(rig)->priv; if (priv) { free(priv); } - rig->state.priv = NULL; + STATE(rig)->priv = NULL; return RIG_OK; } @@ -299,7 +300,7 @@ static int set_band(RIG *rig, freq_t freq) */ int sdr1k_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { - struct sdr1k_priv_data *priv = (struct sdr1k_priv_data *)rig->state.priv; + struct sdr1k_priv_data *priv = (struct sdr1k_priv_data *)STATE(rig)->priv; int i; double ftw; double DDS_step_size; @@ -380,7 +381,7 @@ int sdr1k_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int sdr1k_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - struct sdr1k_priv_data *priv = (struct sdr1k_priv_data *)rig->state.priv; + struct sdr1k_priv_data *priv = (struct sdr1k_priv_data *)STATE(rig)->priv; *freq = priv->dds_freq; rig_debug(RIG_DEBUG_TRACE, "%s: %"PRIll"\n", __func__, (int64_t)priv->dds_freq); @@ -452,7 +453,7 @@ int sdr1k_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int write_latch(RIG *rig, latch_t which, unsigned value, unsigned mask) { - struct sdr1k_priv_data *priv = (struct sdr1k_priv_data *)rig->state.priv; + struct sdr1k_priv_data *priv = (struct sdr1k_priv_data *)STATE(rig)->priv; hamlib_port_t *pport = RIGPORT(rig); if (!(L_EXT <= which && which <= L_DDS1)) diff --git a/rigs/wj/wj.c b/rigs/wj/wj.c index 3396f7d64..f1a847237 100644 --- a/rigs/wj/wj.c +++ b/rigs/wj/wj.c @@ -66,7 +66,7 @@ const struct confparams wj_cfg_params[] = */ static int wj_transaction(RIG *rig, int monitor) { - struct wj_priv_data *priv = (struct wj_priv_data *)rig->state.priv; + struct wj_priv_data *priv = (struct wj_priv_data *)STATE(rig)->priv; hamlib_port_t *rp = RIGPORT(rig); unsigned char buf[CMDSZ] = { 0x8, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -209,15 +209,15 @@ int wj_init(RIG *rig) return -RIG_EINVAL; } - rig->state.priv = (struct wj_priv_data *)calloc(1, sizeof(struct wj_priv_data)); + STATE(rig)->priv = (struct wj_priv_data *)calloc(1, sizeof(struct wj_priv_data)); - if (!rig->state.priv) + if (!STATE(rig)->priv) { /* whoops! memory shortage! */ return -RIG_ENOMEM; } - priv = rig->state.priv; + priv = STATE(rig)->priv; priv->receiver_id = 0; priv->freq = kHz(500); @@ -239,12 +239,12 @@ int wj_cleanup(RIG *rig) return -RIG_EINVAL; } - if (rig->state.priv) + if (STATE(rig)->priv) { - free(rig->state.priv); + free(STATE(rig)->priv); } - rig->state.priv = NULL; + STATE(rig)->priv = NULL; return RIG_OK; } @@ -252,11 +252,11 @@ int wj_cleanup(RIG *rig) /* - * Assumes rig!=NULL, rig->state.priv!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL */ int wj_set_conf(RIG *rig, hamlib_token_t token, const char *val) { - struct wj_priv_data *priv = (struct wj_priv_data *)rig->state.priv; + struct wj_priv_data *priv = (struct wj_priv_data *)STATE(rig)->priv; switch (token) { @@ -273,12 +273,12 @@ int wj_set_conf(RIG *rig, hamlib_token_t token, const char *val) /* * assumes rig!=NULL, - * Assumes rig!=NULL, rig->state.priv!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL * and val points to a buffer big enough to hold the conf value. */ int wj_get_conf2(RIG *rig, hamlib_token_t token, char *val, int val_len) { - const struct wj_priv_data *priv = (struct wj_priv_data *)rig->state.priv; + const struct wj_priv_data *priv = (struct wj_priv_data *)STATE(rig)->priv; switch (token) { @@ -304,7 +304,7 @@ int wj_get_conf(RIG *rig, hamlib_token_t token, char *val) */ int wj_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { - struct wj_priv_data *priv = (struct wj_priv_data *)rig->state.priv; + struct wj_priv_data *priv = (struct wj_priv_data *)STATE(rig)->priv; priv->freq = freq; @@ -317,7 +317,7 @@ int wj_set_freq(RIG *rig, vfo_t vfo, freq_t freq) */ int wj_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - const struct wj_priv_data *priv = (struct wj_priv_data *)rig->state.priv; + const struct wj_priv_data *priv = (struct wj_priv_data *)STATE(rig)->priv; int retval; retval = wj_transaction(rig, 1); @@ -338,7 +338,7 @@ int wj_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) */ int wj_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { - struct wj_priv_data *priv = (struct wj_priv_data *)rig->state.priv; + struct wj_priv_data *priv = (struct wj_priv_data *)STATE(rig)->priv; priv->mode = mode; @@ -361,7 +361,7 @@ int wj_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) */ int wj_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - const struct wj_priv_data *priv = (struct wj_priv_data *)rig->state.priv; + const struct wj_priv_data *priv = (struct wj_priv_data *)STATE(rig)->priv; int retval; retval = wj_transaction(rig, 1); @@ -385,7 +385,7 @@ int wj_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) */ int wj_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { - struct wj_priv_data *priv = (struct wj_priv_data *)rig->state.priv; + struct wj_priv_data *priv = (struct wj_priv_data *)STATE(rig)->priv; switch (level) { @@ -415,7 +415,7 @@ int wj_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) */ int wj_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - struct wj_priv_data *priv = (struct wj_priv_data *)rig->state.priv; + struct wj_priv_data *priv = (struct wj_priv_data *)STATE(rig)->priv; int retval = RIG_OK; retval = wj_transaction(rig, 1); From 4b436479d1667f1ee3f9f50db07a2a3fc9bdb7e4 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Sat, 16 Mar 2024 11:25:46 -0400 Subject: [PATCH 3/6] More pointers to state --- rigs/kenwood/elecraft.c | 14 +++++++------- rigs/kenwood/flex.c | 4 ++-- rigs/kenwood/flex6xxx.c | 8 ++++---- rigs/kenwood/k2.c | 4 ++-- rigs/kenwood/k3.c | 28 ++++++++++++++-------------- rigs/kenwood/pihpsdr.c | 13 +++++++------ rigs/kenwood/th.c | 38 ++++++++++++++++++++------------------ rigs/kenwood/thd72.c | 16 ++++++++-------- rigs/kenwood/thd74.c | 18 +++++++++--------- rigs/kenwood/thg71.c | 11 ++++++----- rigs/kenwood/tmd710.c | 26 +++++++++++++------------- rigs/kenwood/tmv7.c | 6 +++--- rigs/kenwood/transfox.c | 2 +- rigs/kenwood/ts2000.c | 4 ++-- rigs/kenwood/ts870s.c | 4 ++-- rigs/kenwood/ts990s.c | 6 +++--- 16 files changed, 103 insertions(+), 99 deletions(-) diff --git a/rigs/kenwood/elecraft.c b/rigs/kenwood/elecraft.c index 05b32835f..dc2e8c6cb 100644 --- a/rigs/kenwood/elecraft.c +++ b/rigs/kenwood/elecraft.c @@ -96,10 +96,10 @@ int elecraft_open(RIG *rig) { int err; char buf[KENWOOD_MAX_BUF_LEN]; - struct kenwood_priv_data *priv = rig->state.priv; char *model = "Unknown"; - struct rig_state *rs = &rig->state; + struct rig_state *rs = STATE(rig); struct hamlib_port *rp = RIGPORT(rig); + struct kenwood_priv_data *priv = rs->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called, rig version=%s\n", __func__, rig->caps->version); @@ -395,7 +395,7 @@ int elecraft_open(RIG *rig) int elecraft_close(RIG *rig) { - const struct kenwood_priv_data *priv = rig->state.priv; + const struct kenwood_priv_data *priv = STATE(rig)->priv; if (priv->save_k2_ext_lvl >= 0) { @@ -622,12 +622,12 @@ int elecraft_get_vfo_tq(RIG *rig, vfo_t *vfo) rig_debug(RIG_DEBUG_ERR, "%s: unable to parse TQ '%s'\n", __func__, splitbuf); } - *vfo = rig->state.tx_vfo = RIG_VFO_A; + *vfo = STATE(rig)->tx_vfo = RIG_VFO_A; - if (tq && ft == 1) { *vfo = rig->state.tx_vfo = RIG_VFO_B; } - else if (tq && ft == 0) { *vfo = rig->state.tx_vfo = RIG_VFO_A; } + if (tq && ft == 1) { *vfo = STATE(rig)->tx_vfo = RIG_VFO_B; } + else if (tq && ft == 0) { *vfo = STATE(rig)->tx_vfo = RIG_VFO_A; } - if (!tq && fr == 1) { *vfo = rig->state.rx_vfo = rig->state.tx_vfo = RIG_VFO_B; } + if (!tq && fr == 1) { *vfo = STATE(rig)->rx_vfo = STATE(rig)->tx_vfo = RIG_VFO_B; } RETURNFUNC2(RIG_OK); } diff --git a/rigs/kenwood/flex.c b/rigs/kenwood/flex.c index 733a219e0..d1f66e483 100644 --- a/rigs/kenwood/flex.c +++ b/rigs/kenwood/flex.c @@ -113,13 +113,13 @@ int verify_flexradio_id(RIG *rig, char *id) int flexradio_open(RIG *rig) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; int err; char id[FLEXRADIO_MAX_BUF_LEN]; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - //struct flexradio_priv_data *priv = rig->state.priv; + //struct flexradio_priv_data *priv = STATE(rig)->priv; /* Use check for "ID017;" to verify rig is reachable */ err = verify_flexradio_id(rig, id); diff --git a/rigs/kenwood/flex6xxx.c b/rigs/kenwood/flex6xxx.c index ab9082213..43ee6581c 100644 --- a/rigs/kenwood/flex6xxx.c +++ b/rigs/kenwood/flex6xxx.c @@ -178,7 +178,7 @@ static int flex6k_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) if ((vfo == RIG_VFO_VFO) || (vfo == RIG_VFO_CURR)) { - vfo = rig->state.current_vfo; + vfo = STATE(rig)->current_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s: setting VFO to current\n", __func__); } @@ -275,7 +275,7 @@ static int powersdr_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, if ((vfo == RIG_VFO_VFO) || (vfo == RIG_VFO_CURR)) { - vfo = rig->state.current_vfo; + vfo = STATE(rig)->current_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s: setting VFO to current\n", __func__); } @@ -451,7 +451,7 @@ static int flex6k_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) if ((vfo == RIG_VFO_VFO) || (vfo == RIG_VFO_CURR)) { - vfo = rig->state.current_vfo; + vfo = STATE(rig)->current_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s: setting VFO to current\n", __func__); } @@ -523,7 +523,7 @@ static int powersdr_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) if ((vfo == RIG_VFO_VFO) || (vfo == RIG_VFO_CURR)) { - vfo = rig->state.current_vfo; + vfo = STATE(rig)->current_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s: setting VFO to current\n", __func__); } diff --git a/rigs/kenwood/k2.c b/rigs/kenwood/k2.c index 0af922307..7e2142d86 100644 --- a/rigs/kenwood/k2.c +++ b/rigs/kenwood/k2.c @@ -259,7 +259,7 @@ struct rig_caps k2_caps = int k2_open(RIG *rig) { int err; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -293,7 +293,7 @@ int k2_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) int err; char f = '*'; struct k2_filt_lst_s *flt; - const struct kenwood_priv_data *priv = rig->state.priv; + const struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); diff --git a/rigs/kenwood/k3.c b/rigs/kenwood/k3.c index eb70d37c0..53aab4f94 100644 --- a/rigs/kenwood/k3.c +++ b/rigs/kenwood/k3.c @@ -1007,7 +1007,7 @@ int k3_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) char *cmd_data = "DT"; char *cmd_bw = "BW"; int cmd_bw_len = 6; - const struct kenwood_priv_data *priv = rig->state.priv; + const struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called vfo=%s\n", __func__, rig_strvfo(vfo)); @@ -1031,7 +1031,7 @@ int k3_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) if (vfo == RIG_VFO_CURR) { - vfo = rig->state.current_vfo; + vfo = STATE(rig)->current_vfo; } err = kenwood_get_mode(rig, vfo, &temp_m, &temp_w); @@ -1159,14 +1159,14 @@ int k3_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) char buf[KENWOOD_MAX_BUF_LEN]; char *dtcmd; struct kenwood_priv_caps *caps = kenwood_caps(rig); - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called vfo=%s mode=%s width=%d\n", __func__, rig_strvfo(vfo), rig_strrmode(mode), (int)width); if (vfo == RIG_VFO_CURR) { - vfo = rig->state.current_vfo; + vfo = STATE(rig)->current_vfo; } rmode_t tmodeA, tmodeB; @@ -1361,7 +1361,7 @@ int k3_set_vfo(RIG *rig, vfo_t vfo) ENTERFUNC; // we emulate vfo selection for Elecraft - rig->state.current_vfo = vfo; + STATE(rig)->current_vfo = vfo; RETURNFUNC(RIG_OK); } @@ -1370,7 +1370,7 @@ int k3_get_vfo(RIG *rig, vfo_t *vfo) { ENTERFUNC; - *vfo = rig->state.current_vfo; + *vfo = STATE(rig)->current_vfo; RETURNFUNC(RIG_OK); } @@ -1552,7 +1552,7 @@ int k3_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_width) char kmode; int err; char cmd_m[16]; - const struct kenwood_priv_data *priv = rig->state.priv; + const struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1828,7 +1828,7 @@ static int k3_get_maxpower(RIG *rig) //int retval; int maxpower = 15; // K3 default power level //char levelbuf[KENWOOD_MAX_BUF_LEN]; - const struct kenwood_priv_data *priv = rig->state.priv; + const struct kenwood_priv_data *priv = STATE(rig)->priv; // default range is 0-15 if there is no KPA3 installed if (priv->has_kpa3 || priv->has_kpa100) @@ -1952,9 +1952,9 @@ int k3_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int i; int foundit = 0; - for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rig->state.attenuator[i]; i++) + for (i = 0; i < HAMLIB_MAXDBLSTSIZ && STATE(rig)->attenuator[i]; i++) { - if (val.i == rig->state.attenuator[i]) + if (val.i == STATE(rig)->attenuator[i]) { SNPRINTF(levelbuf, sizeof(levelbuf), "RA%02d", i + 1); foundit = 1; @@ -2019,7 +2019,7 @@ int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int retval; int lvl; size_t len; - const struct kenwood_priv_data *priv = rig->state.priv; + const struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -2191,7 +2191,7 @@ int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) for (i = 0; i < lvl && i < HAMLIB_MAXDBLSTSIZ; i++) { - if (rig->state.attenuator[i] == 0) + if (STATE(rig)->attenuator[i] == 0) { rig_debug(RIG_DEBUG_ERR, "%s: unexpected att level %d\n", __func__, lvl); return -RIG_EPROTO; @@ -2203,7 +2203,7 @@ int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return -RIG_EINTERNAL; } - val->i = rig->state.attenuator[i - 1]; + val->i = STATE(rig)->attenuator[i - 1]; } break; @@ -2432,7 +2432,7 @@ int kx3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) case RIG_LEVEL_RFPOWER_METER_WATTS: { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; char levelbuf[KENWOOD_MAX_BUF_LEN]; int pwr; diff --git a/rigs/kenwood/pihpsdr.c b/rigs/kenwood/pihpsdr.c index 974214ec2..579d8205f 100644 --- a/rigs/kenwood/pihpsdr.c +++ b/rigs/kenwood/pihpsdr.c @@ -793,6 +793,7 @@ int pihpsdr_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { char levelbuf[16]; int i, kenwood_val; + struct rig_state *rs = STATE(rig); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -853,9 +854,9 @@ int pihpsdr_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { int foundit = 0; - for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rig->state.attenuator[i]; i++) + for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rs->attenuator[i]; i++) { - if (val.i == rig->state.attenuator[i]) + if (val.i == rs->attenuator[i]) { SNPRINTF(levelbuf, sizeof(levelbuf), "RA%02d", i + 1); foundit = 1; @@ -882,9 +883,9 @@ int pihpsdr_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { int foundit = 0; - for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rig->state.preamp[i]; i++) + for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rs->preamp[i]; i++) { - if (val.i == rig->state.preamp[i]) + if (val.i == rs->preamp[i]) { SNPRINTF(levelbuf, sizeof(levelbuf), "PA%01d", i + 1); foundit = 1; @@ -987,7 +988,7 @@ int pihpsdr_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) if (lvl > 9) { - val->i = rig->state.preamp[0]; + val->i = STATE(rig)->preamp[0]; } break; @@ -1018,7 +1019,7 @@ int pihpsdr_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) if (lvl > 99) { - val->i = rig->state.attenuator[0]; /* Since the TS-2000 only has one step on the attenuator */ + val->i = STATE(rig)->attenuator[0]; /* Since the TS-2000 only has one step on the attenuator */ } break; diff --git a/rigs/kenwood/th.c b/rigs/kenwood/th.c index 5e3e6b7ae..f4fea37dd 100644 --- a/rigs/kenwood/th.c +++ b/rigs/kenwood/th.c @@ -214,7 +214,7 @@ th_set_freq(RIG *rig, vfo_t vfo, freq_t freq) rig_debug(RIG_DEBUG_TRACE, "%s: called %s\n", __func__, rig_strvfo(vfo)); - if (vfo != RIG_VFO_CURR && vfo != rig->state.current_vfo) + if (vfo != RIG_VFO_CURR && vfo != STATE(rig)->current_vfo) { return kenwood_wrong_vfo(__func__, vfo); } @@ -254,7 +254,7 @@ th_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); - if (vfo != RIG_VFO_CURR && vfo != rig->state.current_vfo) + if (vfo != RIG_VFO_CURR && vfo != STATE(rig)->current_vfo) { return kenwood_wrong_vfo(__func__, vfo); } @@ -292,7 +292,7 @@ th_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); - if (vfo != RIG_VFO_CURR && vfo != rig->state.current_vfo) + if (vfo != RIG_VFO_CURR && vfo != STATE(rig)->current_vfo) { return kenwood_wrong_vfo(__func__, vfo); } @@ -348,7 +348,7 @@ th_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); - if (vfo != RIG_VFO_CURR && vfo != rig->state.current_vfo) + if (vfo != RIG_VFO_CURR && vfo != STATE(rig)->current_vfo) { return kenwood_wrong_vfo(__func__, vfo); } @@ -624,7 +624,8 @@ th_get_vfo(RIG *rig, vfo_t *vfo) */ int tm_set_vfo_bc2(RIG *rig, vfo_t vfo) { - const struct kenwood_priv_data *priv = rig->state.priv; + struct rig_state *rs = STATE(rig); + const struct kenwood_priv_data *priv = rs->priv; char cmd[16]; int vfonum, txvfonum, vfomode = 0; int retval; @@ -638,14 +639,14 @@ int tm_set_vfo_bc2(RIG *rig, vfo_t vfo) vfonum = 0; /* put back split mode when toggling */ txvfonum = (priv->split == RIG_SPLIT_ON && - rig->state.tx_vfo == RIG_VFO_B) ? 1 : vfonum; + rs->tx_vfo == RIG_VFO_B) ? 1 : vfonum; break; case RIG_VFO_B: vfonum = 1; /* put back split mode when toggling */ txvfonum = (priv->split == RIG_SPLIT_ON && - rig->state.tx_vfo == RIG_VFO_A) ? 0 : vfonum; + rs->tx_vfo == RIG_VFO_A) ? 0 : vfonum; break; case RIG_VFO_MEM: @@ -687,7 +688,7 @@ int tm_set_vfo_bc2(RIG *rig, vfo_t vfo) int th_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; char vfobuf[16]; int vfonum, txvfonum; int retval; @@ -758,7 +759,7 @@ int th_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) int th_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *txvfo) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; char buf[10]; int retval; @@ -1125,12 +1126,13 @@ th_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) char vch, buf[10], ackbuf[20]; int retval, v; unsigned int l; + struct rig_state *rs = STATE(rig); vfo_t tvfo; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); - tvfo = (vfo == RIG_VFO_CURR) ? rig->state.current_vfo : vfo; + tvfo = (vfo == RIG_VFO_CURR) ? rs->current_vfo : vfo; switch (tvfo) { @@ -1277,7 +1279,7 @@ th_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) } else { - val->i = rig->state.attenuator[ackbuf[4] - '1']; + val->i = rs->attenuator[ackbuf[4] - '1']; } break; @@ -1318,7 +1320,7 @@ int th_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); - tvfo = (vfo == RIG_VFO_CURR) ? rig->state.current_vfo : vfo; + tvfo = (vfo == RIG_VFO_CURR) ? STATE(rig)->current_vfo : vfo; switch (tvfo) { @@ -1700,7 +1702,7 @@ th_set_mem(RIG *rig, vfo_t vfo, int ch) rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); - tvfo = (vfo == RIG_VFO_CURR) ? rig->state.current_vfo : vfo; + tvfo = (vfo == RIG_VFO_CURR) ? STATE(rig)->current_vfo : vfo; switch (tvfo) { @@ -1741,7 +1743,7 @@ th_get_mem(RIG *rig, vfo_t vfo, int *ch) rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); /* store current VFO */ - cvfo = rig->state.current_vfo; + cvfo = STATE(rig)->current_vfo; /* check if we should switch VFO */ if (cvfo != RIG_VFO_MEM) @@ -1866,7 +1868,7 @@ int th_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) { rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); - if (vfo != RIG_VFO_CURR && vfo != rig->state.current_vfo) + if (vfo != RIG_VFO_CURR && vfo != STATE(rig)->current_vfo) { return kenwood_wrong_vfo(__func__, vfo); } @@ -2053,7 +2055,7 @@ int th_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only) chan->flags = lockout ? RIG_CHFLAG_SKIP : 0; chan->freq = freq; chan->vfo = RIG_VFO_MEM; - chan->tuning_step = rig->state.tuning_steps[step].ts; + chan->tuning_step = STATE(rig)->tuning_steps[step].ts; if (priv->mode_table) { @@ -2228,8 +2230,8 @@ int th_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan) channel_num = chan->channel_num; - for (step = 0; rig->state.tuning_steps[step].ts != 0; step++) - if (chan->tuning_step <= rig->state.tuning_steps[step].ts) + for (step = 0; STATE(rig)->tuning_steps[step].ts != 0; step++) + if (chan->tuning_step <= STATE(rig)->tuning_steps[step].ts) { break; } diff --git a/rigs/kenwood/thd72.c b/rigs/kenwood/thd72.c index 28c49692e..fb164decf 100644 --- a/rigs/kenwood/thd72.c +++ b/rigs/kenwood/thd72.c @@ -148,7 +148,7 @@ static struct kenwood_priv_caps thd72_priv_caps = int thd72_open(RIG *rig) { int ret; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; strcpy(priv->verify_cmd, "ID\r"); //ret = kenwood_transaction(rig, "", NULL, 0); @@ -170,12 +170,12 @@ static int thd72_set_vfo(RIG *rig, vfo_t vfo) case RIG_VFO_VFO: case RIG_VFO_MAIN: cmd = "BC 0"; - rig->state.current_vfo = RIG_VFO_A; + STATE(rig)->current_vfo = RIG_VFO_A; break; case RIG_VFO_B: case RIG_VFO_SUB: - rig->state.current_vfo = RIG_VFO_B; + STATE(rig)->current_vfo = RIG_VFO_B; cmd = "BC 1"; break; @@ -192,7 +192,7 @@ static int thd72_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { int retval; char vfobuf[16]; - const struct kenwood_priv_data *priv = rig->state.priv; + const struct kenwood_priv_data *priv = STATE(rig)->priv; char vfonum = '0'; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -257,7 +257,7 @@ static int thd72_get_vfo(RIG *rig, vfo_t *vfo) static int thd72_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; char vfobuf[16]; int retval; @@ -302,7 +302,7 @@ static int thd72_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) static int thd72_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *txvfo) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; char buf[10]; int retval; @@ -340,7 +340,7 @@ static int thd72_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, static int thd72_vfoc(RIG *rig, vfo_t vfo, char *vfoc) { rig_debug(RIG_DEBUG_TRACE, "%s: called VFO=%s\n", __func__, rig_strvfo(vfo)); - vfo = (vfo == RIG_VFO_CURR) ? rig->state.current_vfo : vfo; + vfo = (vfo == RIG_VFO_CURR) ? STATE(rig)->current_vfo : vfo; switch (vfo) { @@ -1520,7 +1520,7 @@ int thd72_get_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) int i, j, ret; hamlib_port_t *rp = RIGPORT(rig); channel_t *chan; - chan_t *chan_list = rig->state.chan_list; + chan_t *chan_list = STATE(rig)->chan_list; int chan_next = chan_list[0].start; char block[BLOCK_SZ]; char resp[CMD_SZ]; diff --git a/rigs/kenwood/thd74.c b/rigs/kenwood/thd74.c index 3a37cb9aa..5ae158f9f 100644 --- a/rigs/kenwood/thd74.c +++ b/rigs/kenwood/thd74.c @@ -156,7 +156,7 @@ static struct kenwood_priv_caps thd74_priv_caps = int thd74_open(RIG *rig) { //int ret; - //struct kenwood_priv_data *priv = rig->state.priv; + //struct kenwood_priv_data *priv = STATE(rig)->priv; // this is already done in kenwood_init //strcpy(priv->verify_cmd, "ID\r"); @@ -239,7 +239,7 @@ static int thd74_get_vfo(RIG *rig, vfo_t *vfo) static int thd74_vfoc(RIG *rig, vfo_t vfo, char *vfoc) { - vfo = (vfo == RIG_VFO_CURR) ? rig->state.current_vfo : vfo; + vfo = (vfo == RIG_VFO_CURR) ? STATE(rig)->current_vfo : vfo; switch (vfo) { @@ -395,7 +395,7 @@ static int thd74_round_freq(RIG *rig, vfo_t vfo, freq_t freq) static int thd74_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; int retval; char buf[128], fbuf[12]; @@ -422,7 +422,7 @@ static int thd74_set_freq(RIG *rig, vfo_t vfo, freq_t freq) static int thd74_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; int retval; char buf[128]; @@ -1347,7 +1347,7 @@ static int thd74_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int thd74_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -1363,7 +1363,7 @@ int thd74_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) int thd74_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *txvfo) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -1385,7 +1385,7 @@ otherwise return -RIG_EPROTO */ int thd74_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; int retval; char buf[128]; @@ -1417,7 +1417,7 @@ otherwise return -RIG_EPROTO */ int thd74_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -1512,7 +1512,7 @@ int thd74_get_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) int i, j, ret; hamlib_port_t *rp = RIGPORT(rig); channel_t *chan; - chan_t *chan_list = rig->state.chan_list; + chan_t *chan_list = STATE(rig)->chan_list; int chan_next = chan_list[0].start; char block[BLOCK_SZ]; char resp[CMD_SZ]; diff --git a/rigs/kenwood/thg71.c b/rigs/kenwood/thg71.c index 57302725c..f25af0aab 100644 --- a/rigs/kenwood/thg71.c +++ b/rigs/kenwood/thg71.c @@ -497,6 +497,7 @@ int thg71_open(RIG *rig) char ackbuf[ACKBUF_LEN]; int retval, i; const freq_range_t frend = RIG_FRNG_END; + struct rig_state *rs = STATE(rig); /* this will check the model id */ retval = kenwood_open(rig); @@ -546,7 +547,7 @@ int thg71_open(RIG *rig) frng.high_power = -1; frng.low_power = -1; frng.label = ""; - rig->state.rx_range_list[i] = frng; + rs->rx_range_list[i] = frng; if (frng.startf > MHz(200)) { @@ -558,12 +559,12 @@ int thg71_open(RIG *rig) } frng.low_power = mW(50); - rig->state.tx_range_list[i] = frng; + rs->tx_range_list[i] = frng; } - rig->state.rx_range_list[i] = frend; - rig->state.tx_range_list[i] = frend; - rig->state.vfo_list = RIG_VFO_A | RIG_VFO_MEM ; + rs->rx_range_list[i] = frend; + rs->tx_range_list[i] = frend; + rs->vfo_list = RIG_VFO_A | RIG_VFO_MEM ; return RIG_OK; } diff --git a/rigs/kenwood/tmd710.c b/rigs/kenwood/tmd710.c index 0acddb997..c42a18cfe 100644 --- a/rigs/kenwood/tmd710.c +++ b/rigs/kenwood/tmd710.c @@ -659,14 +659,14 @@ static int tmd710_open(RIG *rig) rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); - rig->state.tx_vfo = RIG_VFO_A; + STATE(rig)->tx_vfo = RIG_VFO_A; // Get current RX and TX VFO state, do not care if we succeed or not tmd710_get_vfo(rig, &vfo); tmd710_get_split_vfo(rig, RIG_VFO_CURR, &split, &vfo); - rig_debug(RIG_DEBUG_TRACE, "rig->state.tx_vfo: %s\n", - rig_strvfo(rig->state.tx_vfo)); + rig_debug(RIG_DEBUG_TRACE, "STATE(rig)->tx_vfo: %s\n", + rig_strvfo(STATE(rig)->tx_vfo)); return 0; } @@ -1288,7 +1288,7 @@ int tmd710_set_split_freq(RIG *rig, vfo_t vfo, freq_t freq) rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); // Use the TX VFO for split - return tmd710_do_set_freq(rig, rig->state.tx_vfo, freq); + return tmd710_do_set_freq(rig, STATE(rig)->tx_vfo, freq); } /* @@ -1301,7 +1301,7 @@ int tmd710_get_split_freq(RIG *rig, vfo_t vfo, freq_t *freq) rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); // Use the TX VFO for split - return tmd710_do_get_freq(rig, rig->state.tx_vfo, freq); + return tmd710_do_get_freq(rig, STATE(rig)->tx_vfo, freq); } static int tmd710_find_ctcss_index(RIG *rig, tone_t tone, int *ctcss_index) @@ -1645,7 +1645,7 @@ static int tmd710_find_tuning_step_index(RIG *rig, shortfreq_t ts, { int k, stepind = -1; - for (k = 0; rig->state.tuning_steps[k].ts != 0; ++k) + for (k = 0; STATE(rig)->tuning_steps[k].ts != 0; ++k) { if ((rig->caps->tuning_steps[k].modes == RIG_MODE_NONE) @@ -2030,7 +2030,7 @@ int tmd710_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) return retval; } - rig->state.tx_vfo = txvfo; + STATE(rig)->tx_vfo = txvfo; return RIG_OK; } @@ -2062,10 +2062,10 @@ int tmd710_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *txvfo) return -RIG_EPROTO; } - rig->state.tx_vfo = *txvfo; + STATE(rig)->tx_vfo = *txvfo; // Rig is always in "split mode" and VFOs are targetable, so simply check current and TX VFOs - *split = rig->state.current_vfo == rig->state.tx_vfo ? RIG_SPLIT_OFF : + *split = STATE(rig)->current_vfo == STATE(rig)->tx_vfo ? RIG_SPLIT_OFF : RIG_SPLIT_ON; return RIG_OK; @@ -2097,7 +2097,7 @@ int tmd710_get_mem(RIG *rig, vfo_t vfo, int *ch) } else { - vfonum = rig->state.current_vfo == RIG_VFO_A ? 0 : 1; + vfonum = STATE(rig)->current_vfo == RIG_VFO_A ? 0 : 1; } snprintf(cmd, sizeof(cmd), "MR %d", vfonum); @@ -2143,7 +2143,7 @@ int tmd710_set_mem(RIG *rig, vfo_t vfo, int ch) } else { - vfonum = rig->state.current_vfo == RIG_VFO_A ? 0 : 1; + vfonum = STATE(rig)->current_vfo == RIG_VFO_A ? 0 : 1; } snprintf(cmd, sizeof(cmd), "MR %d,%03d", vfonum, ch); @@ -2904,7 +2904,7 @@ int tmd710_set_parm(RIG *rig, setting_t parm, value_t val) /* * tmd710_get_ext_level - * Assumes rig!=NULL, rig->state.priv!=NULL, val!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL, val!=NULL * */ int tmd710_get_ext_level(RIG *rig, vfo_t vfo, hamlib_token_t token, value_t *val) @@ -2938,7 +2938,7 @@ int tmd710_get_ext_level(RIG *rig, vfo_t vfo, hamlib_token_t token, value_t *val /* * tmd710_set_ext_level - * Assumes rig!=NULL, rig->state.priv!=NULL + * Assumes rig!=NULL, STATE(rig)->priv!=NULL * */ int tmd710_set_ext_level(RIG *rig, vfo_t vfo, hamlib_token_t token, value_t val) diff --git a/rigs/kenwood/tmv7.c b/rigs/kenwood/tmv7.c index 06899d424..d1ff45e84 100644 --- a/rigs/kenwood/tmv7.c +++ b/rigs/kenwood/tmv7.c @@ -567,7 +567,7 @@ int tmv7_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only) chan->freq = freq; chan->vfo = RIG_VFO_MEM; - chan->tuning_step = rig->state.tuning_steps[step].ts; + chan->tuning_step = STATE(rig)->tuning_steps[step].ts; if (freq < MHz(138)) { @@ -672,8 +672,8 @@ int tmv7_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan) freq = (long)chan->freq; - for (step = 0; rig->state.tuning_steps[step].ts != 0; step++) - if (chan->tuning_step == rig->state.tuning_steps[step].ts) { break; } + for (step = 0; STATE(rig)->tuning_steps[step].ts != 0; step++) + if (chan->tuning_step == STATE(rig)->tuning_steps[step].ts) { break; } switch (chan->rptr_shift) { diff --git a/rigs/kenwood/transfox.c b/rigs/kenwood/transfox.c index ccdafb88d..e7da235e7 100644 --- a/rigs/kenwood/transfox.c +++ b/rigs/kenwood/transfox.c @@ -170,7 +170,7 @@ int transfox_open(RIG *rig) { rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); - rig->state.current_vfo = RIG_VFO_A; + STATE(rig)->current_vfo = RIG_VFO_A; /* do not call kenwood_open(rig), rig has no "ID" command */ diff --git a/rigs/kenwood/ts2000.c b/rigs/kenwood/ts2000.c index 5e127407e..477b541c7 100644 --- a/rigs/kenwood/ts2000.c +++ b/rigs/kenwood/ts2000.c @@ -275,7 +275,7 @@ int ts2000_init(RIG *rig) return retval; } - priv = (struct kenwood_priv_data *) rig->state.priv; + priv = (struct kenwood_priv_data *) STATE(rig)->priv; priv->ag_format = 3; priv->micgain_min = 0; @@ -1004,7 +1004,7 @@ static int ts2000_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { int retval; char buf[7]; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; diff --git a/rigs/kenwood/ts870s.c b/rigs/kenwood/ts870s.c index ed54c9296..c069c7d34 100644 --- a/rigs/kenwood/ts870s.c +++ b/rigs/kenwood/ts870s.c @@ -439,7 +439,7 @@ static int ts870s_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) else { for (i = 0; i < lvl && i < HAMLIB_MAXDBLSTSIZ; i++) - if (rig->state.attenuator[i] == 0) + if (STATE(rig)->attenuator[i] == 0) { rig_debug(RIG_DEBUG_ERR, "ts870s_get_level: " "unexpected att level %d\n", lvl); @@ -451,7 +451,7 @@ static int ts870s_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return -RIG_EINTERNAL; } - val->i = rig->state.attenuator[i - 1]; + val->i = STATE(rig)->attenuator[i - 1]; } break; diff --git a/rigs/kenwood/ts990s.c b/rigs/kenwood/ts990s.c index a336a170b..2785d981e 100644 --- a/rigs/kenwood/ts990s.c +++ b/rigs/kenwood/ts990s.c @@ -412,11 +412,11 @@ int ts990s_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) switch (vfo) { case RIG_VFO_MAIN: - val->i = '1' == lvlbuf[2] ? rig->state.preamp[0] : 0; + val->i = '1' == lvlbuf[2] ? STATE(rig)->preamp[0] : 0; break; case RIG_VFO_SUB: - val->i = '1' == lvlbuf[3] ? rig->state.preamp[0] : 0; + val->i = '1' == lvlbuf[3] ? STATE(rig)->preamp[0] : 0; break; default: @@ -456,7 +456,7 @@ int ts990s_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) } else { - val->i = rig->state.attenuator[lvlbuf[3] - '1']; + val->i = STATE(rig)->attenuator[lvlbuf[3] - '1']; } } break; From 2d0b8b807d220c10e49ba9c0f94b408ac3fd9d68 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Sun, 17 Mar 2024 03:43:25 -0400 Subject: [PATCH 4/6] Pointerize all state references in rigs/kenwood/* --- rigs/kenwood/ic10.c | 6 +- rigs/kenwood/kenwood.c | 166 +++++++++++++++++++++-------------------- rigs/kenwood/kenwood.h | 2 +- rigs/kenwood/ts450s.c | 4 +- rigs/kenwood/ts480.c | 22 +++--- rigs/kenwood/ts570.c | 6 +- rigs/kenwood/ts590.c | 8 +- rigs/kenwood/tx500.c | 4 +- rigs/kenwood/xg3.c | 14 ++-- 9 files changed, 118 insertions(+), 114 deletions(-) diff --git a/rigs/kenwood/ic10.c b/rigs/kenwood/ic10.c index 38d8fad08..ac57db4b8 100644 --- a/rigs/kenwood/ic10.c +++ b/rigs/kenwood/ic10.c @@ -67,7 +67,7 @@ int ic10_cmd_trim(char *data, int data_len) /** * ic10_transaction - * Assumes rig!=NULL rig->state!=NULL rig->caps!=NULL + * Assumes rig!=NULL STATE(rig)!=NULL rig->caps!=NULL **/ int ic10_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len) @@ -99,7 +99,7 @@ transaction: if (!data) { char buffer[50]; - const struct kenwood_priv_data *priv = rig->state.priv; + const struct kenwood_priv_data *priv = STATE(rig)->priv; if (RIG_OK != (retval = write_block(rp, (unsigned char *) priv->verify_cmd, strlen(priv->verify_cmd)))) @@ -451,7 +451,7 @@ int ic10_set_freq(RIG *rig, vfo_t vfo, freq_t freq) if (vfo == RIG_VFO_CURR) { - tvfo = rig->state.current_vfo; + tvfo = STATE(rig)->current_vfo; } else { diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index 19b54fabe..2562e01fc 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -234,7 +234,7 @@ struct confparams kenwood_cfg_params[] = /** * kenwood_transaction - * Assumes rig!=NULL rig->state!=NULL rig->caps!=NULL + * Assumes rig!=NULL STATE(rig)!=NULL rig->caps!=NULL * * Parameters: * cmdstr: Command to be sent to the rig. cmdstr can also be NULL, @@ -262,7 +262,7 @@ int kenwood_transaction(RIG *rig, const char *cmdstr, char *data, char *cmd; int len; int retry_read = 0; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; struct kenwood_priv_caps *caps = kenwood_caps(rig); struct rig_state *rs; struct hamlib_port *rp; /* Pointer to rigport structure */ @@ -285,7 +285,7 @@ int kenwood_transaction(RIG *rig, const char *cmdstr, char *data, RETURNFUNC2(-RIG_EINVAL); } - rs = &rig->state; + rs = STATE(rig); rp = RIGPORT(rig); rs->transaction_active = 1; @@ -396,7 +396,7 @@ transaction_write: if (!datasize && strncmp(cmdstr, "KY", 2) != 0) { - rig->state.transaction_active = 0; + rs->transaction_active = 0; // there are some commands that have problems with immediate follow-up // so we'll just ignore them @@ -749,7 +749,7 @@ int kenwood_safe_transaction(RIG *rig, const char *cmd, char *buf, // QRPLABS can't seem top decide if they give 37 or 38 bytes for IF command if (strncmp(cmd, "IF", 2) == 0 && rig->caps->rig_model == RIG_MODEL_QRPLABS) { break; } - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_ERR, "%s: wrong answer; len for cmd %s: expected = %d, got %d\n", @@ -809,14 +809,14 @@ int kenwood_init(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called, version %s/%s\n", __func__, BACKEND_VER, rig->caps->version); - rig->state.priv = calloc(1, sizeof(struct kenwood_priv_data)); + STATE(rig)->priv = calloc(1, sizeof(struct kenwood_priv_data)); - if (rig->state.priv == NULL) + if (STATE(rig)->priv == NULL) { RETURNFUNC2(-RIG_ENOMEM); } - priv = rig->state.priv; + priv = STATE(rig)->priv; memset(priv, 0x00, sizeof(struct kenwood_priv_data)); @@ -878,15 +878,15 @@ int kenwood_cleanup(RIG *rig) { ENTERFUNC; - free(rig->state.priv); - rig->state.priv = NULL; + free(STATE(rig)->priv); + STATE(rig)->priv = NULL; RETURNFUNC(RIG_OK); } int kenwood_open(RIG *rig) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; struct kenwood_priv_caps *caps = kenwood_caps(rig); int err, i; char *idptr; @@ -900,7 +900,7 @@ int kenwood_open(RIG *rig) priv->question_mark_response_means_rejected = 0; - if (rig->state.auto_power_on) + if (STATE(rig)->auto_power_on) { // Ensure rig is on rig_set_powerstat(rig, 1); @@ -923,7 +923,7 @@ int kenwood_open(RIG *rig) err = rig_get_powerstat(rig, &powerstat); if (err == RIG_OK && powerstat == 0 && priv->poweron == 0 - && rig->state.auto_power_on) + && STATE(rig)->auto_power_on) { priv->has_ps = 1; rig_debug(RIG_DEBUG_TRACE, "%s: got PS0 so powerup\n", __func__); @@ -1074,7 +1074,7 @@ int kenwood_open(RIG *rig) __func__, kenwood_id_string_list[i].id); // current vfo is rx_vfo - rig_get_vfo(rig, &rig->state.rx_vfo); + rig_get_vfo(rig, &STATE(rig)->rx_vfo); if (kenwood_id_string_list[i].model == rig->caps->rig_model) { @@ -1138,7 +1138,7 @@ int kenwood_open(RIG *rig) int kenwood_close(RIG *rig) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; @@ -1151,7 +1151,7 @@ int kenwood_close(RIG *rig) it's not supported */ } - if (rig->state.auto_power_off) + if (STATE(rig)->auto_power_off) { rig_debug(RIG_DEBUG_TRACE, "%s: got PS1 so powerdown\n", __func__); rig_set_powerstat(rig, 0); @@ -1186,7 +1186,7 @@ int kenwood_get_id(RIG *rig, char *buf) */ int kenwood_get_if(RIG *rig) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; struct kenwood_priv_caps *caps = kenwood_caps(rig); int retval; int post_write_delay_save = 0; @@ -1196,8 +1196,8 @@ int kenwood_get_if(RIG *rig) // Malachite has a 400ms delay but some get commands can work with no delay if (RIG_IS_MALACHITE) { - post_write_delay_save = rig->state.post_write_delay; - rig->state.post_write_delay = 0; + post_write_delay_save = STATE(rig)->post_write_delay; + STATE(rig)->post_write_delay = 0; } retval = kenwood_safe_transaction(rig, "IF", priv->info, @@ -1205,7 +1205,7 @@ int kenwood_get_if(RIG *rig) if (RIG_IS_MALACHITE) { - rig->state.post_write_delay = post_write_delay_save; + STATE(rig)->post_write_delay = post_write_delay_save; } RETURNFUNC(retval); @@ -1222,7 +1222,7 @@ int kenwood_set_vfo(RIG *rig, vfo_t vfo) char cmdbuf[12]; int retval; char vfo_function; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; rig_debug(RIG_DEBUG_VERBOSE, @@ -1243,7 +1243,7 @@ int kenwood_set_vfo(RIG *rig, vfo_t vfo) #if 0 - if (rig->state.current_vfo == vfo) + if (STATE(rig)->current_vfo == vfo) { rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo already is %s...skipping\n", __func__, rig_strvfo(vfo)); @@ -1267,19 +1267,19 @@ int kenwood_set_vfo(RIG *rig, vfo_t vfo) break; case RIG_VFO_TX: - vfo_function = rig->state.tx_vfo == RIG_VFO_B ? '1' : '0'; + vfo_function = STATE(rig)->tx_vfo == RIG_VFO_B ? '1' : '0'; break; #if 0 // VFO_RX really should NOT be VFO_CURR as VFO_CURR could be either VFO case RIG_VFO_RX: - vfo_function = rig->state.rx_vfo == RIG_VFO_B ? '1' : '0'; + vfo_function = STATE(rig)->rx_vfo == RIG_VFO_B ? '1' : '0'; break; #endif case RIG_VFO_CURR: HAMLIB_TRACE; - rig->state.current_vfo = RIG_VFO_CURR; + STATE(rig)->current_vfo = RIG_VFO_CURR; RETURNFUNC2(RIG_OK); default: @@ -1344,7 +1344,7 @@ int kenwood_set_vfo(RIG *rig, vfo_t vfo) } HAMLIB_TRACE; - rig->state.current_vfo = vfo; + STATE(rig)->current_vfo = vfo; /* if FN command then there's no FT or FR */ /* If split mode on, the don't change TxVFO */ @@ -1473,7 +1473,7 @@ int kenwood_get_vfo_main_sub(RIG *rig, vfo_t *vfo) */ int kenwood_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; char cmdbuf[12]; int retval; unsigned char vfo_function; @@ -1496,7 +1496,7 @@ int kenwood_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) RETURNFUNC2(kenwood_transaction(rig, cmdbuf, NULL, 0)); } - if (vfo == RIG_VFO_CURR) { vfo = rig->state.current_vfo; } + if (vfo == RIG_VFO_CURR) { vfo = STATE(rig)->current_vfo; } if (vfo == RIG_VFO_TX || vfo == RIG_VFO_RX) { vfo = vfo_fixup(rig, vfo, split); } @@ -1640,7 +1640,7 @@ int kenwood_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) */ int kenwood_set_split(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; char cmdbuf[6]; int retval; @@ -1674,7 +1674,8 @@ int kenwood_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, { int transmitting; int retval; - struct kenwood_priv_data *priv = rig->state.priv; + struct rig_state *rs = STATE(rig); + struct kenwood_priv_data *priv = rs->priv; ENTERFUNC; @@ -1694,13 +1695,13 @@ int kenwood_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, { *split = RIG_SPLIT_ON; *txvfo = RIG_VFO_SUB; - priv->tx_vfo = rig->state.tx_vfo = *txvfo; + priv->tx_vfo = rs->tx_vfo = *txvfo; } else { *split = RIG_SPLIT_OFF; *txvfo = RIG_VFO_MAIN; - priv->tx_vfo = rig->state.tx_vfo = *txvfo; + priv->tx_vfo = rs->tx_vfo = *txvfo; } } @@ -1740,35 +1741,35 @@ int kenwood_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, switch (priv->info[30]) { case '0': - if (rig->state.rx_vfo == RIG_VFO_A) + if (rs->rx_vfo == RIG_VFO_A) { HAMLIB_TRACE; - *txvfo = rig->state.tx_vfo = priv->tx_vfo = (*split + *txvfo = rs->tx_vfo = priv->tx_vfo = (*split && !transmitting) ? RIG_VFO_B : RIG_VFO_A; } - else if (rig->state.rx_vfo == RIG_VFO_B) + else if (rs->rx_vfo == RIG_VFO_B) { HAMLIB_TRACE; - *txvfo = rig->state.tx_vfo = priv->tx_vfo = (*split + *txvfo = rs->tx_vfo = priv->tx_vfo = (*split && !transmitting) ? RIG_VFO_B : RIG_VFO_A; } else { rig_debug(RIG_DEBUG_WARN, "%s(%d): unknown rx_vfo=%s\n", __func__, __LINE__, - rig_strvfo(rig->state.rx_vfo)); + rig_strvfo(rs->rx_vfo)); *txvfo = RIG_VFO_A; // pick a default - rig->state.rx_vfo = priv->tx_vfo = RIG_VFO_A; + rs->rx_vfo = priv->tx_vfo = RIG_VFO_A; } break; case '1': - if (rig->state.rx_vfo == RIG_VFO_A) + if (rs->rx_vfo == RIG_VFO_A) { HAMLIB_TRACE; *txvfo = priv->tx_vfo = (*split && !transmitting) ? RIG_VFO_A : RIG_VFO_B; } - else if (rig->state.rx_vfo == RIG_VFO_B) + else if (rs->rx_vfo == RIG_VFO_B) { HAMLIB_TRACE; *txvfo = priv->tx_vfo = (*split && !transmitting) ? RIG_VFO_B : RIG_VFO_A; @@ -1776,9 +1777,9 @@ int kenwood_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, else { rig_debug(RIG_DEBUG_WARN, "%s(%d): unknown rx_vfo=%s\n", __func__, __LINE__, - rig_strvfo(rig->state.rx_vfo)); + rig_strvfo(rs->rx_vfo)); *txvfo = RIG_VFO_A; // pick a default - rig->state.rx_vfo = RIG_VFO_A; + rs->rx_vfo = RIG_VFO_A; } break; @@ -1812,7 +1813,8 @@ int kenwood_get_vfo_if(RIG *rig, vfo_t *vfo) { int retval; int split_and_transmitting; - struct kenwood_priv_data *priv = rig->state.priv; + struct rig_state *rs = STATE(rig); + struct kenwood_priv_data *priv = rs->priv; ENTERFUNC; @@ -1838,10 +1840,10 @@ int kenwood_get_vfo_if(RIG *rig, vfo_t *vfo) switch (priv->info[30]) { case '0': - *vfo = rig->state.rx_vfo = rig->state.tx_vfo = priv->tx_vfo = + *vfo = rs->rx_vfo = rs->tx_vfo = priv->tx_vfo = split_and_transmitting ? RIG_VFO_B : RIG_VFO_A; - if (priv->info[32] == '1') { priv->tx_vfo = rig->state.tx_vfo = RIG_VFO_B; } + if (priv->info[32] == '1') { priv->tx_vfo = rs->tx_vfo = RIG_VFO_B; } break; @@ -1876,13 +1878,13 @@ int kenwood_set_freq(RIG *rig, vfo_t vfo, freq_t freq) vfo_t tvfo; freq_t tfreq = 0; int err; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called vfo=%s freq=%.0f\n", __func__, rig_strvfo(vfo), freq); tvfo = (vfo == RIG_VFO_CURR - || vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; + || vfo == RIG_VFO_VFO) ? STATE(rig)->current_vfo : vfo; rig_debug(RIG_DEBUG_TRACE, "%s: tvfo=%s\n", __func__, rig_strvfo(tvfo)); @@ -1897,7 +1899,7 @@ int kenwood_set_freq(RIG *rig, vfo_t vfo, freq_t freq) // Malchite is so slow we don't do the get_freq // And when we have detected Doppler operations we just set the freq all the time // This should provide stable timing for set_ptt operation so relay delays are consistent - if (!RIG_IS_MALACHITE && rig->state.doppler == 0) + if (!RIG_IS_MALACHITE && STATE(rig)->doppler == 0) { rig_get_freq(rig, tvfo, &tfreq); @@ -1995,7 +1997,7 @@ int kenwood_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int kenwood_get_freq_if(RIG *rig, vfo_t vfo, freq_t *freq) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; char freqbuf[50]; int retval; @@ -2030,7 +2032,7 @@ int kenwood_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int retval; unsigned char vfo_letter = '\0'; vfo_t tvfo; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; @@ -2040,7 +2042,7 @@ int kenwood_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) } tvfo = (vfo == RIG_VFO_CURR - || vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; + || vfo == RIG_VFO_VFO) ? STATE(rig)->current_vfo : vfo; if (RIG_VFO_CURR == tvfo) { @@ -2109,7 +2111,7 @@ int kenwood_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { int retval; char buf[7]; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; @@ -2145,7 +2147,7 @@ int kenwood_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) int rit_enabled; int xit_enabled; shortfreq_t curr_rit; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called: vfo=%s, rit=%ld\n", __func__, @@ -2354,13 +2356,13 @@ int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) int err; int datamode = 0; int needdata; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; struct kenwood_priv_caps *caps = kenwood_caps(rig); rig_debug(RIG_DEBUG_VERBOSE, "%s called, vfo=%s, mode=%s, width=%d, curr_vfo=%s\n", __func__, rig_strvfo(vfo), rig_strrmode(mode), (int)width, - rig_strvfo(rig->state.current_vfo)); + rig_strvfo(STATE(rig)->current_vfo)); // we wont' set opposite VFO if the mode is the same as requested // setting VFOB mode requires split modifications which cause VFO flashing @@ -2515,7 +2517,7 @@ int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) if (vfo == RIG_VFO_CURR) { HAMLIB_TRACE; - vfo = rig->state.current_vfo; + vfo = STATE(rig)->current_vfo; } if ((vfo & (RIG_VFO_A | RIG_VFO_MAIN)) && ((priv->datamodeA == 0 && datamode) @@ -2689,11 +2691,11 @@ int kenwood_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) int retval; int kmode; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; struct kenwood_priv_caps *caps = kenwood_caps(rig); rig_debug(RIG_DEBUG_VERBOSE, "%s called, curr_vfo=%s\n", __func__, - rig_strvfo(rig->state.current_vfo)); + rig_strvfo(STATE(rig)->current_vfo)); if (!mode || !width) { @@ -2705,7 +2707,7 @@ int kenwood_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) /* only need to get it if it has to be initialized */ if (priv->curr_mode > 0 && priv->is_emulation && vfo == RIG_VFO_B) { - rig->state.current_vfo = RIG_VFO_A; + STATE(rig)->current_vfo = RIG_VFO_A; RETURNFUNC2(RIG_OK); } @@ -2844,7 +2846,7 @@ int kenwood_get_mode_if(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { int err; struct kenwood_priv_caps *caps = kenwood_caps(rig); - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; @@ -2956,7 +2958,7 @@ static int kenwood_get_power_minmax(RIG *rig, int *power_now, int *power_min, // we batch these commands together for speed char *cmd; int n; - struct rig_state *rs = &rig->state; + struct rig_state *rs = STATE(rig); struct hamlib_port *rp = RIGPORT(rig); ENTERFUNC; @@ -3184,7 +3186,8 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { char levelbuf[16]; int i, kenwood_val, len, result; - struct kenwood_priv_data *priv = rig->state.priv; + struct rig_state *rs = STATE(rig); + struct kenwood_priv_data *priv = rs->priv; struct kenwood_priv_caps *caps = kenwood_caps(rig); gran_t *level_info; @@ -3331,9 +3334,9 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { int foundit = 0; - for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rig->state.attenuator[i]; i++) + for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rs->attenuator[i]; i++) { - if (val.i == rig->state.attenuator[i]) + if (val.i == rs->attenuator[i]) { SNPRINTF(levelbuf, sizeof(levelbuf), "RA%0*d", len, i + 1); foundit = 1; @@ -3360,9 +3363,9 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { int foundit = 0; - for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rig->state.preamp[i]; i++) + for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rs->preamp[i]; i++) { - if (val.i == rig->state.preamp[i]) + if (val.i == rs->preamp[i]) { SNPRINTF(levelbuf, sizeof(levelbuf), "PA%01d", i + 1); foundit = 1; @@ -3565,7 +3568,8 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int retval; int lvl; int i, ret, agclevel, len, value; - struct kenwood_priv_data *priv = rig->state.priv; + struct rig_state *rs = STATE(rig); + struct kenwood_priv_data *priv = rs->priv; struct kenwood_priv_caps *caps = kenwood_caps(rig); gran_t *level_info; @@ -3728,7 +3732,7 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { for (i = 0; i < lvl && i < HAMLIB_MAXDBLSTSIZ; i++) { - if (rig->state.attenuator[i] == 0) + if (rs->attenuator[i] == 0) { rig_debug(RIG_DEBUG_ERR, "%s: " "unexpected att level %d\n", @@ -3742,7 +3746,7 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) RETURNFUNC(-RIG_EINTERNAL); } - val->i = rig->state.attenuator[i - 1]; + val->i = rs->attenuator[i - 1]; } break; @@ -3765,7 +3769,7 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) for (i = 0; i < lvl && i < HAMLIB_MAXDBLSTSIZ; i++) { - if (rig->state.preamp[i] == 0) + if (rs->preamp[i] == 0) { rig_debug(RIG_DEBUG_ERR, "%s: " "unexpected preamp level %d\n", @@ -3779,7 +3783,7 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) RETURNFUNC(-RIG_EINTERNAL); } - val->i = rig->state.preamp[i - 1]; + val->i = rs->preamp[i - 1]; } else { @@ -4500,11 +4504,11 @@ int kenwood_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) /* * kenwood_get_ctcss_tone - * Assumes rig->state.priv != NULL + * Assumes STATE(rig)->priv != NULL */ int kenwood_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; struct rig_caps *caps; char tonebuf[3]; int i, retval; @@ -4891,7 +4895,7 @@ int kenwood_get_ant(RIG *rig, vfo_t vfo, ant_t dummy, value_t *option, */ int kenwood_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; int retval; ENTERFUNC; @@ -5128,7 +5132,7 @@ int kenwood_set_powerstat(RIG *rig, powerstat_t status) { int retval; struct hamlib_port *rp = RIGPORT(rig); - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; if ((priv->is_k3 || priv->is_k3s) && status == RIG_POWER_ON) { @@ -5195,7 +5199,7 @@ int kenwood_get_powerstat(RIG *rig, powerstat_t *status) char pwrbuf[6]; int result; struct hamlib_port *rp = RIGPORT(rig); - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; @@ -5433,7 +5437,7 @@ int kenwood_stop_morse(RIG *rig, vfo_t vfo) int kenwood_send_voice_mem(RIG *rig, vfo_t vfo, int bank) { char cmd[16]; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; #if 0 // don't really need to turn on the list @@ -5477,7 +5481,7 @@ int kenwood_send_voice_mem(RIG *rig, vfo_t vfo, int bank) int kenwood_stop_voice_mem(RIG *rig, vfo_t vfo) { char cmd[16]; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; if (rig->caps->rig_model == RIG_MODEL_TS2000 @@ -5648,7 +5652,7 @@ int kenwood_get_mem_if(RIG *rig, vfo_t vfo, int *ch) { int err; char buf[4]; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; @@ -5887,7 +5891,7 @@ int kenwood_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan) int kenwood_set_ext_parm(RIG *rig, hamlib_token_t token, value_t val) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; char buf[4]; ENTERFUNC; @@ -5920,7 +5924,7 @@ int kenwood_set_ext_parm(RIG *rig, hamlib_token_t token, value_t val) int kenwood_get_ext_parm(RIG *rig, hamlib_token_t token, value_t *val) { int err; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; diff --git a/rigs/kenwood/kenwood.h b/rigs/kenwood/kenwood.h index eb6aee8e0..b512a3308 100644 --- a/rigs/kenwood/kenwood.h +++ b/rigs/kenwood/kenwood.h @@ -334,7 +334,7 @@ extern struct rig_caps trudx_caps; static int inline kenwood_simple_transaction(RIG *rig, const char *cmd, size_t expected) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; return kenwood_safe_transaction(rig, cmd, priv->info, KENWOOD_MAX_BUF_LEN, expected); } diff --git a/rigs/kenwood/ts450s.c b/rigs/kenwood/ts450s.c index e5e393512..51aba0836 100644 --- a/rigs/kenwood/ts450s.c +++ b/rigs/kenwood/ts450s.c @@ -94,8 +94,8 @@ int ts450_open(RIG *rig) if (err != RIG_OK) { rig_debug(RIG_DEBUG_VERBOSE, "%s: tone unit not detected\n", __func__); - rig->state.has_set_func &= ~RIG_FUNC_TONE; - rig->state.has_get_func &= ~RIG_FUNC_TONE; + STATE(rig)->has_set_func &= ~RIG_FUNC_TONE; + STATE(rig)->has_get_func &= ~RIG_FUNC_TONE; } RIGPORT(rig)->retry = maxtries; diff --git a/rigs/kenwood/ts480.c b/rigs/kenwood/ts480.c index f9034ad7b..eb194d1ac 100644 --- a/rigs/kenwood/ts480.c +++ b/rigs/kenwood/ts480.c @@ -823,7 +823,7 @@ static int ts480_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { int retval; char buf[7]; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; @@ -1207,7 +1207,7 @@ int ts480_init(RIG *rig) return retval; } - priv = (struct kenwood_priv_data *) rig->state.priv; + priv = (struct kenwood_priv_data *) STATE(rig)->priv; priv->ag_format = 2; priv->micgain_min = 0; @@ -2167,7 +2167,7 @@ int malachite_init(RIG *rig) retval = kenwood_init(rig); - priv = rig->state.priv; + priv = STATE(rig)->priv; priv->no_id = 1; // the Malchite doesn't like the ID; verify cmd @@ -2178,20 +2178,20 @@ int malachite_init(RIG *rig) int malachite_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - int post_write_delay_save = rig->state.post_write_delay; - rig->state.post_write_delay = 0; + int post_write_delay_save = STATE(rig)->post_write_delay; + STATE(rig)->post_write_delay = 0; int retval = kenwood_get_mode(rig, vfo, mode, width); - rig->state.post_write_delay = post_write_delay_save; + STATE(rig)->post_write_delay = post_write_delay_save; return retval; } int malachite_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - int post_write_delay_save = rig->state.post_write_delay; + int post_write_delay_save = STATE(rig)->post_write_delay; ENTERFUNC; - rig->state.post_write_delay = 0; + STATE(rig)->post_write_delay = 0; int retval = kenwood_get_freq(rig, vfo, freq); - rig->state.post_write_delay = post_write_delay_save; + STATE(rig)->post_write_delay = post_write_delay_save; RETURNFUNC(retval); } @@ -2212,13 +2212,13 @@ int malachite_set_freq(RIG *rig, vfo_t vfo, freq_t freq) // Malachite has a bug where it takes two freq set to make it work // under band changes -- so we just do this all the time retval = kenwood_set_freq(rig, vfo, freq + 1); - rig->state.post_write_delay = 250; // need a bit more time on band change + STATE(rig)->post_write_delay = 250; // need a bit more time on band change if (retval != RIG_OK) { RETURNFUNC(retval); } } else { - rig->state.post_write_delay = 125; + STATE(rig)->post_write_delay = 125; } retval = kenwood_set_freq(rig, vfo, freq); diff --git a/rigs/kenwood/ts570.c b/rigs/kenwood/ts570.c index dc676250d..fd1f57519 100644 --- a/rigs/kenwood/ts570.c +++ b/rigs/kenwood/ts570.c @@ -351,7 +351,7 @@ ts570_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int i; for (i = 0; i < HAMLIB_MAXDBLSTSIZ; i++) - if (kenwood_val == rig->state.preamp[i]) + if (kenwood_val == STATE(rig)->preamp[i]) { SNPRINTF(levelbuf, sizeof(levelbuf), "PA%01d", i + 1); break; /* found - stop searching */ @@ -475,7 +475,7 @@ ts570_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) for (i = 0; i < levelint && i < HAMLIB_MAXDBLSTSIZ; i++) { - if (rig->state.preamp[i] == 0) + if (STATE(rig)->preamp[i] == 0) { rig_debug(RIG_DEBUG_ERR, "%s: unexpected att level %d\n", __func__, (int)levelint); @@ -488,7 +488,7 @@ ts570_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return -RIG_EINTERNAL; } - val->i = rig->state.preamp[i - 1]; + val->i = STATE(rig)->preamp[i - 1]; } break; diff --git a/rigs/kenwood/ts590.c b/rigs/kenwood/ts590.c index 84903494c..f38b46418 100644 --- a/rigs/kenwood/ts590.c +++ b/rigs/kenwood/ts590.c @@ -326,7 +326,7 @@ static int ts590_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) char cmd[32], ackbuf[32]; int retval; - if (vfo == RIG_VFO_CURR) { vfo = rig->state.current_vfo; } + if (vfo == RIG_VFO_CURR) { vfo = STATE(rig)->current_vfo; } if (vfo == RIG_VFO_TX || vfo == RIG_VFO_RX) { vfo = vfo_fixup(rig, vfo, CACHE(rig)->split); } @@ -541,7 +541,7 @@ static int ts590_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) static int ts590_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; char levelbuf[16]; int kenwood_val; int result; @@ -731,7 +731,7 @@ static int ts590_read_meters(RIG *rig, int *swr, int *comp, int *alc) static int ts590_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; char ackbuf[50]; size_t ack_len, ack_len_expected; int levelint = 0; @@ -1148,7 +1148,7 @@ static int ts590_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { int retval; char buf[7]; - struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_data *priv = STATE(rig)->priv; ENTERFUNC; diff --git a/rigs/kenwood/tx500.c b/rigs/kenwood/tx500.c index f8b8184f0..43d422b32 100644 --- a/rigs/kenwood/tx500.c +++ b/rigs/kenwood/tx500.c @@ -854,7 +854,7 @@ int ts2000_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) if (lvl > 9) { - val->i = rig->state.preamp[0]; + val->i = STATE(rig)->preamp[0]; } break; @@ -885,7 +885,7 @@ int ts2000_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) if (lvl > 99) { - val->i = rig->state.attenuator[0]; /* Since the TS-2000 only has one step on the attenuator */ + val->i = STATE(rig)->attenuator[0]; /* Since the TS-2000 only has one step on the attenuator */ } break; diff --git a/rigs/kenwood/xg3.c b/rigs/kenwood/xg3.c index e8c8526fc..271bebca2 100644 --- a/rigs/kenwood/xg3.c +++ b/rigs/kenwood/xg3.c @@ -197,12 +197,12 @@ int xg3_init(RIG *rig) return -RIG_ENOMEM; } - rig->state.priv = (void *)priv; + STATE(rig)->priv = (void *)priv; RIGPORT(rig)->type.rig = RIG_PORT_SERIAL; // Tried set_trn to turn transceiver on/off but turning it on isn't enabled in hamlib for some reason // So we use PTT instead -// rig->state.transceive = RIG_TRN_RIG; // this allows xg3_set_trn to be called - rig->state.current_vfo = RIG_VFO_A; +// STATE(rig)->transceive = RIG_TRN_RIG; // this allows xg3_set_trn to be called + STATE(rig)->current_vfo = RIG_VFO_A; // priv->last_vfo = RIG_VFO_A; // priv->ptt = RIG_PTT_ON; // priv->powerstat = RIG_POWER_ON; @@ -352,7 +352,7 @@ int xg3_get_vfo(RIG *rig, vfo_t *vfo) return -RIG_EINVAL; } - *vfo = rig->state.current_vfo; // VFOA or MEM + *vfo = STATE(rig)->current_vfo; // VFOA or MEM return RIG_OK; } @@ -372,7 +372,7 @@ int xg3_set_vfo(RIG *rig, vfo_t vfo) // We don't actually set the vfo on the XG3 // But we need this so we can set frequencies on the band buttons - rig->state.current_vfo = vfo; + STATE(rig)->current_vfo = vfo; return RIG_OK; } @@ -388,7 +388,7 @@ int xg3_set_freq(RIG *rig, vfo_t vfo, freq_t freq) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); tvfo = (vfo == RIG_VFO_CURR || - vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; + vfo == RIG_VFO_VFO) ? STATE(rig)->current_vfo : vfo; switch (tvfo) { @@ -440,7 +440,7 @@ int xg3_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) } tvfo = (vfo == RIG_VFO_CURR || - vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; + vfo == RIG_VFO_VFO) ? STATE(rig)->current_vfo : vfo; rp = RIGPORT(rig); switch (tvfo) From 295ad7475762ab2a4b0d8eb0923e3e255ae84500 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Tue, 26 Mar 2024 02:04:53 -0400 Subject: [PATCH 5/6] Add macros for amplifier and rotator state pointers. --- include/hamlib/rig.h | 6 ++++++ src/amp_conf.c | 4 ++-- src/amp_settings.c | 4 ++-- src/amplifier.c | 24 +++++++++++++----------- src/rot_conf.c | 6 +++--- src/rot_settings.c | 14 +++++++------- src/rotator.c | 42 ++++++++++++++++++++++-------------------- 7 files changed, 55 insertions(+), 45 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 7f3607bcf..9ecb99d46 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2491,6 +2491,8 @@ typedef hamlib_port_t port_t; #define ROTPORT(r) (&r->state.rotport) #define ROTPORT2(r) (&r->state.rotport2) #define STATE(r) (&r->state) +#define AMPSTATE(a) (&(a)->state) +#define ROTSTATE(r) (&(r)->state) /* 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 @@ -2506,6 +2508,8 @@ typedef hamlib_port_t port_t; #define HAMLIB_ROTPORT(r) ((hamlib_port_t *)rot_data_pointer(r, RIG_PTRX_ROTPORT)) #define HAMLIB_ROTPORT2(r) ((hamlib_port_t *)rot_data_pointer(r, RIG_PTRX_ROTPORT2)) #define HAMLIB_STATE(r) ((struct rig_state *)rig_data_pointer(r, RIG_PTRX_STATE)) +#define HAMLIB_AMPSTATE(a) ((struct amp_state *)amp_data_pointer(a, RIG_PTRX_AMPSTATE)) +#define HAMLIB_ROTSTATE(r) ((struct rot_state *)rot_data_pointer(r, RIG_PTRX_ROTSTATE)) #endif typedef enum { @@ -2518,6 +2522,8 @@ typedef enum { RIG_PTRX_ROTPORT, RIG_PTRX_ROTPORT2, RIG_PTRX_STATE, + RIG_PTRX_AMPSTATE, + RIG_PTRX_ROTSTATE, // New entries go directly above this line==================== RIG_PTRX_MAXIMUM } rig_ptrx_t; diff --git a/src/amp_conf.c b/src/amp_conf.c index e6a734a5a..434c9e72d 100644 --- a/src/amp_conf.c +++ b/src/amp_conf.c @@ -44,7 +44,7 @@ /* - * Configuration options available in the amp->state struct. + * Configuration options available in the amp_state struct. */ static const struct confparams ampfrontend_cfg_params[] = { @@ -112,7 +112,7 @@ int frontamp_set_conf(AMP *amp, hamlib_token_t token, const char *val) hamlib_port_t *ampp = AMPPORT(amp); int val_i; - rs = &->state; + rs = AMPSTATE(amp); amp_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); diff --git a/src/amp_settings.c b/src/amp_settings.c index ffd399c23..749c42904 100644 --- a/src/amp_settings.c +++ b/src/amp_settings.c @@ -75,7 +75,7 @@ setting_t HAMLIB_API amp_has_set_level(AMP *amp, setting_t level) return 0; } - return (amp->state.has_set_level & level); + return (AMPSTATE(amp)->has_set_level & level); } /** @@ -108,7 +108,7 @@ setting_t HAMLIB_API amp_has_get_level(AMP *amp, setting_t level) return 0; } - return (amp->state.has_get_level & level); + return (AMPSTATE(amp)->has_get_level & level); } /*! @} */ diff --git a/src/amplifier.c b/src/amplifier.c index 896f71f9c..aa41d650c 100644 --- a/src/amplifier.c +++ b/src/amplifier.c @@ -65,7 +65,7 @@ #include "token.h" //! @cond Doxygen_Suppress -#define CHECK_AMP_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state) +#define CHECK_AMP_ARG(r) (!(r) || !(r)->caps || !AMPSTATE(r)->comm_state) //! @endcond /* @@ -224,7 +224,7 @@ AMP *HAMLIB_API amp_init(amp_model_t amp_model) /** * \todo Read the Preferences here! */ - rs = &->state; + rs = AMPSTATE(amp); //TODO allocate and link new ampport // For now, use the embedded one @@ -285,8 +285,8 @@ AMP *HAMLIB_API amp_init(amp_model_t amp_model) // Now we have to copy our new rig state hamlib_port structure to the deprecated one // Clients built on older 4.X versions will use the old structure // Clients built on newer 4.5 versions will use the new structure - memcpy(&->state.ampport_deprecated, ap, - sizeof(amp->state.ampport_deprecated)); + memcpy(&rs->ampport_deprecated, ap, + sizeof(rs->ampport_deprecated)); return amp; } @@ -324,7 +324,7 @@ int HAMLIB_API amp_open(AMP *amp) } caps = amp->caps; - rs = &->state; + rs = AMPSTATE(amp); if (rs->comm_state) { @@ -419,8 +419,8 @@ int HAMLIB_API amp_open(AMP *amp) if (status != RIG_OK) { - memcpy(&->state.ampport_deprecated, ap, - sizeof(amp->state.ampport_deprecated)); + memcpy(&rs->ampport_deprecated, ap, + sizeof(rs->ampport_deprecated)); return status; } } @@ -443,8 +443,8 @@ int HAMLIB_API amp_open(AMP *amp) ser_set_rts(ap, 0); } - memcpy(&->state.ampport_deprecated, ap, - sizeof(amp->state.ampport_deprecated)); + memcpy(&rs->ampport_deprecated, ap, + sizeof(rs->ampport_deprecated)); return RIG_OK; } @@ -488,7 +488,7 @@ int HAMLIB_API amp_close(AMP *amp) } caps = amp->caps; - rs = &->state; + rs = AMPSTATE(amp); if (!rs->comm_state) { @@ -571,7 +571,7 @@ int HAMLIB_API amp_cleanup(AMP *amp) /* * check if they forgot to close the amp */ - if (amp->state.comm_state) + if (AMPSTATE(amp)->comm_state) { amp_close(amp); } @@ -969,6 +969,8 @@ void * HAMLIB_API amp_data_pointer(AMP *amp, rig_ptrx_t idx) { case RIG_PTRX_AMPPORT: return AMPPORT(amp); + case RIG_PTRX_AMPSTATE: + return AMPSTATE(amp); default: amp_debug(RIG_DEBUG_ERR, "%s: Invalid data index=%d\n", __func__, idx); return NULL; diff --git a/src/rot_conf.c b/src/rot_conf.c index 89a616382..6d96b4be9 100644 --- a/src/rot_conf.c +++ b/src/rot_conf.c @@ -45,7 +45,7 @@ /* - * Configuration options available in the rot->state struct. + * Configuration options available in the rot_state struct. */ static const struct confparams rotfrontend_cfg_params[] = { @@ -143,7 +143,7 @@ int frontrot_set_conf(ROT *rot, hamlib_token_t token, const char *val) hamlib_port_t *rotp = ROTPORT(rot); int val_i; - rs = &rot->state; + rs = ROTSTATE(rot); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -412,7 +412,7 @@ int frontrot_get_conf(ROT *rot, hamlib_token_t token, char *val, int val_len) hamlib_port_t *rotp = ROTPORT(rot); const char *s; - rs = &rot->state; + rs = ROTSTATE(rot); rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); diff --git a/src/rot_settings.c b/src/rot_settings.c index a75c55844..bee4a8f29 100644 --- a/src/rot_settings.c +++ b/src/rot_settings.c @@ -47,7 +47,7 @@ #ifndef DOC_HIDDEN -# define CHECK_ROT_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state) +# define CHECK_ROT_ARG(r) (!(r) || !(r)->caps || !(ROTSTATE(r)->comm_state)) #endif /* !DOC_HIDDEN */ @@ -255,7 +255,7 @@ setting_t HAMLIB_API rot_has_get_level(ROT *rot, setting_t level) return 0; } - return (rot->state.has_get_level & level); + return (ROTSTATE(rot)->has_get_level & level); } @@ -293,7 +293,7 @@ setting_t HAMLIB_API rot_has_set_level(ROT *rot, setting_t level) return 0; } - return (rot->state.has_set_level & level); + return (ROTSTATE(rot)->has_set_level & level); } @@ -330,7 +330,7 @@ setting_t HAMLIB_API rot_has_get_parm(ROT *rot, setting_t parm) return 0; } - return (rot->state.has_get_parm & parm); + return (ROTSTATE(rot)->has_get_parm & parm); } @@ -367,7 +367,7 @@ setting_t HAMLIB_API rot_has_set_parm(ROT *rot, setting_t parm) return 0; } - return (rot->state.has_set_parm & parm); + return (ROTSTATE(rot)->has_set_parm & parm); } @@ -404,7 +404,7 @@ setting_t HAMLIB_API rot_has_get_func(ROT *rot, setting_t func) return 0; } - return (rot->state.has_get_func & func); + return (ROTSTATE(rot)->has_get_func & func); } @@ -440,7 +440,7 @@ setting_t HAMLIB_API rot_has_set_func(ROT *rot, setting_t func) return 0; } - return (rot->state.has_set_func & func); + return (ROTSTATE(rot)->has_set_func & func); } diff --git a/src/rotator.c b/src/rotator.c index b1db5c478..166fe7a6a 100644 --- a/src/rotator.c +++ b/src/rotator.c @@ -89,7 +89,7 @@ # define DEFAULT_PARALLEL_PORT "/dev/parport0" #endif -#define CHECK_ROT_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state) +#define CHECK_ROT_ARG(r) (!(r) || !(r)->caps || !(ROTSTATE(r)->comm_state)) /* @@ -258,7 +258,7 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model) /** * \todo Read the Preferences here! */ - rs = &rot->state; + rs = ROTSTATE(rot); //TODO Allocate new rotport[2] // For now, use the embedded ones @@ -345,8 +345,8 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model) // Now we have to copy our new rig state hamlib_port structure to the deprecated one // Clients built on older 4.X versions will use the old structure // Clients built on newer 4.5 versions will use the new structure - memcpy(&rot->state.rotport_deprecated, rotp, - sizeof(rot->state.rotport_deprecated)); + memcpy(&rs->rotport_deprecated, rotp, + sizeof(rs->rotport_deprecated)); return rot; } @@ -386,7 +386,7 @@ int HAMLIB_API rot_open(ROT *rot) } caps = rot->caps; - rs = &rot->state; + rs = ROTSTATE(rot); if (rs->comm_state) { @@ -520,8 +520,8 @@ int HAMLIB_API rot_open(ROT *rot) if (status != RIG_OK) { - memcpy(&rot->state.rotport_deprecated, rotp, - sizeof(rot->state.rotport_deprecated)); + memcpy(&rs->rotport_deprecated, rotp, + sizeof(rs->rotport_deprecated)); return status; } } @@ -544,8 +544,8 @@ int HAMLIB_API rot_open(ROT *rot) ser_set_rts(rotp, 0); } - memcpy(&rot->state.rotport_deprecated, rotp, - sizeof(rot->state.rotport_deprecated)); + memcpy(&rs->rotport_deprecated, rotp, + sizeof(rs->rotport_deprecated)); return RIG_OK; } @@ -580,7 +580,7 @@ int HAMLIB_API rot_close(ROT *rot) } caps = rot->caps; - rs = &rot->state; + rs = ROTSTATE(rot); if (!rs->comm_state) { @@ -632,8 +632,8 @@ int HAMLIB_API rot_close(ROT *rot) rs->comm_state = 0; - memcpy(&rot->state.rotport_deprecated, rotp, - sizeof(rot->state.rotport_deprecated)); + memcpy(&rs->rotport_deprecated, rotp, + sizeof(rs->rotport_deprecated)); return RIG_OK; } @@ -667,7 +667,7 @@ int HAMLIB_API rot_cleanup(ROT *rot) /* * check if they forgot to close the rot */ - if (rot->state.comm_state) + if (ROTSTATE(rot)->comm_state) { rot_close(rot); } @@ -726,11 +726,11 @@ int HAMLIB_API rot_set_position(ROT *rot, return -RIG_EINVAL; } - azimuth += rot->state.az_offset; - elevation += rot->state.el_offset; - caps = rot->caps; - rs = &rot->state; + rs = ROTSTATE(rot); + + azimuth += rs->az_offset; + elevation += rs->el_offset; rot_debug(RIG_DEBUG_VERBOSE, "%s: south_zero=%d \n", __func__, rs->south_zero); @@ -801,7 +801,7 @@ int HAMLIB_API rot_get_position(ROT *rot, } caps = rot->caps; - rs = &rot->state; + rs = ROTSTATE(rot); if (caps->get_position == NULL) { @@ -820,8 +820,8 @@ int HAMLIB_API rot_get_position(ROT *rot, rot_debug(RIG_DEBUG_VERBOSE, "%s: south adj to az=%.2f\n", __func__, az); } - *azimuth = az - rot->state.az_offset; - *elevation = el - rot->state.el_offset; + *azimuth = az - rs->az_offset; + *elevation = el - rs->el_offset; return RIG_OK; } @@ -1057,6 +1057,8 @@ void * HAMLIB_API rot_data_pointer(ROT *rot, rig_ptrx_t idx) return ROTPORT(rot); case RIG_PTRX_ROTPORT2: return ROTPORT2(rot); + case RIG_PTRX_ROTSTATE: + return ROTSTATE(rot); default: rot_debug(RIG_DEBUG_ERR, "%s: Invalid data index=%d\n", __func__, idx); return NULL; From 9f997d799d7c132b5d7c0d18f85785bad5141595 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Thu, 28 Mar 2024 16:26:21 -0400 Subject: [PATCH 6/6] Fix incorrect port read for elevation Add missing port parameters for rotp2 Remove funky character(^B) from simrotorez.c so `file` and `more` think it is plain text. Dunno if this works on the real H/W, but at least the simulator can get and set az/el position without errors. --- rotators/rotorez/rotorez.c | 2 +- simulators/simrotorez.c | 2 +- src/rotator.c | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rotators/rotorez/rotorez.c b/rotators/rotorez/rotorez.c index ec4e559ca..819675870 100644 --- a/rotators/rotorez/rotorez.c +++ b/rotators/rotorez/rotorez.c @@ -667,7 +667,7 @@ static int rotorez_rot_get_position(ROT *rot, azimuth_t *azimuth, //TODO: Should this be rotp or rotp2???? //err = read_block(&rs->rotport, (unsigned char *) az, AZ_READ_LEN); - err = read_block(rotp, (unsigned char *) az, AZ_READ_LEN); + err = read_block(rotp2, (unsigned char *) az, AZ_READ_LEN); if (err != AZ_READ_LEN) { diff --git a/simulators/simrotorez.c b/simulators/simrotorez.c index aa1ebc6ea..95f21262f 100644 --- a/simulators/simrotorez.c +++ b/simulators/simrotorez.c @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) int flag = 0; while (1) - { + { int bytes; if (!flag) bytes = getmyline(fd, buf); else bytes = getmyline(fd2, buf); diff --git a/src/rotator.c b/src/rotator.c index 166fe7a6a..5dd492b18 100644 --- a/src/rotator.c +++ b/src/rotator.c @@ -266,12 +266,12 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model) rotp2 = ROTPORT2(rot); rs->comm_state = 0; - rotp->type.rig = caps->port_type; /* default from caps */ + rotp->type.rig = rotp2->type.rig = caps->port_type; /* default from caps */ - rotp->write_delay = caps->write_delay; - rotp->post_write_delay = caps->post_write_delay; - rotp->timeout = caps->timeout; - rotp->retry = caps->retry; + rotp->write_delay = rotp2->write_delay = caps->write_delay; + rotp->post_write_delay = rotp2->post_write_delay = caps->post_write_delay; + rotp->timeout = rotp2->timeout = caps->timeout; + rotp->retry = rotp2->retry = caps->retry; switch (caps->port_type) {