/* 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;
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)) {
/* 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) */
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;