X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdata%2Fdecodesignal.cpp;h=6bc691abb5d49a29185a6b404c80bb88f22a548f;hp=253e3a987c6dbeb59e1f6344deff7d76c5aa4692;hb=9f97b3576f527239594ea0accb82a4087147c746;hpb=ecd07c20d34ce940163ac2e7fb26cb7ceac565bb diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 253e3a9..6bc691a 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -42,6 +42,8 @@ DecodeSignal::DecodeSignal(shared_ptr decoder_stack) : { set_name(QString::fromUtf8(decoder_stack_->stack().front()->decoder()->name)); + update_channel_list(); + connect(decoder_stack_.get(), SIGNAL(new_annotations()), this, SLOT(on_new_annotations())); } @@ -70,12 +72,14 @@ void DecodeSignal::stack_decoder(srd_decoder *decoder) assert(decoder); assert(decoder_stack); decoder_stack_->push(make_shared(decoder)); + update_channel_list(); decoder_stack_->begin_decode(); } void DecodeSignal::remove_decoder(int index) { decoder_stack_->remove(index); + update_channel_list(); decoder_stack_->begin_decode(); } @@ -104,6 +108,33 @@ QString DecodeSignal::error_message() const return decoder_stack_->error_message(); } +const list DecodeSignal::get_channels() const +{ + return channels_; +} + +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 +149,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