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.
g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
for (DecodeChannel *ch : channels_) {
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;
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);
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);
}
g_hash_table_insert(channels, ch->pdch_->id, gvar);
}
if (!ch_added) {
// Create new entry without a mapped signal
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);
QString::fromUtf8(pdch->name), QString::fromUtf8(pdch->desc),
SRD_INITIAL_PIN_SAME_AS_SAMPLE0, decoder, pdch};
channels_.push_back(ch);
if (!ch_added) {
// Create new entry without a mapped signal
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);
QString::fromUtf8(pdch->name), QString::fromUtf8(pdch->desc),
SRD_INITIAL_PIN_SAME_AS_SAMPLE0, decoder, pdch};
channels_.push_back(ch);
vector<uint8_t> signal_in_bytepos;
vector<uint8_t> signal_in_bitpos;
vector<uint8_t> signal_in_bytepos;
vector<uint8_t> signal_in_bitpos;
for (data::DecodeChannel &ch : channels_)
if (ch.assigned_signal) {
for (data::DecodeChannel &ch : channels_)
if (ch.assigned_signal) {
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);
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);
- 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;
const bool is_optional;
const pv::data::SignalBase *assigned_signal;
const QString name, desc;