X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fdata%2Fdecodesignal.cpp;h=5b2bb31d75e1217e7567d634f289eaab0985bd03;hb=132a5c6d4b3c220d1cb6d942bf9d7e8b180ab1c3;hp=253e3a987c6dbeb59e1f6344deff7d76c5aa4692;hpb=ecd07c20d34ce940163ac2e7fb26cb7ceac565bb;p=pulseview.git diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 253e3a9..5b2bb31 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -36,12 +36,17 @@ using pv::data::decode::Row; namespace pv { namespace data { -DecodeSignal::DecodeSignal(shared_ptr decoder_stack) : +DecodeSignal::DecodeSignal(shared_ptr decoder_stack, + const unordered_set< shared_ptr > &all_signals) : SignalBase(nullptr, SignalBase::DecodeChannel), - decoder_stack_(decoder_stack) + decoder_stack_(decoder_stack), + all_signals_(all_signals) { set_name(QString::fromUtf8(decoder_stack_->stack().front()->decoder()->name)); + update_channel_list(); + auto_assign_signals(); + connect(decoder_stack_.get(), SIGNAL(new_annotations()), this, SLOT(on_new_annotations())); } @@ -70,12 +75,18 @@ void DecodeSignal::stack_decoder(srd_decoder *decoder) assert(decoder); assert(decoder_stack); decoder_stack_->push(make_shared(decoder)); + + // Include the newly created decode channels in the channel list + update_channel_list(); + + auto_assign_signals(); decoder_stack_->begin_decode(); } void DecodeSignal::remove_decoder(int index) { decoder_stack_->remove(index); + update_channel_list(); decoder_stack_->begin_decode(); } @@ -104,6 +115,46 @@ QString DecodeSignal::error_message() const return decoder_stack_->error_message(); } +const list DecodeSignal::get_channels() const +{ + return channels_; +} + +void DecodeSignal::auto_assign_signals() +{ + // Try to auto-select channels that don't have signals assigned yet + for (data::DecodeChannel &ch : channels_) { + if (ch.assigned_signal) + continue; + + for (shared_ptr s : all_signals_) + if (s->logic_data() && (ch.name.toLower().contains(s->name().toLower()))) + ch.assigned_signal = s.get(); + } +} + +void DecodeSignal::assign_signal(const uint16_t channel_id, const SignalBase *signal) +{ + for (data::DecodeChannel &ch : channels_) + if (ch.id == channel_id) + ch.assigned_signal = signal; + + channels_updated(); + + decoder_stack_->begin_decode(); +} + +void DecodeSignal::set_initial_pin_state(const uint16_t channel_id, const int init_state) +{ + for (data::DecodeChannel &ch : channels_) + if (ch.id == channel_id) + ch.initial_pin_state = init_state; + + channels_updated(); + + decoder_stack_->begin_decode(); +} + vector DecodeSignal::visible_rows() const { return decoder_stack_->get_visible_rows(); @@ -118,6 +169,68 @@ void DecodeSignal::get_annotation_subset( start_sample, end_sample); } +void DecodeSignal::update_channel_list() +{ + list prev_channels = channels_; + channels_.clear(); + + uint16_t id = 0; + + // Copy existing entries, create new as needed + for (shared_ptr decoder : decoder_stack_->stack()) { + const srd_decoder* srd_d = decoder->decoder(); + const GSList *l; + + // Mandatory channels + for (l = srd_d->channels; l; l = l->next) { + const struct srd_channel *const pdch = (struct srd_channel *)l->data; + bool ch_added = false; + + // Copy but update ID if this channel was in the list before + for (data::DecodeChannel ch : prev_channels) + if (ch.pdch_ == pdch) { + ch.id = id++; + channels_.push_back(ch); + ch_added = true; + break; + } + + if (!ch_added) { + // Create new entry without a mapped signal + data::DecodeChannel ch = {id++, false, nullptr, + QString::fromUtf8(pdch->name), QString::fromUtf8(pdch->desc), + SRD_INITIAL_PIN_SAME_AS_SAMPLE0, decoder, pdch}; + channels_.push_back(ch); + } + } + + // Optional channels + for (l = srd_d->opt_channels; l; l = l->next) { + const struct srd_channel *const pdch = (struct srd_channel *)l->data; + bool ch_added = false; + + // Copy but update ID if this channel was in the list before + for (data::DecodeChannel ch : prev_channels) + if (ch.pdch_ == pdch) { + ch.id = id++; + channels_.push_back(ch); + ch_added = true; + break; + } + + if (!ch_added) { + // Create new entry without a mapped signal + data::DecodeChannel ch = {id++, true, nullptr, + QString::fromUtf8(pdch->name), QString::fromUtf8(pdch->desc), + SRD_INITIAL_PIN_SAME_AS_SAMPLE0, decoder, pdch}; + channels_.push_back(ch); + } + } + } + + channels_updated(); +} + void DecodeSignal::on_new_annotations() { // Forward the signal to the frontend