Fix IC910 behavior with gpredict -- also should fix some Main/Sub behavior elsewhere too

https://github.com/Hamlib/Hamlib/issues/657
pull/668/head
Mike Black W9MDB 2021-04-11 11:49:37 -05:00
rodzic 778758200e
commit 73464a6c2e
3 zmienionych plików z 17 dodań i 273 usunięć

Wyświetl plik

@ -65,266 +65,6 @@ static int ic910_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
}
#endif /* HAVE_WEIRD_IC910_MODES */
/* this function compares 2 frequencies
* returns 1 if they are in the same band
* returns 0 if they are in different bands
*/
static int compareFrequencies(RIG *rig, freq_t freq1, freq_t freq2)
{
int freq1band = 0, freq2band = 0;
freq_range_t noband = RIG_FRNG_END;
while (rig->caps->rx_range_list1[freq1band].startf != noband.startf)
{
if (freq1 >= rig->caps->rx_range_list1[freq1band].startf &&
freq1 <= rig->caps->rx_range_list1[freq1band].endf)
{
break;
}
++freq1band;
//fprintf(stderr, "%i\n", freq1band);
}
while (rig->caps->rx_range_list1[freq2band].startf != noband.startf)
{
if (freq2 >= rig->caps->rx_range_list1[freq2band].startf &&
freq2 <= rig->caps->rx_range_list1[freq2band].endf)
{
break;
}
++freq2band;
}
if (freq2band == freq1band) { return 1; }
else { return 0; }
}
static int ic910_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
{
int retval;
freq_t otherfreq;
freq_t origfreq;
if ((retval = icom_get_freq(rig, RIG_VFO_CURR, &origfreq)) != RIG_OK) { return retval; }
if (compareFrequencies(rig, freq, origfreq))
{
/* correct band already */
if (RIG_VFO_A == vfo || RIG_VFO_B == vfo)
{
/* switch to desired VFO and read its frequency */
if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; }
if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) { return retval; }
retval = icom_set_freq(rig, RIG_VFO_CURR, freq);
if (otherfreq != origfreq)
{
/* swap VFOs back as original was the other one */
icom_set_vfo(rig, RIG_VFO_A == vfo ? RIG_VFO_B : RIG_VFO_A);
}
}
else if (RIG_VFO_MAIN == vfo || RIG_VFO_SUB == vfo)
{
/* switch to the desired of MAIN and SUB and read its frequency */
if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; }
if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) { return retval; }
if (otherfreq != origfreq)
{
/* started on a different so band exchange MAIN and SUB */
if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) { return retval; }
retval = icom_set_freq(rig, RIG_VFO_CURR, freq);
/* swap MAIN/SUB back as original was the other one */
icom_set_vfo(rig, RIG_VFO_MAIN == vfo ? RIG_VFO_SUB : RIG_VFO_MAIN);
}
else
{
/* already correct one of MAIN and SUB */
retval = icom_set_freq(rig, RIG_VFO_CURR, freq);
}
}
else if (RIG_VFO_CURR == vfo)
{
retval = icom_set_freq(rig, RIG_VFO_CURR, freq);
}
else { retval = -RIG_EVFO; }
}
else
{
/* wrong band */
if (RIG_VFO_A == vfo || RIG_VFO_B == vfo)
{
/* try and set frequency, may fail if band is already on other of MAIN/SUB */
retval = icom_set_freq(rig, RIG_VFO_CURR, freq);
if (-RIG_ERJCTED == retval)
{
/* exchange MAIN & SUB */
if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) { return retval; }
if ((retval = icom_get_freq(rig, vfo, &origfreq)) != RIG_OK) { return retval; }
if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; }
if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) { return retval; }
retval = icom_set_freq(rig, RIG_VFO_CURR, freq);
if (-RIG_ERJCTED == retval)
{
/* band not fitted so swap MAIN & SUB back and give up */
icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG);
return retval;
}
else if (retval != RIG_OK) { return retval; }
if (otherfreq != origfreq)
{
/* swap VFOs back as original was the other one */
icom_set_vfo(rig, RIG_VFO_A == vfo ? RIG_VFO_B : RIG_VFO_A);
}
/* we do not exchange bands back as this is taken to
mean set VFOA/B on MAIN to the specified frequency
as Hamlib does not recognize A on MAIN or B on SUB
etc. This is probably reasonable since we cannot Tx
on SUB */
return retval;
}
/* we changed band to the "third band" which always makes
VFO A current so just make the requested one the
specified frequency as well if it is VFO B. There is no
way of going to the "third band" without changing VFO
A */
if (RIG_VFO_B == vfo)
{
if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; }
retval = icom_set_freq(rig, RIG_VFO_CURR, freq);
icom_set_vfo(rig, RIG_VFO_A);
}
}
else if (RIG_VFO_MAIN == vfo || RIG_VFO_SUB == vfo)
{
if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; }
if ((retval = icom_get_freq(rig, vfo, &otherfreq)) != RIG_OK) { return retval; }
retval = icom_set_freq(rig, RIG_VFO_CURR, freq);
if (-RIG_ERJCTED == retval)
{
/* required band is on other of MAIN or SUB */
if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) { return retval; }
retval = icom_set_freq(rig, RIG_VFO_CURR, freq);
}
else if (retval != RIG_OK) { return retval; }
if (otherfreq != origfreq)
{
/* started on other of MAIN & SUB so switch back */
icom_set_vfo(rig,
RIG_VFO_MAIN == vfo ?
RIG_VFO_SUB : RIG_VFO_MAIN);
}
}
else if (RIG_VFO_CURR == vfo)
{
retval = icom_set_freq(rig, RIG_VFO_CURR, freq);
if (-RIG_ERJCTED == retval)
{
/* exchange MAIN & SUB */
if ((retval = icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG)) != RIG_OK) { return retval; }
retval = icom_set_freq(rig, RIG_VFO_CURR, freq);
if (-RIG_ERJCTED == retval)
{
/* band not fitted so swap MAIN & SUB back and give up */
icom_vfo_op(rig, RIG_VFO_CURR, RIG_OP_XCHG);
return retval;
}
}
}
else { retval = -RIG_EVFO; }
}
return retval;
}
static int ic910_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
{
int retval;
freq_t origfreq;
vfo_t vfo_save;
struct icom_priv_data *priv = (struct icom_priv_data *) rig->state.priv;
/* start off by reading the current VFO frequency */
if ((retval = icom_get_freq(rig, RIG_VFO_CURR, &origfreq)) != RIG_OK) { return retval; }
vfo_save = rig->state.current_vfo;
rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo));
if (RIG_VFO_A == vfo || RIG_VFO_B == vfo)
{
/* switch to desired VFO and read its frequency */
if (vfo_save != vfo)
{
if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; }
}
if ((retval = icom_get_freq(rig, vfo, freq)) != RIG_OK) { return retval; }
if (vfo_save != vfo)
{
/* swap VFOs back as original was the other one */
icom_set_vfo(rig, vfo_save);
}
}
else if (RIG_VFO_MAIN == vfo || RIG_VFO_SUB == vfo)
{
/* switch to the desired of MAIN and SUB and read its frequency */
if ((retval = icom_set_vfo(rig, vfo)) != RIG_OK) { return retval; }
if ((retval = icom_get_freq(rig, vfo, freq)) != RIG_OK) { return retval; }
if (*freq != origfreq)
{
/* started on a different so switch back MAIN or SUB */
icom_set_vfo(rig, RIG_VFO_MAIN == vfo ? RIG_VFO_SUB : RIG_VFO_MAIN);
}
}
else if (RIG_VFO_CURR == vfo)
{
*freq = origfreq;
}
else if (RIG_VFO_TX == vfo)
{
vfo = priv->tx_vfo;
rig_debug(RIG_DEBUG_VERBOSE, "%s: VFO_TX asked for so vfo=%s\n", __func__,
rig_strvfo(vfo));
}
else if (RIG_VFO_RX == vfo)
{
vfo = priv->rx_vfo;
rig_debug(RIG_DEBUG_VERBOSE, "%s: VFO_RX asked for so vfo=%s\n", __func__,
rig_strvfo(vfo));
}
else { retval = -RIG_EVFO; }
return retval;
}
/*
* This function does the special bandwidth coding for IC-910
* (1 - normal, 2 - narrow)
@ -464,7 +204,7 @@ const struct rig_caps ic910_caps =
RIG_MODEL(RIG_MODEL_IC910),
.model_name = "IC-910",
.mfg_name = "Icom",
.version = BACKEND_VER ".0",
.version = BACKEND_VER ".1",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rig_type = RIG_TYPE_TRANSCEIVER,
@ -574,8 +314,8 @@ const struct rig_caps ic910_caps =
.set_conf = icom_set_conf,
.get_conf = icom_get_conf,
.get_freq = ic910_get_freq,
.set_freq = ic910_set_freq,
.get_freq = icom_get_freq,
.set_freq = icom_set_freq,
#ifdef HAVE_WEIRD_IC910_MODES
.get_mode = ic910_get_mode,

Wyświetl plik

@ -2234,6 +2234,8 @@ int icom_set_vfo(RIG *rig, vfo_t vfo)
}
else if (vfo == RIG_VFO_TX)
{
rig_debug(RIG_DEBUG_TRACE, "%s: vfo line#%d vfo=%s\n", __func__, __LINE__,
rig_strvfo(vfo));
vfo = RIG_VFO_A;
if (VFO_HAS_A_B_ONLY && rig->state.cache.satmode) { vfo = RIG_VFO_B; }
@ -2243,13 +2245,17 @@ int icom_set_vfo(RIG *rig, vfo_t vfo)
else if ((vfo == RIG_VFO_A || vfo == RIG_VFO_MAIN) && VFO_HAS_DUAL)
{
rig_debug(RIG_DEBUG_TRACE, "%s: vfo line#%d vfo=%s, split=%d\n", __func__,
__LINE__, rig_strvfo(vfo), rig->state.cache.split);
// If we're being asked for A/Main but we are a MainA/MainB rig change it
vfo = RIG_VFO_MAIN;
if (rig->state.cache.split == RIG_SPLIT_ON) { vfo = RIG_VFO_A; }
if (rig->state.cache.split == RIG_SPLIT_ON && !rig->state.cache.satmode) { vfo = RIG_VFO_A; }
}
else if ((vfo == RIG_VFO_B || vfo == RIG_VFO_SUB) && VFO_HAS_DUAL)
{
rig_debug(RIG_DEBUG_TRACE, "%s: vfo line#%d vfo=%s\n", __func__, __LINE__,
rig_strvfo(vfo));
// If we're being asked for B/Sub but we are a MainA/MainB rig change it
vfo = RIG_VFO_SUB;
@ -2286,7 +2292,7 @@ int icom_set_vfo(RIG *rig, vfo_t vfo)
priv->curr_freq = 0; // reset curr_freq so set_freq works 1st time
}
rig_debug(RIG_DEBUG_TRACE, "%s: debug#2\n", __func__);
rig_debug(RIG_DEBUG_TRACE, "%s: line#%d\n", __func__, __LINE__);
switch (vfo)
{
@ -2439,10 +2445,10 @@ int icom_set_vfo(RIG *rig, vfo_t vfo)
RETURNFUNC(-RIG_EINVAL);
}
rig_debug(RIG_DEBUG_TRACE, "%s: debug#3\n", __func__);
rig_debug(RIG_DEBUG_TRACE, "%s: line#%d\n", __func__, __LINE__);
retval = icom_transaction(rig, C_SET_VFO, icvfo, NULL, 0,
ackbuf, &ack_len);
rig_debug(RIG_DEBUG_TRACE, "%s: debug#4\n", __func__);
rig_debug(RIG_DEBUG_TRACE, "%s: line#%d\n", __func__, __LINE__);
if (retval != RIG_OK)
{
@ -2464,7 +2470,7 @@ int icom_set_vfo(RIG *rig, vfo_t vfo)
}
rig->state.current_vfo = vfo;
rig_debug(RIG_DEBUG_TRACE, "%s: debug#5 curr_vfo=%s\n", __func__,
rig_debug(RIG_DEBUG_TRACE, "%s: line#%d curr_vfo=%s\n", __func__, __LINE__,
rig_strvfo(rig->state.current_vfo));
RETURNFUNC(RIG_OK);
}

Wyświetl plik

@ -2525,7 +2525,7 @@ int HAMLIB_API rig_set_vfo(RIG *rig, vfo_t vfo)
if (retcode == RIG_OK)
{
rig->state.current_vfo = vfo;
vfo = rig->state.current_vfo; // vfo may change in the rig backend
rig->state.cache.vfo = vfo;
elapsed_ms(&rig->state.cache.time_vfo, HAMLIB_ELAPSED_SET);
rig_debug(RIG_DEBUG_TRACE, "%s: rig->state.current_vfo=%s\n", __func__,
@ -3778,10 +3778,8 @@ int HAMLIB_API rig_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq)
if (caps->set_vfo)
{
// If we started with RIG_VFO_CURR we need to choose VFO_A/MAIN as appropriate to return to
if (save_vfo == RIG_VFO_CURR)
{
save_vfo = VFO_HAS_A_B_ONLY ? RIG_VFO_A : RIG_VFO_MAIN;
}
//rig_debug(RIG_DEBUG_TRACE, "%s: save_vfo=%s, hasmainsub=%d\n",__func__, rig_strvfo(save_vfo), VFO_HAS_MAIN_SUB);
save_vfo = VFO_HAS_MAIN_SUB ? RIG_VFO_MAIN : RIG_VFO_A;
rig_debug(RIG_DEBUG_TRACE, "%s: restoring vfo=%s\n", __func__,
rig_strvfo(save_vfo));