]> sigrok.org Git - pulseview.git/commitdiff
Prepare for generated signals
authorSoeren Apel <redacted>
Tue, 5 May 2020 18:26:05 +0000 (20:26 +0200)
committerSoeren Apel <redacted>
Mon, 11 May 2020 19:24:22 +0000 (21:24 +0200)
pv/data/signalbase.cpp
pv/data/signalbase.hpp
pv/session.cpp
pv/session.hpp
pv/views/viewbase.cpp
pv/views/viewbase.hpp

index 86ef68566ce118b0b09d0ccdfc94d4f06b35bf87..2b38fe1ef1d3b7ec03af221453527d70cfd4f641 100644 (file)
@@ -52,8 +52,10 @@ SignalBase::SignalBase(shared_ptr<sigrok::Channel> 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;
 }
index 065dbc99f68801fb36e99df52f19638a59b07720..7e1196521d0d3ae303a8b6258e6f62dce71cb798 100644 (file)
@@ -100,6 +100,7 @@ public:
 public:
        /**
         * Returns the underlying SR channel.
+        * Generated channels don't have a SR channel.
         */
        shared_ptr<sigrok::Channel> 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
index fb8ee5fe9a3456dc2533078cdcbdad59b040e36a..f53383789f3ff669adb21af9bd7b0bb997c43cd6 100644 (file)
@@ -857,6 +857,28 @@ const vector< shared_ptr<data::SignalBase> > Session::signalbases() const
        return signalbases_;
 }
 
+void Session::add_generated_signal(shared_ptr<data::SignalBase> signal)
+{
+       signalbases_.push_back(signal);
+
+       for (shared_ptr<views::ViewBase>& view : views_)
+               view->add_signalbase(signal);
+
+       update_signals();
+}
+
+void Session::remove_generated_signal(shared_ptr<data::SignalBase> signal)
+{
+       signalbases_.erase(std::remove_if(signalbases_.begin(), signalbases_.end(),
+               [&](shared_ptr<data::SignalBase> s) { return s == signal; }),
+               signalbases_.end());
+
+       for (shared_ptr<views::ViewBase>& 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<void (const QString)> error_handler)
                lock_guard<recursive_mutex> lock(data_mutex_);
                cur_logic_segment_.reset();
                cur_analog_segments_.clear();
+               for (shared_ptr<data::SignalBase> 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> logic)
+void Session::feed_in_logic(shared_ptr<sigrok::Logic> 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> logic)
        data_received();
 }
 
-void Session::feed_in_analog(shared_ptr<Analog> analog)
+void Session::feed_in_analog(shared_ptr<sigrok::Analog> analog)
 {
        if (analog->num_samples() == 0) {
                qDebug() << "WARNING: Received analog packet with 0 samples.";
index eefdd12bd20bf67262b17f5e2948c47d77d63a35..7c7d0dde3ab13bfb8a961c55b09fa11e79f0ebb8 100644 (file)
@@ -188,6 +188,8 @@ public:
        bool has_view(shared_ptr<views::ViewBase> view);
 
        const vector< shared_ptr<data::SignalBase> > signalbases() const;
+       void add_generated_signal(shared_ptr<data::SignalBase> signal);
+       void remove_generated_signal(shared_ptr<data::SignalBase> signal);
 
        bool all_segments_complete(uint32_t segment_id) const;
 
index 6dd83c675c9b932e5ceb7d0a0e3fafac0f5ec9ac..ff3a4fdbbb3e30be432667338dba559f0806e0bd 100644 (file)
@@ -111,6 +111,18 @@ void ViewBase::add_signalbase(const shared_ptr<data::SignalBase> signalbase)
                this, SLOT(on_samples_added(uint64_t, uint64_t, uint64_t)));
 }
 
+void ViewBase::remove_signalbase(const shared_ptr<data::SignalBase> 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<data::SignalBase> s) { return s == signalbase; }),
+               signalbases_.end());
+}
+
 #ifdef ENABLE_DECODE
 void ViewBase::clear_decode_signals()
 {
index 5e9f8fdc48776fa3e8e8a9771e82f87fe6ea2ef2..eff962311cc549434e51dc48db45f6bda704c5bc 100644 (file)
@@ -93,6 +93,7 @@ public:
        virtual void clear_signalbases();
 
        virtual void add_signalbase(const shared_ptr<data::SignalBase> signalbase);
+       virtual void remove_signalbase(const shared_ptr<data::SignalBase> signalbase);
 
 #ifdef ENABLE_DECODE
        virtual void clear_decode_signals();