kopia lustrzana https://github.com/Hamlib/Hamlib
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.pull/1722/head
rodzic
12265fde9a
commit
c8838cd3a6
|
@ -19,6 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -421,9 +422,14 @@ static rmode_t modeMapGetHamlib(const char *modeACLog)
|
|||
/*
|
||||
* aclog_get_freq
|
||||
* Assumes rig!=NULL, STATE(rig)->priv!=NULL, freq!=NULL
|
||||
*
|
||||
* string='<CMD><READBMFRESPONSE><BAND>23</BAND><MODE>SSB</MODE><MODETEST>PH</MODETEST><FREQ>1,296.171100</FREQ></CMD> '
|
||||
*/
|
||||
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>");
|
||||
*freq = 0;
|
||||
|
||||
if (p) { sscanf(p, "<FREQ>%'lf", freq); }
|
||||
if (p)
|
||||
{
|
||||
// Move the pointer to the first digit.
|
||||
p += strlen("<FREQ>");
|
||||
|
||||
// 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
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue