Add set_twiddle and get_twiddle functions

Add -W switch to rigctld to set twiddle timeout..don't need switch for rigctl since it can set from there with \set_twiddle
pull/224/head
Michael Black 2020-02-24 09:34:02 -06:00
rodzic bceba85205
commit 8b462a0242
4 zmienionych plików z 120 dodań i 9 usunięć

Wyświetl plik

@ -1787,7 +1787,8 @@ struct rig_state {
wired PTT asserted - used by rigs that
don't do CAT while in Tx */
freq_t lo_freq; /*!< Local oscillator frequency of any transverter */
time_t twiddling; /*!< time when vfo twiddling was detected */
time_t twiddle_time; /*!< time when vfo twiddling was detected */
int twiddle_timeout; /*!< timeout to resume from twiddling */
};
@ -2362,6 +2363,14 @@ rig_set_pltune_callback HAMLIB_PARAMS((RIG *,
pltune_cb_t,
rig_ptr_t));
extern HAMLIB_EXPORT(int)
rig_set_twiddle HAMLIB_PARAMS((RIG *rig,
int seconds));
extern HAMLIB_EXPORT(int)
rig_get_twiddle HAMLIB_PARAMS((RIG *rig,
int *seconds));
extern HAMLIB_EXPORT(const char *)
rig_get_info HAMLIB_PARAMS((RIG *rig));

Wyświetl plik

@ -1053,6 +1053,58 @@ int HAMLIB_API rig_cleanup(RIG *rig)
return RIG_OK;
}
/**
* \brief timeout (secs) to stop rigctld when VFO is manually changed
* \param rig The rig handle
* \param timeout_secs The timeout to set to
*
* timeout (secs) to stop rigctld when VFO is manually changed
* turns on/off the radio.
* See \set_twiddle
*
* \return RIG_OK if the operation has been sucessful, ortherwise
* a negative value if an error occured (in which case, cause is
* set appropriately).
*
* \sa rig_set_twiddle()
*/
int HAMLIB_API rig_set_twiddle(RIG *rig, int seconds)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig))
{
return -RIG_EINVAL;
}
rig->state.twiddle_timeout = seconds;
return RIG_OK;
}
/**
* \brief get the twiddle timeout value (secs)
* \param rig The rig handle
* \param seconds The timeout value
*
* \return RIG_OK if the operation has been sucessful, otherwise
* a negative value if an error occured (in which case, cause is
* set appropriately).
*
* \sa rig_set_powerstat()
*/
int HAMLIB_API rig_get_twiddle(RIG *rig, int *seconds)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_RIG_ARG(rig) || !seconds)
{
return -RIG_EINVAL;
}
*seconds = rig->state.twiddle_timeout;
return RIG_OK;
}
// detect if somebody is twiddling the VFO
// indicator is last set freq doesn't match current freq
@ -1061,7 +1113,7 @@ static int twiddling(RIG *rig)
{
const struct rig_caps *caps;
return 0; // disable for the moment
if (rig->state.twiddle_timeout == 0) { return 0; } // don't detect twiddling
caps = rig->caps;
@ -1085,13 +1137,13 @@ static int twiddling(RIG *rig)
return 0; // not twiddling as first time freq is being set
}
rig->state.twiddling = time(NULL); // update last twiddle time
rig->state.twiddle_time = time(NULL); // update last twiddle time
rig->state.current_freq = curr_freq; // we have a new freq to remember
}
elapsed = time(NULL) - rig->state.twiddling;
elapsed = time(NULL) - rig->state.twiddle_time;
if (elapsed < 3)
if (elapsed < rig->state.twiddle_timeout)
{
rig_debug(RIG_DEBUG_TRACE, "%s: Twiddle elapsed < 3, elapsed=%d\n", __func__,
elapsed);
@ -1662,8 +1714,9 @@ int HAMLIB_API rig_set_vfo(RIG *rig, vfo_t vfo)
{
rig->state.current_vfo = vfo;
}
// we need to update our internal freq to avoid getting detected as twiddling
if (caps->get_freq) retcode = rig_get_freq(rig, RIG_VFO_CURR, &curr_freq);
if (caps->get_freq) { retcode = rig_get_freq(rig, RIG_VFO_CURR, &curr_freq); }
return retcode;
}
@ -3896,7 +3949,7 @@ int HAMLIB_API rig_set_powerstat(RIG *rig, powerstat_t status)
/**
* \brief get the on/off status of the radio
* \param rig The rig handle
* \param status The locatation where to store the current status
* \param status The location where to store the current status
*
* Retrieve the status of the radio. See RIG_POWER_ON, RIG_POWER_OFF and
* RIG_POWER_STANDBY defines for the \a status.

Wyświetl plik

@ -222,6 +222,8 @@ declare_proto_rig(get_powerstat);
declare_proto_rig(send_dtmf);
declare_proto_rig(recv_dtmf);
declare_proto_rig(chk_vfo);
declare_proto_rig(set_twiddle);
declare_proto_rig(get_twiddle);
declare_proto_rig(halt);
declare_proto_rig(pause);
@ -297,8 +299,10 @@ static struct test_table test_list[] =
{ 'w', "send_cmd", ACTION(send_cmd), ARG_IN1 | ARG_IN_LINE | ARG_OUT2 | ARG_NOVFO, "Cmd", "Reply" },
{ 'W', "send_cmd_rx", ACTION(send_cmd), ARG_IN | ARG_OUT2 | ARG_NOVFO, "Cmd", "Reply"},
{ 'b', "send_morse", ACTION(send_morse), ARG_IN | ARG_IN_LINE, "Morse" },
{ 0x94, "send_voice_mem", ACTION(send_voice_mem), ARG_IN, "Voice Mem#" },
{ 0x94, "send_voice_mem", ACTION(send_voice_mem), ARG_IN, "Voice Mem#" },
{ 0x8b, "get_dcd", ACTION(get_dcd), ARG_OUT, "DCD" },
{ 0x8c, "set_twiddle", ACTION(set_twiddle), ARG_IN | ARG_NOVFO, "Timeout (secs)" },
{ 0x8d, "get_twiddle", ACTION(get_twiddle), ARG_OUT | ARG_NOVFO, "Timeout (secs)" },
{ '2', "power2mW", ACTION(power2mW), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1 | ARG_NOVFO, "Power [0.0..1.0]", "Frequency", "Mode", "Power mW" },
{ '4', "mW2power", ACTION(mW2power), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1 | ARG_NOVFO, "Power mW", "Frequency", "Mode", "Power [0.0..1.0]" },
{ '1', "dump_caps", ACTION(dump_caps), ARG_NOVFO },
@ -4413,3 +4417,36 @@ declare_proto_rig(pause)
sleep(seconds);
return RIG_OK;
}
/* '0x8d' */
declare_proto_rig(set_twiddle)
{
int seconds;
CHKSCN1ARG(sscanf(arg1, "%d", &seconds));
return rig_set_twiddle(rig, seconds);
}
/* '0x8e' */
declare_proto_rig(get_twiddle)
{
int status;
int seconds;
status = rig_get_twiddle(rig, &seconds);
if (status != RIG_OK)
{
return status;
}
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
{
fprintf(fout, "%s: ", cmd->arg1);
}
fprintf(fout, "%d\n", seconds);
return status;
}

Wyświetl plik

@ -85,7 +85,7 @@
* NB: do NOT use -W since it's reserved by POSIX.
* TODO: add an option to read from a file
*/
#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:lLuovhVZ"
#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:lLuovhVWZ"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
@ -106,6 +106,7 @@ static struct option long_options[] =
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
{"twiddle_timeout", 0, 0, 'W'},
{"debug-time-stamps", 0, 0, 'Z'},
{0, 0, 0, 0}
};
@ -498,6 +499,16 @@ int main(int argc, char *argv[])
dump_caps_opt++;
break;
case 'W':
if (!optarg)
{
usage(); /* wrong arg count */
exit(1);
}
my_rig->state.twiddle_timeout = atoi(optarg);
break;
case 'Z':
rig_set_debug_time_stamp(1);
break;
@ -1105,6 +1116,7 @@ void usage(void)
" -u, --dump-caps dump capabilities and exit\n"
" -o, --vfo do not default to VFO_CURR, require extra vfo arg\n"
" -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n"
" -W, --twiddle_timeout timeout after detecting vfo manual change\n"
" -Z, --debug-time-stamps enable time stamps for debug messages\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n",