diff --git a/DSView/pv/data/decode/decoder.cpp b/DSView/pv/data/decode/decoder.cpp index c51d9cf3..dfabf09f 100644 --- a/DSView/pv/data/decode/decoder.cpp +++ b/DSView/pv/data/decode/decoder.cpp @@ -23,6 +23,7 @@ #include #include "decoder.h" #include +#include "../../log.h" namespace pv { @@ -85,13 +86,67 @@ bool Decoder::commit() _decode_end = _decode_end_back; _setted = false; return true; - } else { + } + else { return false; } } +int Decoder::first_probe_index() +{ + auto it = _probes.begin(); + if (it != _probes.end()){ + return (*it).second; + } + + return -1; +} + +bool Decoder::is_binded_probe(const srd_channel *const pdch) +{ + assert(pdch); + + auto it = _probes.find(pdch); + return it != _probes.end(); +} + +int Decoder::binded_probe_index(const srd_channel *const pdch) +{ + assert(pdch); + + auto it = _probes.find(pdch); + if (it != _probes.end()){ + return (*it).second; + } + + return -1; +} + +std::vector Decoder::binded_probe_list() +{ + std::vector lst; + + for (auto it = _probes.begin(); it != _probes.end(); ++it){ + lst.push_back((*it).first); + } + + return lst; +} + bool Decoder::have_required_probes() { + dsv_info("decoder:%p", this); + + for (GSList *l = _decoder->channels; l; l = l->next) { + const srd_channel *const pdch = (const srd_channel*)l->data; + dsv_info("base decoder:%p", (void*)pdch); + } + + for (auto it = _probes.begin(); it != _probes.end(); ++it){ + const srd_channel *const pdch = (const srd_channel*)(*it).first; + dsv_info("got decoder:%p", (void*)pdch); + } + for (GSList *l = _decoder->channels; l; l = l->next) { const srd_channel *const pdch = (const srd_channel*)l->data; assert(pdch); diff --git a/DSView/pv/data/decode/decoder.h b/DSView/pv/data/decode/decoder.h index 268ff134..9f8e0841 100644 --- a/DSView/pv/data/decode/decoder.h +++ b/DSView/pv/data/decode/decoder.h @@ -28,7 +28,7 @@ #include #include #include - +#include #include struct srd_decoder; @@ -58,13 +58,21 @@ public: } inline void show(bool show = true){ - _shown = show; + _shown = show; } - inline std::map& channels(){ - return _probes; + inline bool have_probes(){ + return _probes.size() > 0; } + int first_probe_index(); + + bool is_binded_probe(const srd_channel *const pdch); + + int binded_probe_index(const srd_channel *const pdch); + + std::vector binded_probe_list(); + void set_probes(std::map probes); inline std::map& options(){ diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index 3449ddb8..a2bf1658 100644 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -449,9 +449,9 @@ void DecoderStack::do_decode_work() // This works because we are currently assuming all // LogicSignals have the same data/snapshot for (auto dec : _stack) { - if (!dec->channels().empty()) { + if (dec->have_probes()) { for(auto s : _session->get_signals()) { - if(s->get_index() == (*dec->channels().begin()).second && s->signal_type() == SR_CHANNEL_LOGIC) + if(s->get_index() == dec->first_probe_index() && s->signal_type() == SR_CHANNEL_LOGIC) { _snapshot = ((pv::view::LogicSignal*)s)->data(); if (_snapshot != NULL) diff --git a/DSView/pv/dialogs/decoderoptionsdlg.cpp b/DSView/pv/dialogs/decoderoptionsdlg.cpp index 355a1b19..bf0b8e93 100644 --- a/DSView/pv/dialogs/decoderoptionsdlg.cpp +++ b/DSView/pv/dialogs/decoderoptionsdlg.cpp @@ -292,29 +292,31 @@ DsComboBox* DecoderOptionsDlg::create_probe_selector( const auto &sigs = AppControl::Instance()->GetSession()->get_signals(); - data::decode::Decoder *_dec = const_cast(dec); - auto probe_iter = _dec->channels().find(pdch); + data::decode::Decoder *decoder = const_cast(dec); + DsComboBox *selector = new DsComboBox(parent); selector->addItem("-", QVariant::fromValue(-1)); - - if (probe_iter == _dec->channels().end()) - selector->setCurrentIndex(0); - + int dex = 0; + const int binded_index = decoder->binded_probe_index(pdch); for(auto s : sigs) { + dex++; + if (s->signal_type() == SR_CHANNEL_LOGIC && s->enabled()){ selector->addItem(s->get_name(),QVariant::fromValue(s->get_index())); - if (probe_iter != _dec->channels().end()) { - if ((*probe_iter).second == s->get_index()) - selector->setCurrentIndex(dex + 1); + if (binded_index == s->get_index()){ + selector->setCurrentIndex(dex); } - } - ++dex; + } } + if (binded_index == -1){ + selector->setCurrentIndex(0); + } + return selector; } @@ -433,8 +435,6 @@ void DecoderOptionsDlg::create_decoder_form( const ProbeSelector s = {combo, dec, pdch}; _probe_selectors.push_back(s); - - connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_probe_selected(int))); } // Add the optional channels @@ -463,8 +463,6 @@ void DecoderOptionsDlg::create_decoder_form( const ProbeSelector s = {combo, dec, pdch}; _probe_selectors.push_back(s); - - connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_probe_selected(int))); } // Add the options @@ -491,11 +489,6 @@ void DecoderOptionsDlg::commit_probes() } } -void DecoderOptionsDlg::on_probe_selected(int) -{ - commit_probes(); -} - void DecoderOptionsDlg::commit_decoder_probes(data::decode::Decoder *dec) { assert(dec); @@ -549,5 +542,10 @@ void DecoderOptionsDlg::on_trans_pramas() this->reject(); } +void DecoderOptionsDlg::apply_setting() +{ + commit_probes(); +} + }//dialogs }//pv diff --git a/DSView/pv/dialogs/decoderoptionsdlg.h b/DSView/pv/dialogs/decoderoptionsdlg.h index f1632e57..18d47cce 100644 --- a/DSView/pv/dialogs/decoderoptionsdlg.h +++ b/DSView/pv/dialogs/decoderoptionsdlg.h @@ -91,6 +91,8 @@ public: return _is_reload_form; } + void apply_setting(); + private: void load_options_view(); @@ -107,7 +109,6 @@ private: void update_decode_range(); private slots: - void on_probe_selected(int); void on_region_set(int index); void on_accept(); void on_trans_pramas(); diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index 90a5b201..e1bc5c0f 100644 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -1224,9 +1224,11 @@ bool StoreSession::gen_decoders_json(QJsonArray &array) const bool have_probes = (d->channels || d->opt_channels) != 0; if (have_probes) { - for(auto it = dec->channels().begin();it != dec->channels().end(); it++) { + auto binded_probes = dec->binded_probe_list(); + for(auto probe : binded_probes) { QJsonObject ch_obj; - ch_obj[(*it).first->id] = QJsonValue::fromVariant((*it).second); + int binded_index = dec->binded_probe_index(probe); + ch_obj[probe->id] = QJsonValue::fromVariant(binded_index); ch_array.push_back(ch_obj); } } diff --git a/DSView/pv/view/decodetrace.cpp b/DSView/pv/view/decodetrace.cpp index ab815478..63515b01 100644 --- a/DSView/pv/view/decodetrace.cpp +++ b/DSView/pv/view/decodetrace.cpp @@ -373,18 +373,25 @@ void DecodeTrace::draw_annotation(const pv::data::decode::Annotation &a, draw_range(a, p, fill, outline, text_color, h, start, end, y, fore, back); - if ((a.type()/100 == 2) && (end - start > 20)) { - for(auto dec : _decoder_stack->stack()) { - for (auto& iter : dec->channels()) { - int type = dec->get_channel_type(iter.first); + if ((a.type()/100 == 2) && (end - start > 20)) + { + for(auto dec : _decoder_stack->stack()) + { + auto probes = dec->binded_probe_list(); + + for (auto probe : probes) { + int type = dec->get_channel_type(probe); + if ((type == SRD_CHANNEL_COMMON) || - ((type%100 != a.type()%100) && (type%100 != 0))) - continue; + ((type%100 != a.type()%100) && (type%100 != 0))){ + continue; + } const double mark_end = a.end_sample() / samples_per_pixel - pixels_offset; for(auto s : _session->get_signals()) { - if((s->get_index() == iter.second) && s->signal_type() == SR_CHANNEL_LOGIC) { + int binded_index = dec->binded_probe_index(probe); + if((s->get_index() == binded_index) && s->signal_type() == SR_CHANNEL_LOGIC) { view::LogicSignal *logicSig = (view::LogicSignal*)s; logicSig->paint_mark(p, start, mark_end, type/100); break; @@ -677,6 +684,8 @@ bool DecodeTrace::create_popup(bool isnew) if (QDialog::Accepted == dlg_ret) { + dlg.apply_setting(); + for(auto dec : _decoder_stack->stack()) { if (dec->commit() || _decoder_stack->options_changed()) {