diff --git a/src/hardware/norma-dmm/protocol.c b/src/hardware/norma-dmm/protocol.c index 7e0f2a10..fcaae133 100644 --- a/src/hardware/norma-dmm/protocol.c +++ b/src/hardware/norma-dmm/protocol.c @@ -91,7 +91,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 +123,7 @@ 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)); + sr_analog_init(&analog, &encoding, &meaning, &spec, 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]); 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 +209,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 +286,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 +295,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 +331,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 */ @@ -359,12 +362,12 @@ static void nma_process_line(const struct sr_dev_inst *sdi) (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(sdi, &packet);