Add detection of VFO twiddling

In the case of gpredict there are times when one has to adjust the
VFO to dial in a frequency while gpredict is tracking.
We now detect this situation and have a 3-second delay every time
VFO twiddling is detected.  set_freq and set_vfo calls will be
ignored during this delay.
May make this a settable value if needed.
pull/224/head
Michael Black 2020-02-23 08:28:19 -06:00
rodzic 1550a04716
commit 95986b9685
2 zmienionych plików z 41 dodań i 2 usunięć

Wyświetl plik

@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <inttypes.h>
#include <time.h>
/* Rig list is in a separate file so as not to mess up w/ this one */
#include <hamlib/riglist.h>
@ -1784,8 +1785,8 @@ struct rig_state {
int transmit; /*!< rig should be transmitting i.e. hard
wired PTT asserted - used by rigs that
don't do CAT while in Tx */
freq_t lo_freq; /*!< Local oscillator frequency of any
transverter */
freq_t lo_freq; /*!< Local oscillator frequency of any transverter */
time_t twiddling; /*!< time when vfo twiddling was detected */
};

Wyświetl plik

@ -1042,6 +1042,34 @@ int HAMLIB_API rig_cleanup(RIG *rig)
}
// detect if somebody is twiddling the VFO
// indicator is last set freq doesn't match current freq
// so we have to query freq every time we set freq or vfo to handle this
static int twiddling(RIG *rig)
{
const struct rig_caps *caps;
caps = rig->caps;
if ( caps->get_freq) { // gotta have get_freq of course
freq_t curr_freq = 0;
int retval2;
int elapsed;
retval2 = caps->get_freq(rig, RIG_VFO_CURR, &curr_freq);
if (retval2 == RIG_OK && rig->state.current_freq != curr_freq) {
rig_debug(RIG_DEBUG_TRACE,"%s: Somebody twiddling the VFO? last_freq=%.0f, curr_freq=%.0f\n", __func__, rig->state.current_freq, curr_freq);
rig->state.twiddling = time(NULL); // update last twiddle time
}
elapsed = time(NULL) - rig->state.twiddling;
if (elapsed < 3) {
rig_debug(RIG_DEBUG_TRACE,"%s: Twiddle elapsed < 3, elapsed=%d\n", __func__, elapsed);
return 1; // would be better as error but other software won't handle it
}
}
return 0; //
}
/**
* \brief set the frequency of the target VFO
* \param rig The rig handle
@ -1108,6 +1136,11 @@ int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
return retcode;
}
if (twiddling(rig)) {
rig_debug(RIG_DEBUG_TRACE,"%s: Ignoring set_freq due to VFO twiddling\n", __func__);
return RIG_OK; // would be better as error but other software won't handle errors
}
retcode = caps->set_freq(rig, vfo, freq);
/* try and revert even if we had an error above */
rc2 = caps->set_vfo(rig, curr_vfo);
@ -1571,6 +1604,11 @@ int HAMLIB_API rig_set_vfo(RIG *rig, vfo_t vfo)
return -RIG_ENAVAIL;
}
if (twiddling(rig)) {
rig_debug(RIG_DEBUG_TRACE,"%s: Ignoring set_vfo due to VFO twiddling\n", __func__);
return RIG_OK; // would be better as error but other software won't handle errors
}
retcode = caps->set_vfo(rig, vfo);
if (retcode == RIG_OK)