X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fdmm%2Fmetex14.c;h=d93052a85b84bc7cbfbe50b5b3c266df50dbf665;hb=33306b13acdc34fb50b35a56d362f1ab56fc0afd;hp=2d0a70d640475d9778a92c03973e974d0c7c8d2e;hpb=556a926d432dd21a1d911daec13c6a6bbc49cdbb;p=libsigrok.git diff --git a/src/dmm/metex14.c b/src/dmm/metex14.c index 2d0a70d6..d93052a8 100644 --- a/src/dmm/metex14.c +++ b/src/dmm/metex14.c @@ -22,7 +22,6 @@ * * Metex 14-bytes ASCII protocol parser. * - * @internal * This should work for various multimeters which use this kind of protocol, * even though there is some variation in which modes each DMM supports. * @@ -146,8 +145,14 @@ static void parse_flags(const char *buf, struct metex14_info *info) info->is_kilo = info->is_hertz = TRUE; else if (!g_ascii_strcasecmp(u, "C")) info->is_celsius = TRUE; + else if (!g_ascii_strcasecmp(u, "F")) + info->is_fahrenheit = TRUE; else if (!g_ascii_strcasecmp(u, "DB")) info->is_decibel = TRUE; + else if (!g_ascii_strcasecmp(u, "dBm")) + info->is_decibel_mw = TRUE; + else if (!g_ascii_strcasecmp(u, "W")) + info->is_watt = TRUE; else if (!g_ascii_strcasecmp(u, "")) info->is_unitless = TRUE; @@ -156,15 +161,25 @@ static void parse_flags(const char *buf, struct metex14_info *info) (!strncmp(buf, " ", 2) && info->is_ohm); info->is_capacity = !strncmp(buf, "CA", 2) || (!strncmp(buf, " ", 2) && info->is_farad); - info->is_temperature = !strncmp(buf, "TE", 2); + info->is_temperature = !strncmp(buf, "TE", 2) || + info->is_celsius || info->is_fahrenheit; info->is_diode = !strncmp(buf, "DI", 2) || (!strncmp(buf, " ", 2) && info->is_volt && info->is_milli); info->is_frequency = !strncmp(buf, "FR", 2) || (!strncmp(buf, " ", 2) && info->is_hertz); - info->is_gain = !strncmp(buf, "DB", 2); + info->is_gain = !strncmp(buf, "DB", 2) && info->is_decibel; + info->is_power = (!strncmp(buf, "dB", 2) && info->is_decibel_mw) || + ((!strncmp(buf, "WT", 2) && info->is_watt)); + info->is_power_factor = !strncmp(buf, "CO", 2) && info->is_unitless; info->is_hfe = !strncmp(buf, "HF", 2) || - (!strncmp(buf, " ", 2) && !info->is_volt && !info->is_ohm && - !info->is_logic && !info->is_farad && !info->is_hertz); + (!strncmp(buf, " ", 2) && !info->is_ampere &&!info->is_volt && + !info->is_resistance && !info->is_capacity && !info->is_frequency && + !info->is_temperature && !info->is_power && !info->is_power_factor && + !info->is_gain && !info->is_logic && !info->is_diode); + info->is_min = !strncmp(buf, "MN", 2); + info->is_max = !strncmp(buf, "MX", 2); + info->is_avg = !strncmp(buf, "AG", 2); + /* * Note: * - Protocol doesn't distinguish "resistance" from "beep" mode. @@ -178,8 +193,12 @@ static void parse_flags(const char *buf, struct metex14_info *info) static void handle_flags(struct sr_datafeed_analog *analog, float *floatval, int *exponent, const struct metex14_info *info) { - int factor = 0; + int factor; + + (void)exponent; + /* Factors */ + factor = 0; if (info->is_pico) factor -= 12; if (info->is_nano) @@ -193,7 +212,6 @@ static void handle_flags(struct sr_datafeed_analog *analog, float *floatval, if (info->is_mega) factor += 6; *floatval *= powf(10, factor); - *exponent += factor; /* Measurement modes */ if (info->is_volt) { @@ -216,14 +234,32 @@ static void handle_flags(struct sr_datafeed_analog *analog, float *floatval, analog->meaning->mq = SR_MQ_CAPACITANCE; analog->meaning->unit = SR_UNIT_FARAD; } - if (info->is_celsius) { + if (info->is_temperature) { analog->meaning->mq = SR_MQ_TEMPERATURE; - analog->meaning->unit = SR_UNIT_CELSIUS; + if (info->is_celsius) + analog->meaning->unit = SR_UNIT_CELSIUS; + else if (info->is_fahrenheit) + analog->meaning->unit = SR_UNIT_FAHRENHEIT; + else + analog->meaning->unit = SR_UNIT_UNITLESS; } if (info->is_diode) { analog->meaning->mq = SR_MQ_VOLTAGE; analog->meaning->unit = SR_UNIT_VOLT; } + if (info->is_power) { + analog->meaning->mq = SR_MQ_POWER; + if (info->is_decibel_mw) + analog->meaning->unit = SR_UNIT_DECIBEL_MW; + else if (info->is_watt) + analog->meaning->unit = SR_UNIT_WATT; + else + analog->meaning->unit = SR_UNIT_UNITLESS; + } + if (info->is_power_factor) { + analog->meaning->mq = SR_MQ_POWER_FACTOR; + analog->meaning->unit = SR_UNIT_UNITLESS; + } if (info->is_gain) { analog->meaning->mq = SR_MQ_GAIN; analog->meaning->unit = SR_UNIT_DECIBEL_VOLT; @@ -244,6 +280,12 @@ static void handle_flags(struct sr_datafeed_analog *analog, float *floatval, analog->meaning->mqflags |= SR_MQFLAG_DC; if (info->is_diode) analog->meaning->mqflags |= SR_MQFLAG_DIODE | SR_MQFLAG_DC; + if (info->is_min) + analog->meaning->mqflags |= SR_MQFLAG_MIN; + if (info->is_max) + analog->meaning->mqflags |= SR_MQFLAG_MAX; + if (info->is_avg) + analog->meaning->mqflags |= SR_MQFLAG_AVG; } static gboolean flags_valid(const struct metex14_info *info) @@ -286,14 +328,23 @@ static gboolean flags_valid(const struct metex14_info *info) return TRUE; } -#ifdef HAVE_LIBSERIALPORT +#ifdef HAVE_SERIAL_COMM SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial) { const uint8_t wbuf = 'D'; + size_t wrlen; + int ret; sr_spew("Requesting DMM packet."); - return serial_write_blocking(serial, &wbuf, 1, 0); + wrlen = sizeof(wbuf); + ret = serial_write_blocking(serial, &wbuf, wrlen, 0); + if (ret < 0) + return ret; + if ((size_t)ret != wrlen) + return SR_ERR_IO; + + return SR_OK; } #endif @@ -353,7 +404,7 @@ SR_PRIV int sr_metex14_parse(const uint8_t *buf, float *floatval, int ret, exponent = 0; struct metex14_info *info_local; - info_local = (struct metex14_info *)info; + info_local = info; /* Don't print byte 13. That one contains the carriage return. */ sr_dbg("DMM packet: \"%.13s\"", buf);