From: Soeren Apel Date: Tue, 5 May 2020 18:26:05 +0000 (+0200) Subject: Prepare for generated signals X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=999869aa676f7077b7181355eee28e9b025d4cea;p=pulseview.git Prepare for generated signals --- diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index 86ef6856..2b38fe1e 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -52,8 +52,10 @@ SignalBase::SignalBase(shared_ptr channel, ChannelType channel_ min_value_(0), max_value_(0) { - if (channel_) + if (channel_) { internal_name_ = QString::fromStdString(channel_->name()); + index_ = channel_->index(); + } connect(&delayed_conversion_starter_, SIGNAL(timeout()), this, SLOT(on_delayed_conversion_start())); @@ -81,6 +83,11 @@ QString SignalBase::internal_name() const return internal_name_; } +void SignalBase::set_internal_name(QString internal_name) +{ + internal_name_ = internal_name; +} + QString SignalBase::display_name() const { if ((name() != internal_name_) && (!internal_name_.isEmpty())) @@ -119,13 +126,18 @@ SignalBase::ChannelType SignalBase::type() const unsigned int SignalBase::index() const { - return (channel_) ? channel_->index() : 0; + return index_; +} + +void SignalBase::set_index(unsigned int index) +{ + index_ = index; } unsigned int SignalBase::logic_bit_index() const { if (channel_type_ == LogicChannel) - return channel_->index(); + return index_; else return 0; } diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index 065dbc99..7e119652 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -100,6 +100,7 @@ public: public: /** * Returns the underlying SR channel. + * Generated channels don't have a SR channel. */ shared_ptr channel() const; @@ -125,6 +126,13 @@ public: */ unsigned int index() const; + /** + * Sets the index number of this channel, i.e. a unique ID assigned by + * the device driver or the logic bit index (see below). + * Only use immediately after creating the signal and leave it untouched after. + */ + void set_index(unsigned int index); + /** * Returns which bit of a given sample for this signal represents the * signal itself. This is relevant for compound signals like logic, @@ -139,10 +147,16 @@ public: QString name() const; /** - * Gets the internal name of this signal, i.e. how the device calls it. + * Gets the internal name of this signal, i.e. how the device/generator calls it. */ QString internal_name() const; + /** + * Sets the internal name of this signal, i.e. how the device/generator calls it. + * Only use immediately after creating the signal and leave it untouched after. + */ + void set_internal_name(QString internal_name); + /** * Produces a string for this signal that can be used for display, * i.e. it contains one or both of the signal/internal names. @@ -352,6 +366,7 @@ protected: QString internal_name_, name_; QColor color_, bgcolor_; + unsigned int index_; }; } // namespace data diff --git a/pv/session.cpp b/pv/session.cpp index fb8ee5fe..f5338378 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -857,6 +857,28 @@ const vector< shared_ptr > Session::signalbases() const return signalbases_; } +void Session::add_generated_signal(shared_ptr signal) +{ + signalbases_.push_back(signal); + + for (shared_ptr& view : views_) + view->add_signalbase(signal); + + update_signals(); +} + +void Session::remove_generated_signal(shared_ptr signal) +{ + signalbases_.erase(std::remove_if(signalbases_.begin(), signalbases_.end(), + [&](shared_ptr s) { return s == signal; }), + signalbases_.end()); + + for (shared_ptr& view : views_) + view->remove_signalbase(signal); + + update_signals(); +} + bool Session::all_segments_complete(uint32_t segment_id) const { bool all_complete = true; @@ -1106,6 +1128,8 @@ void Session::sample_thread_proc(function error_handler) lock_guard lock(data_mutex_); cur_logic_segment_.reset(); cur_analog_segments_.clear(); + for (shared_ptr sb : signalbases_) + sb->clear_sample_data(); } highest_segment_id_ = -1; frame_began_ = false; @@ -1348,7 +1372,7 @@ void Session::feed_in_frame_end() signal_segment_completed(); } -void Session::feed_in_logic(shared_ptr logic) +void Session::feed_in_logic(shared_ptr logic) { if (logic->data_length() == 0) { qDebug() << "WARNING: Received logic packet with 0 samples."; @@ -1392,7 +1416,7 @@ void Session::feed_in_logic(shared_ptr logic) data_received(); } -void Session::feed_in_analog(shared_ptr analog) +void Session::feed_in_analog(shared_ptr analog) { if (analog->num_samples() == 0) { qDebug() << "WARNING: Received analog packet with 0 samples."; diff --git a/pv/session.hpp b/pv/session.hpp index eefdd12b..7c7d0dde 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -188,6 +188,8 @@ public: bool has_view(shared_ptr view); const vector< shared_ptr > signalbases() const; + void add_generated_signal(shared_ptr signal); + void remove_generated_signal(shared_ptr signal); bool all_segments_complete(uint32_t segment_id) const; diff --git a/pv/views/viewbase.cpp b/pv/views/viewbase.cpp index 6dd83c67..ff3a4fdb 100644 --- a/pv/views/viewbase.cpp +++ b/pv/views/viewbase.cpp @@ -111,6 +111,18 @@ void ViewBase::add_signalbase(const shared_ptr signalbase) this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t))); } +void ViewBase::remove_signalbase(const shared_ptr signalbase) +{ + disconnect(signalbase.get(), SIGNAL(samples_cleared()), + this, SLOT(on_data_updated())); + disconnect(signalbase.get(), SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)), + this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t))); + + signalbases_.erase(std::remove_if(signalbases_.begin(), signalbases_.end(), + [&](shared_ptr s) { return s == signalbase; }), + signalbases_.end()); +} + #ifdef ENABLE_DECODE void ViewBase::clear_decode_signals() { diff --git a/pv/views/viewbase.hpp b/pv/views/viewbase.hpp index 5e9f8fdc..eff96231 100644 --- a/pv/views/viewbase.hpp +++ b/pv/views/viewbase.hpp @@ -93,6 +93,7 @@ public: virtual void clear_signalbases(); virtual void add_signalbase(const shared_ptr signalbase); + virtual void remove_signalbase(const shared_ptr signalbase); #ifdef ENABLE_DECODE virtual void clear_decode_signals();