From 4aec46133750f55e13cb2b3310635f5c196c7460 Mon Sep 17 00:00:00 2001 From: Mikael Nousiainen Date: Thu, 8 Jun 2023 18:56:29 +0300 Subject: [PATCH] Improve Icom power status handling. Add auto power on/off to netrigctl. --- rigs/dummy/netrigctl.c | 11 +++++++++++ rigs/icom/icom.c | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/rigs/dummy/netrigctl.c b/rigs/dummy/netrigctl.c index d2d381c60..a79eeaaa2 100644 --- a/rigs/dummy/netrigctl.c +++ b/rigs/dummy/netrigctl.c @@ -905,16 +905,27 @@ static int netrigctl_open(RIG *rig) } while (1); + if (rs->auto_power_on) + { + rig_set_powerstat(rig, 1); + } + RETURNFUNC(RIG_OK); } static int netrigctl_close(RIG *rig) { + struct rig_state *rs = &rig->state; int ret; char buf[BUF_MAX]; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (rs->auto_power_off && rs->comm_state) + { + rig_set_powerstat(rig, 0); + } + ret = netrigctl_transaction(rig, "q\n", 2, buf); if (ret != RIG_OK) diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index 92788ef77..803b1cdb7 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -8039,6 +8039,7 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) unsigned char fe_buf[fe_max]; // for FE's to power up int i; int retry, retry_save; + short timeout_retry_save; struct rig_state *rs = &rig->state; struct icom_priv_data *priv = (struct icom_priv_data *) rs->priv; @@ -8048,19 +8049,21 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) // elimininate retries to speed this up // especially important when rig is not turned on retry_save = rs->rigport.retry; + timeout_retry_save = rs->rigport.timeout_retry; + rs->rigport.retry = 0; + rs->rigport.timeout_retry = 0; switch (status) { case RIG_POWER_ON: - // ic7300 manual says ~150 for 115,200 // we'll just send a few more to be sure for all speeds memset(fe_buf, 0xfe, fe_max); // sending more than enough 0xfe's to wake up the rs232 write_block(&rs->rigport, fe_buf, fe_max); - hl_usleep(200 * - 1000); // need to wait a bit for RigPI and others to queue the echo + // need to wait a bit for RigPI and others to queue the echo + hl_usleep(200 * 1000); // we'll try 0x18 0x01 now -- should work on STBY rigs too pwr_sc = S_PWR_ON; @@ -8085,11 +8088,18 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) { retval = icom_get_usb_echo_off(rig); - if (retval != RIG_OK) { sleep(1); } + if (retval != RIG_OK) + { + sleep(1); + } + } + if (retval == RIG_OK) + { + priv->poweron = 1; } - if (retval == RIG_OK) { priv->poweron = 1; } - + rs->rigport.retry = retry_save; + rs->rigport.retry = timeout_retry_save; return RIG_OK; } @@ -8128,6 +8138,8 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) if (retval == RIG_OK) { rig->state.current_vfo = icom_current_vfo(rig); + rs->rigport.retry = retry_save; + rs->rigport.retry = timeout_retry_save; RETURNFUNC2(retval); } else @@ -8142,6 +8154,7 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) } rs->rigport.retry = retry_save; + rs->rigport.retry = timeout_retry_save; if (i == retry) { @@ -8208,19 +8221,29 @@ int icom_get_powerstat(RIG *rig, powerstat_t *status) } if (rig->caps->rig_model == RIG_MODEL_IC2730 + || rig->caps->rig_model == RIG_MODEL_IC705 || rig->caps->rig_model == RIG_MODEL_IC7100 || rig->caps->rig_model == RIG_MODEL_IC7300 || rig->caps->rig_model == RIG_MODEL_IC7600 || rig->caps->rig_model == RIG_MODEL_IC7610 || rig->caps->rig_model == RIG_MODEL_IC7700 || rig->caps->rig_model == RIG_MODEL_IC7800 + || rig->caps->rig_model == RIG_MODEL_IC785x + || rig->caps->rig_model == RIG_MODEL_IC9700 || rig->caps->rig_model == RIG_MODEL_IC905) { freq_t freq; - int retrysave = rig->caps->retry; + short retry_save = rig->state.rigport.retry; + short timeout_retry_save = rig->state.rigport.timeout_retry; + rig->state.rigport.retry = 0; - int retval = rig_get_freq(rig, RIG_VFO_A, &freq); - rig->state.rigport.retry = retrysave; + rig->state.rigport.timeout_retry = 0; + + retval = rig_get_freq(rig, RIG_VFO_A, &freq); + + rig->state.rigport.retry = retry_save; + rig->state.rigport.timeout_retry = timeout_retry_save; + *status = retval == RIG_OK ? RIG_POWER_ON : RIG_POWER_OFF; return retval; }