]> sigrok.org Git - libsigrok.git/commitdiff
session: Convert from SR_DF_ANALOG to SR_DF_ANALOG2 automatically.
authorMartin Ling <redacted>
Wed, 9 Sep 2015 23:34:53 +0000 (00:34 +0100)
committerUwe Hermann <redacted>
Tue, 20 Oct 2015 21:32:45 +0000 (23:32 +0200)
This fixes bus #640.

src/session.c

index 993d9bdf037430f819e7a1d565ea26095127e82d..f058e0720f870a6b49c7b26f2f40beb29f90353c 100644 (file)
@@ -1081,6 +1081,43 @@ SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
                return SR_ERR_BUG;
        }
 
+       if (packet->type == SR_DF_ANALOG) {
+               /* Convert to SR_DF_ANALOG2. */
+               const struct sr_datafeed_analog *analog = packet->payload;
+               struct sr_analog_encoding encoding;
+               struct sr_analog_meaning meaning;
+               struct sr_analog_spec spec;
+               struct sr_datafeed_analog2 analog2;
+               struct sr_datafeed_packet a2_packet;
+               a2_packet.type = SR_DF_ANALOG2;
+               a2_packet.payload = &analog2;
+               analog2.data = analog->data;
+               analog2.num_samples = analog->num_samples;
+               analog2.encoding = &encoding;
+               analog2.meaning = &meaning;
+               analog2.spec = &spec;
+               encoding.unitsize = sizeof(float);
+               encoding.is_signed = TRUE;
+               encoding.is_float = TRUE;
+#ifdef WORDS_BIGENDIAN
+               encoding.is_bigendian = TRUE;
+#else
+               encoding.is_bigendian = FALSE;
+#endif
+               encoding.digits = 0;
+               encoding.is_digits_decimal = FALSE;
+               encoding.scale.p = 1;
+               encoding.scale.q = 1;
+               encoding.offset.p = 0;
+               encoding.offset.q = 1;
+               meaning.mq = analog->mq;
+               meaning.unit = analog->unit;
+               meaning.mqflags = analog->mqflags;
+               meaning.channels = analog->channels;
+               spec.spec_digits = 0;
+               return sr_session_send(sdi, &a2_packet);
+       }
+
        /*
         * Pass the packet to the first transform module. If that returns
         * another packet (instead of NULL), pass that packet to the next