kopia lustrzana https://github.com/Hamlib/Hamlib
Fix issues with power status handling in rigctl+rigctld and the Yaesu backend
rodzic
8730e6a0b1
commit
fd68723da1
|
@ -10534,10 +10534,11 @@ int newcat_get_cmd(RIG *rig)
|
|||
int retry_count = 0;
|
||||
int rc = -RIG_EPROTO;
|
||||
int is_read_cmd = 0;
|
||||
int is_power_status_cmd = strncmp(priv->cmd_str, "PS", 2) == 0;
|
||||
|
||||
ENTERFUNC;
|
||||
|
||||
if (state->powerstat == 0)
|
||||
if (state->powerstat == 0 && !is_power_status_cmd)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_WARN, "%s: Cannot get from rig when power is off\n", __func__);
|
||||
return RIG_OK; // to prevent repeats
|
||||
|
@ -10614,14 +10615,13 @@ int newcat_get_cmd(RIG *rig)
|
|||
|| strcmp(priv->cmd_str, "VT0;") == 0
|
||||
|| strcmp(priv->cmd_str, "VT1;") == 0;
|
||||
|
||||
if (priv->cmd_str[2] !=
|
||||
';' && !is_read_cmd) // then we must be setting something so we'll invalidate the cache
|
||||
if (priv->cmd_str[2] != ';' && !is_read_cmd)
|
||||
{
|
||||
// then we must be setting something so we'll invalidate the cache
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: cache invalidated\n", __func__);
|
||||
priv->cache_start.tv_sec = 0;
|
||||
}
|
||||
|
||||
|
||||
while (rc != RIG_OK && retry_count++ <= state->rigport.retry)
|
||||
{
|
||||
rig_flush(&state->rigport); /* discard any unsolicited data */
|
||||
|
@ -10630,11 +10630,8 @@ int newcat_get_cmd(RIG *rig)
|
|||
/* send the command */
|
||||
rig_debug(RIG_DEBUG_TRACE, "cmd_str = %s\n", priv->cmd_str);
|
||||
|
||||
|
||||
if (strncmp(priv->cmd_str,"PS",2)==0) state->rigport.timeout_retry = 0;
|
||||
if (RIG_OK != (rc = write_block(&state->rigport,
|
||||
(unsigned char *) priv->cmd_str,
|
||||
strlen(priv->cmd_str))))
|
||||
rc = write_block(&state->rigport, (unsigned char *) priv->cmd_str, strlen(priv->cmd_str));
|
||||
if (rc != RIG_OK)
|
||||
{
|
||||
RETURNFUNC(rc);
|
||||
}
|
||||
|
@ -10646,9 +10643,10 @@ int newcat_get_cmd(RIG *rig)
|
|||
&cat_term, sizeof(cat_term), 0, 1)) <= 0)
|
||||
{
|
||||
// if we get a timeout from PS probably means power is off
|
||||
if (strncmp(priv->cmd_str,"PS",2)==0) {
|
||||
if (rc == -RIG_ETIMEOUT && is_power_status_cmd)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_WARN, "%s: rig power is off?\n", __func__);
|
||||
return -RIG_ETIMEOUT;
|
||||
RETURNFUNC(rc);
|
||||
}
|
||||
continue; /* usually a timeout - retry */
|
||||
}
|
||||
|
|
14
src/rig.c
14
src/rig.c
|
@ -100,7 +100,7 @@ const char *hamlib_version2 = "Hamlib " PACKAGE_VERSION " " HAMLIBDATETIME " "
|
|||
ARCHBITS;
|
||||
HAMLIB_EXPORT_VAR(int) cookie_use;
|
||||
HAMLIB_EXPORT_VAR(int) lock_mode; // for use by rigctld
|
||||
HAMLIB_EXPORT_VAR(powerstat_t) rig_powerstat; // for use by rigctld
|
||||
HAMLIB_EXPORT_VAR(powerstat_t) rig_powerstat; // for use by both rigctld and rigctl
|
||||
//! @endcond
|
||||
|
||||
struct rig_caps caps_test;
|
||||
|
@ -6167,6 +6167,12 @@ int HAMLIB_API rig_set_powerstat(RIG *rig, powerstat_t status)
|
|||
|
||||
HAMLIB_TRACE;
|
||||
retcode = rig->caps->set_powerstat(rig, status);
|
||||
|
||||
if (retcode == RIG_OK)
|
||||
{
|
||||
rig->state.powerstat = status;
|
||||
}
|
||||
|
||||
// if anything is queued up flush it
|
||||
rig_flush_force(&rig->state.rigport, 1);
|
||||
RETURNFUNC(retcode);
|
||||
|
@ -6214,7 +6220,11 @@ int HAMLIB_API rig_get_powerstat(RIG *rig, powerstat_t *status)
|
|||
HAMLIB_TRACE;
|
||||
retcode = rig->caps->get_powerstat(rig, status);
|
||||
|
||||
if (retcode != RIG_OK)
|
||||
if (retcode == RIG_OK)
|
||||
{
|
||||
rig->state.powerstat = *status;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if failed, assume power is on
|
||||
*status = RIG_POWER_ON;
|
||||
|
|
|
@ -111,6 +111,7 @@ static struct option long_options[] =
|
|||
};
|
||||
|
||||
extern char rig_resp_sep;
|
||||
extern powerstat_t rig_powerstat;
|
||||
|
||||
#define MAXCONFLEN 1024
|
||||
|
||||
|
@ -149,6 +150,7 @@ int main(int argc, char *argv[])
|
|||
int i;
|
||||
char rigstartup[1024];
|
||||
char vbuf[1024];
|
||||
rig_powerstat = RIG_POWER_ON; // defaults to power on
|
||||
|
||||
int err = setvbuf(stderr, vbuf, _IOFBF, sizeof(vbuf));
|
||||
|
||||
|
@ -575,6 +577,12 @@ int main(int argc, char *argv[])
|
|||
my_rig->caps->model_name);
|
||||
}
|
||||
|
||||
if (my_rig->caps->get_powerstat)
|
||||
{
|
||||
rig_get_powerstat(my_rig, &rig_powerstat);
|
||||
my_rig->state.powerstat = rig_powerstat;
|
||||
}
|
||||
|
||||
if (my_rig->caps->rig_model == RIG_MODEL_NETRIGCTL)
|
||||
{
|
||||
/* We automatically detect if we need to be in vfo mode or not */
|
||||
|
@ -650,6 +658,21 @@ int main(int argc, char *argv[])
|
|||
interactive, prompt, &vfo_opt, send_cmd_term,
|
||||
&ext_resp, &rig_resp_sep, 0);
|
||||
|
||||
// If we get a timeout, the rig might be powered off
|
||||
// Update our power status in case power gets turned off
|
||||
if (retcode == -RIG_ETIMEOUT && my_rig->caps->get_powerstat)
|
||||
{
|
||||
powerstat_t powerstat;
|
||||
|
||||
rig_get_powerstat(my_rig, &powerstat);
|
||||
rig_powerstat = powerstat;
|
||||
|
||||
if (powerstat == RIG_POWER_OFF || powerstat == RIG_POWER_STANDBY)
|
||||
{
|
||||
retcode = -RIG_EPOWER;
|
||||
}
|
||||
}
|
||||
|
||||
// if we get a hard error we try to reopen the rig again
|
||||
// this should cover short dropouts that can occur
|
||||
if (retcode < 0 && !RIG_IS_SOFT_ERRCODE(-retcode))
|
||||
|
|
|
@ -104,7 +104,7 @@ char rigctld_password[64];
|
|||
int is_passwordOK;
|
||||
int is_rigctld;
|
||||
extern int lock_mode; // used by rigctld
|
||||
extern int rig_powerstat;
|
||||
extern powerstat_t rig_powerstat;
|
||||
|
||||
|
||||
|
||||
|
@ -4723,7 +4723,6 @@ declare_proto_rig(set_powerstat)
|
|||
retval = rig_set_powerstat(rig, (powerstat_t) stat);
|
||||
if (retval == RIG_OK)
|
||||
{
|
||||
rig->state.powerstat = stat;
|
||||
rig_powerstat = stat; // update our global so others can see powerstat
|
||||
}
|
||||
fflush(fin);
|
||||
|
@ -4752,7 +4751,6 @@ declare_proto_rig(get_powerstat)
|
|||
}
|
||||
|
||||
fprintf(fout, "%d\n", stat);
|
||||
rig->state.powerstat = stat;
|
||||
rig_powerstat = stat; // update our global so others can see powerstat
|
||||
|
||||
RETURNFUNC2(status);
|
||||
|
|
|
@ -1278,9 +1278,9 @@ void *handle_socket(void *arg)
|
|||
|
||||
if (retcode != 0) { rig_debug(RIG_DEBUG_VERBOSE, "%s: rigctl_parse retcode=%d\n", __func__, retcode); }
|
||||
|
||||
// update our power stat in case power gets turned off
|
||||
if (retcode == -RIG_ETIMEOUT
|
||||
&& my_rig->caps->get_powerstat) // if we get a timeout we might be powered off
|
||||
// If we get a timeout, the rig might be powered off
|
||||
// Update our power status in case power gets turned off
|
||||
if (retcode == -RIG_ETIMEOUT && my_rig->caps->get_powerstat)
|
||||
{
|
||||
rig_get_powerstat(my_rig, &powerstat);
|
||||
rig_powerstat = powerstat;
|
||||
|
|
Ładowanie…
Reference in New Issue