norma-dmm: Convert to SR_DF_ANALOG.

This commit is contained in:
Uwe Hermann 2016-05-14 17:21:49 +02:00
parent 67eb7c6bdf
commit 55bee166eb
1 changed files with 49 additions and 46 deletions

View File

@ -91,7 +91,10 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
int mmode, devstat; /* Measuring mode, device status */ int mmode, devstat; /* Measuring mode, device status */
float value; /* Measured value */ float value; /* Measured value */
float scale; /* Scaling factor depending on range and function */ 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; struct sr_datafeed_packet packet;
devc = sdi->priv; devc = sdi->priv;
@ -120,7 +123,7 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
/* Start decoding. */ /* Start decoding. */
value = 0.0; value = 0.0;
scale = 1.0; scale = 1.0;
memset(&analog, 0, sizeof(struct sr_datafeed_analog_old)); sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
/* /*
* The numbers are hex digits, starting from 0. * The numbers are hex digits, starting from 0.
@ -131,35 +134,35 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
vt = xgittoint(devc->buf[2]); vt = xgittoint(devc->buf[2]);
switch (vt) { switch (vt) {
case 0: case 0:
analog.mq = SR_MQ_VOLTAGE; analog.meaning->mq = SR_MQ_VOLTAGE;
break; break;
case 1: case 1:
analog.mq = SR_MQ_CURRENT; /* 2A */ analog.meaning->mq = SR_MQ_CURRENT; /* 2A */
break; break;
case 2: case 2:
analog.mq = SR_MQ_RESISTANCE; analog.meaning->mq = SR_MQ_RESISTANCE;
break; break;
case 3: case 3:
analog.mq = SR_MQ_CAPACITANCE; analog.meaning->mq = SR_MQ_CAPACITANCE;
break; break;
case 4: case 4:
analog.mq = SR_MQ_TEMPERATURE; analog.meaning->mq = SR_MQ_TEMPERATURE;
break; break;
case 5: case 5:
analog.mq = SR_MQ_FREQUENCY; analog.meaning->mq = SR_MQ_FREQUENCY;
break; break;
case 6: case 6:
analog.mq = SR_MQ_CURRENT; /* 10A */ analog.meaning->mq = SR_MQ_CURRENT; /* 10A */
break; break;
case 7: case 7:
analog.mq = SR_MQ_GAIN; /* TODO: Scale factor */ analog.meaning->mq = SR_MQ_GAIN; /* TODO: Scale factor */
break; break;
case 8: case 8:
analog.mq = SR_MQ_GAIN; /* Percentage */ analog.meaning->mq = SR_MQ_GAIN; /* Percentage */
scale /= 100.0; scale /= 100.0;
break; break;
case 9: case 9:
analog.mq = SR_MQ_GAIN; /* dB */ analog.meaning->mq = SR_MQ_GAIN; /* dB */
scale /= 100.0; scale /= 100.0;
break; break;
default: default:
@ -206,53 +209,53 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
mmode = xgittoint(devc->buf[10]); mmode = xgittoint(devc->buf[10]);
switch (mmode) { switch (mmode) {
case 0: /* Frequency */ case 0: /* Frequency */
analog.unit = SR_UNIT_HERTZ; analog.meaning->unit = SR_UNIT_HERTZ;
break; break;
case 1: /* V TRMS, only type 5 */ case 1: /* V TRMS, only type 5 */
analog.unit = SR_UNIT_VOLT; analog.meaning->unit = SR_UNIT_VOLT;
analog.mqflags |= (SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS); analog.meaning->mqflags |= (SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS);
break; break;
case 2: /* V AC */ case 2: /* V AC */
analog.unit = SR_UNIT_VOLT; analog.meaning->unit = SR_UNIT_VOLT;
analog.mqflags |= SR_MQFLAG_AC; analog.meaning->mqflags |= SR_MQFLAG_AC;
if (devc->type >= 3) if (devc->type >= 3)
analog.mqflags |= SR_MQFLAG_RMS; analog.meaning->mqflags |= SR_MQFLAG_RMS;
break; break;
case 3: /* V DC */ case 3: /* V DC */
analog.unit = SR_UNIT_VOLT; analog.meaning->unit = SR_UNIT_VOLT;
analog.mqflags |= SR_MQFLAG_DC; analog.meaning->mqflags |= SR_MQFLAG_DC;
break; break;
case 4: /* Ohm */ case 4: /* Ohm */
analog.unit = SR_UNIT_OHM; analog.meaning->unit = SR_UNIT_OHM;
break; break;
case 5: /* Continuity */ case 5: /* Continuity */
analog.unit = SR_UNIT_BOOLEAN; analog.meaning->unit = SR_UNIT_BOOLEAN;
analog.mq = SR_MQ_CONTINUITY; analog.meaning->mq = SR_MQ_CONTINUITY;
/* TODO: Continuity handling is a bit odd in libsigrok. */ /* TODO: Continuity handling is a bit odd in libsigrok. */
break; break;
case 6: /* Degree Celsius */ case 6: /* Degree Celsius */
analog.unit = SR_UNIT_CELSIUS; analog.meaning->unit = SR_UNIT_CELSIUS;
break; break;
case 7: /* Capacity */ case 7: /* Capacity */
analog.unit = SR_UNIT_FARAD; analog.meaning->unit = SR_UNIT_FARAD;
break; break;
case 8: /* Current DC */ case 8: /* Current DC */
analog.unit = SR_UNIT_AMPERE; analog.meaning->unit = SR_UNIT_AMPERE;
analog.mqflags |= SR_MQFLAG_DC; analog.meaning->mqflags |= SR_MQFLAG_DC;
break; break;
case 9: /* Current AC */ case 9: /* Current AC */
analog.unit = SR_UNIT_AMPERE; analog.meaning->unit = SR_UNIT_AMPERE;
analog.mqflags |= SR_MQFLAG_AC; analog.meaning->mqflags |= SR_MQFLAG_AC;
if (devc->type >= 3) if (devc->type >= 3)
analog.mqflags |= SR_MQFLAG_RMS; analog.meaning->mqflags |= SR_MQFLAG_RMS;
break; break;
case 0xa: /* Current TRMS, only type 5 */ case 0xa: /* Current TRMS, only type 5 */
analog.unit = SR_UNIT_AMPERE; analog.meaning->unit = SR_UNIT_AMPERE;
analog.mqflags |= (SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS); analog.meaning->mqflags |= (SR_MQFLAG_AC | SR_MQFLAG_DC | SR_MQFLAG_RMS);
break; break;
case 0xb: /* Diode */ case 0xb: /* Diode */
analog.unit = SR_UNIT_VOLT; analog.meaning->unit = SR_UNIT_VOLT;
analog.mqflags |= (SR_MQFLAG_DIODE | SR_MQFLAG_DC); analog.meaning->mqflags |= (SR_MQFLAG_DIODE | SR_MQFLAG_DC);
break; break;
default: default:
sr_err("Unknown mmode: 0x%02x.", mmode); sr_err("Unknown mmode: 0x%02x.", mmode);
@ -283,7 +286,7 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
flags = (xgittoint(devc->buf[12]) << 8) | xgittoint(devc->buf[13]); flags = (xgittoint(devc->buf[12]) << 8) | xgittoint(devc->buf[13]);
/* 0x80: PRINT TODO: Stop polling when discovered? */ /* 0x80: PRINT TODO: Stop polling when discovered? */
/* 0x40: EXTR */ /* 0x40: EXTR */
if (analog.mq == SR_MQ_CONTINUITY) { if (analog.meaning->mq == SR_MQ_CONTINUITY) {
if (flags & 0x20) if (flags & 0x20)
value = 1.0; /* Beep */ value = 1.0; /* Beep */
else else
@ -292,26 +295,26 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
/* 0x10: AVG */ /* 0x10: AVG */
/* 0x08: Diode */ /* 0x08: Diode */
if (flags & 0x04) /* REL */ if (flags & 0x04) /* REL */
analog.mqflags |= SR_MQFLAG_RELATIVE; analog.meaning->mqflags |= SR_MQFLAG_RELATIVE;
/* 0x02: SHIFT */ /* 0x02: SHIFT */
if (flags & 0x01) /* % */ if (flags & 0x01) /* % */
analog.unit = SR_UNIT_PERCENTAGE; analog.meaning->unit = SR_UNIT_PERCENTAGE;
/* 14, 15 */ /* 14, 15 */
flags = (xgittoint(devc->buf[14]) << 8) | xgittoint(devc->buf[15]); flags = (xgittoint(devc->buf[14]) << 8) | xgittoint(devc->buf[15]);
if (!(flags & 0x80)) /* MAN: Manual range */ 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 */ if (flags & 0x40) /* LOBATT1: Low battery, measurement still within specs */
devc->lowbatt = 1; devc->lowbatt = 1;
/* 0x20: PEAK */ /* 0x20: PEAK */
/* 0x10: COUNT */ /* 0x10: COUNT */
if (flags & 0x08) /* HOLD */ if (flags & 0x08) /* HOLD */
analog.mqflags |= SR_MQFLAG_HOLD; analog.meaning->mqflags |= SR_MQFLAG_HOLD;
/* 0x04: LIMIT */ /* 0x04: LIMIT */
if (flags & 0x02) /* MAX */ if (flags & 0x02) /* MAX */
analog.mqflags |= SR_MQFLAG_MAX; analog.meaning->mqflags |= SR_MQFLAG_MAX;
if (flags & 0x01) /* MIN */ if (flags & 0x01) /* MIN */
analog.mqflags |= SR_MQFLAG_MIN; analog.meaning->mqflags |= SR_MQFLAG_MIN;
/* 16, 17 */ /* 16, 17 */
flags = (xgittoint(devc->buf[16]) << 8) | xgittoint(devc->buf[17]); flags = (xgittoint(devc->buf[16]) << 8) | xgittoint(devc->buf[17]);
@ -328,10 +331,10 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
* TODO: The Norma has an adjustable dB reference value. If * TODO: The Norma has an adjustable dB reference value. If
* changed from default, this is not correct. * changed from default, this is not correct.
*/ */
if (analog.unit == SR_UNIT_VOLT) if (analog.meaning->unit == SR_UNIT_VOLT)
analog.unit = SR_UNIT_DECIBEL_VOLT; analog.meaning->unit = SR_UNIT_DECIBEL_VOLT;
else else
analog.unit = SR_UNIT_UNITLESS; analog.meaning->unit = SR_UNIT_UNITLESS;
} }
/* 18, 19 */ /* 18, 19 */
@ -359,12 +362,12 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
(double)scale, (double)value); (double)scale, (double)value);
/* Finish and send packet. */ /* Finish and send packet. */
analog.channels = sdi->channels; analog.meaning->channels = sdi->channels;
analog.num_samples = 1; analog.num_samples = 1;
analog.data = &value; analog.data = &value;
memset(&packet, 0, sizeof(struct sr_datafeed_packet)); memset(&packet, 0, sizeof(struct sr_datafeed_packet));
packet.type = SR_DF_ANALOG_OLD; packet.type = SR_DF_ANALOG;
packet.payload = &analog; packet.payload = &analog;
sr_session_send(sdi, &packet); sr_session_send(sdi, &packet);