]> sigrok.org Git - libsigrok.git/commitdiff
dmm/mm38xr: fix values for digits properties
authorFrank Stettner <redacted>
Fri, 23 Dec 2022 14:03:13 +0000 (15:03 +0100)
committerGerhard Sittig <redacted>
Sun, 19 Feb 2023 10:27:45 +0000 (11:27 +0100)
Unify the mm38xr package parser with the other drivers regarding the use of the
digits properties in the analog payload. This commit adjusts the previously
unclear, but now clarified, use of these properties:

Number of significant digits after the decimal point, if positive. When
negative, exponent with reversed polarity that is necessary to express the
value with all digits without a decimal point.

src/dmm/mm38xr.c

index 1e4ecd5abdc8a0163bf2090cbd74796cd1c39dfa..8f51adda1e81d7b98ff650b77b4da8185783f2d8 100644 (file)
@@ -341,7 +341,6 @@ SR_PRIV int meterman_38xr_parse(const uint8_t *buf, float *floatval,
        struct sr_datafeed_analog *analog, void *info)
 {
        gboolean is_overload, is_bad_jack;
        struct sr_datafeed_analog *analog, void *info)
 {
        gboolean is_overload, is_bad_jack;
-       int exponent;
        int digits;
        struct meterman_info mi;
 
        int digits;
        struct meterman_info mi;
 
@@ -350,6 +349,8 @@ SR_PRIV int meterman_38xr_parse(const uint8_t *buf, float *floatval,
        if (meterman_38xr_decode(buf, &mi) != SR_OK)
                return SR_ERR;
 
        if (meterman_38xr_decode(buf, &mi) != SR_OK)
                return SR_ERR;
 
+       digits = 0;
+
        if (mi.meas_mode != MEAS_MODE_CONTINUITY) {
                is_overload = mi.reading == METERMAN_DIGITS_OVERLOAD;
                is_bad_jack = mi.reading == METERMAN_DIGITS_BAD_INPUT_JACK;
        if (mi.meas_mode != MEAS_MODE_CONTINUITY) {
                is_overload = mi.reading == METERMAN_DIGITS_OVERLOAD;
                is_bad_jack = mi.reading == METERMAN_DIGITS_BAD_INPUT_JACK;
@@ -440,18 +441,17 @@ SR_PRIV int meterman_38xr_parse(const uint8_t *buf, float *floatval,
        if (mi.rflag_h == 0x0a || mi.peakstatus == 0x0b)
                analog->meaning->mqflags |= SR_MQFLAG_AUTORANGE;
        if (mi.meas_mode != MEAS_MODE_CONTINUITY) {
        if (mi.rflag_h == 0x0a || mi.peakstatus == 0x0b)
                analog->meaning->mqflags |= SR_MQFLAG_AUTORANGE;
        if (mi.meas_mode != MEAS_MODE_CONTINUITY) {
-               digits = decimal_digits[mi.meas_mode][mi.rangecode];
-               exponent = units_exponents[mi.meas_mode][mi.rangecode];
+               digits = units_exponents[mi.meas_mode][mi.rangecode] -
+                       decimal_digits[mi.meas_mode][mi.rangecode];
 
                *floatval = mi.reading;
                if (meterman_38xr_is_negative(&mi)) {
                        *floatval *= -1.0f;
                }
 
                *floatval = mi.reading;
                if (meterman_38xr_is_negative(&mi)) {
                        *floatval *= -1.0f;
                }
-               *floatval *= powf(10, -digits);
-               *floatval *= powf(10, exponent);
+               *floatval *= powf(10, digits);
        }
        }
-       analog->encoding->digits = 4;
-       analog->spec->spec_digits = 4;
+       analog->encoding->digits = -digits;
+       analog->spec->spec_digits = -digits;
 
        return SR_OK;
 }
 
        return SR_OK;
 }