From: Martin Ling Date: Wed, 9 Sep 2015 23:34:53 +0000 (+0100) Subject: session: Convert from SR_DF_ANALOG to SR_DF_ANALOG2 automatically. X-Git-Tag: libsigrok-0.4.0~205 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ca79993bba12e8cb48c4327e92b9c296c10a9866;p=libsigrok.git session: Convert from SR_DF_ANALOG to SR_DF_ANALOG2 automatically. This fixes bus #640. --- diff --git a/src/session.c b/src/session.c index 993d9bdf..f058e072 100644 --- a/src/session.c +++ b/src/session.c @@ -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