From: Soeren Apel Date: Sun, 8 Dec 2019 22:29:07 +0000 (+0100) Subject: Move DecodeChannel from data:: to data::decoder:: X-Git-Url: http://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=a82325d16a1412f3474423fa3fa56bb85af1fb00 Move DecodeChannel from data:: to data::decoder:: --- diff --git a/pv/data/decode/decoder.cpp b/pv/data/decode/decoder.cpp index f86c5d08..45a33e4a 100644 --- a/pv/data/decode/decoder.cpp +++ b/pv/data/decode/decoder.cpp @@ -29,7 +29,6 @@ #include #include -using pv::data::DecodeChannel; using std::map; using std::string; diff --git a/pv/data/decode/decoder.hpp b/pv/data/decode/decoder.hpp index 55742c60..b7ef6080 100644 --- a/pv/data/decode/decoder.hpp +++ b/pv/data/decode/decoder.hpp @@ -27,6 +27,8 @@ #include +#include + using std::map; using std::string; using std::vector; @@ -40,12 +42,26 @@ namespace pv { namespace data { -struct DecodeChannel; class Logic; class SignalBase; namespace decode { +class Decoder; + +struct DecodeChannel +{ + uint16_t id; ///< Global numerical ID for the decode channels in the stack + uint16_t bit_id; ///< Tells which bit within a sample represents this channel + const bool is_optional; + const pv::data::SignalBase *assigned_signal; + const QString name, desc; + int initial_pin_state; + const shared_ptr decoder_; + const srd_channel *pdch_; +}; + + class Decoder { public: @@ -58,8 +74,8 @@ public: bool shown() const; void show(bool show = true); - const vector& channels() const; - void set_channels(vector channels); + const vector& channels() const; + void set_channels(vector channels); const map& options() const; @@ -72,12 +88,14 @@ public: srd_decoder_inst* create_decoder_inst(srd_session *session); void invalidate_decoder_inst(); + + private: const srd_decoder *const decoder_; bool shown_; - vector channels_; + vector channels_; map options_; srd_decoder_inst *decoder_inst_; }; diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index c497b862..f7fe004c 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -28,7 +28,6 @@ #include "decodesignal.hpp" #include "signaldata.hpp" -#include #include #include #include @@ -43,6 +42,7 @@ using std::out_of_range; using std::shared_ptr; using std::unique_lock; using pv::data::decode::Annotation; +using pv::data::decode::DecodeChannel; using pv::data::decode::Decoder; using pv::data::decode::Row; @@ -206,7 +206,7 @@ void DecodeSignal::begin_decode() // Make sure that all assigned channels still provide logic data // (can happen when a converted signal was assigned but the // conversion removed in the meanwhile) - for (data::DecodeChannel& ch : channels_) + for (decode::DecodeChannel& ch : channels_) if (ch.assigned_signal && !(ch.assigned_signal->logic_data() != nullptr)) ch.assigned_signal = nullptr; @@ -291,7 +291,7 @@ QString DecodeSignal::error_message() const return error_message_; } -const vector DecodeSignal::get_channels() const +const vector DecodeSignal::get_channels() const { return channels_; } @@ -301,7 +301,7 @@ void DecodeSignal::auto_assign_signals(const shared_ptr dec) bool new_assignment = false; // Try to auto-select channels that don't have signals assigned yet - for (data::DecodeChannel& ch : channels_) { + for (decode::DecodeChannel& ch : channels_) { // If a decoder is given, auto-assign only its channels if (dec && (ch.decoder_ != dec)) continue; @@ -350,7 +350,7 @@ void DecodeSignal::auto_assign_signals(const shared_ptr dec) void DecodeSignal::assign_signal(const uint16_t channel_id, const SignalBase *signal) { - for (data::DecodeChannel& ch : channels_) + for (decode::DecodeChannel& ch : channels_) if (ch.id == channel_id) { ch.assigned_signal = signal; logic_mux_data_invalid_ = true; @@ -366,12 +366,12 @@ int DecodeSignal::get_assigned_signal_count() const { // Count all channels that have a signal assigned to them return count_if(channels_.begin(), channels_.end(), - [](data::DecodeChannel ch) { return ch.assigned_signal; }); + [](decode::DecodeChannel ch) { return ch.assigned_signal; }); } void DecodeSignal::set_initial_pin_state(const uint16_t channel_id, const int init_state) { - for (data::DecodeChannel& ch : channels_) + for (decode::DecodeChannel& ch : channels_) if (ch.id == channel_id) ch.initial_pin_state = init_state; @@ -411,7 +411,7 @@ int64_t DecodeSignal::get_working_sample_count(uint32_t segment_id) const int64_t count = std::numeric_limits::max(); bool no_signals_assigned = true; - for (const data::DecodeChannel& ch : channels_) + for (const decode::DecodeChannel& ch : channels_) if (ch.assigned_signal) { no_signals_assigned = false; @@ -625,7 +625,7 @@ void DecodeSignal::save_settings(QSettings &settings) const for (unsigned int channel_id = 0; channel_id < channels_.size(); channel_id++) { auto channel = find_if(channels_.begin(), channels_.end(), - [&](data::DecodeChannel ch) { return ch.id == channel_id; }); + [&](decode::DecodeChannel ch) { return ch.id == channel_id; }); if (channel == channels_.end()) { qDebug() << "ERROR: Gap in channel index:" << channel_id; @@ -699,7 +699,7 @@ void DecodeSignal::restore_settings(QSettings &settings) for (unsigned int channel_id = 0; channel_id < channels; channel_id++) { auto channel = find_if(channels_.begin(), channels_.end(), - [&](data::DecodeChannel ch) { return ch.id == channel_id; }); + [&](decode::DecodeChannel ch) { return ch.id == channel_id; }); if (channel == channels_.end()) { qDebug() << "ERROR: Non-existant channel index:" << channel_id; @@ -739,7 +739,7 @@ uint32_t DecodeSignal::get_input_segment_count() const uint64_t count = std::numeric_limits::max(); bool no_signals_assigned = true; - for (const data::DecodeChannel& ch : channels_) + for (const decode::DecodeChannel& ch : channels_) if (ch.assigned_signal) { no_signals_assigned = false; @@ -759,7 +759,7 @@ uint32_t DecodeSignal::get_input_samplerate(uint32_t segment_id) const { double samplerate = 0; - for (const data::DecodeChannel& ch : channels_) + for (const decode::DecodeChannel& ch : channels_) if (ch.assigned_signal) { const shared_ptr logic_data = ch.assigned_signal->logic_data(); if (!logic_data || logic_data->logic_segments().empty()) @@ -779,7 +779,7 @@ uint32_t DecodeSignal::get_input_samplerate(uint32_t segment_id) const void DecodeSignal::update_channel_list() { - vector prev_channels = channels_; + vector prev_channels = channels_; channels_.clear(); uint16_t id = 0; @@ -795,7 +795,7 @@ void DecodeSignal::update_channel_list() bool ch_added = false; // Copy but update ID if this channel was in the list before - for (data::DecodeChannel& ch : prev_channels) + for (decode::DecodeChannel& ch : prev_channels) if (ch.pdch_ == pdch) { ch.id = id++; channels_.push_back(ch); @@ -805,7 +805,7 @@ void DecodeSignal::update_channel_list() if (!ch_added) { // Create new entry without a mapped signal - data::DecodeChannel ch = {id++, 0, false, nullptr, + decode::DecodeChannel ch = {id++, 0, false, nullptr, QString::fromUtf8(pdch->name), QString::fromUtf8(pdch->desc), SRD_INITIAL_PIN_SAME_AS_SAMPLE0, decoder, pdch}; channels_.push_back(ch); @@ -818,7 +818,7 @@ void DecodeSignal::update_channel_list() bool ch_added = false; // Copy but update ID if this channel was in the list before - for (data::DecodeChannel& ch : prev_channels) + for (decode::DecodeChannel& ch : prev_channels) if (ch.pdch_ == pdch) { ch.id = id++; channels_.push_back(ch); @@ -828,7 +828,7 @@ void DecodeSignal::update_channel_list() if (!ch_added) { // Create new entry without a mapped signal - data::DecodeChannel ch = {id++, 0, true, nullptr, + decode::DecodeChannel ch = {id++, 0, true, nullptr, QString::fromUtf8(pdch->name), QString::fromUtf8(pdch->desc), SRD_INITIAL_PIN_SAME_AS_SAMPLE0, decoder, pdch}; channels_.push_back(ch); @@ -843,8 +843,8 @@ void DecodeSignal::update_channel_list() } else { // Same number but assignment may still differ, so compare all channels for (size_t i = 0; i < channels_.size(); i++) { - const data::DecodeChannel& p_ch = prev_channels[i]; - const data::DecodeChannel& ch = channels_[i]; + const decode::DecodeChannel& p_ch = prev_channels[i]; + const decode::DecodeChannel& ch = channels_[i]; if ((p_ch.pdch_ != ch.pdch_) || (p_ch.assigned_signal != ch.assigned_signal)) { @@ -862,9 +862,9 @@ void DecodeSignal::commit_decoder_channels() { // Submit channel list to every decoder, containing only the relevant channels for (shared_ptr dec : stack_) { - vector channel_list; + vector channel_list; - for (data::DecodeChannel& ch : channels_) + for (decode::DecodeChannel& ch : channels_) if (ch.decoder_ == dec) channel_list.push_back(&ch); @@ -873,7 +873,7 @@ void DecodeSignal::commit_decoder_channels() // Channel bit IDs must be in sync with the channel's apperance in channels_ int id = 0; - for (data::DecodeChannel& ch : channels_) + for (decode::DecodeChannel& ch : channels_) if (ch.assigned_signal) ch.bit_id = id++; } @@ -890,7 +890,7 @@ void DecodeSignal::mux_logic_samples(uint32_t segment_id, const int64_t start, c vector signal_in_bytepos; vector signal_in_bitpos; - for (data::DecodeChannel& ch : channels_) + for (decode::DecodeChannel& ch : channels_) if (ch.assigned_signal) { const shared_ptr logic_data = ch.assigned_signal->logic_data(); @@ -1264,7 +1264,7 @@ void DecodeSignal::connect_input_notifiers() disconnect(this, SLOT(on_data_received())); // Connect the currently used signals to our slot - for (data::DecodeChannel& ch : channels_) { + for (decode::DecodeChannel& ch : channels_) { if (!ch.assigned_signal) continue; diff --git a/pv/data/decodesignal.hpp b/pv/data/decodesignal.hpp index 6162a20e..a01ff3ee 100644 --- a/pv/data/decodesignal.hpp +++ b/pv/data/decodesignal.hpp @@ -30,6 +30,7 @@ #include +#include #include #include #include @@ -59,18 +60,6 @@ class LogicSegment; class SignalBase; class SignalData; -struct DecodeChannel -{ - uint16_t id; ///< Global numerical ID for the decode channels in the stack - uint16_t bit_id; ///< Tells which bit within a sample represents this channel - const bool is_optional; - const pv::data::SignalBase *assigned_signal; - const QString name, desc; - int initial_pin_state; - const shared_ptr decoder_; - const srd_channel *pdch_; -}; - struct DecodeBinaryData { vector data; @@ -113,7 +102,7 @@ public: bool is_paused() const; QString error_message() const; - const vector get_channels() const; + const vector get_channels() const; void auto_assign_signals(const shared_ptr dec); void assign_signal(const uint16_t channel_id, const SignalBase *signal); int get_assigned_signal_count() const; @@ -218,7 +207,7 @@ private Q_SLOTS: private: pv::Session &session_; - vector channels_; + vector channels_; struct srd_session *srd_session_; diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index c7796efc..3d8a9e45 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -70,7 +70,7 @@ using std::vector; using pv::data::decode::Annotation; using pv::data::decode::Row; -using pv::data::DecodeChannel; +using pv::data::decode::DecodeChannel; using pv::data::DecodeSignal; namespace pv { diff --git a/pv/views/trace/decodetrace.hpp b/pv/views/trace/decodetrace.hpp index b74524c5..3a61c31d 100644 --- a/pv/views/trace/decodetrace.hpp +++ b/pv/views/trace/decodetrace.hpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -178,9 +179,9 @@ private: QWidget *parent, QFormLayout *form); QComboBox* create_channel_selector(QWidget *parent, - const data::DecodeChannel *ch); + const data::decode::DecodeChannel *ch); QComboBox* create_channel_selector_init_state(QWidget *parent, - const data::DecodeChannel *ch); + const data::decode::DecodeChannel *ch); void export_annotations(vector *annotations) const;