Skip to content

Commit

Permalink
Slow freq events to 4 per second
Browse files Browse the repository at this point in the history
  • Loading branch information
mdblack98 committed Mar 3, 2024
1 parent c74b3c1 commit dc38d19
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/hamlib/rig.h
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ============================================
};

Expand Down
16 changes: 13 additions & 3 deletions src/event.c
Expand Up @@ -627,12 +627,22 @@ int rig_fire_freq_event(RIG *rig, vfo_t vfo, freq_t freq)
rig->state.use_cached_freq = 1;
}

if (rig->state.freq_event_elapsed.tv_sec == 0)
{
elapsed_ms(&rig->state.freq_event_elapsed, HAMLIB_ELAPSED_SET);
}

network_publish_rig_transceive_data(rig);
double e = elapsed_ms(&rig->state.freq_event_elapsed, HAMLIB_ELAPSED_GET);

if (rig->callbacks.freq_event)
if (e >= 250) // throttle events to 4 per sec
{
rig->callbacks.freq_event(rig, vfo, freq, rig->callbacks.freq_arg);
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);
Expand Down

0 comments on commit dc38d19

Please sign in to comment.