X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fcommon%2Fdmm%2Fmetex14.c;h=9091885614d2c46e8754e594fe8aca62a4428392;hb=7ab89f4827d516313cafc9b7b9670ee99dc9c584;hp=b15ac4f0c9a294a5be9387f1b78a7cd7e361c53a;hpb=2477fb95693aeeeab04323618ba18b1ebdbc3eb2;p=libsigrok.git diff --git a/hardware/common/dmm/metex14.c b/hardware/common/dmm/metex14.c index b15ac4f0..90918856 100644 --- a/hardware/common/dmm/metex14.c +++ b/hardware/common/dmm/metex14.c @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the libsigrok project. * * Copyright (C) 2012 Uwe Hermann * @@ -34,14 +34,14 @@ #include "libsigrok.h" #include "libsigrok-internal.h" -/* Message logging helpers with driver-specific prefix string. */ -#define DRIVER_LOG_DOMAIN "metex14: " -#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args) -#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args) -#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args) -#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args) -#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args) -#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args) +/* 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) static int parse_value(const uint8_t *buf, float *result) { @@ -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; @@ -126,6 +126,13 @@ static void parse_flags(const char *buf, struct metex14_info *info) info->is_temperature = !strncmp(buf, "TE", 2); info->is_diode = !strncmp(buf, "DI", 2); info->is_frequency = !strncmp(buf, "FR", 2); + info->is_gain = !strncmp(buf, "DB", 2); + info->is_hfe = !strncmp(buf, "HF", 2); + + /* + * Note: "DB" shows the logarithmic ratio of input voltage to a + * pre-stored (user-changeable) value in the DMM. + */ if (info->is_dc || info->is_ac) info->is_volt = TRUE; @@ -159,6 +166,10 @@ static void parse_flags(const char *buf, struct metex14_info *info) info->is_kilo = info->is_hertz = TRUE; else if (!strncmp(buf + 9, " C", 4)) info->is_celsius = TRUE; + else if (!strncmp(buf + 9, " DB", 4)) + info->is_decibel = TRUE; + else if (!strncmp(buf + 9, " ", 4)) + info->is_unitless = TRUE; /* Byte 13: Always '\r' (carriage return, 0x0d, 13) */ } @@ -207,6 +218,14 @@ static void handle_flags(struct sr_datafeed_analog *analog, float *floatval, analog->mq = SR_MQ_VOLTAGE; analog->unit = SR_UNIT_VOLT; } + if (info->is_gain) { + analog->mq = SR_MQ_GAIN; + analog->unit = SR_UNIT_DECIBEL_VOLT; + } + if (info->is_hfe) { + analog->mq = SR_MQ_GAIN; + analog->unit = SR_UNIT_UNITLESS; + } /* Measurement related flags */ if (info->is_ac) @@ -254,6 +273,15 @@ static gboolean flags_valid(const struct metex14_info *info) return TRUE; } +SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial) +{ + const uint8_t wbuf = 'D'; + + sr_spew("Requesting DMM packet."); + + return (serial_write(serial, &wbuf, 1) == 1) ? SR_OK : SR_ERR; +} + SR_PRIV gboolean sr_metex14_packet_valid(const uint8_t *buf) { struct metex14_info info;