diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index bfb2b92e9..8f0fa52f0 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -4637,8 +4637,10 @@ int newcat_get_channel(RIG *rig, channel_t *chan, int read_only) chan->freq = atof(retval); #warning Need to add setting rig to channel values - if (!read_only) { - // Set rig to channel values + + if (!read_only) + { + // Set rig to channel values } return RIG_OK; @@ -6130,6 +6132,25 @@ int newcat_get_cmd(RIG *rig) int retry_count = 0; int rc = -RIG_EPROTO; + // try to cache rapid repeats of the IF command + // this is for WSJT-X/JTDX sequence of v/f/m/t + // should reduce 3 IF requests to 1 request and 2 cache hits + if (strcmp(priv->cmd_str, "IF") == 0 && priv->cache_start.tv_sec != 0) + { + int cache_age_ms; + + cache_age_ms = elapsed_ms(&priv->cache_start, 0); + + if (cache_age_ms < 500) // 500ms cache time + { + rig_debug(RIG_DEBUG_TRACE, "%s: cache hit, age=%dms\n", __func__, cache_age_ms); + strcpy(priv->ret_data, priv->last_if_response); + return RIG_OK; + } + + // else we drop through and do the real IF command + } + while (rc != RIG_OK && retry_count++ <= state->rigport.retry) { if (rc != -RIG_BUSBUSY) @@ -6223,6 +6244,10 @@ int newcat_get_cmd(RIG *rig) } } + // update the cache + elapsed_ms(&priv->cache_start, 1); + strcpy(priv->last_if_response, priv->ret_data); + return rc; } diff --git a/rigs/yaesu/newcat.h b/rigs/yaesu/newcat.h index 8edc1377e..ed5d0e81d 100644 --- a/rigs/yaesu/newcat.h +++ b/rigs/yaesu/newcat.h @@ -88,6 +88,8 @@ struct newcat_priv_data { int trn_state; /* AI state found at startup */ int fast_set_commands; /* do not check for ACK/NAK; needed for high throughput > 100 commands/s */ int width_frequency; /* found at startup */ + struct timespec cache_start; + char last_if_response[NEWCAT_DATA_LEN]; }; diff --git a/src/misc.c b/src/misc.c index b51c791e1..e6259a465 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1252,6 +1252,29 @@ void HAMLIB_API rig_no_restore_ai() no_restore_ai = -1; } + +//! @cond Doxygen_Suppress +int HAMLIB_API elapsed_ms(struct timespec *start, int flag_start) +{ + // If flag_start then we are starting the timing, else we get elapsed + struct timespec stop; + double elapsed_secs; + + if (flag_start) + { + clock_gettime(CLOCK_REALTIME, start); + return 0; + } + else + { + clock_gettime(CLOCK_REALTIME, &stop); + } + + elapsed_secs = (stop.tv_sec - start->tv_sec) * 1e6 + (stop.tv_nsec - + start->tv_nsec) / 1e3; + return elapsed_secs / 1000; +} + //! @endcond /** @} */ diff --git a/src/misc.h b/src/misc.h index 99ae92874..b39902dbc 100644 --- a/src/misc.h +++ b/src/misc.h @@ -100,6 +100,8 @@ extern HAMLIB_EXPORT(setting_t) rig_idx2setting(int i); extern HAMLIB_EXPORT(int) hl_usleep(useconds_t usec); +extern HAMLIB_EXPORT(int) elapsed_ms(struct timespec *start, int start_flag); + #ifdef PRId64 /** \brief printf(3) format to be used for long long (64bits) type */ # define PRIll PRId64