From 24eaeecfdfa1eacd11b64e927db75376ea9ecee8 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 15:01:08 -0600 Subject: [PATCH] Fix sleep macros and newcat.c set_powerstat --- include/hamlib/rig.h | 10 ++++++---- yaesu/newcat.c | 14 ++++++-------- yaesu/newcat.h | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index b03b38553..cb256f060 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -97,16 +97,18 @@ #undef usleep #define usleep(n)\ do {\ + unsigned long sec = n/1000000ul;\ + unsigned long nsec = n*1000ul - (sec * 1000000000ul);\ struct timespec t;\ - t.tv_sec=0;\ - t.tv_nsec = n*1000ul;\ + t.tv_sec=sec;\ + t.tv_nsec = nsec;\ nanosleep(&t,NULL);\ } while(0) #define sleep(n)\ do {\ struct timespec t;\ - t.tv_sec=0;\ - t.tv_nsec = n*1000000000ul;\ + t.tv_sec=n;\ + t.tv_nsec = 0;\ nanosleep(&t,NULL);\ } while(0) diff --git a/yaesu/newcat.c b/yaesu/newcat.c index 82197f3e2..ed5167132 100644 --- a/yaesu/newcat.c +++ b/yaesu/newcat.c @@ -2260,6 +2260,10 @@ int newcat_set_powerstat(RIG *rig, powerstat_t status) { case RIG_POWER_ON: ps = '1'; + // when powering on need a dummy byte to wake it up + // then sleep from 1 to 2 seconds so we'll do 1.5 secs + write_block(&state->rigport, "\n", 1); + usleep(1500000); break; case RIG_POWER_OFF: @@ -2273,15 +2277,9 @@ int newcat_set_powerstat(RIG *rig, powerstat_t status) snprintf(priv->cmd_str, sizeof(priv->cmd_str), "PS%c%c", ps, cat_term); - if (RIG_OK != (err = write_block(&state->rigport, priv->cmd_str, - strlen(priv->cmd_str)))) - { - return err; - } + err = write_block(&state->rigport, priv->cmd_str, strlen(priv->cmd_str)); - // delay 1.5 seconds - usleep(1500000); - return write_block(&state->rigport, priv->cmd_str, strlen(priv->cmd_str)); + return err; } diff --git a/yaesu/newcat.h b/yaesu/newcat.h index 8fcf77bf3..60b2a5983 100644 --- a/yaesu/newcat.h +++ b/yaesu/newcat.h @@ -50,7 +50,7 @@ typedef char ncboolean; /* shared function version */ -#define NEWCAT_VER "0.25" +#define NEWCAT_VER "0.26" /* Hopefully large enough for future use, 128 chars plus '\0' */ #define NEWCAT_DATA_LEN 129