From 86a7a0636c278c5dfdc86baeb9fdb291e559fdc4 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Fri, 14 Jun 2024 15:34:48 -0400 Subject: [PATCH] Definitions, storage and infrastructure for queuing config commands --- include/hamlib/rig.h | 16 ++++++++++++++++ src/misc.c | 34 ++++++++++++++++++++++++++++++++++ src/misc.h | 2 ++ 3 files changed, 52 insertions(+) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index dd0cb43ab..51004c71c 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -1853,6 +1853,22 @@ struct rig_spectrum_line unsigned char *spectrum_data; /*!< 8-bit spectrum data covering bandwidth of either the span_freq in center mode or from low edge to high edge in fixed mode. A higher value represents higher signal strength. */ }; +/** + * Config item for deferred processing + **/ +struct deferred_config_item { + struct deferred_config_item *next; + hamlib_token_t token; + char *value; // strdup'ed, must be freed +}; +typedef struct deferred_config_item deferred_config_item_t; + +struct deferred_config_header { + struct deferred_config_item *first; // NULL if none + struct deferred_config_item *last; +}; +typedef struct deferred_config_header deferred_config_header_t; + /** * \brief Rig data structure. * diff --git a/src/misc.c b/src/misc.c index 8d17baf6b..2e6c5aef6 100644 --- a/src/misc.c +++ b/src/misc.c @@ -3125,4 +3125,38 @@ int rig_test_2038(RIG *rig) //! @endcond +/** + * Add item to be sent to device after it is opened + * (currently only used by rotators) + **/ +int queue_deferred_config(deferred_config_header_t *head, hamlib_token_t token, const char *val) +{ + deferred_config_item_t *item; + + if (!(item = malloc(sizeof(deferred_config_item_t)))) + { + return -RIG_ENOMEM; + } + if (!(item->value = strdup(val))) + { + free(item); + return -RIG_ENOMEM; + } + + item->token = token; + item->next = NULL; + + if (!head->first) + { + head->first = item; + } + else + { + head->last->next = item; + } + + head->last = item; + + return RIG_OK; +} /** @} */ diff --git a/src/misc.h b/src/misc.h index 86608de57..18a2050cc 100644 --- a/src/misc.h +++ b/src/misc.h @@ -211,6 +211,8 @@ extern HAMLIB_EXPORT(int) rig_settings_load_all(char *settings_file); extern int check_level_param(RIG *rig, setting_t level, value_t val, gran_t **gran); +extern int queue_deferred_config(deferred_config_header_t *head, hamlib_token_t token, const char *val); + // Takes rig-specific band result and maps it the bandlist int the rig's backend extern HAMLIB_EXPORT(hamlib_band_t) rig_get_band(RIG *rig, freq_t freq, int band); extern HAMLIB_EXPORT(const char*) rig_get_band_str(RIG *rig, hamlib_band_t band, int which);