From: Soeren Apel Date: Thu, 12 Dec 2019 11:23:18 +0000 (+0100) Subject: Implement binary class selector X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b2b18d3aabf497666c3cff76d0c6663623539e36;p=pulseview.git Implement binary class selector --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 6016ff68..10ef7d1a 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -1429,13 +1429,15 @@ void DecodeSignal::binary_callback(srd_proto_data *pdata, void *decode_signal) chunk->data.resize(pdb->size); memcpy(chunk->data.data(), pdb->data, pdb->size); - // Note: using pdb->bin_class is only unique for each decoder in the stack, - // so if two stacked decoders both emit binary data with the same bin_class, - // we may be triggering unnecessary updates. Should be ok for now as that - // case isn't possible yet. When it is, we might add the decoder's name - // as an additional parameter to the signal, although string comparisons - // are not really fast. - ds->new_binary_data(ds->current_segment_id_, pdb->bin_class); + // Find decoder class instance + Decoder* dec = nullptr; + for (const shared_ptr& d : ds->decoder_stack()) + if (d->decoder() == decc) { + dec = d.get(); + break; + } + + ds->new_binary_data(ds->current_segment_id_, (void*)dec, pdb->bin_class); } void DecodeSignal::on_capture_state_changed(int state) diff --git a/pv/data/decodesignal.hpp b/pv/data/decodesignal.hpp index 94913b9d..0a45b5e5 100644 --- a/pv/data/decodesignal.hpp +++ b/pv/data/decodesignal.hpp @@ -206,7 +206,7 @@ Q_SIGNALS: void decoder_stacked(void* decoder); ///< decoder is of type decode::Decoder* void decoder_removed(void* decoder); ///< decoder is of type decode::Decoder* void new_annotations(); // TODO Supply segment for which they belong to - void new_binary_data(unsigned int segment_id, unsigned int bin_class_id); + void new_binary_data(unsigned int segment_id, void* decoder, unsigned int bin_class_id); void decode_reset(); void decode_finished(); void channels_updated(); diff --git a/pv/views/decoder_output/QHexView.cpp b/pv/views/decoder_output/QHexView.cpp index 53120ce0..586a5cda 100644 --- a/pv/views/decoder_output/QHexView.cpp +++ b/pv/views/decoder_output/QHexView.cpp @@ -69,6 +69,8 @@ void QHexView::setData(QByteArray *data) data_ = data; cursorPos_ = 0; resetSelection(0); + + viewport()->update(); } void QHexView::showFromOffset(size_t offset) diff --git a/pv/views/decoder_output/view.cpp b/pv/views/decoder_output/view.cpp index 4480211a..052d7163 100644 --- a/pv/views/decoder_output/view.cpp +++ b/pv/views/decoder_output/view.cpp @@ -87,6 +87,8 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) : connect(decoder_selector_, SIGNAL(currentIndexChanged(int)), this, SLOT(on_selected_decoder_changed(int))); + connect(class_selector_, SIGNAL(currentIndexChanged(int)), + this, SLOT(on_selected_class_changed(int))); hex_view_->setData(merged_data_); @@ -118,6 +120,7 @@ void View::clear_decode_signals() ViewBase::clear_decode_signals(); decoder_selector_->clear(); + class_selector_->clear(); format_selector_->setCurrentIndex(0); signal_ = nullptr; } @@ -136,14 +139,17 @@ void View::add_decode_signal(shared_ptr signal) // Add all decoders provided by this signal auto stack = signal->decoder_stack(); if (stack.size() > 1) { - for (const shared_ptr& dec : stack) { - QString title = QString("%1 (%2)").arg(signal->name(), dec->name()); - decoder_selector_->addItem(title, QVariant::fromValue((void*)dec.get())); - } + for (const shared_ptr& dec : stack) + // Only add the decoder if it has binary output + if (dec->get_binary_class_count() > 0) { + QString title = QString("%1 (%2)").arg(signal->name(), dec->name()); + decoder_selector_->addItem(title, QVariant::fromValue((void*)dec.get())); + } } else if (!stack.empty()) { shared_ptr& dec = stack.at(0); - decoder_selector_->addItem(signal->name(), QVariant::fromValue((void*)dec.get())); + if (dec->get_binary_class_count() > 0) + decoder_selector_->addItem(signal->name(), QVariant::fromValue((void*)dec.get())); } } @@ -197,30 +203,45 @@ void View::update_data() merged_data_->resize(data.size()); memcpy(merged_data_->data(), data.data(), data.size()); + + hex_view_->setData(merged_data_); } void View::on_selected_decoder_changed(int index) { if (signal_) - disconnect(signal_, SIGNAL(new_binary_data(unsigned int, unsigned int))); + disconnect(signal_, SIGNAL(new_binary_data(unsigned int, void*, unsigned int))); decoder_ = (Decoder*)decoder_selector_->itemData(index).value(); // Find the signal that contains the selected decoder signal_ = nullptr; - for (const shared_ptr& sb : signalbases_) { - shared_ptr ds = dynamic_pointer_cast(sb); + for (const shared_ptr& ds : decode_signals_) + for (const shared_ptr& dec : ds->decoder_stack()) + if (decoder_ == dec.get()) + signal_ = ds.get(); - if (ds) - for (const shared_ptr& dec : ds->decoder_stack()) - if (decoder_ == dec.get()) - signal_ = ds.get(); + class_selector_->clear(); + + if (signal_) { + // Populate binary class selector + uint8_t bin_classes = decoder_->get_binary_class_count(); + for (uint8_t i = 0; i < bin_classes; i++) { + const data::decode::DecodeBinaryClassInfo* class_info = decoder_->get_binary_class(i); + class_selector_->addItem(class_info->name, QVariant::fromValue(i)); + } + + connect(signal_, SIGNAL(new_binary_data(unsigned int, void*, unsigned int)), + this, SLOT(on_new_binary_data(unsigned int, void*, unsigned int))); } - if (signal_) - connect(signal_, SIGNAL(new_binary_data(unsigned int, unsigned int)), - this, SLOT(on_new_binary_data(unsigned int, unsigned int))); + update_data(); +} + +void View::on_selected_class_changed(int index) +{ + bin_class_id_ = class_selector_->itemData(index).value(); update_data(); } @@ -255,9 +276,9 @@ void View::on_signal_name_changed(const QString &name) } } -void View::on_new_binary_data(unsigned int segment_id, unsigned int bin_class_id) +void View::on_new_binary_data(unsigned int segment_id, void* decoder, unsigned int bin_class_id) { - if ((segment_id == current_segment_) && (bin_class_id == bin_class_id_)) + if ((segment_id == current_segment_) && (decoder == decoder_) && (bin_class_id == bin_class_id_)) update_data(); } @@ -267,6 +288,10 @@ void View::on_decoder_stacked(void* decoder) Decoder* d = static_cast(decoder); + // Only add the decoder if it has binary output + if (d->get_binary_class_count() == 0) + return; + // Find the signal that contains the selected decoder DecodeSignal* signal = nullptr; diff --git a/pv/views/decoder_output/view.hpp b/pv/views/decoder_output/view.hpp index 4f4bc450..47abfe3d 100644 --- a/pv/views/decoder_output/view.hpp +++ b/pv/views/decoder_output/view.hpp @@ -67,8 +67,9 @@ private: private Q_SLOTS: void on_selected_decoder_changed(int index); + void on_selected_class_changed(int index); void on_signal_name_changed(const QString &name); - void on_new_binary_data(unsigned int segment_id, unsigned int bin_class_id); + void on_new_binary_data(unsigned int segment_id, void* decoder, unsigned int bin_class_id); void on_decoder_stacked(void* decoder); void on_decoder_removed(void* decoder);