]> sigrok.org Git - pulseview.git/commitdiff
Fix #1024 by changing decode channel assigment to PDs
authorSoeren Apel <redacted>
Fri, 8 Sep 2017 16:14:47 +0000 (18:14 +0200)
committerSoeren Apel <redacted>
Fri, 8 Sep 2017 19:01:41 +0000 (21:01 +0200)
When assigning the decoder stack channels to the libsrd
instance's channels, channels that had no signal assigned
to them were still assigned anyway. This patch fixes this bug.

After doing this, another subtle bug became apparent:
The mapping between channels and bits in the data stream sent
to the PD was done via DecodeChannel->id. This is however
insufficient as the channels of the decoder stack have
IDs that may or may not match the ID needed for the data
stream. Example:

A PD has 4 channels: A, B, C and D. In PV, those channels
have the IDs 0, 1, 2 and 3. If the user only assigns A and D,
Decoder::create_decoder_inst() will use the IDs 0 and 3 as
the bit positions of those signals in the data stream sent
to libsrd. This is obviously wrong.

Hence, we now use a separate bit_id for this purpose.

pv/data/decode/decoder.cpp
pv/data/decodesignal.cpp
pv/data/decodesignal.hpp

index 511f7bffb67abcc4d65b9cfa1888a6cc55a5e2ba..1c941074a0a13ea1150d1f93391148247e01b88d 100644 (file)
@@ -122,11 +122,14 @@ srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session) const
                g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
 
        for (DecodeChannel *ch : channels_) {
+               if (!ch->assigned_signal)
+                       continue;
+
                init_pin_states->data[ch->id] = ch->initial_pin_state;
 
-               GVariant *const gvar = g_variant_new_int32(ch->id);  // id = bit position
+               GVariant *const gvar = g_variant_new_int32(ch->bit_id);  // bit_id = bit position
                g_variant_ref_sink(gvar);
-               // key is channel name, value is bit position in each sample
+               // key is channel name (pdch->id), value is bit position in each sample (gvar)
                g_hash_table_insert(channels, ch->pdch_->id, gvar);
        }
 
index daa52ed62d67231821f4fee2647fd506853d96a7..6aa3f42f13ac7c93c6e272c4f43115300e19034a 100644 (file)
@@ -574,7 +574,7 @@ void DecodeSignal::update_channel_list()
 
                        if (!ch_added) {
                                // Create new entry without a mapped signal
-                               data::DecodeChannel ch = {id++, false, nullptr,
+                               data::DecodeChannel ch = {id++, 0, false, nullptr,
                                        QString::fromUtf8(pdch->name), QString::fromUtf8(pdch->desc),
                                        SRD_INITIAL_PIN_SAME_AS_SAMPLE0, decoder, pdch};
                                channels_.push_back(ch);
@@ -597,7 +597,7 @@ void DecodeSignal::update_channel_list()
 
                        if (!ch_added) {
                                // Create new entry without a mapped signal
-                               data::DecodeChannel ch = {id++, true, nullptr,
+                               data::DecodeChannel ch = {id++, 0, true, nullptr,
                                        QString::fromUtf8(pdch->name), QString::fromUtf8(pdch->desc),
                                        SRD_INITIAL_PIN_SAME_AS_SAMPLE0, decoder, pdch};
                                channels_.push_back(ch);
@@ -654,8 +654,11 @@ void DecodeSignal::mux_logic_samples(const int64_t start, const int64_t end)
        vector<uint8_t> signal_in_bytepos;
        vector<uint8_t> signal_in_bitpos;
 
+       int id = 0;
        for (data::DecodeChannel &ch : channels_)
                if (ch.assigned_signal) {
+                       ch.bit_id = id++;
+
                        const shared_ptr<Logic> logic_data = ch.assigned_signal->logic_data();
                        const shared_ptr<LogicSegment> segment = logic_data->logic_segments().front();
                        segments.push_back(segment);
index 0e0911521b09973ed2d28fd1ca72efa1f139b0df..04f3b77f45c3393d2bc3fa378929588cff41adc5 100644 (file)
@@ -61,7 +61,8 @@ class SignalData;
 
 struct DecodeChannel
 {
-       uint16_t id;  // Also tells which bit within a sample represents this channel
+       uint16_t id;     ///< Global numerical ID for the decode channels in the stack
+       uint16_t bit_id; ///< Tells which bit within a sample represents this channel
        const bool is_optional;
        const pv::data::SignalBase *assigned_signal;
        const QString name, desc;