From dc38d19449a0a7e0c97298a46876887e484fb80c Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Sun, 3 Mar 2024 12:23:33 -0600 Subject: [PATCH] Slow freq events to 4 per second --- include/hamlib/rig.h | 3 ++- src/event.c | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 025518036..339ad0148 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2663,7 +2663,7 @@ typedef unsigned int rig_comm_status_t; * that may be updated (ie. customized) * * It is NOT fine to move fields around as it can break share library offset - * As of 2021-03-03 vfo_list is the last known item being reference externally + * As of 2024-03-03 freq_event_elapsed is the last known item being reference externally * So any additions or changes to this structure must be at the end of the structure */ struct rig_state { @@ -2849,6 +2849,7 @@ struct rig_state { char device_id[HAMLIB_RIGNAMSIZ]; int dual_watch; /*!< Boolean DUAL_WATCH status */ int post_ptt_delay; /*!< delay after PTT to allow for relays and such */ + struct timespec freq_event_elapsed; // New rig_state items go before this line ============================================ }; diff --git a/src/event.c b/src/event.c index c756c1201..5671be0a6 100644 --- a/src/event.c +++ b/src/event.c @@ -627,12 +627,22 @@ int rig_fire_freq_event(RIG *rig, vfo_t vfo, freq_t freq) rig->state.use_cached_freq = 1; } - - network_publish_rig_transceive_data(rig); - - if (rig->callbacks.freq_event) + if (rig->state.freq_event_elapsed.tv_sec == 0) { - rig->callbacks.freq_event(rig, vfo, freq, rig->callbacks.freq_arg); + elapsed_ms(&rig->state.freq_event_elapsed, HAMLIB_ELAPSED_SET); + } + + double e = elapsed_ms(&rig->state.freq_event_elapsed, HAMLIB_ELAPSED_GET); + + if (e >= 250) // throttle events to 4 per sec + { + elapsed_ms(&rig->state.freq_event_elapsed, HAMLIB_ELAPSED_SET); + network_publish_rig_transceive_data(rig); + + if (rig->callbacks.freq_event) + { + rig->callbacks.freq_event(rig, vfo, freq, rig->callbacks.freq_arg); + } } RETURNFUNC(0);