]> sigrok.org Git - pulseview.git/commitdiff
Implement binary class selector
authorSoeren Apel <redacted>
Thu, 12 Dec 2019 11:23:18 +0000 (12:23 +0100)
committerSoeren Apel <redacted>
Thu, 12 Dec 2019 11:23:18 +0000 (12:23 +0100)
pv/data/decodesignal.cpp
pv/data/decodesignal.hpp
pv/views/decoder_output/QHexView.cpp
pv/views/decoder_output/view.cpp
pv/views/decoder_output/view.hpp

index 6016ff6825a677eb7880642a834cd91dc5dc12c0..10ef7d1a0b7a5538af7aad9c93c526c43bc9584f 100644 (file)
@@ -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<decode::Decoder>& 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)
index 94913b9d8285c6291cf22ae3041f2d75412df778..0a45b5e57755fe2abc9bce77ad48f4a81d4290f9 100644 (file)
@@ -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();
index 53120ce07b75a6cdc296cd6a88e9e87510bdd8fd..586a5cdac373da49b36515b1903349c7500e1d5a 100644 (file)
@@ -69,6 +69,8 @@ void QHexView::setData(QByteArray *data)
        data_ = data;
        cursorPos_ = 0;
        resetSelection(0);
+
+       viewport()->update();
 }
 
 void QHexView::showFromOffset(size_t offset)
index 4480211ad3e29068c0b02e77720ad32fecc00fa7..052d716318c816d0d8392c4de11bdc46c54ccfcf 100644 (file)
@@ -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<data::DecodeSignal> signal)
        // Add all decoders provided by this signal
        auto stack = signal->decoder_stack();
        if (stack.size() > 1) {
-               for (const shared_ptr<Decoder>& 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<Decoder>& 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<Decoder>& 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<void*>();
 
        // Find the signal that contains the selected decoder
        signal_ = nullptr;
 
-       for (const shared_ptr<data::SignalBase>& sb : signalbases_) {
-               shared_ptr<DecodeSignal> ds = dynamic_pointer_cast<DecodeSignal>(sb);
+       for (const shared_ptr<DecodeSignal>& ds : decode_signals_)
+               for (const shared_ptr<Decoder>& dec : ds->decoder_stack())
+                       if (decoder_ == dec.get())
+                               signal_ = ds.get();
 
-               if (ds)
-                       for (const shared_ptr<Decoder>& 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<uint8_t>();
 
        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*>(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;
 
index 4f4bc4505fe892121acdee849463a82bea167918..47abfe3dcd367e8dd4af5b707dd452a8c2bff5e0 100644 (file)
@@ -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);