From: Mathieu Pilato Date: Tue, 21 Mar 2023 09:36:59 +0000 (+0100) Subject: fluke-dmm: Fix digit count in handle_qm_28x function. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=078ad492d372ef6d8e0915ebc26b31de558c7a25;p=libsigrok.git fluke-dmm: Fix digit count in handle_qm_28x function. This requires splitting the measurement into mantissa and exponent, as the exponent affects the significant digits count. --- diff --git a/src/hardware/fluke-dmm/protocol.c b/src/hardware/fluke-dmm/protocol.c index 212e4c40..d8837f66 100644 --- a/src/hardware/fluke-dmm/protocol.c +++ b/src/hardware/fluke-dmm/protocol.c @@ -206,17 +206,37 @@ static void handle_qm_28x(const struct sr_dev_inst *sdi, char **tokens) struct sr_analog_spec spec; float fvalue; int digits; + int exponent; + char *e; devc = sdi->priv; if (!tokens[1]) return; + /* Split measurement into mantissa / exponent */ + e = tokens[0]; + while (*e) { + if (*e == 'e' || *e == 'E') { + *e = '\0'; + e++; + break; + } + e++; + } + if (sr_atof_ascii(tokens[0], &fvalue) != SR_OK) { - sr_err("Invalid float '%s'.", tokens[0]); + sr_err("Invalid mantissa '%s'.", tokens[0]); return; } - digits = count_digits(tokens[0]); + + if (sr_atoi(e, &exponent) != SR_OK) { + sr_err("Invalid exponent '%s'.", e); + return; + } + + digits = count_digits(tokens[0]) - exponent; + fvalue *= pow(10.0f, exponent); sr_analog_init(&analog, &encoding, &meaning, &spec, digits); analog.data = &fvalue;