fluke-dmm: Make protocol parsers locale-independent.

This commit is contained in:
Bert Vermeulen 2014-01-21 16:33:34 +01:00
parent d2cd06e7e9
commit 357e341d9a
1 changed files with 12 additions and 9 deletions

View File

@ -40,10 +40,17 @@ static struct sr_datafeed_analog *handle_qm_18x(const struct sr_dev_inst *sdi,
if ((e = strstr(tokens[1], "Out of range"))) { if ((e = strstr(tokens[1], "Out of range"))) {
is_oor = TRUE; is_oor = TRUE;
fvalue = -1; fvalue = -1;
while(*e && *e != '.')
e++;
} else { } else {
is_oor = FALSE; is_oor = FALSE;
fvalue = strtof(tokens[1], &e); /* Delimit the float, since sr_atof_ascii() wants only
if (fvalue == 0.0 && e == tokens[1]) { * a valid float here. */
e = tokens[1];
while(*e && *e != ' ')
e++;
*e++ = '\0';
if (sr_atof_ascii(tokens[1], &fvalue) != SR_OK || fvalue == 0.0) {
/* Happens all the time, when switching modes. */ /* Happens all the time, when switching modes. */
sr_dbg("Invalid float."); sr_dbg("Invalid float.");
return NULL; return NULL;
@ -154,14 +161,12 @@ static struct sr_datafeed_analog *handle_qm_28x(const struct sr_dev_inst *sdi,
{ {
struct sr_datafeed_analog *analog; struct sr_datafeed_analog *analog;
float fvalue; float fvalue;
char *eptr;
if (!tokens[1]) if (!tokens[1])
return NULL; return NULL;
fvalue = strtof(tokens[0], &eptr); if (sr_atof_ascii(tokens[0], &fvalue) != SR_OK || fvalue == 0.0) {
if (fvalue == 0.0 && eptr == tokens[0]) { sr_err("Invalid float '%s'.", tokens[0]);
sr_err("Invalid float.");
return NULL; return NULL;
} }
@ -363,7 +368,6 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens)
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog; struct sr_datafeed_analog analog;
float fvalue; float fvalue;
char *eptr;
if (!strcmp(tokens[0], "9.9E+37")) { if (!strcmp(tokens[0], "9.9E+37")) {
/* An invalid measurement shows up on the display as "OL", but /* An invalid measurement shows up on the display as "OL", but
@ -371,8 +375,7 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens)
* is rather problematic, we'll cut through this here. */ * is rather problematic, we'll cut through this here. */
fvalue = NAN; fvalue = NAN;
} else { } else {
fvalue = strtof(tokens[0], &eptr); if (sr_atof_ascii(tokens[0], &fvalue) != SR_OK || fvalue == 0.0) {
if (fvalue == 0.0 && eptr == tokens[0]) {
sr_err("Invalid float '%s'.", tokens[0]); sr_err("Invalid float '%s'.", tokens[0]);
return; return;
} }