Merge pull request #1573 from GeoBaltz/rp12

More conversion to pointers
This commit is contained in:
Michael Black 2024-07-02 17:25:29 -05:00 committed by GitHub
commit f98fc86f93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 482 additions and 400 deletions

View File

@ -28,31 +28,32 @@ int commradio_transaction(RIG *rig, const unsigned char *cmd, int cmd_len,
{
int ret = -RIG_EINTERNAL;
struct rig_state *rs;
hamlib_port_t *rp = RIGPORT(rig);
ENTERFUNC;
rs = &rig->state;
rs = STATE(rig);
rs->transaction_active = 1;
/*
* Flush is needed until async mode is done. The CTX-10 sends frames every
* time the VFO changes.
*/
rig_flush(&rs->rigport);
rig_flush(rp);
int frame_len;
unsigned char frame[3+2*(cmd_len+2)];
size_t rx_len = CR_FRAMELENGTH;
unsigned char rx[rx_len];
frame_len = frame_message(frame, cmd, cmd_len);
ret = write_block(&rs->rigport, frame, frame_len);
ret = write_block(rp, frame, frame_len);
if (ret < RIG_OK)
{
goto transaction_quit;
}
const char stopset[] = { CR_EOF };
ret = read_string(&rs->rigport, rx, rx_len-1, stopset, 1, 0, 1);
ret = read_string(rp, rx, rx_len-1, stopset, 1, 0, 1);
if (ret < RIG_OK)
{
goto transaction_quit;

View File

@ -353,7 +353,7 @@ static int pstrotator_rot_close(ROT *rot)
priv = (struct pstrotator_rot_priv_data *)ROTSTATE(rot)->priv;
pstrotator_handler_priv_data *pstrotator_handler_priv;
pstrotator_handler_priv = (pstrotator_handler_priv_data *)
rot->state.pstrotator_handler_priv_data;
ROTSTATE(rot)->pstrotator_handler_priv_data;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);

View File

@ -793,7 +793,7 @@ int tt565_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
char ttmode, ttreceiver;
int retry;
int timeout;
int widthOld = rig->state.cache.widthMainA;
int widthOld = CACHE(rig)->widthMainA;
struct rig_state *rs = STATE(rig);
ttreceiver = which_receiver(rig, vfo);

View File

@ -403,8 +403,8 @@ static int pmr171_init(RIG *rig)
return -RIG_ENOMEM;
}
rig->state.cache.freqMainA = 14999000;
rig->state.cache.freqMainB = 14999000;
CACHE(rig)->freqMainA = 14999000;
CACHE(rig)->freqMainB = 14999000;
return RIG_OK;
}
@ -475,7 +475,7 @@ static int pmr171_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
// probably already read VFO_A so just return cache for VFO_B for now
if (vfo == RIG_VFO_B)
{
*freq = rig->state.cache.freqMainB;
*freq = cachep->freqMainB;
return RIG_OK;
}
@ -484,16 +484,16 @@ static int pmr171_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
read_block(rp, &reply[5], reply[4]);
vfoa = from_bcd_be(&reply[9], 8);
vfob = from_bcd_be(&reply[13], 8);
rig->state.cache.freqMainA = vfoa;
rig->state.cache.freqMainB = vfob;
cachep->freqMainA = vfoa;
cachep->freqMainB = vfob;
rig_debug(RIG_DEBUG_VERBOSE, "%s: vfoa=%.0f, vfob=%.0f\n", __func__, vfoa,
vfob);
// Now grab the ptt status
rig->state.cache.ptt = reply[6] == 1;
cachep->ptt = reply[6] == 1;
// And the mode
rig->state.cache.modeMainA = pmr171_modes[reply[7]];
rig->state.cache.modeMainB = pmr171_modes[reply[8]];
cachep->modeMainA = pmr171_modes[reply[7]];
cachep->modeMainB = pmr171_modes[reply[8]];
if (vfo == RIG_VFO_B) { *freq = cachep->freqMainA; }
else { *freq = cachep->freqMainB; }
@ -514,7 +514,7 @@ static int pmr171_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
static int pmr171_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo)
{
*split = rig->state.cache.split;
*split = CACHE(rig)->split;
if (*split) *tx_vfo=RIG_VFO_B;
else *tx_vfo = RIG_VFO_A;
return RIG_OK;
@ -524,7 +524,7 @@ static int pmr171_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
{
//struct pmr171_priv_data *p = (struct pmr171_priv_data *) STATE(rig)->priv;
rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__);
*ptt = rig->state.cache.ptt;
*ptt = CACHE(rig)->ptt;
return RIG_OK;
}
@ -795,13 +795,13 @@ static int pmr171_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
/* fill in the frequency */
if (vfo == RIG_VFO_B)
{
to_bcd_be(&cmd[6], rig->state.cache.freqMainA, 8);
to_bcd_be(&cmd[6], CACHE(rig)->freqMainA, 8);
to_bcd_be(&cmd[10], freq, 8);
}
else
{
to_bcd_be(&cmd[6], freq, 8);
to_bcd_be(&cmd[10], rig->state.cache.freqMainB, 8);
to_bcd_be(&cmd[10], CACHE(rig)->freqMainB, 8);
}
unsigned int crc = CRC16Check(&cmd[4], 12);
@ -828,13 +828,13 @@ static int pmr171_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
{
if (vfo == RIG_VFO_B)
{
cmd[6] = rig->state.cache.modeMainA;
cmd[6] = CACHE(rig)->modeMainA;
cmd[7] = i;
}
else
{
cmd[6] = i;
cmd[7] = rig->state.cache.modeMainB;
cmd[7] = CACHE(rig)->modeMainB;
}
crc = CRC16Check(&cmd[4], 4);

View File

@ -24,7 +24,7 @@
#include "cache.h"
#include "misc.h"
#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state)
#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !STATE(r)->comm_state)
/**
* \file cache.c
@ -35,6 +35,7 @@
int rig_set_cache_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
{
struct rig_cache *cachep = CACHE(rig);
struct rig_state *rs = STATE(rig);
ENTERFUNC;
@ -43,16 +44,16 @@ int rig_set_cache_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
if (vfo == RIG_VFO_CURR)
{
// if CURR then update this before we figure out the real VFO
vfo = rig->state.current_vfo;
vfo = rs->current_vfo;
}
else if (vfo == RIG_VFO_TX)
{
vfo = rig->state.tx_vfo;
vfo = rs->tx_vfo;
rig_debug(RIG_DEBUG_VERBOSE, "%s: TX VFO = %s\n", __func__, rig_strvfo(vfo));
}
else if (vfo == RIG_VFO_RX)
{
vfo = rig->state.rx_vfo;
vfo = rs->rx_vfo;
rig_debug(RIG_DEBUG_VERBOSE, "%s: RX VFO = %s\n", __func__, rig_strvfo(vfo));
}
@ -63,7 +64,7 @@ int rig_set_cache_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
if (vfo == RIG_VFO_OTHER) { vfo = vfo_fixup(rig, vfo, cachep->split); }
if (vfo == rig->state.current_vfo)
if (vfo == rs->current_vfo)
{
cachep->modeCurr = mode;
if (width > 0)
@ -157,6 +158,7 @@ int rig_set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq)
{
int flag = HAMLIB_ELAPSED_SET;
struct rig_cache *cachep = CACHE(rig);
struct rig_state *rs = STATE(rig);
if (rig_need_debug(RIG_DEBUG_CACHE))
{
@ -165,12 +167,12 @@ int rig_set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq)
rig_debug(RIG_DEBUG_CACHE, "%s(%d): vfo=%s, current_vfo=%s\n", __func__,
__LINE__,
rig_strvfo(vfo), rig_strvfo(rig->state.current_vfo));
rig_strvfo(vfo), rig_strvfo(rs->current_vfo));
if (vfo == RIG_VFO_CURR)
{
// if CURR then update this before we figure out the real VFO
vfo = rig->state.current_vfo;
vfo = rs->current_vfo;
}
// if freq == 0 then we are asking to invalidate the cache
@ -188,7 +190,7 @@ int rig_set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq)
rig_strvfo(vfo), freq);
}
if (vfo == rig->state.current_vfo)
if (vfo == rs->current_vfo)
{
cachep->freqCurr = freq;
elapsed_ms(&cachep->time_freqCurr, flag);
@ -307,6 +309,7 @@ int rig_get_cache(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms_freq,
rmode_t *mode, int *cache_ms_mode, pbwidth_t *width, int *cache_ms_width)
{
struct rig_cache *cachep = CACHE(rig);
struct rig_state *rs = STATE(rig);
if (CHECK_RIG_ARG(rig) || !freq || !cache_ms_freq ||
!mode || !cache_ms_mode || !width || !cache_ms_width)
@ -321,25 +324,25 @@ int rig_get_cache(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms_freq,
rig_debug(RIG_DEBUG_CACHE, "%s(%d): vfo=%s, current_vfo=%s\n", __func__,
__LINE__,
rig_strvfo(vfo), rig_strvfo(rig->state.current_vfo));
rig_strvfo(vfo), rig_strvfo(rs->current_vfo));
if (vfo == RIG_VFO_CURR)
{
vfo = rig->state.current_vfo;
vfo = rs->current_vfo;
}
else if (vfo == RIG_VFO_TX)
{
vfo = rig->state.tx_vfo;
vfo = rs->tx_vfo;
rig_debug(RIG_DEBUG_VERBOSE, "%s: TX VFO = %s\n", __func__, rig_strvfo(vfo));
}
else if (vfo == RIG_VFO_RX)
{
vfo = rig->state.rx_vfo;
vfo = rs->rx_vfo;
rig_debug(RIG_DEBUG_VERBOSE, "%s: RX VFO = %s\n", __func__, rig_strvfo(vfo));
}
else if (vfo == RIG_VFO_OTHER)
{
switch (rig->state.current_vfo)
switch (rs->current_vfo)
{
case RIG_VFO_CURR:
break; // no change
@ -384,7 +387,7 @@ int rig_get_cache(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms_freq,
default:
rig_debug(RIG_DEBUG_WARN, "%s(%d): unknown vfo=%s, curr_vfo=%s\n", __func__,
__LINE__,
rig_strvfo(vfo), rig_strvfo(rig->state.current_vfo));
rig_strvfo(vfo), rig_strvfo(rs->current_vfo));
}
}
@ -574,7 +577,7 @@ void rig_cache_show(RIG *rig, const char *func, int line)
cachep->freqMainB, rig_strrmode(cachep->modeMainB),
(int)cachep->widthMainB);
if (rig->state.vfo_list & RIG_VFO_SUB_A)
if (STATE(rig)->vfo_list & RIG_VFO_SUB_A)
{
rig_debug(RIG_DEBUG_CACHE,
"%s(%d): freqSubA=%.0f, modeSubA=%s, widthSubA=%d\n", func, line,

View File

@ -42,7 +42,7 @@
/*
* Configuration options available in the rig->state struct.
* Configuration options available in the STATE(rig) struct.
*/
static const struct confparams frontend_cfg_params[] =
{
@ -255,7 +255,7 @@ static int frontend_set_conf(RIG *rig, hamlib_token_t token, const char *val)
long val_i;
caps = rig->caps;
rs = &rig->state;
rs = STATE(rig);
switch (token)
{
@ -276,8 +276,9 @@ static int frontend_set_conf(RIG *rig, hamlib_token_t token, const char *val)
}
sprintf(rs->rigport_deprecated.pathname, "%s:%s", val2, "4992");
strcpy(rs->rigport.pathname, rs->rigport_deprecated.pathname);
rig_debug(RIG_DEBUG_WARN, "%s: pathname=%s\n", __func__, rs->rigport.pathname);
strcpy(rp->pathname, rs->rigport_deprecated.pathname);
rig_debug(RIG_DEBUG_WARN, "%s: pathname=%s\n", __func__, rp->pathname);
free(val2);
}
else
@ -606,7 +607,6 @@ static int frontend_set_conf(RIG *rig, hamlib_token_t token, const char *val)
}
// JTDX and WSJTX currently use state.pttport to check for PTT_NONE
// rig->state.pttport.type.ptt = pttp->type.ptt;
rs->pttport_deprecated.type.ptt = pttp->type.ptt;
break;
@ -896,7 +896,7 @@ static int frontend_get_conf2(RIG *rig, hamlib_token_t token, char *val,
hamlib_port_t *pttp = PTTPORT(rig);
hamlib_port_t *dcdp = DCDPORT(rig);
rs = &rig->state;
rs = STATE(rig);
switch (token)
{

View File

@ -50,7 +50,7 @@
#include "cache.h"
#include "network.h"
#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state)
#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !STATE(r)->comm_state)
#ifdef HAVE_PTHREAD
typedef struct rig_poll_routine_args_s
@ -68,7 +68,7 @@ void *rig_poll_routine(void *arg)
{
rig_poll_routine_args *args = (rig_poll_routine_args *)arg;
RIG *rig = args->rig;
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
struct rig_cache *cachep = CACHE(rig);
int update_occurred;
@ -98,15 +98,15 @@ void *rig_poll_routine(void *arg)
while (rs->poll_routine_thread_run)
{
if (rig->state.current_vfo != vfo)
if (rs->current_vfo != vfo)
{
vfo = rig->state.current_vfo;
vfo = rs->current_vfo;
update_occurred = 1;
}
if (rig->state.tx_vfo != tx_vfo)
if (rs->tx_vfo != tx_vfo)
{
tx_vfo = rig->state.tx_vfo;
tx_vfo = rs->tx_vfo;
update_occurred = 1;
}
@ -266,7 +266,7 @@ void *rig_poll_routine(void *arg)
*/
int rig_poll_routine_start(RIG *rig)
{
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
rig_poll_routine_priv_data *poll_routine_priv;
ENTERFUNC;
@ -321,7 +321,7 @@ int rig_poll_routine_start(RIG *rig)
*/
int rig_poll_routine_stop(RIG *rig)
{
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
rig_poll_routine_priv_data *poll_routine_priv;
ENTERFUNC;
@ -614,6 +614,7 @@ int rig_fire_freq_event(RIG *rig, vfo_t vfo, freq_t freq)
{
ENTERFUNC;
struct rig_state *rs = STATE(rig);
double dfreq = freq;
rig_debug(RIG_DEBUG_TRACE, "Event: freq changed to %.0f Hz on %s\n",
dfreq, rig_strvfo(vfo));
@ -624,19 +625,19 @@ int rig_fire_freq_event(RIG *rig, vfo_t vfo, freq_t freq)
// Should work for most other rigs using AI1; mode
if (RIG_BACKEND_NUM(rig->caps->rig_model) != RIG_ICOM)
{
rig->state.use_cached_freq = 1;
rs->use_cached_freq = 1;
}
if (rig->state.freq_event_elapsed.tv_sec == 0)
if (rs->freq_event_elapsed.tv_sec == 0)
{
elapsed_ms(&rig->state.freq_event_elapsed, HAMLIB_ELAPSED_SET);
elapsed_ms(&rs->freq_event_elapsed, HAMLIB_ELAPSED_SET);
}
double e = elapsed_ms(&rig->state.freq_event_elapsed, HAMLIB_ELAPSED_GET);
double e = elapsed_ms(&rs->freq_event_elapsed, HAMLIB_ELAPSED_GET);
if (e >= 250) // throttle events to 4 per sec
{
elapsed_ms(&rig->state.freq_event_elapsed, HAMLIB_ELAPSED_SET);
elapsed_ms(&rs->freq_event_elapsed, HAMLIB_ELAPSED_SET);
network_publish_rig_transceive_data(rig);
if (rig->callbacks.freq_event)
@ -663,7 +664,7 @@ int rig_fire_mode_event(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
// Should work for most other rigs using AI1; mode
if (RIG_BACKEND_NUM(rig->caps->rig_model) != RIG_ICOM)
{
rig->state.use_cached_mode = 1;
STATE(rig)->use_cached_mode = 1;
}
network_publish_rig_transceive_data(rig);

View File

@ -44,7 +44,7 @@
#ifndef DOC_HIDDEN
#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state)
#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !STATE(r)->comm_state)
#endif /* !DOC_HIDDEN */
@ -87,7 +87,7 @@ int HAMLIB_API rig_set_mem(RIG *rig, vfo_t vfo, int ch)
if ((caps->targetable_vfo & RIG_TARGETABLE_MEM)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == STATE(rig)->current_vfo)
{
return caps->set_mem(rig, vfo, ch);
}
@ -97,7 +97,7 @@ int HAMLIB_API rig_set_mem(RIG *rig, vfo_t vfo, int ch)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = STATE(rig)->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -150,7 +150,7 @@ int HAMLIB_API rig_get_mem(RIG *rig, vfo_t vfo, int *ch)
if ((caps->targetable_vfo & RIG_TARGETABLE_MEM)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == STATE(rig)->current_vfo)
{
return caps->get_mem(rig, vfo, ch);
}
@ -160,7 +160,7 @@ int HAMLIB_API rig_get_mem(RIG *rig, vfo_t vfo, int *ch)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = STATE(rig)->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -213,7 +213,7 @@ int HAMLIB_API rig_set_bank(RIG *rig, vfo_t vfo, int bank)
if ((caps->targetable_vfo & RIG_TARGETABLE_BANK)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == STATE(rig)->current_vfo)
{
return caps->set_bank(rig, vfo, bank);
}
@ -223,7 +223,7 @@ int HAMLIB_API rig_set_bank(RIG *rig, vfo_t vfo, int bank)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = STATE(rig)->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -727,7 +727,7 @@ int HAMLIB_API rig_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
}
can_emulate_by_vfo_mem = rc->set_vfo
&& ((rig->state.vfo_list & RIG_VFO_MEM) == RIG_VFO_MEM);
&& ((STATE(rig)->vfo_list & RIG_VFO_MEM) == RIG_VFO_MEM);
can_emulate_by_vfo_op = rc->vfo_op
&& rig_has_vfo_op(rig, RIG_OP_FROM_VFO);
@ -737,7 +737,7 @@ int HAMLIB_API rig_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = STATE(rig)->current_vfo;
if (vfotmp == RIG_VFO_MEM)
{
@ -872,7 +872,7 @@ int HAMLIB_API rig_get_channel(RIG *rig, vfo_t vfox, channel_t *chan,
}
can_emulate_by_vfo_mem = rc->set_vfo
&& ((rig->state.vfo_list & RIG_VFO_MEM) == RIG_VFO_MEM);
&& ((STATE(rig)->vfo_list & RIG_VFO_MEM) == RIG_VFO_MEM);
can_emulate_by_vfo_op = rc->vfo_op
&& rig_has_vfo_op(rig, RIG_OP_TO_VFO);
@ -882,7 +882,7 @@ int HAMLIB_API rig_get_channel(RIG *rig, vfo_t vfox, channel_t *chan,
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = STATE(rig)->current_vfo;
if (vfotmp == RIG_VFO_MEM)
{
@ -940,7 +940,7 @@ int get_chan_all_cb_generic(RIG *rig, vfo_t vfo, chan_cb_t chan_cb,
rig_ptr_t arg)
{
int i, j;
chan_t *chan_list = rig->state.chan_list;
chan_t *chan_list = STATE(rig)->chan_list;
channel_t *chan;
for (i = 0; !RIG_IS_CHAN_END(chan_list[i]) && i < HAMLIB_CHANLSTSIZ; i++)
@ -1006,7 +1006,7 @@ int set_chan_all_cb_generic(RIG *rig, vfo_t vfo, chan_cb_t chan_cb,
rig_ptr_t arg)
{
int i, j, retval;
chan_t *chan_list = rig->state.chan_list;
chan_t *chan_list = STATE(rig)->chan_list;
channel_t *chan;
for (i = 0; !RIG_IS_CHAN_END(chan_list[i]) && i < HAMLIB_CHANLSTSIZ; i++)
@ -1600,7 +1600,7 @@ const chan_t *HAMLIB_API rig_lookup_mem_caps(RIG *rig, int ch)
if (ch == RIG_MEM_CAPS_ALL)
{
memset(&chan_list_all, 0, sizeof(chan_list_all));
chan_list = rig->state.chan_list;
chan_list = STATE(rig)->chan_list;
chan_list_all.startc = chan_list[0].startc;
chan_list_all.type = RIG_MTYPE_NONE; /* meaningless */
@ -1626,7 +1626,7 @@ const chan_t *HAMLIB_API rig_lookup_mem_caps(RIG *rig, int ch)
return &chan_list_all;
}
chan_list = rig->state.chan_list;
chan_list = STATE(rig)->chan_list;
for (i = 0; i < HAMLIB_CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++)
{
@ -1661,7 +1661,7 @@ int HAMLIB_API rig_mem_count(RIG *rig)
return -RIG_EINVAL;
}
chan_list = rig->state.chan_list;
chan_list = STATE(rig)->chan_list;
count = 0;
for (i = 0; i < HAMLIB_CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++)

View File

@ -30,11 +30,11 @@
*/
#ifdef HAVE_PTHREAD
#include <pthread.h>
#define set_transaction_active(rig) {pthread_mutex_lock(&rig->state.mutex_set_transaction);(rig)->state.transaction_active = 1;}
#define set_transaction_inactive(rig) {(rig)->state.transaction_active = 0;pthread_mutex_unlock(&rig->state.mutex_set_transaction);}
#define set_transaction_active(rig) {pthread_mutex_lock(&STATE(rig)->mutex_set_transaction);STATE(rig)->transaction_active = 1;}
#define set_transaction_inactive(rig) {STATE(rig)->transaction_active = 0;pthread_mutex_unlock(&STATE(rig)->mutex_set_transaction);}
#else
#define set_transaction_active(rig) {(rig)->state.transaction_active = 1;}
#define set_transaction_inactive(rig) {(rig)->state.transaction_active = 0;}
#define set_transaction_active(rig) {STATE(rig)->transaction_active = 1;}
#define set_transaction_inactive(rig) {STATE(rig)->transaction_active = 0;}
#endif
__BEGIN_DECLS
@ -157,24 +157,24 @@ extern HAMLIB_EXPORT(char *)date_strget(char *buf, int buflen, int localtime);
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
void errmsg(int err, char *s, const char *func, const char *file, int line);
#define ERRMSG(err, s) errmsg(err, s, __func__, __FILENAME__, __LINE__)
#define ENTERFUNC { ++rig->state.depth; \
rig_debug(RIG_DEBUG_VERBOSE, "%s%d:%s(%d):%s entered\n", spaces(rig->state.depth), rig->state.depth, __FILENAME__, __LINE__, __func__); \
#define ENTERFUNC { ++STATE(rig)->depth; \
rig_debug(RIG_DEBUG_VERBOSE, "%s%d:%s(%d):%s entered\n", spaces(STATE(rig)->depth), STATE(rig)->depth, __FILENAME__, __LINE__, __func__); \
}
#define ENTERFUNC2 { rig_debug(RIG_DEBUG_VERBOSE, "%s(%d):%s entered\n", __FILENAME__, __LINE__, __func__); \
}
// we need to refer to rc just once as it
// could be a function call
#define RETURNFUNC(rc) {do { \
int rctmp = rc; \
rig_debug(RIG_DEBUG_VERBOSE, "%s%d:%s(%d):%s returning(%ld) %s\n", spaces(rig->state.depth), rig->state.depth, __FILENAME__, __LINE__, __func__, (long int) (rctmp), rctmp<0?rigerror2(rctmp):""); \
--rig->state.depth; \
return (rctmp); \
} while(0);}
int rctmp = rc; \
rig_debug(RIG_DEBUG_VERBOSE, "%s%d:%s(%d):%s returning(%ld) %s\n", spaces(STATE(rig)->depth), STATE(rig)->depth, __FILENAME__, __LINE__, __func__, (long int) (rctmp), rctmp<0?rigerror2(rctmp):""); \
--STATE(rig)->depth; \
return (rctmp); \
} while(0);}
#define RETURNFUNC2(rc) {do { \
int rctmp = rc; \
rig_debug(RIG_DEBUG_VERBOSE, "%s(%d):%s returning2(%ld) %s\n", __FILENAME__, __LINE__, __func__, (long int) (rctmp), rctmp<0?rigerror2(rctmp):""); \
return (rctmp); \
} while(0);}
int rctmp = rc; \
rig_debug(RIG_DEBUG_VERBOSE, "%s(%d):%s returning2(%ld) %s\n", __FILENAME__, __LINE__, __func__, (long int) (rctmp), rctmp<0?rigerror2(rctmp):""); \
return (rctmp); \
} while(0);}
#define CACHE_RESET {\
elapsed_ms(&CACHE(rig)->time_freqMainA, HAMLIB_ELAPSED_INVALIDATE);\

View File

@ -33,9 +33,10 @@ static struct sockaddr_in dest_addr = {0};
int multicast_stop(RIG *rig)
{
if (rig->state.multicast) { rig->state.multicast->runflag = 0; }
struct rig_state *rs = STATE(rig);
if (rs->multicast) { rs->multicast->runflag = 0; }
pthread_join(rig->state.multicast->threadid, NULL);
pthread_join(rs->multicast->threadid, NULL);
return RIG_OK;
}
@ -44,6 +45,7 @@ static int multicast_status_changed(RIG *rig)
{
int retval;
struct rig_cache *cachep = CACHE(rig);
struct rig_state *rs = STATE(rig);
#if 0
freq_t freq, freqsave = cachep->freqMainA;
@ -63,7 +65,7 @@ static int multicast_status_changed(RIG *rig)
#if 0
if (rig->state.multicast->seqnumber % 2 == 0
if (rs->multicast->seqnumber % 2 == 0
&& (retval = rig_get_mode(rig, RIG_VFO_A, &modeA, &widthA)) != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: rig_get_modeA:%s\n", __func__, rigerror(retval));
@ -77,7 +79,7 @@ static int multicast_status_changed(RIG *rig)
#if 0
if (rig->state.multicast->seqnumber % 2 == 0
if (rs->multicast->seqnumber % 2 == 0
&& (rig->caps->targetable_vfo & RIG_TARGETABLE_MODE)
&& (retval = rig_get_mode(rig, RIG_VFO_B, &modeB, &widthB)) != RIG_OK)
{
@ -94,14 +96,14 @@ static int multicast_status_changed(RIG *rig)
#if 0
if (rig->state.multicast->seqnumber % 2 == 0
if (rs->multicast->seqnumber % 2 == 0
&& (retval = rig_get_ptt(rig, RIG_VFO_CURR, &ptt)) != RIG_OK)
if (ptt != pttsave) { return 1; }
split_t split, splitsave = cachep->split;
vfo_t txvfo;
if (rig->state.multicast->seqnumber % 2 == 0
if (rs->multicast->seqnumber % 2 == 0
&& (retval = rig_get_split_vfo(rig, RIG_VFO_CURR, &split, &txvfo)) != RIG_OK)
if (split != splitsave) { return 1; }
@ -192,6 +194,7 @@ void json_add_time(char *msg, int addComma)
void json_add_vfoA(RIG *rig, char *msg)
{
struct rig_cache *cachep = CACHE(rig);
struct rig_state *rs = STATE(rig);
strcat(msg, "{\n");
json_add_string(msg, "Name", "VFOA", 1);
@ -211,15 +214,15 @@ void json_add_vfoA(RIG *rig, char *msg)
#if 0 // not working quite yet
// what about full duplex? rx_vfo would be in rx all the time?
rig_debug(RIG_DEBUG_ERR, "%s: rx_vfo=%s, tx_vfo=%s, split=%d\n", __func__,
rig_strvfo(rig->state.rx_vfo), rig_strvfo(rig->state.tx_vfo),
rig_strvfo(rs->rx_vfo), rig_strvfo(rs->tx_vfo),
cachep->split);
printf("%s: rx_vfo=%s, tx_vfo=%s, split=%d\n", __func__,
rig_strvfo(rig->state.rx_vfo), rig_strvfo(rig->state.tx_vfo),
rig_strvfo(rs->rx_vfo), rig_strvfo(rs->tx_vfo),
cachep->split);
if (cachep->split)
{
if (rig->state.tx_vfo && (RIG_VFO_B | RIG_VFO_MAIN_B))
if (rs->tx_vfo && (RIG_VFO_B | RIG_VFO_MAIN_B))
{
json_add_boolean(msg, "RX", !cachep->ptt, 1);
json_add_boolean(msg, "TX", 0, 0);
@ -230,7 +233,7 @@ void json_add_vfoA(RIG *rig, char *msg)
json_add_boolean(msg, "TX", cachep->ptt, 0);
}
}
else if (rig->state.current_vfo && (RIG_VFO_A | RIG_VFO_MAIN_A))
else if (rs->current_vfo && (RIG_VFO_A | RIG_VFO_MAIN_A))
{
json_add_boolean(msg, "RX", !cachep->ptt, 1);
json_add_boolean(msg, "TX", cachep->ptt, 0);
@ -248,6 +251,7 @@ void json_add_vfoA(RIG *rig, char *msg)
void json_add_vfoB(RIG *rig, char *msg)
{
struct rig_cache *cachep = CACHE(rig);
struct rig_state *rs = STATE(rig);
strcat(msg, ",\n{\n");
json_add_string(msg, "Name", "VFOB", 1);
@ -266,9 +270,9 @@ void json_add_vfoB(RIG *rig, char *msg)
#if 0 // not working yet
if (rig->state.rx_vfo != rig->state.tx_vfo && cachep->split)
if (rs->rx_vfo != rs->tx_vfo && cachep->split)
{
if (rig->state.tx_vfo && (RIG_VFO_B | RIG_VFO_MAIN_B))
if (rs->tx_vfo && (RIG_VFO_B | RIG_VFO_MAIN_B))
{
json_add_boolean(msg, "RX", 0, 1);
json_add_boolean(msg, "TX", cachep->ptt, 0);
@ -279,7 +283,7 @@ void json_add_vfoB(RIG *rig, char *msg)
json_add_boolean(msg, "TX", 0, 0);
}
}
else if (rig->state.current_vfo && (RIG_VFO_A | RIG_VFO_MAIN_A))
else if (rs->current_vfo && (RIG_VFO_A | RIG_VFO_MAIN_A))
{
json_add_boolean(msg, "RX", !cachep->ptt, 1);
json_add_boolean(msg, "TX", cachep->ptt, 0);
@ -300,7 +304,8 @@ static int multicast_send_json(RIG *rig)
char msg[8192]; // could be pretty big
char buf[4096];
struct rig_cache *cachep = CACHE(rig);
struct rig_state *rs = STATE(rig);
// sprintf(msg,"%s:f=%.1f", date_strget(msg, (int)sizeof(msg), 0), f);
msg[0] = 0;
snprintf(buf, sizeof(buf), "%s:%s", rig->caps->model_name,
@ -308,11 +313,11 @@ static int multicast_send_json(RIG *rig)
strcat(msg, "{\n");
json_add_string(msg, "ID", buf, 1);
json_add_time(msg, 1);
json_add_int(msg, "Sequence", rig->state.multicast->seqnumber++, 1);
json_add_string(msg, "VFOCurr", rig_strvfo(rig->state.current_vfo), 1);
json_add_int(msg, "Sequence", rs->multicast->seqnumber++, 1);
json_add_string(msg, "VFOCurr", rig_strvfo(rs->current_vfo), 1);
json_add_int(msg, "PTT", cachep->ptt, 1);
json_add_int(msg, "Split", cachep->split, 1);
rig_sprintf_mode(buf, sizeof(buf), rig->state.mode_list);
rig_sprintf_mode(buf, sizeof(buf), rs->mode_list);
json_add_string(msg, "ModeList", buf, 1);
strcat(msg, "\"VFOs\": [\n");
json_add_vfoA(rig, msg);
@ -333,17 +338,18 @@ void *multicast_thread_rx(void *vrig)
// int ret = 0;
RIG *rig = (RIG *)vrig;
hamlib_port_t port;
rig->state.rig_type = RIG_TYPE_TRANSCEIVER;
rig->state.ptt_type = RIG_PTT_RIG;
rig->state.port_type = RIG_PORT_UDP_NETWORK;
struct rig_state *rs = STATE(rig);
rs->rig_type = RIG_TYPE_TRANSCEIVER;
rs->ptt_type = RIG_PTT_RIG;
rs->port_type = RIG_PORT_UDP_NETWORK;
strcpy(port.pathname, "127.0.0.1:4532");
//rig_debug(RIG_DEBUG_TRACE, "%s: started\n", __func__);
#if 0
network_open(&port, 4532);
#endif
//while (rig->state.multicast->runflag && ret >= 0)
while (rig->state.multicast->runflag)
//while (rs->multicast->runflag && ret >= 0)
while (rs->multicast->runflag)
{
#if 0
ret = read_string(RIGPORT(rig), (unsigned char *) buf, sizeof(buf), "\n",
@ -377,10 +383,11 @@ void *multicast_thread(void *vrig)
mode_t modeB, modeBsave = 0;
ptt_t ptt, pttsave = 0;
struct rig_cache *cachep = CACHE(rig);
struct rig_state *rs = STATE(rig);
rig->state.multicast->runflag = 1;
rs->multicast->runflag = 1;
while (rig->state.multicast->runflag)
while (rs->multicast->runflag)
{
#if 0
@ -470,7 +477,9 @@ static char *GetWinsockLastError(char *errorBuffer, DWORD errorBufferSize)
int multicast_init(RIG *rig, char *addr, int port)
{
if (rig->state.multicast && rig->state.multicast->multicast_running) { return RIG_OK; }
struct rig_state *rs = STATE(rig);
if (rs->multicast && rs->multicast->multicast_running) { return RIG_OK; }
#ifdef _WIN32
WSADATA wsaData;
@ -485,22 +494,22 @@ int multicast_init(RIG *rig, char *addr, int port)
#endif
if (rig->state.multicast == NULL)
if (rs->multicast == NULL)
{
rig->state.multicast = calloc(1, sizeof(struct multicast_s));
rs->multicast = calloc(1, sizeof(struct multicast_s));
}
else if (rig->state.multicast->multicast_running) { return RIG_OK; } // we only need one port
else if (rs->multicast->multicast_running) { return RIG_OK; } // we only need one port
//rig->state.multicast->mreq = {0};
//rs->multicast->mreq = {0};
if (addr == NULL) { addr = RIG_MULTICAST_ADDR; }
if (port == 0) { port = RIG_MULTICAST_PORT; }
// Create a UDP socket
rig->state.multicast->sock = socket(AF_INET, SOCK_DGRAM, 0);
rs->multicast->sock = socket(AF_INET, SOCK_DGRAM, 0);
if (rig->state.multicast->sock < 0)
if (rs->multicast->sock < 0)
{
#ifdef _WIN32
int err = WSAGetLastError();
@ -515,7 +524,7 @@ int multicast_init(RIG *rig, char *addr, int port)
// Set the SO_REUSEADDR option to allow multiple processes to use the same address
int optval = 1;
if (setsockopt(rig->state.multicast->sock, SOL_SOCKET, SO_REUSEADDR,
if (setsockopt(rs->multicast->sock, SOL_SOCKET, SO_REUSEADDR,
(char *)&optval,
sizeof(optval)) < 0)
{
@ -533,7 +542,7 @@ int multicast_init(RIG *rig, char *addr, int port)
#if 0
if (bind(rig->state.multicast->sock, (struct sockaddr *)&saddr,
if (bind(rs->multicast->sock, (struct sockaddr *)&saddr,
sizeof(saddr)) < 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: bind: %s\n", __func__, strerror(errno));
@ -544,13 +553,13 @@ int multicast_init(RIG *rig, char *addr, int port)
// Construct the multicast group address
// struct ip_mreq mreq = {0};
rig->state.multicast->mreq.imr_multiaddr.s_addr = inet_addr(addr);
rig->state.multicast->mreq.imr_interface.s_addr = htonl(INADDR_ANY);
rs->multicast->mreq.imr_multiaddr.s_addr = inet_addr(addr);
rs->multicast->mreq.imr_interface.s_addr = htonl(INADDR_ANY);
// Set the multicast TTL (time-to-live) to limit the scope of the packets
char ttl = 1;
if (setsockopt(rig->state.multicast->sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl,
if (setsockopt(rs->multicast->sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl,
sizeof(ttl)) < 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: setsockopt: %s\n", __func__, strerror(errno));
@ -561,8 +570,8 @@ int multicast_init(RIG *rig, char *addr, int port)
// look like we need to implement the client in a separate thread?
// Join the multicast group
if (setsockopt(rig->state.multicast->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char *)&rig->state.multicast->mreq, sizeof(rig->state.multicast->mreq)) < 0)
if (setsockopt(rs->multicast->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char *)&rs->multicast->mreq, sizeof(rs->multicast->mreq)) < 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: setsockopt: %s\n", __func__, strerror(errno));
//return -RIG_EIO;
@ -571,19 +580,19 @@ int multicast_init(RIG *rig, char *addr, int port)
#endif
// prime the dest_addr for the send routine
memset(&rig->state.multicast->dest_addr, 0,
sizeof(rig->state.multicast->dest_addr));
rig->state.multicast->dest_addr.sin_family = AF_INET;
rig->state.multicast->dest_addr.sin_addr.s_addr = inet_addr(addr);
rig->state.multicast->dest_addr.sin_port = htons(port);
memset(&rs->multicast->dest_addr, 0,
sizeof(rs->multicast->dest_addr));
rs->multicast->dest_addr.sin_family = AF_INET;
rs->multicast->dest_addr.sin_addr.s_addr = inet_addr(addr);
rs->multicast->dest_addr.sin_port = htons(port);
#if 0
rig->state.multicast->runflag = 1;
pthread_create(&rig->state.multicast->threadid, NULL, multicast_thread,
rs->multicast->runflag = 1;
pthread_create(&rs->multicast->threadid, NULL, multicast_thread,
(void *)rig);
//printf("threadid=%ld\n", rig->state.multicast->threadid);
rig->state.multicast->multicast_running = 1;
pthread_create(&rig->state.multicast->threadid, NULL, multicast_thread_rx,
//printf("threadid=%ld\n", rs->multicast->threadid);
rs->multicast->multicast_running = 1;
pthread_create(&rs->multicast->threadid, NULL, multicast_thread_rx,
(void *)rig);
#endif
return RIG_OK;
@ -592,17 +601,19 @@ int multicast_init(RIG *rig, char *addr, int port)
// cppcheck-suppress unusedFunction
void multicast_close(RIG *rig)
{
struct rig_state *rs = STATE(rig);
// Leave the multicast group
if (setsockopt(rig->state.multicast->sock, IPPROTO_IP,
IP_DROP_MEMBERSHIP, (char *)&rig->state.multicast->mreq,
sizeof(rig->state.multicast->mreq)) < 0)
if (setsockopt(rs->multicast->sock, IPPROTO_IP,
IP_DROP_MEMBERSHIP, (char *)&rs->multicast->mreq,
sizeof(rs->multicast->mreq)) < 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: setsockopt: %s\n", __func__, strerror(errno));
return;
}
// Close the socket
if (close(rig->state.multicast->sock))
if (close(rs->multicast->sock))
{
rig_debug(RIG_DEBUG_ERR, "%s: close: %s\n", __func__, strerror(errno));
}
@ -626,7 +637,7 @@ int multicast_send(RIG *rig, const char *msg, int msglen)
// Send the message to the multicast group
ssize_t num_bytes = sendto(rig->state.multicast->sock, msg, msglen, 0,
ssize_t num_bytes = sendto(STATE(rig)->multicast->sock, msg, msglen, 0,
(struct sockaddr *)&addr,
sizeof(addr));
@ -665,7 +676,7 @@ int main(int argc, const char *argv[])
RIGPORT(rig)->parm.serial.rate = 38400;
rig_open(rig);
multicast_init(rig, "224.0.0.1", 4532);
pthread_join(rig->state.multicast->threadid, NULL);
pthread_join(STATE(rig)->multicast->threadid, NULL);
pthread_exit(NULL);
return 0;
}

View File

@ -219,9 +219,9 @@ int network_init()
}
/**
* \brief Open network port using rig.state data
* \brief Open network port using STATE(rig) data
*
* Open Open network port using rig.state data.
* Open network port using STATE(rig) data.
* NB: The signal PIPE will be ignored for the whole application.
*
* \param rp Port data structure (must spec port id eg hostname:port)
@ -781,7 +781,7 @@ retry:
static void multicast_publisher_write_lock(RIG *rig)
{
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
multicast_publisher_priv_data *priv_data = (multicast_publisher_priv_data *)
rs->multicast_publisher_priv_data;
pthread_mutex_lock(&priv_data->args.write_lock);
@ -789,7 +789,7 @@ static void multicast_publisher_write_lock(RIG *rig)
static void multicast_publisher_write_unlock(RIG *rig)
{
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
multicast_publisher_priv_data *priv_data = (multicast_publisher_priv_data *)
rs->multicast_publisher_priv_data;
pthread_mutex_unlock(&priv_data->args.write_lock);
@ -798,7 +798,7 @@ static void multicast_publisher_write_unlock(RIG *rig)
static int multicast_publisher_write_packet_header(RIG *rig,
multicast_publisher_data_packet *packet)
{
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
multicast_publisher_priv_data *mcast_publisher_priv;
multicast_publisher_args *mcast_publisher_args;
ssize_t result;
@ -828,7 +828,7 @@ static int multicast_publisher_write_packet_header(RIG *rig,
// cppcheck-suppress unusedFunction
int network_publish_rig_poll_data(RIG *rig)
{
const struct rig_state *rs = &rig->state;
const struct rig_state *rs = STATE(rig);
int result;
multicast_publisher_data_packet packet =
{
@ -852,7 +852,7 @@ int network_publish_rig_poll_data(RIG *rig)
// cppcheck-suppress unusedFunction
int network_publish_rig_transceive_data(RIG *rig)
{
const struct rig_state *rs = &rig->state;
const struct rig_state *rs = STATE(rig);
int result;
multicast_publisher_data_packet packet =
{
@ -876,7 +876,7 @@ int network_publish_rig_transceive_data(RIG *rig)
int network_publish_rig_spectrum_data(RIG *rig, struct rig_spectrum_line *line)
{
int result;
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
multicast_publisher_priv_data *mcast_publisher_priv;
multicast_publisher_args *mcast_publisher_args;
multicast_publisher_data_packet packet =
@ -1006,7 +1006,7 @@ void *multicast_publisher(void *arg)
struct multicast_publisher_args_s *args = (struct multicast_publisher_args_s *)
arg;
RIG *rig = args->rig;
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
struct rig_spectrum_line spectrum_line;
uint8_t packet_type = MULTICAST_PUBLISHER_DATA_PACKET_TYPE_SPECTRUM;
multicast_publisher_priv_data *mcast_publisher_priv =
@ -1348,7 +1348,7 @@ void *multicast_receiver(void *arg)
struct multicast_receiver_args_s *args = (struct multicast_receiver_args_s *)
arg;
RIG *rig = args->rig;
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
multicast_receiver_priv_data *mcast_receiver_priv =
(multicast_receiver_priv_data *)
rs->multicast_receiver_priv_data;
@ -1572,7 +1572,7 @@ void *multicast_receiver(void *arg)
int network_multicast_publisher_start(RIG *rig, const char *multicast_addr,
int multicast_port, enum multicast_item_e items)
{
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
multicast_publisher_priv_data *mcast_publisher_priv;
int socket_fd;
int status;
@ -1729,7 +1729,7 @@ int network_multicast_publisher_start(RIG *rig, const char *multicast_addr,
*/
int network_multicast_publisher_stop(RIG *rig)
{
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
multicast_publisher_priv_data *mcast_publisher_priv;
ENTERFUNC;
@ -1787,7 +1787,7 @@ int network_multicast_publisher_stop(RIG *rig)
int network_multicast_receiver_start(RIG *rig, const char *multicast_addr,
int multicast_port)
{
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
multicast_receiver_priv_data *mcast_receiver_priv;
int socket_fd;
int status;
@ -1897,7 +1897,7 @@ int network_multicast_receiver_start(RIG *rig, const char *multicast_addr,
*/
int network_multicast_receiver_stop(RIG *rig)
{
struct rig_state *rs = &rig->state;
struct rig_state *rs = STATE(rig);
multicast_receiver_priv_data *mcast_receiver_priv;
ENTERFUNC;

419
src/rig.c

File diff suppressed because it is too large Load Diff

View File

@ -128,7 +128,7 @@ int is_uh_radio_fd(int fd)
/**
* \brief Open serial port using rig.state data
* \brief Open serial port using STATE(rig) data
* \param rp port data structure (must spec port id eg /dev/ttyS1)
* \return RIG_OK or < 0 if error
*/

View File

@ -48,7 +48,7 @@
#ifndef DOC_HIDDEN
# define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state)
# define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !STATE(r)->comm_state)
#endif /* !DOC_HIDDEN */
@ -92,7 +92,7 @@ int HAMLIB_API rig_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
if ((caps->targetable_vfo & RIG_TARGETABLE_LEVEL)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == STATE(rig)->current_vfo)
{
#if defined(HAVE_PTHREAD)
@ -112,7 +112,7 @@ int HAMLIB_API rig_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = STATE(rig)->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -153,6 +153,7 @@ int HAMLIB_API rig_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
{
const struct rig_caps *caps;
struct rig_state *rs = STATE(rig);
int retcode;
vfo_t curr_vfo;
@ -177,7 +178,7 @@ int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
if (level == RIG_LEVEL_STRENGTH
&& (caps->has_get_level & RIG_LEVEL_STRENGTH) == 0
&& rig_has_get_level(rig, RIG_LEVEL_RAWSTR)
&& rig->state.str_cal.size)
&& rs->str_cal.size)
{
value_t rawstr;
@ -189,14 +190,14 @@ int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
return retcode;
}
val->i = (int)rig_raw2val(rawstr.i, &rig->state.str_cal);
val->i = (int)rig_raw2val(rawstr.i, &rs->str_cal);
return RIG_OK;
}
if ((caps->targetable_vfo & RIG_TARGETABLE_LEVEL)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == rs->current_vfo)
{
return caps->get_level(rig, vfo, level, val);
@ -207,7 +208,7 @@ int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = rs->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -315,7 +316,7 @@ setting_t HAMLIB_API rig_has_get_level(RIG *rig, setting_t level)
return 0;
}
return (rig->state.has_get_level & level);
return (STATE(rig)->has_get_level & level);
}
@ -345,7 +346,7 @@ setting_t HAMLIB_API rig_has_set_level(RIG *rig, setting_t level)
return 0;
}
return (rig->state.has_set_level & level);
return (STATE(rig)->has_set_level & level);
}
@ -374,7 +375,7 @@ setting_t HAMLIB_API rig_has_get_parm(RIG *rig, setting_t parm)
return 0;
}
return (rig->state.has_get_parm & parm);
return (STATE(rig)->has_get_parm & parm);
}
@ -403,7 +404,7 @@ setting_t HAMLIB_API rig_has_set_parm(RIG *rig, setting_t parm)
return 0;
}
return (rig->state.has_set_parm & parm);
return (STATE(rig)->has_set_parm & parm);
}
@ -433,7 +434,7 @@ setting_t HAMLIB_API rig_has_get_func(RIG *rig, setting_t func)
return 0;
}
return (rig->state.has_get_func & func);
return (STATE(rig)->has_get_func & func);
}
@ -462,7 +463,7 @@ setting_t HAMLIB_API rig_has_set_func(RIG *rig, setting_t func)
return 0;
}
return (rig->state.has_set_func & func);
return (STATE(rig)->has_set_func & func);
}
@ -487,6 +488,7 @@ setting_t HAMLIB_API rig_has_set_func(RIG *rig, setting_t func)
int HAMLIB_API rig_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
{
const struct rig_caps *caps;
struct rig_state *rs = STATE(rig);
int retcode;
vfo_t curr_vfo;
@ -500,36 +502,36 @@ int HAMLIB_API rig_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
caps = rig->caps;
if ((caps->set_func == NULL || !rig_has_set_func(rig, func))
&& access(rig->state.tuner_control_pathname, X_OK) == -1)
&& access(rs->tuner_control_pathname, X_OK) == -1)
{
return -RIG_ENAVAIL;
}
if (access(rig->state.tuner_control_pathname, X_OK) != -1)
if (access(rs->tuner_control_pathname, X_OK) != -1)
{
char cmd[1024];
snprintf(cmd, sizeof(cmd), "%s %d", rig->state.tuner_control_pathname, status);
snprintf(cmd, sizeof(cmd), "%s %d", rs->tuner_control_pathname, status);
rig_debug(RIG_DEBUG_TRACE, "%s: Calling external script '%s'\n", __func__,
rig->state.tuner_control_pathname);
rs->tuner_control_pathname);
retcode = system(cmd);
if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: executing %s failed\n", __func__, rig->state.tuner_control_pathname); }
if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: executing %s failed\n", __func__, rs->tuner_control_pathname); }
return (retcode == 0 ? RIG_OK : -RIG_ERJCTED);
}
else
{
if (strcmp(rig->state.tuner_control_pathname, "hamlib_tuner_control"))
if (strcmp(rs->tuner_control_pathname, "hamlib_tuner_control"))
{
rig_debug(RIG_DEBUG_ERR, "%s: unable to find '%s'\n", __func__,
rig->state.tuner_control_pathname);
rs->tuner_control_pathname);
return -RIG_EINVAL;
}
}
if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == rs->current_vfo)
{
return caps->set_func(rig, vfo, func, status);
@ -538,7 +540,7 @@ int HAMLIB_API rig_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
{
int targetable = caps->targetable_vfo & RIG_TARGETABLE_FUNC;
rig_debug(RIG_DEBUG_TRACE, "%s: targetable=%d, vfo=%s, currvfo=%s\n", __func__,
targetable, rig_strvfo(vfo), rig_strvfo(rig->state.current_vfo));
targetable, rig_strvfo(vfo), rig_strvfo(rs->current_vfo));
}
if (!caps->set_vfo)
@ -546,7 +548,7 @@ int HAMLIB_API rig_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = rs->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -583,6 +585,7 @@ int HAMLIB_API rig_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
int HAMLIB_API rig_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
{
const struct rig_caps *caps;
struct rig_state *rs = STATE(rig);
int retcode;
vfo_t curr_vfo;
@ -603,7 +606,7 @@ int HAMLIB_API rig_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == rs->current_vfo)
{
return caps->get_func(rig, vfo, func, status);
@ -614,7 +617,7 @@ int HAMLIB_API rig_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = rs->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -669,7 +672,7 @@ int HAMLIB_API rig_set_ext_level(RIG *rig,
if ((caps->targetable_vfo & RIG_TARGETABLE_LEVEL)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == STATE(rig)->current_vfo)
{
return caps->set_ext_level(rig, vfo, token, val);
@ -680,7 +683,7 @@ int HAMLIB_API rig_set_ext_level(RIG *rig,
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = STATE(rig)->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -735,7 +738,7 @@ int HAMLIB_API rig_get_ext_level(RIG *rig,
if ((caps->targetable_vfo & RIG_TARGETABLE_LEVEL)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == STATE(rig)->current_vfo)
{
return caps->get_ext_level(rig, vfo, token, val);
@ -746,7 +749,7 @@ int HAMLIB_API rig_get_ext_level(RIG *rig,
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = STATE(rig)->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -800,7 +803,7 @@ int HAMLIB_API rig_set_ext_func(RIG *rig,
if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == STATE(rig)->current_vfo)
{
return caps->set_ext_func(rig, vfo, token, status);
@ -811,7 +814,7 @@ int HAMLIB_API rig_set_ext_func(RIG *rig,
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = STATE(rig)->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -866,7 +869,7 @@ int HAMLIB_API rig_get_ext_func(RIG *rig,
if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == STATE(rig)->current_vfo)
{
return caps->get_ext_func(rig, vfo, token, status);
@ -877,7 +880,7 @@ int HAMLIB_API rig_get_ext_func(RIG *rig,
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = STATE(rig)->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)

View File

@ -20,16 +20,17 @@ static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig)
cJSON *node;
char buf[1024];
struct rig_cache *cachep = CACHE(rig);
struct rig_state *rs = STATE(rig);
cJSON *id_node = cJSON_CreateObject();
cJSON_AddStringToObject(id_node, "model", rig->caps->model_name);
cJSON_AddStringToObject(id_node, "endpoint", RIGPORT(rig)->pathname);
cJSON_AddStringToObject(id_node, "process", snapshot_data_pid);
cJSON_AddStringToObject(id_node, "deviceId", rig->state.device_id);
cJSON_AddStringToObject(id_node, "deviceId", rs->device_id);
cJSON_AddItemToObject(rig_node, "id", id_node);
node = cJSON_AddStringToObject(rig_node, "status",
rig_strcommstatus(rig->state.comm_status));
rig_strcommstatus(rs->comm_status));
if (node == NULL)
{
@ -75,7 +76,7 @@ static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig)
goto error;
}
rig_sprintf_mode(buf, sizeof(buf), rig->state.mode_list);
rig_sprintf_mode(buf, sizeof(buf), rs->mode_list);
char *p;
cJSON *modes_array = cJSON_CreateArray();
@ -113,6 +114,7 @@ static int snapshot_serialize_vfo(cJSON *vfo_node, RIG *rig, vfo_t vfo)
int is_rx, is_tx;
cJSON *node;
struct rig_cache *cachep = CACHE(rig);
struct rig_state *rs = STATE(rig);
// TODO: This data should match rig_get_info command response
@ -153,9 +155,9 @@ static int snapshot_serialize_vfo(cJSON *vfo_node, RIG *rig, vfo_t vfo)
split = cachep->split;
split_vfo = cachep->split_vfo;
is_rx = (split == RIG_SPLIT_OFF && vfo == rig->state.current_vfo)
is_rx = (split == RIG_SPLIT_OFF && vfo == rs->current_vfo)
|| (split == RIG_SPLIT_ON && vfo != split_vfo);
is_tx = (split == RIG_SPLIT_OFF && vfo == rig->state.current_vfo)
is_tx = (split == RIG_SPLIT_OFF && vfo == rs->current_vfo)
|| (split == RIG_SPLIT_ON && vfo == split_vfo);
ptt = cachep->ptt && is_tx;
@ -336,6 +338,7 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig,
char buf[256];
int result;
int i;
struct rig_state *rs = STATE(rig);
root_node = cJSON_CreateObject();
@ -360,7 +363,7 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig,
}
node = cJSON_AddNumberToObject(root_node, "seq",
rig->state.snapshot_packet_sequence_number);
rs->snapshot_packet_sequence_number);
if (node == NULL)
{
@ -410,7 +413,7 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig,
for (i = 0; i < HAMLIB_MAX_VFOS; i++)
{
vfo_t vfo = rig->state.vfo_list & RIG_VFO_N(i);
vfo_t vfo = rs->vfo_list & RIG_VFO_N(i);
if (!vfo)
{
@ -464,7 +467,7 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig,
RETURNFUNC2(-RIG_EINVAL);
}
rig->state.snapshot_packet_sequence_number++;
rs->snapshot_packet_sequence_number++;
return RIG_OK;

View File

@ -68,7 +68,7 @@ tone_t full_dcs_list[] = { FULL_DCS_LIST };
#ifndef DOC_HIDDEN
#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state)
#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !STATE(r)->comm_state)
#endif /* !DOC_HIDDEN */
@ -98,6 +98,7 @@ tone_t full_dcs_list[] = { FULL_DCS_LIST };
int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
{
const struct rig_caps *caps;
struct rig_state *rs = STATE(rig);
int retcode;
vfo_t curr_vfo;
@ -117,7 +118,7 @@ int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == rs->current_vfo)
{
return caps->set_ctcss_tone(rig, vfo, tone);
@ -128,7 +129,7 @@ int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = rs->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -165,6 +166,7 @@ int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
int HAMLIB_API rig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone)
{
const struct rig_caps *caps;
struct rig_state *rs = STATE(rig);
int retcode;
vfo_t curr_vfo;
@ -184,7 +186,7 @@ int HAMLIB_API rig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone)
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == rs->current_vfo)
{
return caps->get_ctcss_tone(rig, vfo, tone);
@ -195,7 +197,7 @@ int HAMLIB_API rig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = rs->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -228,6 +230,7 @@ int HAMLIB_API rig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone)
int HAMLIB_API rig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code)
{
const struct rig_caps *caps;
struct rig_state *rs = STATE(rig);
int retcode;
vfo_t curr_vfo;
@ -247,7 +250,7 @@ int HAMLIB_API rig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code)
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == rs->current_vfo)
{
return caps->set_dcs_code(rig, vfo, code);
@ -258,7 +261,7 @@ int HAMLIB_API rig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = rs->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -290,6 +293,7 @@ int HAMLIB_API rig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code)
int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code)
{
const struct rig_caps *caps;
struct rig_state *rs = STATE(rig);
int retcode;
vfo_t curr_vfo;
@ -309,7 +313,7 @@ int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code)
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == rs->current_vfo)
{
return caps->get_dcs_code(rig, vfo, code);
@ -320,7 +324,7 @@ int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = rs->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -360,6 +364,7 @@ int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code)
int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone)
{
const struct rig_caps *caps;
struct rig_state *rs = STATE(rig);
int retcode;
vfo_t curr_vfo;
@ -379,7 +384,7 @@ int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone)
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == rs->current_vfo)
{
return caps->set_ctcss_sql(rig, vfo, tone);
@ -390,7 +395,7 @@ int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = rs->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -427,6 +432,7 @@ int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone)
int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone)
{
const struct rig_caps *caps;
struct rig_state *rs = STATE(rig);
int retcode;
vfo_t curr_vfo;
@ -446,7 +452,7 @@ int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone)
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == rs->current_vfo)
{
return caps->get_ctcss_sql(rig, vfo, tone);
@ -457,7 +463,7 @@ int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = rs->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -489,6 +495,7 @@ int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone)
int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code)
{
const struct rig_caps *caps;
struct rig_state *rs = STATE(rig);
int retcode;
vfo_t curr_vfo;
@ -508,7 +515,7 @@ int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code)
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == rs->current_vfo)
{
return caps->set_dcs_sql(rig, vfo, code);
@ -519,7 +526,7 @@ int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = rs->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)
@ -551,6 +558,7 @@ int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code)
int HAMLIB_API rig_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code)
{
const struct rig_caps *caps;
struct rig_state *rs = STATE(rig);
int retcode;
vfo_t curr_vfo;
@ -570,7 +578,7 @@ int HAMLIB_API rig_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code)
if ((caps->targetable_vfo & RIG_TARGETABLE_TONE)
|| vfo == RIG_VFO_CURR
|| vfo == rig->state.current_vfo)
|| vfo == rs->current_vfo)
{
return caps->get_dcs_sql(rig, vfo, code);
@ -581,7 +589,7 @@ int HAMLIB_API rig_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code)
return -RIG_ENTARGET;
}
curr_vfo = rig->state.current_vfo;
curr_vfo = rs->current_vfo;
retcode = caps->set_vfo(rig, vfo);
if (retcode != RIG_OK)

View File

@ -489,6 +489,7 @@ int clear_chans(RIG *rig, const char *infilename)
{
int i, j, ret;
channel_t chan;
struct rig_state *rs = STATE(rig);
memset(&chan, 0, sizeof(chan));
chan.freq = RIG_FREQ_NONE;
@ -497,10 +498,10 @@ int clear_chans(RIG *rig, const char *infilename)
chan.tx_mode = RIG_MODE_NONE;
chan.vfo = RIG_VFO_MEM;
for (i = 0; rig->state.chan_list[i].type; i++)
for (i = 0; rs->chan_list[i].type; i++)
{
for (j = rig->state.chan_list[i].startc;
j <= rig->state.chan_list[i].endc; j++)
for (j = rs->chan_list[i].startc;
j <= rs->chan_list[i].endc; j++)
{
chan.channel_num = j;