X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fcommon%2Fdmm%2Fmetex14.c;h=7aa22a766a434d9171f3043ca917ca1c37bcd081;hb=fe9d5abefcebb3a382d990e069d93c28e9541e35;hp=f54188210f64d06a8243f86515934c61e389c0da;hpb=1a807c13fcf4bc015fb22311c70292e9c51bb5f9;p=libsigrok.git diff --git a/hardware/common/dmm/metex14.c b/hardware/common/dmm/metex14.c index f5418821..7aa22a76 100644 --- a/hardware/common/dmm/metex14.c +++ b/hardware/common/dmm/metex14.c @@ -34,14 +34,7 @@ #include "libsigrok.h" #include "libsigrok-internal.h" -/* Message logging helpers with subsystem-specific prefix string. */ -#define LOG_PREFIX "metex14: " -#define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args) -#define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args) -#define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args) -#define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args) -#define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args) -#define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args) +#define LOG_PREFIX "metex14" static int parse_value(const uint8_t *buf, float *result) { @@ -57,10 +50,14 @@ static int parse_value(const uint8_t *buf, float *result) /* Bytes 5-7: Over limit (various forms) */ is_ol = 0; - is_ol += (!strcmp((const char *)&valstr, ".OL")) ? 1 : 0; - is_ol += (!strcmp((const char *)&valstr, "O.L")) ? 1 : 0; - is_ol += (!strcmp((const char *)&valstr, "OL.")) ? 1 : 0; - is_ol += (!strcmp((const char *)&valstr, "OL")) ? 1 : 0; + is_ol += (!strcasecmp((const char *)&valstr, ".OL")) ? 1 : 0; + is_ol += (!strcasecmp((const char *)&valstr, "O.L")) ? 1 : 0; + is_ol += (!strcasecmp((const char *)&valstr, "OL.")) ? 1 : 0; + is_ol += (!strcasecmp((const char *)&valstr, "OL")) ? 1 : 0; + is_ol += (!strcasecmp((const char *)&valstr, "-.OL")) ? 1 : 0; + is_ol += (!strcasecmp((const char *)&valstr, "-O.L")) ? 1 : 0; + is_ol += (!strcasecmp((const char *)&valstr, "-OL.")) ? 1 : 0; + is_ol += (!strcasecmp((const char *)&valstr, "-OL")) ? 1 : 0; if (is_ol != 0) { sr_spew("Over limit."); *result = INFINITY; @@ -112,33 +109,35 @@ static void parse_flags(const char *buf, struct metex14_info *info) /* Bytes 9-12: Unit */ u = (const char *)&unit; - if (!strcmp(u, "A")) + if (!strcasecmp(u, "A")) info->is_ampere = TRUE; - else if (!strcmp(u, "mA")) + else if (!strcasecmp(u, "mA")) info->is_milli = info->is_ampere = TRUE; - else if (!strcmp(u, "uA")) + else if (!strcasecmp(u, "uA")) info->is_micro = info->is_ampere = TRUE; - else if (!strcmp(u, "V")) + else if (!strcasecmp(u, "V")) info->is_volt = TRUE; - else if (!strcmp(u, "mV")) + else if (!strcasecmp(u, "mV")) info->is_milli = info->is_volt = TRUE; - else if (!strcmp(u, "Ohm")) + else if (!strcasecmp(u, "Ohm")) info->is_ohm = TRUE; - else if (!strcmp(u, "KOhm")) + else if (!strcasecmp(u, "KOhm")) info->is_kilo = info->is_ohm = TRUE; - else if (!strcmp(u, "MOhm")) + else if (!strcasecmp(u, "MOhm")) info->is_mega = info->is_ohm = TRUE; - else if (!strcmp(u, "nF")) + else if (!strcasecmp(u, "pF")) + info->is_pico = info->is_farad = TRUE; + else if (!strcasecmp(u, "nF")) info->is_nano = info->is_farad = TRUE; - else if (!strcmp(u, "uF")) + else if (!strcasecmp(u, "uF")) info->is_micro = info->is_farad = TRUE; - else if (!strcmp(u, "KHz")) + else if (!strcasecmp(u, "KHz")) info->is_kilo = info->is_hertz = TRUE; - else if (!strcmp(u, "C")) + else if (!strcasecmp(u, "C")) info->is_celsius = TRUE; - else if (!strcmp(u, "DB")) + else if (!strcasecmp(u, "DB")) info->is_decibel = TRUE; - else if (!strcmp(u, "")) + else if (!strcasecmp(u, "")) info->is_unitless = TRUE; /* Byte 13: Always '\r' (carriage return, 0x0d, 13) */ @@ -148,6 +147,8 @@ static void handle_flags(struct sr_datafeed_analog *analog, float *floatval, const struct metex14_info *info) { /* Factors */ + if (info->is_pico) + *floatval /= 1000000000000ULL; if (info->is_nano) *floatval /= 1000000000; if (info->is_micro) @@ -212,13 +213,14 @@ static gboolean flags_valid(const struct metex14_info *info) /* Does the packet have more than one multiplier? */ count = 0; + count += (info->is_pico) ? 1 : 0; count += (info->is_nano) ? 1 : 0; count += (info->is_micro) ? 1 : 0; count += (info->is_milli) ? 1 : 0; count += (info->is_kilo) ? 1 : 0; count += (info->is_mega) ? 1 : 0; if (count > 1) { - sr_err("More than one multiplier detected in packet."); + sr_dbg("More than one multiplier detected in packet."); return FALSE; } @@ -232,19 +234,20 @@ static gboolean flags_valid(const struct metex14_info *info) count += (info->is_diode) ? 1 : 0; count += (info->is_frequency) ? 1 : 0; if (count > 1) { - sr_err("More than one measurement type detected in packet."); + sr_dbg("More than one measurement type detected in packet."); return FALSE; } /* Both AC and DC set? */ if (info->is_ac && info->is_dc) { - sr_err("Both AC and DC flags detected in packet."); + sr_dbg("Both AC and DC flags detected in packet."); return FALSE; } return TRUE; } +#ifdef HAVE_LIBSERIALPORT SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial) { const uint8_t wbuf = 'D'; @@ -253,6 +256,7 @@ SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial) return (serial_write(serial, &wbuf, 1) == 1) ? SR_OK : SR_ERR; } +#endif SR_PRIV gboolean sr_metex14_packet_valid(const uint8_t *buf) { @@ -297,7 +301,7 @@ SR_PRIV int sr_metex14_parse(const uint8_t *buf, float *floatval, sr_dbg("DMM packet: \"%.13s\"", buf); if ((ret = parse_value(buf, floatval)) != SR_OK) { - sr_err("Error parsing value: %d.", ret); + sr_dbg("Error parsing value: %d.", ret); return ret; }