]> sigrok.org Git - libsigrok.git/blobdiff - hardware/common/dmm/metex14.c
metex14: Fix 'is_ol' handling.
[libsigrok.git] / hardware / common / dmm / metex14.c
index 5e99fefffddd0cac26aad4cc566c44db9183b56a..c3d9a4f613fc09e9a52ea47399d899ceb2246230 100644 (file)
@@ -61,10 +61,10 @@ static int parse_value(const uint8_t *buf, float *result)
 
        /* Bytes 5-7: Over limit (various forms) */
        is_ol = 0;
-       is_ol += !strncmp((char *)&buf[5], ".OL", 3);
-       is_ol += !strncmp((char *)&buf[5], "O.L", 3);
-       is_ol += !strncmp((char *)&buf[5], "OL.", 3);
-       is_ol += !strncmp((char *)&buf[5], " OL", 3);
+       is_ol += (!strncmp((char *)&buf[5], ".OL", 3)) ? 1 : 0;
+       is_ol += (!strncmp((char *)&buf[5], "O.L", 3)) ? 1 : 0;
+       is_ol += (!strncmp((char *)&buf[5], "OL.", 3)) ? 1 : 0;
+       is_ol += (!strncmp((char *)&buf[5], " OL", 3)) ? 1 : 0;
        if (is_ol != 0) {
                sr_spew("Over limit.");
                *result = INFINITY;
@@ -75,6 +75,9 @@ static int parse_value(const uint8_t *buf, float *result)
        factor = 1000;
        for (i = 0; i < 5; i++) {
                digit = buf[4 + i];
+               /* Convert spaces to '0', so that we can parse them. */
+               if (digit == ' ')
+                       digit = '0';
                if (digit == '.') {
                        decimal_point = i;
                } else if (isdigit(digit)) {
@@ -132,27 +135,29 @@ static void parse_flags(const char *buf, struct metex14_info *info)
        /* Bytes 3-8: See parse_value(). */
 
        /* Bytes 9-12: Unit */
-       if (!strcmp(buf + 9, "   A"))
+       if (!strncmp(buf + 9, "   A", 4))
                info->is_ampere = TRUE;
-       else if (!strcmp(buf + 9, "  mA"))
+       else if (!strncmp(buf + 9, "  mA", 4))
                info->is_milli = info->is_ampere = TRUE;
-       else if (!strcmp(buf + 9, "   V"))
+       else if (!strncmp(buf + 9, "  uA", 4))
+               info->is_micro = info->is_ampere = TRUE;
+       else if (!strncmp(buf + 9, "   V", 4))
                info->is_volt = TRUE;
-       else if (!strcmp(buf + 9, "  mV"))
+       else if (!strncmp(buf + 9, "  mV", 4))
                info->is_milli = info->is_volt = TRUE;
-       else if (!strcmp(buf + 9, " Ohm"))
+       else if (!strncmp(buf + 9, " Ohm", 4))
                info->is_ohm = TRUE;
-       else if (!strcmp(buf + 9, "KOhm"))
+       else if (!strncmp(buf + 9, "KOhm", 4))
                info->is_kilo = info->is_ohm = TRUE;
-       else if (!strcmp(buf + 9, "MOhm"))
+       else if (!strncmp(buf + 9, "MOhm", 4))
                info->is_mega = info->is_ohm = TRUE;
-       else if (!strcmp(buf + 9, "  nF"))
+       else if (!strncmp(buf + 9, "  nF", 4))
                info->is_nano = info->is_farad = TRUE;
-       else if (!strcmp(buf + 9, "  uF"))
+       else if (!strncmp(buf + 9, "  uF", 4))
                info->is_micro = info->is_farad = TRUE;
-       else if (!strcmp(buf + 9, " KHz"))
+       else if (!strncmp(buf + 9, " KHz", 4))
                info->is_kilo = info->is_hertz = TRUE;
-       else if (!strcmp(buf + 9, "   C"))
+       else if (!strncmp(buf + 9, "   C", 4))
                info->is_celsius = TRUE;
 
        /* Byte 13: Always '\r' (carriage return, 0x0d, 13) */
@@ -288,6 +293,9 @@ SR_PRIV int sr_metex14_parse(const uint8_t *buf, float *floatval,
 
        info_local = (struct metex14_info *)info;
 
+       /* Don't print byte 13. That one contains the carriage return. */
+       sr_dbg("DMM packet: \"%.13s\"", buf);
+
        if ((ret = parse_value(buf, floatval)) != SR_OK) {
                sr_err("Error parsing value: %d.", ret);
                return ret;