[Hamlib-commits] Hamlib -- Ham radio control libraries branch master updated. b0d5d606fef17e349f5a2
Library to control radio transceivers and receivers
Brought to you by:
n0nb
From: n0nb <n0...@us...> - 2025-06-04 14:39:28
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Hamlib -- Ham radio control libraries". The branch, master has been updated via b0d5d606fef17e349f5a2fd587fa429f8f89be30 (commit) via 1532432236a526a5d019eb1ece48eb8643b1fd7d (commit) via 3bdfdebacb59ab5d044515edd1954d4eba414469 (commit) via 29924af2f123e96241b69beb2185455f94706f64 (commit) via f5eb8f19e9dcdaabf654b095d671135f46ae5c90 (commit) via 1fca93a5a25b1afb6cc591d1769924bbaa746099 (commit) via 6f8bf815149f535831f8e1ced44d2b5e6a01bb97 (commit) via 7d28822273dec229da1ceca809a3d4f241e4749f (commit) via 4d322337c1d6d06edaa42887b2ba8430c53aa4f7 (commit) via 3bc9e5261be8359203419f8d8fe0d100b40f3eb0 (commit) via 6b5c5b48f9c7a0582beb0259f00a1bf1c81bf451 (commit) via 7fa0c863f262a937cae95450fd15056a0fbce12f (commit) via 63e1bb4c0096a974ad3388357c47c4398a587a84 (commit) from cccee9b7916548c2c48a1bfd55116fded3d3a6ed (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit b0d5d606fef17e349f5a2fd587fa429f8f89be30 Author: George Baltz N3GB <Geo...@gm...> Date: Wed Jun 4 09:46:51 2025 -0400 Update NEWS diff --git a/NEWS b/NEWS index 7e2378205..d11a05a6e 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,8 @@ Version 5.x -- future Version 4.7.0 * 2025-12-01 (target) + * Move rig_cache to separate(calloc) storage. Prepare for other moves. + Issue #1420 Version 4.6.3 * 2025-06-10 commit 1532432236a526a5d019eb1ece48eb8643b1fd7d Author: George Baltz N3GB <Geo...@gm...> Date: Wed May 21 13:49:18 2025 -0400 Move more rig_cache infrastructure to cache.[ch] Macros from rig.h, routines from misc.c Add some error checks and comments diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index b9cd59908..6656c5aeb 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2522,7 +2522,7 @@ typedef hamlib_port_t port_t; #define RIGPORT(r) (&r->state.rigport) #define PTTPORT(r) (&r->state.pttport) #define DCDPORT(r) (&r->state.dcdport) -#define CACHE(r) ((r)->cache_addr) +//Moved to cache.h #define CACHE(r) ((r)->cache_addr) #define AMPPORT(a) (&a->state.ampport) #define ROTPORT(r) (&r->state.rotport) #define ROTPORT2(r) (&r->state.rotport2) @@ -2539,7 +2539,7 @@ typedef hamlib_port_t port_t; #define HAMLIB_RIGPORT(r) ((hamlib_port_t *)rig_data_pointer(r, RIG_PTRX_RIGPORT)) #define HAMLIB_PTTPORT(r) ((hamlib_port_t *)rig_data_pointer(r, RIG_PTRX_PTTPORT)) #define HAMLIB_DCDPORT(r) ((hamlib_port_t *)rig_data_pointer(r, RIG_PTRX_DCDPORT)) -#define HAMLIB_CACHE(r) ((struct rig_cache *)rig_data_pointer(r, RIG_PTRX_CACHE)) +//#define HAMLIB_CACHE(r) ((struct rig_cache *)rig_data_pointer(r, RIG_PTRX_CACHE)) #define HAMLIB_AMPPORT(a) ((hamlib_port_t *)amp_data_pointer(a, RIG_PTRX_AMPPORT)) #define HAMLIB_ROTPORT(r) ((hamlib_port_t *)rot_data_pointer(r, RIG_PTRX_ROTPORT)) #define HAMLIB_ROTPORT2(r) ((hamlib_port_t *)rot_data_pointer(r, RIG_PTRX_ROTPORT2)) diff --git a/src/cache.c b/src/cache.c index 3ae4e11ee..d66b64af4 100644 --- a/src/cache.c +++ b/src/cache.c @@ -310,8 +310,8 @@ int rig_set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq) int rig_get_cache(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms_freq, rmode_t *mode, int *cache_ms_mode, pbwidth_t *width, int *cache_ms_width) { - struct rig_cache *cachep = CACHE(rig); - struct rig_state *rs = STATE(rig); + struct rig_cache *cachep; + struct rig_state *rs; if (CHECK_RIG_ARG(rig) || !freq || !cache_ms_freq || !mode || !cache_ms_mode || !width || !cache_ms_width) @@ -319,6 +319,9 @@ int rig_get_cache(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms_freq, return -RIG_EINVAL; } + cachep = CACHE(rig); + rs = STATE(rig); + if (rig_need_debug(RIG_DEBUG_CACHE)) { ENTERFUNC2; @@ -565,6 +568,25 @@ int rig_get_cache_freq(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms_freq_p) return retval; } +/* Get cache timeout period + * Returns value in msec, -1 if error + */ +int HAMLIB_API rig_get_cache_timeout_ms(RIG *rig, hamlib_cache_t selection) +{ + rig_debug(RIG_DEBUG_TRACE, "%s: called selection=%d\n", __func__, selection); + if (!rig) {return -1;} + return CACHE(rig)->timeout_ms; +} + +int HAMLIB_API rig_set_cache_timeout_ms(RIG *rig, hamlib_cache_t selection, + int ms) +{ + rig_debug(RIG_DEBUG_TRACE, "%s: called selection=%d, ms=%d\n", __func__, + selection, ms); + if (!rig) {return -RIG_EINVAL;} + CACHE(rig)->timeout_ms = ms; + return RIG_OK; +} void rig_cache_show(RIG *rig, const char *func, int line) { diff --git a/src/cache.h b/src/cache.h index e977273de..80ee340b8 100644 --- a/src/cache.h +++ b/src/cache.h @@ -28,6 +28,14 @@ __BEGIN_DECLS +/* It should be noted that there are two distinct cache implementations + * in Hamlib. This one is for the app-facing side, providing cached status + * (freq, mode, band, etc) for application queries. The other is used by + * backends for rig status probes, watchdog timers, and other hardware related + * tasks. Also note that they use different times - timespec vs timeval. + * - n3gb 2025-05-14 + */ + /** * \brief Rig cache data * @@ -108,6 +116,13 @@ struct rig_cache { int satmode; // if rig is in satellite mode }; +/* Access macros */ +#define CACHE(r) ((r)->cache_addr) +//#define HAMLIB_CACHE(r) ((struct rig_cache *)rig_data_pointer(r, RIG_PTRX_CACHE)) + +/* Function templates + * Does not include those marked as part of HAMLIB_API + */ int rig_set_cache_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width); int rig_set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq); void rig_cache_show(RIG *rig, const char *func, int line); diff --git a/src/misc.c b/src/misc.c index b81f5b37c..b65722182 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1967,6 +1967,7 @@ double HAMLIB_API elapsed_ms(struct timespec *start, int option) break; } + // Casts used to make sure the add is done as double elapsed_msec = (double)((stop.tv_sec - start->tv_sec) * 1000) + // sec -> ms (double)(stop.tv_nsec - start->tv_nsec) / 1e6; // ns -> ms @@ -1978,22 +1979,6 @@ double HAMLIB_API elapsed_ms(struct timespec *start, int option) } //! @endcond - -int HAMLIB_API rig_get_cache_timeout_ms(RIG *rig, hamlib_cache_t selection) -{ - rig_debug(RIG_DEBUG_TRACE, "%s: called selection=%d\n", __func__, selection); - return CACHE(rig)->timeout_ms; -} - -int HAMLIB_API rig_set_cache_timeout_ms(RIG *rig, hamlib_cache_t selection, - int ms) -{ - rig_debug(RIG_DEBUG_TRACE, "%s: called selection=%d, ms=%d\n", __func__, - selection, ms); - CACHE(rig)->timeout_ms = ms; - return RIG_OK; -} - static char *funcname = "Unknown"; static int linenum = 0; commit 3bdfdebacb59ab5d044515edd1954d4eba414469 Author: George Baltz N3GB <Geo...@gm...> Date: Wed May 14 15:21:24 2025 -0400 Simplify elapsed time computation Do as much of the arithmetic in integers as possible. Convert both parts to final units(msec) and add. The casts are actually unneeded, but show when the conversions are done. And drop an unreachable break. diff --git a/src/misc.c b/src/misc.c index 37566539d..b81f5b37c 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1959,7 +1959,6 @@ double HAMLIB_API elapsed_ms(struct timespec *start, int option) //rig_debug(RIG_DEBUG_TRACE, "%s: after gettime, start = %ld,%ld\n", __func__, // (long)start->tv_sec, (long)start->tv_nsec); return 999 * 1000; // so we can tell the difference in debug where we came from - break; case HAMLIB_ELAPSED_INVALIDATE: clock_gettime(CLOCK_REALTIME, start); @@ -1968,8 +1967,8 @@ double HAMLIB_API elapsed_ms(struct timespec *start, int option) break; } - elapsed_msec = ((stop.tv_sec - start->tv_sec) + (stop.tv_nsec / 1e9 - - start->tv_nsec / 1e9)) * 1e3; + elapsed_msec = (double)((stop.tv_sec - start->tv_sec) * 1000) + // sec -> ms + (double)(stop.tv_nsec - start->tv_nsec) / 1e6; // ns -> ms //rig_debug(RIG_DEBUG_TRACE, "%s: elapsed_msecs=%.0f\n", __func__, elapsed_msec); commit 29924af2f123e96241b69beb2185455f94706f64 Author: George Baltz N3GB <Geo...@gm...> Date: Mon May 12 15:05:51 2025 -0400 Minor cleanups Noticed while perusing cache code. diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index 828731d2e..38e12e82b 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -6030,10 +6030,10 @@ int icom_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) if (ptt) { int cache_ms_freq; - rig_get_cache_freq(rig, vfo, tx_freq, &cache_ms_freq); + retval = rig_get_cache_freq(rig, vfo, tx_freq, &cache_ms_freq); rig_debug(RIG_DEBUG_TRACE, "%s: ptt is on so returning last known freq\n", __func__); - RETURNFUNC2(RIG_OK); + RETURNFUNC2(retval); } } diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index 45bd5012f..1596c2dfe 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -666,19 +666,13 @@ transaction_read: * the decoder for callback. That way we don't ignore any * commands. */ - // if we got FA or FB unexpectedly then perhaps RIG_TRN is enabled and we just need to handle it - if (strncmp(buffer, "FA", 2) == 0) + // If we got FA or FB unexpectedly then perhaps RIG_TRN is enabled + // and we just need to handle it + if (buffer[0] == 'F' && (buffer[1] == 'A' || buffer[1] == 'B')) { freq_t freq; - sscanf(buffer, "FA%lg", &freq); - rig_set_cache_freq(rig, RIG_VFO_A, freq); - goto transaction_read; - } - else if (strncmp(buffer, "FB", 2) == 0) - { - freq_t freq; - sscanf(buffer, "FB%lg", &freq); - rig_set_cache_freq(rig, RIG_VFO_B, freq); + sscanf(buffer + 2, "%lg", &freq); + rig_set_cache_freq(rig, buffer[1] == 'A' ? RIG_VFO_A : RIG_VFO_B, freq); goto transaction_read; } commit f5eb8f19e9dcdaabf654b095d671135f46ae5c90 Author: George Baltz N3GB <Geo...@gm...> Date: Sat May 3 21:56:45 2025 -0400 Add utility routine to release all allocated buffers, including rig itself. One stop shopping for all your rig data cleanup needs. diff --git a/src/rig.c b/src/rig.c index 922f45912..71944b292 100644 --- a/src/rig.c +++ b/src/rig.c @@ -529,6 +529,27 @@ static int rig_check_rig_caps() return (rc); } +/* Final cleanup of rig structure + * + * Release all allocations for this rig, including the rig_struct + * Clear them to catch use-after-free errors + */ +static void vaporize(RIG *rig) +{ + if (CACHE(rig)) + { + free(CACHE(rig)); + CACHE(rig) = NULL; + } + + /* Other buffers go here, as they are converted + * to pointers/calloc - WIP + */ + + free(rig); + return; +} + /** * \brief Allocate a new #RIG handle. * \param rig_model The rig model for this new handle @@ -638,7 +659,7 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) if (!CACHE(rig)) { rig_debug(RIG_DEBUG_ERR, "%s:Cache calloc failed\n", __func__); - free(rig); //TODO Replace with cleanup routine + vaporize(rig); return NULL; } cachep = CACHE(rig); @@ -943,7 +964,7 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) "%s: backend_init failed!\n", __func__); /* cleanup and exit */ - free(rig); + vaporize(rig); return (NULL); } } @@ -1885,15 +1906,8 @@ int HAMLIB_API rig_cleanup(RIG *rig) //pthread_mutex_destroy(&STATE(rig)->api_mutex); - //TODO Release and null any allocated data - - // state, ports, cache, etc. - if (CACHE(rig)) - { - free(CACHE(rig)); - CACHE(rig) = NULL; - } - - free(rig); + /* Release all buffers, and the rig_struct itself */ + vaporize(rig); return (RIG_OK); } commit 1fca93a5a25b1afb6cc591d1769924bbaa746099 Author: George Baltz N3GB <Geo...@gm...> Date: Fri May 2 16:21:43 2025 -0400 Deprecate rig_cache definition in rig.h Add new rig_cache definition in cache.h diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index cb2d7c48f..b9cd59908 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2589,9 +2589,10 @@ typedef enum { * \brief Rig cache data * * This struct contains all the items we cache at the highest level - * DO NOT MODIFY THIS STRUCTURE AT ALL -- we need a new cache that is a pointer rather than a structure + * DO NOT MODIFY THIS STRUCTURE AT ALL -- should go away in 5.0 + * see cache.h - new cache is a pointer rather than an embedded structure */ -struct rig_cache { +struct rig_cache_deprecated { int timeout_ms; // the cache timeout for invalidating itself vfo_t vfo; //freq_t freq; // to be deprecated in 4.1 when full Main/Sub/A/B caching is implemented in 4.1 @@ -2784,7 +2785,7 @@ struct rig_state { int twiddle_timeout; /*!< timeout to resume from twiddling */ // uplink allows gpredict to behave better by no reading the uplink VFO int uplink; /*!< uplink=1 will not read Sub, uplink=2 will not read Main */ - struct rig_cache cache; + struct rig_cache_deprecated cache; // Only here for backward compatability int vfo_opt; /*!< Is -o switch turned on? */ int auto_power_on; /*!< Allow Hamlib to power on rig automatically if supported */ @@ -2984,7 +2985,7 @@ struct rig_state_deprecated { int twiddle_timeout; /*!< timeout to resume from twiddling */ // uplink allows gpredict to behave better by no reading the uplink VFO int uplink; /*!< uplink=1 will not read Sub, uplink=2 will not read Main */ - struct rig_cache cache; + struct rig_cache_deprecated cache; // Here for backward compatibility int vfo_opt; /*!< Is -o switch turned on? */ int auto_power_on; /*!< Allow Hamlib to power on rig automatically if supported */ diff --git a/src/cache.h b/src/cache.h index 08d98ea5f..e977273de 100644 --- a/src/cache.h +++ b/src/cache.h @@ -19,14 +19,99 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ #ifndef _CACHE_H #define _CACHE_H #include <hamlib/rig.h> +__BEGIN_DECLS + +/** + * \brief Rig cache data + * + * This struct contains all the items we cache at the highest level + * Replaces cache structure(s) in state + */ +struct rig_cache { + int timeout_ms; // the cache timeout for invalidating itself + vfo_t vfo; + //freq_t freq; // to be deprecated in 4.1 when full Main/Sub/A/B caching is implemented in 4.1 + // other abstraction here is based on dual vfo rigs and mapped to all others + // So we have four possible states of rig + // MainA, MainB, SubA, SubB + // Main is the Main VFO and Sub is for the 2nd VFO + // Most rigs have MainA and MainB + // Dual VFO rigs can have SubA and SubB too + // For dual VFO rigs simplex operations are all done on MainA/MainB -- ergo this abstraction + freq_t freqCurr; // Other VFO + freq_t freqOther; // Other VFO + freq_t freqMainA; // VFO_A, VFO_MAIN, and VFO_MAINA + freq_t freqMainB; // VFO_B, VFO_SUB, and VFO_MAINB + freq_t freqMainC; // VFO_C, VFO_MAINC + freq_t freqSubA; // VFO_SUBA -- only for rigs with dual Sub VFOs + freq_t freqSubB; // VFO_SUBB -- only for rigs with dual Sub VFOs + freq_t freqSubC; // VFO_SUBC -- only for rigs with 3 Sub VFOs + freq_t freqMem; // VFO_MEM -- last MEM channel + rmode_t modeCurr; + rmode_t modeOther; + rmode_t modeMainA; + rmode_t modeMainB; + rmode_t modeMainC; + rmode_t modeSubA; + rmode_t modeSubB; + rmode_t modeSubC; + rmode_t modeMem; + pbwidth_t widthCurr; // if non-zero then rig has separate width for MainA + pbwidth_t widthOther; // if non-zero then rig has separate width for MainA + pbwidth_t widthMainA; // if non-zero then rig has separate width for MainA + pbwidth_t widthMainB; // if non-zero then rig has separate width for MainB + pbwidth_t widthMainC; // if non-zero then rig has separate width for MainC + pbwidth_t widthSubA; // if non-zero then rig has separate width for SubA + pbwidth_t widthSubB; // if non-zero then rig has separate width for SubB + pbwidth_t widthSubC; // if non-zero then rig has separate width for SubC + pbwidth_t widthMem; // if non-zero then rig has separate width for Mem + ptt_t ptt; + split_t split; + vfo_t split_vfo; // split caches two values + struct timespec time_freqCurr; + struct timespec time_freqOther; + struct timespec time_freqMainA; + struct timespec time_freqMainB; + struct timespec time_freqMainC; + struct timespec time_freqSubA; + struct timespec time_freqSubB; + struct timespec time_freqSubC; + struct timespec time_freqMem; + struct timespec time_vfo; + struct timespec time_modeCurr; + struct timespec time_modeOther; + struct timespec time_modeMainA; + struct timespec time_modeMainB; + struct timespec time_modeMainC; + struct timespec time_modeSubA; + struct timespec time_modeSubB; + struct timespec time_modeSubC; + struct timespec time_modeMem; + struct timespec time_widthCurr; + struct timespec time_widthOther; + struct timespec time_widthMainA; + struct timespec time_widthMainB; + struct timespec time_widthMainC; + struct timespec time_widthSubA; + struct timespec time_widthSubB; + struct timespec time_widthSubC; + struct timespec time_widthMem; + struct timespec time_ptt; + struct timespec time_split; + int satmode; // if rig is in satellite mode +}; + int rig_set_cache_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width); int rig_set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq); void rig_cache_show(RIG *rig, const char *func, int line); +__END_DECLS + #endif commit 6f8bf815149f535831f8e1ced44d2b5e6a01bb97 Author: George Baltz N3GB <Geo...@gm...> Date: Tue Apr 29 02:57:52 2025 -0400 Allocate separate storage for cache buffer Add address to rig_struct, change CACHE() macro to use it. Free it when done. Issue #1420 diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 814eb2921..cb2d7c48f 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -253,10 +253,14 @@ enum rig_debug_level_e { /* --------------- Rig capabilities -----------------*/ -/* Forward struct references */ +/* Forward struct references + * may also include structures defined elsewhere, + * but pointed to by rig + */ struct rig; struct rig_state; +struct rig_cache; /** * \brief Rig structure definition (see rig for details). @@ -2518,7 +2522,7 @@ typedef hamlib_port_t port_t; #define RIGPORT(r) (&r->state.rigport) #define PTTPORT(r) (&r->state.pttport) #define DCDPORT(r) (&r->state.dcdport) -#define CACHE(r) (&r->state.cache) +#define CACHE(r) ((r)->cache_addr) #define AMPPORT(a) (&a->state.ampport) #define ROTPORT(r) (&r->state.rotport) #define ROTPORT2(r) (&r->state.rotport2) @@ -3101,6 +3105,10 @@ struct s_rig { struct rig_callbacks callbacks; /*!< registered event callbacks */ // state should really be a pointer but that's a LOT of changes involved struct rig_state state; /*!< Rig state */ +/* Data beyond this line is for hamlib internal use only, + * and should *NOT* be referenced by applications, as layout will change! + */ + struct rig_cache *cache_addr; }; diff --git a/src/rig.c b/src/rig.c index 1be0bad4a..922f45912 100644 --- a/src/rig.c +++ b/src/rig.c @@ -549,6 +549,7 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) hamlib_port_t *rp, *pttp, *dcdp; struct rig_cache *cachep; int i; + size_t needed; if (rig_test_2038(NULL)) { @@ -598,7 +599,9 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) * okay, we've found it. Allocate some memory and set it to zeros, * and especially the callbacks */ - rig = calloc(1, sizeof(RIG)); + needed = sizeof(RIG); + rig_debug(RIG_DEBUG_TRACE, "Requesting %zd bytes for rig_struct\n", needed); + rig = calloc(1, needed); if (rig == NULL) { @@ -628,7 +631,16 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) pttp = PTTPORT(rig); dcdp = DCDPORT(rig); - //TODO Ditto for cache + // Allocate space for cached data + needed = sizeof(struct rig_cache); + rig_debug(RIG_DEBUG_TRACE, "Requesting %zd bytes for rig_cache\n", needed); + CACHE(rig) = calloc(1, needed); + if (!CACHE(rig)) + { + rig_debug(RIG_DEBUG_ERR, "%s:Cache calloc failed\n", __func__); + free(rig); //TODO Replace with cleanup routine + return NULL; + } cachep = CACHE(rig); rs->rig_model = caps->rig_model; @@ -1875,6 +1887,11 @@ int HAMLIB_API rig_cleanup(RIG *rig) //TODO Release and null any allocated data - // state, ports, cache, etc. + if (CACHE(rig)) + { + free(CACHE(rig)); + CACHE(rig) = NULL; + } free(rig); commit 7d28822273dec229da1ceca809a3d4f241e4749f Author: George Baltz N3GB <Geo...@gm...> Date: Fri Apr 25 15:11:56 2025 -0400 Add '#include "cache.h"' to all files that reference cache structure. Issue #1420 diff --git a/rigs/dummy/dummy.c b/rigs/dummy/dummy.c index a43a8fe23..edf4155bc 100644 --- a/rigs/dummy/dummy.c +++ b/rigs/dummy/dummy.c @@ -43,6 +43,7 @@ #include "tones.h" #include "idx_builtin.h" #include "register.h" +#include "cache.h" #include "dummy.h" diff --git a/rigs/dummy/flrig.c b/rigs/dummy/flrig.c index 7d41e1df9..a150e1bc9 100644 --- a/rigs/dummy/flrig.c +++ b/rigs/dummy/flrig.c @@ -32,6 +32,7 @@ #include "dummy_common.h" #include "flrig.h" +#include "cache.h" #define DEBUG 1 #define DEBUG_TRACE DEBUG_VERBOSE diff --git a/rigs/icom/frame.c b/rigs/icom/frame.c index 5fa28a110..b7c6c817c 100644 --- a/rigs/icom/frame.c +++ b/rigs/icom/frame.c @@ -33,7 +33,6 @@ #include "icom.h" #include "icom_defs.h" #include "frame.h" -#include "cache.h" /* * Build a CI-V frame. diff --git a/rigs/icom/ic7300.c b/rigs/icom/ic7300.c index fe633a77e..3c495563b 100644 --- a/rigs/icom/ic7300.c +++ b/rigs/icom/ic7300.c @@ -30,6 +30,7 @@ #include "icom.h" #include "icom_defs.h" #include "misc.h" +#include "cache.h" #include "bandplan.h" #include "tones.h" #include "ic7300.h" diff --git a/rigs/icom/ic821h.c b/rigs/icom/ic821h.c index 9c1e4b2ba..83527e30a 100644 --- a/rigs/icom/ic821h.c +++ b/rigs/icom/ic821h.c @@ -25,7 +25,7 @@ #include <hamlib/rig.h> #include "icom.h" #include "misc.h" - +#include "cache.h" #define IC821H_MODES (RIG_MODE_SSB|RIG_MODE_CW|RIG_MODE_FM) diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index c25c713da..828731d2e 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -39,6 +39,7 @@ #include "frame.h" #include "misc.h" #include "event.h" +#include "cache.h" // we automatically determine availability of the 1A 03 command enum { ENUM_1A_03_UNK, ENUM_1A_03_YES, ENUM_1A_03_NO }; diff --git a/rigs/icom/id5100.c b/rigs/icom/id5100.c index 9e86b2a5f..deeada4aa 100644 --- a/rigs/icom/id5100.c +++ b/rigs/icom/id5100.c @@ -26,6 +26,7 @@ #include "icom_defs.h" #include "frame.h" #include "misc.h" +#include "cache.h" enum { diff --git a/rigs/icom/xiegu.c b/rigs/icom/xiegu.c index b35382fa6..d1e19a886 100644 --- a/rigs/icom/xiegu.c +++ b/rigs/icom/xiegu.c @@ -38,6 +38,7 @@ #include "icom_defs.h" #include "frame.h" #include "misc.h" +#include "cache.h" #include "tones.h" #include "bandplan.h" diff --git a/rigs/jrc/jst145.c b/rigs/jrc/jst145.c index 573fd268d..a309b3ba4 100644 --- a/rigs/jrc/jst145.c +++ b/rigs/jrc/jst145.c @@ -24,6 +24,7 @@ #include <string.h> #include "hamlib/rig.h" +#include "cache.h" #include "iofunc.h" #include "jrc.h" diff --git a/rigs/kenwood/ts2000.c b/rigs/kenwood/ts2000.c index b7c1ac5ad..5c25d3461 100644 --- a/rigs/kenwood/ts2000.c +++ b/rigs/kenwood/ts2000.c @@ -28,6 +28,7 @@ #include "kenwood.h" #include "token.h" #include "misc.h" +#include "cache.h" #include "iofunc.h" #include "cal.h" diff --git a/rigs/kenwood/ts590.c b/rigs/kenwood/ts590.c index a21528cc5..3cc9cc786 100644 --- a/rigs/kenwood/ts590.c +++ b/rigs/kenwood/ts590.c @@ -27,6 +27,7 @@ #include "hamlib/rig.h" #include "kenwood.h" #include "misc.h" +#include "cache.h" #include "cal.h" #include "iofunc.h" diff --git a/rigs/tentec/orion.c b/rigs/tentec/orion.c index fbed4962d..2ad454553 100644 --- a/rigs/tentec/orion.c +++ b/rigs/tentec/orion.c @@ -77,6 +77,7 @@ #include <hamlib/rig.h> #include "serial.h" #include "misc.h" +#include "cache.h" #include "orion.h" #ifdef TT565_TIME diff --git a/rigs/yaesu/ft100.c b/rigs/yaesu/ft100.c index 94b7cbb3c..ec4084ddd 100644 --- a/rigs/yaesu/ft100.c +++ b/rigs/yaesu/ft100.c @@ -34,6 +34,7 @@ #include "yaesu.h" #include "ft100.h" #include "misc.h" +#include "cache.h" #include "bandplan.h" enum ft100_native_cmd_e diff --git a/rigs/yaesu/ft1000d.c b/rigs/yaesu/ft1000d.c index e6a7d4745..0ae60a82e 100644 --- a/rigs/yaesu/ft1000d.c +++ b/rigs/yaesu/ft1000d.c @@ -35,6 +35,7 @@ #include "bandplan.h" #include "serial.h" #include "misc.h" +#include "cache.h" #include "yaesu.h" #include "ft1000d.h" diff --git a/rigs/yaesu/ft1000mp.c b/rigs/yaesu/ft1000mp.c index 86b5b63c0..9b16ba60b 100644 --- a/rigs/yaesu/ft1000mp.c +++ b/rigs/yaesu/ft1000mp.c @@ -38,6 +38,7 @@ #include "bandplan.h" #include "serial.h" #include "misc.h" +#include "cache.h" #include "yaesu.h" #include "ft1000mp.h" diff --git a/rigs/yaesu/ft747.c b/rigs/yaesu/ft747.c index b8ad27ffa..6426fcaa0 100644 --- a/rigs/yaesu/ft747.c +++ b/rigs/yaesu/ft747.c @@ -39,6 +39,7 @@ #include "hamlib/rig.h" #include "serial.h" #include "misc.h" +#include "cache.h" #include "yaesu.h" #include "ft747.h" diff --git a/rigs/yaesu/ft817.c b/rigs/yaesu/ft817.c index 125e2696b..49bf79981 100644 --- a/rigs/yaesu/ft817.c +++ b/rigs/yaesu/ft817.c @@ -57,6 +57,7 @@ #include "yaesu.h" #include "ft817.h" #include "misc.h" +#include "cache.h" #include "tones.h" #include "bandplan.h" #include "cal.h" diff --git a/rigs/yaesu/ft857.c b/rigs/yaesu/ft857.c index eee908bc2..e514bc2fb 100644 --- a/rigs/yaesu/ft857.c +++ b/rigs/yaesu/ft857.c @@ -63,6 +63,7 @@ #include "ft857.h" #include "ft817.h" /* We use functions from the 817 code */ #include "misc.h" +#include "cache.h" #include "tones.h" #include "bandplan.h" #include "cal.h" diff --git a/rigs/yaesu/ft990v12.c b/rigs/yaesu/ft990v12.c index f56d1bdc3..bd99ce350 100644 --- a/rigs/yaesu/ft990v12.c +++ b/rigs/yaesu/ft990v12.c @@ -45,6 +45,7 @@ #include "bandplan.h" #include "serial.h" #include "misc.h" +//#include "cache.h" #include "yaesu.h" #include "ft990v12.h" diff --git a/rigs/yaesu/ft991.c b/rigs/yaesu/ft991.c index c68b8e920..6417d523e 100644 --- a/rigs/yaesu/ft991.c +++ b/rigs/yaesu/ft991.c @@ -33,6 +33,7 @@ #include <string.h> #include "hamlib/rig.h" #include "misc.h" +#include "cache.h" #include "newcat.h" #include "yaesu.h" #include "ft991.h" diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index b64cce03a..82ed2caf7 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -34,6 +34,7 @@ #include "hamlib/rig.h" #include "iofunc.h" #include "misc.h" +#include "cache.h" #include "cal.h" #include "newcat.h" #include "serial.h" diff --git a/rigs/yaesu/pmr171.c b/rigs/yaesu/pmr171.c index 260395fdc..8c5758c86 100644 --- a/rigs/yaesu/pmr171.c +++ b/rigs/yaesu/pmr171.c @@ -43,6 +43,7 @@ //#include "pmr171.h" #include "misc.h" #include "tones.h" +#include "cache.h" #include "bandplan.h" #include "cal.h" diff --git a/src/misc.c b/src/misc.c index 091655dca..37566539d 100644 --- a/src/misc.c +++ b/src/misc.c @@ -50,6 +50,7 @@ #include <hamlib/amplifier.h> #include "misc.h" +#include "cache.h" #include "serial.h" #include "network.h" #include "sprintflst.h" diff --git a/src/multicast.c b/src/multicast.c index e68e4efd1..6822ea51d 100644 --- a/src/multicast.c +++ b/src/multicast.c @@ -13,6 +13,7 @@ #endif #include "hamlib/rig.h" #include "misc.h" +#include "cache.h" #include "multicast.h" #include "network.h" #include "sprintflst.h" diff --git a/src/snapshot_data.c b/src/snapshot_data.c index c68f13a90..c89b43617 100644 --- a/src/snapshot_data.c +++ b/src/snapshot_data.c @@ -4,6 +4,7 @@ #include <hamlib/config.h> #include <hamlib/rig.h> #include "misc.h" +#include "cache.h" #include "snapshot_data.h" #include "hamlibdatetime.h" #include "sprintflst.h" diff --git a/tests/rigctlcom.c b/tests/rigctlcom.c index e7b8fbf07..8570c33f7 100644 --- a/tests/rigctlcom.c +++ b/tests/rigctlcom.c @@ -78,6 +78,7 @@ #include <hamlib/rig.h> #include "misc.h" +#include "cache.h" #include "iofunc.h" #include "rigctl_parse.h" #include "riglist.h" commit 4d322337c1d6d06edaa42887b2ba8430c53aa4f7 Author: George Baltz N3GB <Geo...@gm...> Date: Sun Jun 1 10:55:32 2025 -0400 Update NEWS diff --git a/NEWS b/NEWS index 090e4ed3b..7e2378205 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ Version 4.6.3 five years from 2020 to 2025. Mike passed away on March 28, 2025 due to complications from ALS (Lou Gehrig's disease). + * Restore IC-7300 spectrum data callback - regression in 4.6 (n3gb) + * Add locking to rig_[gs]et_level() - fixes sending CW from tlf (n3gb) * Fix attempt to use memory returned by setlocale() after being freed (TNX Mooneer Salem) * Language bindings configuration and build fixes (TNX Daniele Forsi) * Various build system and compilation fixes (TNX Daniele Forsi) commit 3bc9e5261be8359203419f8d8fe0d100b40f3eb0 Author: George Baltz N3GB <Geo...@gm...> Date: Sat May 31 14:17:10 2025 -0400 Still more functions made static. diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index 5fec748b5..c25c713da 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -812,7 +812,7 @@ int icom_cleanup(RIG *rig) * Returns 0 when USB ECHO is on * \return Returns < 0 when error occurs (e.g. timeout, nimple, navail) */ -int icom_get_usb_echo_off(RIG *rig) +static int icom_get_usb_echo_off(RIG *rig) { int retval; unsigned char ackbuf[MAXFRAMELEN]; @@ -1419,7 +1419,7 @@ static int icom_set_default_vfo(RIG *rig) // return true if band is changing from last set_freq // Assumes rig is currently on the VFO being changed // This handles the case case Main/Sub cannot be on the same band -int icom_band_changing(RIG *rig, freq_t test_freq) +static int icom_band_changing(RIG *rig, freq_t test_freq) { freq_t curr_freq, freq1, freq2; int retval; @@ -3423,7 +3423,7 @@ int icom_set_vfo(RIG *rig, vfo_t vfo) RETURNFUNC2(RIG_OK); } -int icom_set_cmd(RIG *rig, vfo_t vfo, struct cmdparams *par, value_t val) +static int icom_set_cmd(RIG *rig, vfo_t vfo, struct cmdparams *par, value_t val) { ENTERFUNC; @@ -3491,7 +3491,7 @@ int icom_set_cmd(RIG *rig, vfo_t vfo, struct cmdparams *par, value_t val) &ack_len)); } -int icom_get_cmd(RIG *rig, vfo_t vfo, struct cmdparams *par, value_t *val) +static int icom_get_cmd(RIG *rig, vfo_t vfo, struct cmdparams *par, value_t *val) { ENTERFUNC; @@ -5363,7 +5363,7 @@ int icom_set_conf(RIG *rig, hamlib_token_t token, const char *val) * Assumes rig!=NULL, STATE(rig)->priv!=NULL * and val points to a buffer big enough to hold the conf value. */ -int icom_get_conf2(RIG *rig, hamlib_token_t token, char *val, int val_len) +static int icom_get_conf2(RIG *rig, hamlib_token_t token, char *val, int val_len) { struct icom_priv_data *priv; struct rig_state *rs; @@ -7647,7 +7647,7 @@ int icom_set_parm(RIG *rig, setting_t parm, value_t val) RETURNFUNC(-RIG_EINVAL); } -const char *icom_get_band(RIG *rig, int band) +static const char *icom_get_band(RIG *rig, int band) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); commit 6b5c5b48f9c7a0582beb0259f00a1bf1c81bf451 Author: George Baltz N3GB <Geo...@gm...> Date: Sat May 31 14:10:05 2025 -0400 Don't try to process short spectrum frames. diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index 9f753ebf1..5fec748b5 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -9016,7 +9016,6 @@ int icom_mW2power(RIG *rig, float *power, unsigned int mwpower, freq_t freq, RETURNFUNC(RIG_OK); } - #if defined(HAVE_PTHREAD) static int icom_parse_spectrum_frame(RIG *rig, size_t length, const unsigned char *frame_data) @@ -9025,15 +9024,20 @@ static int icom_parse_spectrum_frame(RIG *rig, size_t length, struct icom_priv_caps *priv_caps = (struct icom_priv_caps *) caps->priv; struct icom_priv_data *priv = (struct icom_priv_data *) STATE(rig)->priv; struct icom_spectrum_scope_cache *cache; - - int division = (int) from_bcd(frame_data + 1, 1 * 2); - int max_division = (int) from_bcd(frame_data + 2, 1 * 2); - + int division, max_division; size_t spectrum_data_length_in_frame; const unsigned char *spectrum_data_start_in_frame; ENTERFUNC; + if (length < 3) + { + rig_debug(RIG_DEBUG_WARN, "%s: Short scope data - len=%zu\n", __func__, length); + RETURNFUNC(-RIG_EPROTO); + } + division = (int) from_bcd(frame_data + 1, 1 * 2); + max_division = (int) from_bcd(frame_data + 2, 1 * 2); + // The first byte indicates spectrum scope ID/VFO: 0 = Main, 1 = Sub int spectrum_id = frame_data[0]; @@ -9048,9 +9052,17 @@ static int icom_parse_spectrum_frame(RIG *rig, size_t length, if (division == 1) { - int spectrum_scope_mode = frame_data[3]; - int out_of_range = frame_data[14]; + int spectrum_scope_mode; + int out_of_range; + if (length < 15) + { + rig_debug(RIG_DEBUG_WARN, "%s: Short scope header - len=%zu\n", __func__, length); + RETURNFUNC(-RIG_EPROTO); + } + + spectrum_scope_mode = frame_data[3]; + out_of_range = frame_data[14]; cache->spectrum_mode = RIG_SPECTRUM_MODE_NONE; switch (spectrum_scope_mode) @@ -9155,9 +9167,7 @@ static int icom_parse_spectrum_frame(RIG *rig, size_t length, .spectrum_data = cache->spectrum_data, }; -#if defined(HAVE_PTHREAD) rig_fire_spectrum_event(rig, &spectrum_line); -#endif cache->spectrum_metadata_valid = 0; } commit 7fa0c863f262a937cae95450fd15056a0fbce12f Author: George Baltz N3GB <Geo...@gm...> Date: Fri May 30 12:39:29 2025 -0400 Don't start async_data_handler until rig is fully opened. Let the <model>_rig_open() finish its setup before trying to read status. diff --git a/src/rig.c b/src/rig.c index 227a4aa15..1be0bad4a 100644 --- a/src/rig.c +++ b/src/rig.c @@ -1422,22 +1422,6 @@ int HAMLIB_API rig_open(RIG *rig) RETURNFUNC2(status); } -#if defined(HAVE_PTHREAD) - - if (!skip_init) - { - status = async_data_handler_start(rig); - - if (status < 0) - { - port_close(rp, rp->type.rig); - rs->comm_status = RIG_COMM_STATUS_ERROR; - RETURNFUNC2(status); - } - } - -#endif - rs->comm_state = 1; rig_debug(RIG_DEBUG_VERBOSE, "%s: %p rs->comm_state==1?=%d\n", __func__, &rs->comm_state, @@ -1488,15 +1472,6 @@ int HAMLIB_API rig_open(RIG *rig) if (status != RIG_OK) { remove_opened_rig(rig); -#if defined(HAVE_PTHREAD) - - if (!skip_init) - { - async_data_handler_stop(rig); - morse_data_handler_stop(rig); - } - -#endif port_close(rp, rp->type.rig); memcpy(&rs->rigport_deprecated, rp, sizeof(hamlib_port_t_deprecated)); rs->comm_state = 0; @@ -1542,6 +1517,15 @@ int HAMLIB_API rig_open(RIG *rig) #if defined(HAVE_PTHREAD) + status = async_data_handler_start(rig); + + if (status < 0) + { + port_close(rp, rp->type.rig); + rs->comm_status = RIG_COMM_STATUS_ERROR; + RETURNFUNC2(status); + } + // Some models don't support CW so don't need morse handler if (rig->caps->send_morse) { commit 63e1bb4c0096a974ad3388357c47c4398a587a84 Author: George Baltz N3GB <Geo...@gm...> Date: Sun May 18 10:49:25 2025 -0400 Pass spectrum data through to callback Fixes issue #1734 diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index 77564a4b1..9f753ebf1 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -772,8 +772,6 @@ int icom_init(RIG *rig) // Reset 0x25/0x26 command detection for the rigs that may support it icom_set_x25x26_ability(rig, -1); - rig_debug(RIG_DEBUG_TRACE, "%s: done\n", __func__); - RETURNFUNC(RIG_OK); } @@ -9201,12 +9199,12 @@ int icom_process_async_frame(RIG *rig, size_t frame_length, * the rest is data * and don't forget one byte at the end for the EOM */ - if (frame[2] != 0x00 || frame[2] == 0x01) + if (frame[2] != BCASTID && frame[2] != CTRLID) { // just ignoring 0x01 for now // fe fe 01 94 1c 03 00 80 07 07 00 fd - rig_debug(RIG_DEBUG_VERBOSE, "%s: 3rd byte not 0x00 or is 0x01...not async\n", - __func__); + rig_debug(RIG_DEBUG_VERBOSE, "%s: Unknown/invalid destination - %#x\n", + __func__, frame[2]); RETURNFUNC(RIG_OK); } diff --git a/rigs/icom/icom.h b/rigs/icom/icom.h index 47d99d91d..1ceedec12 100644 --- a/rigs/icom/icom.h +++ b/rigs/icom/icom.h @@ -35,7 +35,7 @@ #include <sys/time.h> #endif -#define BACKEND_VER "20250107" +#define BACKEND_VER "20250517" #define ICOM_IS_ID31 rig_is_model(rig, RIG_MODEL_ID31) #define ICOM_IS_ID51 rig_is_model(rig, RIG_MODEL_ID51) ----------------------------------------------------------------------- Summary of changes: NEWS | 4 ++ include/hamlib/rig.h | 23 ++++++++---- rigs/dummy/dummy.c | 1 + rigs/dummy/flrig.c | 1 + rigs/icom/frame.c | 1 - rigs/icom/ic7300.c | 1 + rigs/icom/ic821h.c | 2 +- rigs/icom/icom.c | 53 +++++++++++++++----------- rigs/icom/icom.h | 2 +- rigs/icom/id5100.c | 1 + rigs/icom/xiegu.c | 1 + rigs/jrc/jst145.c | 1 + rigs/kenwood/kenwood.c | 16 +++----- rigs/kenwood/ts2000.c | 1 + rigs/kenwood/ts590.c | 1 + rigs/tentec/orion.c | 1 + rigs/yaesu/ft100.c | 1 + rigs/yaesu/ft1000d.c | 1 + rigs/yaesu/ft1000mp.c | 1 + rigs/yaesu/ft747.c | 1 + rigs/yaesu/ft817.c | 1 + rigs/yaesu/ft857.c | 1 + rigs/yaesu/ft990v12.c | 1 + rigs/yaesu/ft991.c | 1 + rigs/yaesu/newcat.c | 1 + rigs/yaesu/pmr171.c | 1 + src/cache.c | 26 ++++++++++++- src/cache.h | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ src/misc.c | 23 ++---------- src/multicast.c | 1 + src/rig.c | 79 ++++++++++++++++++++++---------------- src/snapshot_data.c | 1 + tests/rigctlcom.c | 1 + 33 files changed, 255 insertions(+), 96 deletions(-) hooks/post-receive -- Hamlib -- Ham radio control libraries |