From ff443a95d83e4ef0ccc42964cff78149ca8da771 Mon Sep 17 00:00:00 2001 From: Nate Bargmann Date: Thu, 1 May 2025 19:49:44 -0500 Subject: [PATCH] Avoid truncating AC Log frequencies above 1 GHz Per GitHub issue #1704, frequencies higher than 1 GHz passed from AC Log have an embedded comma. Even though sscanf() offers the "'" (single quote) character as a means of ignoring thousands separator, apparently it depends on the environment variable LC_NUMERIC being set correctly and that may not be supported on all platforms. This patch just parses through the string while skipping any comma that may appear and then uses strtold() to convert to a numeric variable. It is supected that AC Log always uses a comma as a thousands separator. --- rigs/dummy/aclog.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/rigs/dummy/aclog.c b/rigs/dummy/aclog.c index 8baeef075..3b9fb4cef 100644 --- a/rigs/dummy/aclog.c +++ b/rigs/dummy/aclog.c @@ -19,6 +19,7 @@ * */ +#include #include #include #include @@ -421,9 +422,14 @@ static rmode_t modeMapGetHamlib(const char *modeACLog) /* * aclog_get_freq * Assumes rig!=NULL, STATE(rig)->priv!=NULL, freq!=NULL +* +* string='23SSBPH1,296.171100 ' */ static int aclog_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { + int i, j = 0; + char f_string[32]; + char value[MAXARGLEN]; struct aclog_priv_data *priv = (struct aclog_priv_data *) STATE(rig)->priv; @@ -461,7 +467,30 @@ static int aclog_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) char *p = strstr(value, ""); *freq = 0; - if (p) { sscanf(p, "%'lf", freq); } + if (p) + { + // Move the pointer to the first digit. + p += strlen(""); + + // Parse "1,296.171100" ignoring the comma. + for (i = 0; p[i] != '<'; i++) + { + if (isdigit(p[i])) + { + f_string[j++] = p[i]; + } + else if (ispunct(p[i]) && p[i] == '.') + { + f_string[j++] = p[i]; + } + } + + f_string[j] = '\0'; + rig_debug(RIG_DEBUG_TRACE, "%s: f_string=%s\n", __func__, f_string); + + *freq = strtold(f_string, NULL); + rig_debug(RIG_DEBUG_TRACE, "%s: freq=%.0f\n", __func__, *freq); + } *freq *= 1e6; // convert from MHz to Hz