kopia lustrzana https://github.com/Hamlib/Hamlib
Add auto_power_off option from JTDX team
Change rig_get_vfo_info to do real calls intstead of cachepull/574/head
rodzic
8371f335cd
commit
221d87c2e4
|
@ -2198,7 +2198,9 @@ struct rig_state {
|
|||
int uplink; /*!< uplink=1 will not read Sub, uplink=2 will not read Main */
|
||||
struct rig_cache cache;
|
||||
int vfo_opt; /*!< Is -o switch turned on? */
|
||||
int auto_power_on; /*!< Allow Hamlib to power rig
|
||||
int auto_power_on; /*!< Allow Hamlib to power on rig
|
||||
automatically if supported */
|
||||
int auto_power_off; /*!< Allow Hamlib to power off rig
|
||||
automatically if supported */
|
||||
int auto_disable_screensaver; /*!< Allow Hamlib to disable the
|
||||
rig's screen saver automatically if
|
||||
|
|
|
@ -837,8 +837,31 @@ icom_rig_open(RIG *rig)
|
|||
int
|
||||
icom_rig_close(RIG *rig)
|
||||
{
|
||||
int retval = RIG_OK;
|
||||
// Nothing to do yet
|
||||
struct rig_state *rs = &rig->state;
|
||||
struct icom_priv_data *priv = (struct icom_priv_data *) rs->priv;
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__);
|
||||
|
||||
if (priv->poweron != 0 && rs->auto_power_off) {
|
||||
// maybe we need power off?
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s trying power off\n", __func__);
|
||||
retval = abs(rig_set_powerstat(rig, 0));
|
||||
|
||||
// this is only a fatal error if powerstat is implemented
|
||||
// if not iplemented than we're at an error here
|
||||
if (retval != RIG_OK && retval != RIG_ENIMPL && retval != RIG_ENAVAIL)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_WARN, "%s: unexpected retval here: %s\n",
|
||||
__func__, rigerror(retval));
|
||||
|
||||
rig_debug(RIG_DEBUG_WARN, "%s: rig_set_powerstat failed: =%s\n", __func__,
|
||||
rigerror(retval));
|
||||
return retval;
|
||||
}
|
||||
|
||||
}
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -964,6 +964,12 @@ int kenwood_close(RIG *rig)
|
|||
it's not supported */
|
||||
}
|
||||
|
||||
if (priv->poweron != 0 && rig->state.auto_power_off)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: got PS1 so powerdown\n", __func__);
|
||||
rig_set_powerstat(rig, 0);
|
||||
}
|
||||
|
||||
RETURNFUNC(RIG_OK);
|
||||
}
|
||||
|
||||
|
|
|
@ -584,6 +584,7 @@ int newcat_close(RIG *rig)
|
|||
{
|
||||
|
||||
struct newcat_priv_data *priv = rig->state.priv;
|
||||
struct rig_state *rig_s = &rig->state;
|
||||
|
||||
ENTERFUNC;
|
||||
|
||||
|
@ -594,6 +595,11 @@ int newcat_close(RIG *rig)
|
|||
case it's not
|
||||
supported */
|
||||
}
|
||||
if (priv->poweron != 0 && rig_s->auto_power_off)
|
||||
{
|
||||
rig_set_powerstat(rig, 0);
|
||||
priv->poweron = 0;
|
||||
}
|
||||
|
||||
RETURNFUNC(RIG_OK);
|
||||
}
|
||||
|
@ -3145,6 +3151,7 @@ int newcat_set_powerstat(RIG *rig, powerstat_t status)
|
|||
case RIG_POWER_OFF:
|
||||
case RIG_POWER_STANDBY:
|
||||
ps = '0';
|
||||
write_block(&state->rigport, "\n", 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
18
src/conf.c
18
src/conf.c
|
@ -133,6 +133,11 @@ static const struct confparams frontend_cfg_params[] =
|
|||
"True enables compatible rigs to be powered up on open",
|
||||
"0", RIG_CONF_CHECKBUTTON, { }
|
||||
},
|
||||
{
|
||||
TOK_AUTO_POWER_OFF, "auto_power_off", "Auto power off",
|
||||
"True enables compatible rigs to be powered down on close",
|
||||
"0", RIG_CONF_CHECKBUTTON, { }
|
||||
},
|
||||
{
|
||||
TOK_AUTO_DISABLE_SCREENSAVER, "auto_disable_screensaver", "Auto disable screen saver",
|
||||
"True enables compatible rigs to have their screen saver disabled on open",
|
||||
|
@ -596,6 +601,15 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|||
rs->auto_power_on = val_i ? 1 : 0;
|
||||
break;
|
||||
|
||||
case TOK_AUTO_POWER_OFF:
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
return -RIG_EINVAL; //value format error
|
||||
}
|
||||
|
||||
rs->auto_power_off = val_i ? 1 : 0;
|
||||
break;
|
||||
|
||||
case TOK_AUTO_DISABLE_SCREENSAVER:
|
||||
if (1 != sscanf(val, "%d", &val_i))
|
||||
{
|
||||
|
@ -966,6 +980,10 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|||
sprintf(val, "%d", rs->auto_power_on);
|
||||
break;
|
||||
|
||||
case TOK_AUTO_POWER_OFF:
|
||||
sprintf(val, "%d", rs->auto_power_off);
|
||||
break;
|
||||
|
||||
case TOK_AUTO_DISABLE_SCREENSAVER:
|
||||
sprintf(val, "%d", rs->auto_disable_screensaver);
|
||||
break;
|
||||
|
|
135
src/rig.c
135
src/rig.c
|
@ -1321,54 +1321,6 @@ int HAMLIB_API rig_get_twiddle(RIG *rig, int *seconds)
|
|||
RETURNFUNC(RIG_OK);
|
||||
}
|
||||
|
||||
// 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
|
||||
int twiddling(RIG *rig)
|
||||
{
|
||||
const struct rig_caps *caps;
|
||||
|
||||
if (rig->state.twiddle_timeout == 0) { return 0; } // don't detect twiddling
|
||||
|
||||
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);
|
||||
|
||||
if (rig->state.current_freq == 0)
|
||||
{
|
||||
rig->state.current_freq = curr_freq;
|
||||
RETURNFUNC(0); // not twiddling as first time freq is being set
|
||||
}
|
||||
|
||||
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.twiddle_time;
|
||||
|
||||
if (elapsed < rig->state.twiddle_timeout)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: Twiddle elapsed < 3, elapsed=%d\n", __func__,
|
||||
elapsed);
|
||||
RETURNFUNC(1); // would be better as error but other software won't handle it
|
||||
}
|
||||
}
|
||||
|
||||
RETURNFUNC(0);
|
||||
}
|
||||
|
||||
/* caching prototype to be fully implemented in 4.1 */
|
||||
static int set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
||||
{
|
||||
|
@ -1522,6 +1474,55 @@ static int get_cache_freq(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms)
|
|||
RETURNFUNC(RIG_OK);
|
||||
}
|
||||
|
||||
// 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
|
||||
int twiddling(RIG *rig)
|
||||
{
|
||||
const struct rig_caps *caps;
|
||||
|
||||
if (rig->state.twiddle_timeout == 0) { return 0; } // don't detect twiddling
|
||||
|
||||
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);
|
||||
|
||||
if (rig->state.current_freq == 0)
|
||||
{
|
||||
rig->state.current_freq = curr_freq;
|
||||
RETURNFUNC(0); // not twiddling as first time freq is being set
|
||||
}
|
||||
|
||||
rig->state.twiddle_time = time(NULL); // update last twiddle time
|
||||
rig->state.current_freq = curr_freq; // we have a new freq to remember
|
||||
set_cache_freq(rig, RIG_VFO_CURR, curr_freq);
|
||||
}
|
||||
|
||||
elapsed = time(NULL) - rig->state.twiddle_time;
|
||||
|
||||
if (elapsed < rig->state.twiddle_timeout)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: Twiddle elapsed < 3, elapsed=%d\n", __func__,
|
||||
elapsed);
|
||||
RETURNFUNC(1); // would be better as error but other software won't handle it
|
||||
}
|
||||
}
|
||||
|
||||
RETURNFUNC(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief set the frequency of the target VFO
|
||||
* \param rig The rig handle
|
||||
|
@ -1837,7 +1838,7 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
|||
rig->state.cache.freq = *freq;
|
||||
//future 4.1 caching
|
||||
set_cache_freq(rig, vfo, *freq);
|
||||
rig->state.cache.vfo_freq = vfo;
|
||||
rig->state.cache.vfo_freq = *freq;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -5771,6 +5772,8 @@ const char *HAMLIB_API rig_get_info(RIG *rig)
|
|||
int HAMLIB_API rig_get_vfo_info(RIG *rig, vfo_t vfo, freq_t *freq,
|
||||
rmode_t *mode, pbwidth_t *width, split_t *split)
|
||||
{
|
||||
int retval;
|
||||
|
||||
ENTERFUNC;
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called vfo=%s\n", __func__, rig_strvfo(vfo));
|
||||
|
||||
|
@ -5781,34 +5784,16 @@ int HAMLIB_API rig_get_vfo_info(RIG *rig, vfo_t vfo, freq_t *freq,
|
|||
|
||||
if (vfo == RIG_VFO_CURR) { vfo = rig->state.current_vfo; }
|
||||
|
||||
if (vfo == RIG_VFO_A || vfo == RIG_VFO_MAIN || vfo == RIG_VFO_MAIN_A)
|
||||
{
|
||||
*freq = rig->state.cache.freqMainA;
|
||||
*width = rig->state.cache.width;
|
||||
}
|
||||
else if (vfo == RIG_VFO_MAIN_B)
|
||||
{
|
||||
*freq = rig->state.cache.freqMainB;
|
||||
*width = rig->state.cache.width;
|
||||
// we can't use the cached values as some clients may only call this function
|
||||
// like Log4OM which mostly does polling
|
||||
retval = rig_get_freq(rig, vfo, freq);
|
||||
if (retval != RIG_OK) RETURNFUNC(retval);
|
||||
|
||||
if (rig->state.cache.widthB) { *width = rig->state.cache.widthB; }
|
||||
}
|
||||
else if (vfo == RIG_VFO_SUB_B)
|
||||
{
|
||||
*freq = rig->state.cache.freqSubB;
|
||||
*width = rig->state.cache.width;
|
||||
retval = rig_get_mode(rig, vfo, mode, width);
|
||||
if (retval != RIG_OK) RETURNFUNC(retval);
|
||||
|
||||
if (rig->state.cache.widthB) { *width = rig->state.cache.widthB; }
|
||||
}
|
||||
else
|
||||
{
|
||||
*freq = rig->state.cache.freqMainB;
|
||||
*width = rig->state.cache.width;
|
||||
|
||||
if (rig->state.cache.widthB) { *width = rig->state.cache.widthB; }
|
||||
}
|
||||
|
||||
*split = rig->state.cache.split;
|
||||
retval = rig_get_split(rig, vfo, split);
|
||||
if (retval != RIG_OK) RETURNFUNC(retval);
|
||||
|
||||
RETURNFUNC(RIG_OK);
|
||||
}
|
||||
|
|
10
src/token.h
10
src/token.h
|
@ -110,14 +110,16 @@
|
|||
#define TOK_CACHE_TIMEOUT TOKEN_FRONTEND(123)
|
||||
/** \brief rig: Auto power on rig_open when supported */
|
||||
#define TOK_AUTO_POWER_ON TOKEN_FRONTEND(124)
|
||||
/** \brief rig: Auto power off rig_close when supported */
|
||||
#define TOK_AUTO_POWER_OFF TOKEN_FRONTEND(125)
|
||||
/** \brief rig: Auto disable screensaver */
|
||||
#define TOK_AUTO_DISABLE_SCREENSAVER TOKEN_FRONTEND(125)
|
||||
#define TOK_AUTO_DISABLE_SCREENSAVER TOKEN_FRONTEND(126)
|
||||
/** \brief rig: Disable Yaesu band select logic */
|
||||
#define TOK_DISABLE_YAESU_BANDSELECT TOKEN_FRONTEND(126)
|
||||
#define TOK_DISABLE_YAESU_BANDSELECT TOKEN_FRONTEND(127)
|
||||
/** \brief rig: Supporess get_freq on VFOB for satellite RIT tuning */
|
||||
#define TOK_TWIDDLE_TIMEOUT TOKEN_FRONTEND(127)
|
||||
#define TOK_TWIDDLE_TIMEOUT TOKEN_FRONTEND(128)
|
||||
/** \brief rig: Supporess get_freq on VFOB for satellite RIT tuning */
|
||||
#define TOK_TWIDDLE_RIT TOKEN_FRONTEND(128)
|
||||
#define TOK_TWIDDLE_RIT TOKEN_FRONTEND(129)
|
||||
/*
|
||||
* rotator specific tokens
|
||||
* (strictly, should be documented as rotator_internal)
|
||||
|
|
Ładowanie…
Reference in New Issue