X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fnorma-dmm%2Fprotocol.c;h=39924176d484c4ddab04f126a4d245c8dba888c0;hb=b8278e0943317cdf6594057ae9482c786c607f04;hp=a077cf983b05ef392a642f322ebe9991fab0852e;hpb=5faebab2903dc91949edc31f0a4b118d86090a30;p=libsigrok.git
diff --git a/src/hardware/norma-dmm/protocol.c b/src/hardware/norma-dmm/protocol.c
index a077cf98..39924176 100644
--- a/src/hardware/norma-dmm/protocol.c
+++ b/src/hardware/norma-dmm/protocol.c
@@ -17,11 +17,6 @@
* along with this program. If not, see .
*/
-/** @file
- * Norma DM9x0/Siemens B102x DMMs driver.
- * @internal
- */
-
#include
#include "protocol.h"
@@ -30,7 +25,7 @@
SR_PRIV const struct nmadmm_req nmadmm_requests[] = {
{ NMADMM_REQ_IDN, "IDN?" },
{ NMADMM_REQ_IDN, "STATUS?" },
- { 0, NULL },
+ ALL_ZERO
};
static int nma_send_req(const struct sr_dev_inst *sdi, int req, char *params)
@@ -91,7 +86,10 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
int mmode, devstat; /* Measuring mode, device status */
float value; /* Measured value */
float scale; /* Scaling factor depending on range and function */
- struct sr_datafeed_analog_old analog;
+ struct sr_datafeed_analog analog;
+ struct sr_analog_encoding encoding;
+ struct sr_analog_meaning meaning;
+ struct sr_analog_spec spec;
struct sr_datafeed_packet packet;
devc = sdi->priv;
@@ -120,7 +118,8 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
/* Start decoding. */
value = 0.0;
scale = 1.0;
- memset(&analog, 0, sizeof(struct sr_datafeed_analog_old));
+ /* TODO: Use proper 'digits' value for this device (and its modes). */
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
/*
* The numbers are hex digits, starting from 0.
@@ -131,35 +130,35 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
vt = xgittoint(devc->buf[2]);
switch (vt) {
case 0:
- analog.mq = SR_MQ_VOLTAGE;
+ analog.meaning->mq = SR_MQ_VOLTAGE;
break;
case 1:
- analog.mq = SR_MQ_CURRENT; /* 2A */
+ analog.meaning->mq = SR_MQ_CURRENT; /* 2A */
break;
case 2:
- analog.mq = SR_MQ_RESISTANCE;
+ analog.meaning->mq = SR_MQ_RESISTANCE;
break;
case 3:
- analog.mq = SR_MQ_CAPACITANCE;
+ analog.meaning->mq = SR_MQ_CAPACITANCE;
break;
case 4:
- analog.mq = SR_MQ_TEMPERATURE;
+ analog.meaning->mq = SR_MQ_TEMPERATURE;
break;
case 5:
- analog.mq = SR_MQ_FREQUENCY;
+ analog.meaning->mq = SR_MQ_FREQUENCY;
break;
case 6:
- analog.mq = SR_MQ_CURRENT; /* 10A */
+ analog.meaning->mq = SR_MQ_CURRENT; /* 10A */
break;
case 7:
- analog.mq = SR_MQ_GAIN; /* TODO: Scale factor */
+ analog.meaning->mq = SR_MQ_GAIN; /* TODO: Scale factor */
break;
case 8:
- analog.mq = SR_MQ_GAIN; /* Percentage */
+ analog.meaning->mq = SR_MQ_GAIN; /* Percentage */
scale /= 100.0;
break;
case 9:
- analog.mq = SR_MQ_GAIN; /* dB */
+ analog.meaning->mq = SR_MQ_GAIN; /* dB */
scale /= 100.0;
break;
default:
@@ -206,53 +205,53 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
mmode = xgittoint(devc->buf[10]);
switch (mmode) {
case 0: /* Frequency */
- analog.unit = SR_UNIT_HERTZ;
+ analog.meaning->unit = SR_UNIT_HERTZ;
break;
case 1: /* V TRMS, only type 5 */
- analog.unit = SR_UNIT_VOLT;
- analog.mqflags |= (SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS);
+ analog.meaning->unit = SR_UNIT_VOLT;
+ analog.meaning->mqflags |= (SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS);
break;
case 2: /* V AC */
- analog.unit = SR_UNIT_VOLT;
- analog.mqflags |= SR_MQFLAG_AC;
+ analog.meaning->unit = SR_UNIT_VOLT;
+ analog.meaning->mqflags |= SR_MQFLAG_AC;
if (devc->type >= 3)
- analog.mqflags |= SR_MQFLAG_RMS;
+ analog.meaning->mqflags |= SR_MQFLAG_RMS;
break;
case 3: /* V DC */
- analog.unit = SR_UNIT_VOLT;
- analog.mqflags |= SR_MQFLAG_DC;
+ analog.meaning->unit = SR_UNIT_VOLT;
+ analog.meaning->mqflags |= SR_MQFLAG_DC;
break;
case 4: /* Ohm */
- analog.unit = SR_UNIT_OHM;
+ analog.meaning->unit = SR_UNIT_OHM;
break;
case 5: /* Continuity */
- analog.unit = SR_UNIT_BOOLEAN;
- analog.mq = SR_MQ_CONTINUITY;
+ analog.meaning->unit = SR_UNIT_BOOLEAN;
+ analog.meaning->mq = SR_MQ_CONTINUITY;
/* TODO: Continuity handling is a bit odd in libsigrok. */
break;
case 6: /* Degree Celsius */
- analog.unit = SR_UNIT_CELSIUS;
+ analog.meaning->unit = SR_UNIT_CELSIUS;
break;
case 7: /* Capacity */
- analog.unit = SR_UNIT_FARAD;
+ analog.meaning->unit = SR_UNIT_FARAD;
break;
case 8: /* Current DC */
- analog.unit = SR_UNIT_AMPERE;
- analog.mqflags |= SR_MQFLAG_DC;
+ analog.meaning->unit = SR_UNIT_AMPERE;
+ analog.meaning->mqflags |= SR_MQFLAG_DC;
break;
case 9: /* Current AC */
- analog.unit = SR_UNIT_AMPERE;
- analog.mqflags |= SR_MQFLAG_AC;
+ analog.meaning->unit = SR_UNIT_AMPERE;
+ analog.meaning->mqflags |= SR_MQFLAG_AC;
if (devc->type >= 3)
- analog.mqflags |= SR_MQFLAG_RMS;
+ analog.meaning->mqflags |= SR_MQFLAG_RMS;
break;
case 0xa: /* Current TRMS, only type 5 */
- analog.unit = SR_UNIT_AMPERE;
- analog.mqflags |= (SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS);
+ analog.meaning->unit = SR_UNIT_AMPERE;
+ analog.meaning->mqflags |= (SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS);
break;
case 0xb: /* Diode */
- analog.unit = SR_UNIT_VOLT;
- analog.mqflags |= (SR_MQFLAG_DIODE | SR_MQFLAG_DC);
+ analog.meaning->unit = SR_UNIT_VOLT;
+ analog.meaning->mqflags |= (SR_MQFLAG_DIODE | SR_MQFLAG_DC);
break;
default:
sr_err("Unknown mmode: 0x%02x.", mmode);
@@ -283,7 +282,7 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
flags = (xgittoint(devc->buf[12]) << 8) | xgittoint(devc->buf[13]);
/* 0x80: PRINT TODO: Stop polling when discovered? */
/* 0x40: EXTR */
- if (analog.mq == SR_MQ_CONTINUITY) {
+ if (analog.meaning->mq == SR_MQ_CONTINUITY) {
if (flags & 0x20)
value = 1.0; /* Beep */
else
@@ -292,26 +291,26 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
/* 0x10: AVG */
/* 0x08: Diode */
if (flags & 0x04) /* REL */
- analog.mqflags |= SR_MQFLAG_RELATIVE;
+ analog.meaning->mqflags |= SR_MQFLAG_RELATIVE;
/* 0x02: SHIFT */
if (flags & 0x01) /* % */
- analog.unit = SR_UNIT_PERCENTAGE;
+ analog.meaning->unit = SR_UNIT_PERCENTAGE;
/* 14, 15 */
flags = (xgittoint(devc->buf[14]) << 8) | xgittoint(devc->buf[15]);
if (!(flags & 0x80)) /* MAN: Manual range */
- analog.mqflags |= SR_MQFLAG_AUTORANGE;
+ analog.meaning->mqflags |= SR_MQFLAG_AUTORANGE;
if (flags & 0x40) /* LOBATT1: Low battery, measurement still within specs */
devc->lowbatt = 1;
/* 0x20: PEAK */
/* 0x10: COUNT */
if (flags & 0x08) /* HOLD */
- analog.mqflags |= SR_MQFLAG_HOLD;
+ analog.meaning->mqflags |= SR_MQFLAG_HOLD;
/* 0x04: LIMIT */
if (flags & 0x02) /* MAX */
- analog.mqflags |= SR_MQFLAG_MAX;
+ analog.meaning->mqflags |= SR_MQFLAG_MAX;
if (flags & 0x01) /* MIN */
- analog.mqflags |= SR_MQFLAG_MIN;
+ analog.meaning->mqflags |= SR_MQFLAG_MIN;
/* 16, 17 */
flags = (xgittoint(devc->buf[16]) << 8) | xgittoint(devc->buf[17]);
@@ -328,10 +327,10 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
* TODO: The Norma has an adjustable dB reference value. If
* changed from default, this is not correct.
*/
- if (analog.unit == SR_UNIT_VOLT)
- analog.unit = SR_UNIT_DECIBEL_VOLT;
+ if (analog.meaning->unit == SR_UNIT_VOLT)
+ analog.meaning->unit = SR_UNIT_DECIBEL_VOLT;
else
- analog.unit = SR_UNIT_UNITLESS;
+ analog.meaning->unit = SR_UNIT_UNITLESS;
}
/* 18, 19 */
@@ -346,30 +345,30 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
/* 4: Flags. Evaluating this after setting value! */
flags = xgittoint(devc->buf[4]);
if (flags & 0x04) /* Invalid value */
- value = NAN;
+ value = NAN;
else if (flags & 0x01) /* Overload */
- value = INFINITY;
+ value = INFINITY;
if (flags & 0x02) { /* Duplicate value, has been sent before. */
- sr_spew("Duplicate value, dismissing!");
- devc->buflen = 0;
- return;
+ sr_spew("Duplicate value, dismissing!");
+ devc->buflen = 0;
+ return;
}
sr_spew("range=%d/scale=%f/value=%f", range,
(double)scale, (double)value);
/* Finish and send packet. */
- analog.channels = sdi->channels;
+ analog.meaning->channels = sdi->channels;
analog.num_samples = 1;
analog.data = &value;
memset(&packet, 0, sizeof(struct sr_datafeed_packet));
- packet.type = SR_DF_ANALOG_OLD;
+ packet.type = SR_DF_ANALOG;
packet.payload = &analog;
- sr_session_send(devc->cb_data, &packet);
+ sr_session_send(sdi, &packet);
/* Finish processing. */
- devc->num_samples++;
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
devc->buflen = 0;
}
@@ -379,8 +378,6 @@ SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data)
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
int len;
- gboolean terminating;
- gdouble elapsed_s;
(void)fd;
@@ -411,23 +408,10 @@ SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data)
}
}
- /* If number of samples or time limit reached, stop acquisition. */
- terminating = FALSE;
- if (devc->limit_samples && (devc->num_samples >= devc->limit_samples)) {
- sdi->driver->dev_acquisition_stop(sdi, cb_data);
- terminating = TRUE;
- }
-
- if (devc->limit_msec) {
- elapsed_s = g_timer_elapsed(devc->elapsed_msec, NULL);
- if ((elapsed_s * 1000) >= devc->limit_msec) {
- sdi->driver->dev_acquisition_stop(sdi, cb_data);
- terminating = TRUE;
- }
- }
-
- /* Request next package. */
- if (!terminating) {
+ if (sr_sw_limits_check(&devc->limits)) {
+ sr_dev_acquisition_stop(sdi);
+ } else {
+ /* Request next package. */
if (devc->last_req_pending) {
gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at;
if (elapsed_us > NMADMM_TIMEOUT_MS * 1000) {/* Timeout! */