]> sigrok.org Git - pulseview.git/commitdiff
Create signals when device is selected
authorJoel Holdsworth <redacted>
Sat, 4 May 2013 07:44:17 +0000 (08:44 +0100)
committerJoel Holdsworth <redacted>
Sun, 19 May 2013 08:45:59 +0000 (09:45 +0100)
pv/data/analog.cpp
pv/data/analog.h
pv/data/logic.cpp
pv/data/logic.h
pv/data/signaldata.cpp
pv/data/signaldata.h
pv/sigsession.cpp
pv/sigsession.h

index c8497027c5c2d68c5935cbe5295c561352a9e9f4..fadd5c696331ce95a0c79ee057b1d81b40d6434c 100644 (file)
@@ -27,8 +27,8 @@ using namespace std;
 namespace pv {
 namespace data {
 
-Analog::Analog(uint64_t samplerate) :
-       SignalData(samplerate)
+Analog::Analog() :
+       SignalData()
 {
 }
 
@@ -42,5 +42,10 @@ deque< shared_ptr<AnalogSnapshot> >& Analog::get_snapshots()
        return _snapshots;
 }
 
+void Analog::clear_snapshots()
+{
+       _snapshots.clear();
+}
+
 } // namespace data
 } // namespace pv
index c8ec04f175d55215346c11c8d29a14102d36b9f4..3a755159a59a8d66382770d6b5113abfee4f6ae8 100644 (file)
@@ -34,7 +34,7 @@ class AnalogSnapshot;
 class Analog : public SignalData
 {
 public:
-       Analog(uint64_t samplerate);
+       Analog();
 
        void push_snapshot(
                boost::shared_ptr<AnalogSnapshot> &snapshot);
@@ -42,6 +42,8 @@ public:
        std::deque< boost::shared_ptr<AnalogSnapshot> >&
                get_snapshots();
 
+       void clear_snapshots();
+
 private:
        std::deque< boost::shared_ptr<AnalogSnapshot> > _snapshots;
 };
index 4d2254428dee22f44a9ca1bd1efd5a8d25103458..c62a2f2e3ad693833b1a55dbac3977d72c62deb5 100644 (file)
@@ -27,8 +27,8 @@ using namespace std;
 namespace pv {
 namespace data {
 
-Logic::Logic(unsigned int num_probes, uint64_t samplerate) :
-       SignalData(samplerate),
+Logic::Logic(unsigned int num_probes) :
+       SignalData(),
        _num_probes(num_probes)
 {
        assert(_num_probes > 0);
@@ -50,5 +50,10 @@ deque< shared_ptr<LogicSnapshot> >& Logic::get_snapshots()
        return _snapshots;
 }
 
+void Logic::clear_snapshots()
+{
+       _snapshots.clear();
+}
+
 } // namespace data
 } // namespace pv
index e29427a6f3669ab889cc8e3b727d9202ed821b94..4fe4c42e6b4a30280f8256503ad27924e6abd7e8 100644 (file)
@@ -34,7 +34,7 @@ class LogicSnapshot;
 class Logic : public SignalData
 {
 public:
-       Logic(unsigned int num_probes, uint64_t samplerate);
+       Logic(unsigned int num_probes);
 
        int get_num_probes() const;
 
@@ -44,6 +44,8 @@ public:
        std::deque< boost::shared_ptr<LogicSnapshot> >&
                get_snapshots();
 
+       void clear_snapshots();
+
 private:
        const unsigned int _num_probes;
        std::deque< boost::shared_ptr<LogicSnapshot> > _snapshots;
index 2c6e3c66c38fb55cb5c65f40cb6a71d8cac02ea7..78e5e91d1544b14f4f06a7da7dc5c85522efb3c2 100644 (file)
@@ -23,9 +23,9 @@
 namespace pv {
 namespace data {
 
-SignalData::SignalData(double samplerate) :
-       _samplerate(samplerate),
-       _start_time(0)
+SignalData::SignalData() :
+       _start_time(0),
+       _samplerate(0)
 {
 }
 
@@ -34,6 +34,12 @@ double SignalData::get_samplerate() const
        return _samplerate;
 }
 
+void SignalData::set_samplerate(double samplerate)
+{
+       _samplerate = samplerate;
+       clear_snapshots();
+}
+
 double SignalData::get_start_time() const
 {
        return _start_time;
index 7f64bdb4cc122d83579c315e4b56cb8957e992c7..c43b7a37e7e3e1934858ffd438ee0a80a95968e0 100644 (file)
@@ -29,15 +29,20 @@ namespace data {
 class SignalData
 {
 public:
-       SignalData(double samplerate);
+       SignalData();
 
 public:
        double get_samplerate() const;
+       void set_samplerate(double samplerate);
+
        double get_start_time() const;
 
+       virtual void clear_snapshots() = 0;
+
 protected:
-       const double _samplerate;
        const double _start_time;
+
+       double _samplerate;
 };
 
 } // namespace data
index 80802e5c7123d395edd16fcf46d8515e27c05b2c..bda4b0d32c38c03fe5d7c26a5645ae03f85b64cc 100644 (file)
@@ -79,6 +79,7 @@ void SigSession::set_device(struct sr_dev_inst *sdi)
        if (sdi)
                _device_manager.use_device(sdi, this);
        _sdi = sdi;
+       update_signals();
 }
 
 void SigSession::release_device(struct sr_dev_inst *sdi)
@@ -87,6 +88,7 @@ void SigSession::release_device(struct sr_dev_inst *sdi)
 
        assert(_capture_state == Stopped);
        _sdi = NULL;
+       update_signals();
 }
 
 void SigSession::load_file(const string &name,
@@ -242,6 +244,91 @@ sr_input* SigSession::load_input_file_format(const string &filename,
        return in;
 }
 
+void SigSession::update_signals()
+{
+       assert(_capture_state == Stopped);
+
+       shared_ptr<view::Signal> signal;
+       unsigned int logic_probe_count = 0;
+       unsigned int analog_probe_count = 0;
+
+       // Detect what data types we will receive
+       if(_sdi) {
+               for (const GSList *l = _sdi->probes; l; l = l->next) {
+                       const sr_probe *const probe = (const sr_probe *)l->data;
+                       if (!probe->enabled)
+                               continue;
+
+                       switch(probe->type) {
+                       case SR_PROBE_LOGIC:
+                               logic_probe_count++;
+                               break;
+
+                       case SR_PROBE_ANALOG:
+                               analog_probe_count++;
+                               break;
+                       }
+               }
+       }
+
+       // Create data containers for the data snapshots
+       {
+               lock_guard<mutex> data_lock(_data_mutex);
+
+               _logic_data.reset();
+               if (logic_probe_count != 0) {
+                       _logic_data.reset(new data::Logic(
+                               logic_probe_count));
+                       assert(_logic_data);
+               }
+
+               _analog_data.reset();
+               if (analog_probe_count != 0) {
+                       _analog_data.reset(new data::Analog());
+                       assert(_analog_data);
+               }
+       }
+
+       // Make the Signals list
+       {
+               lock_guard<mutex> lock(_signals_mutex);
+
+               _signals.clear();
+
+               if(_sdi) {
+                       for (const GSList *l = _sdi->probes; l; l = l->next) {
+                               const sr_probe *const probe =
+                                       (const sr_probe *)l->data;
+                               assert(probe);
+                               if (!probe->enabled)
+                                       continue;
+
+                               switch(probe->type) {
+                               case SR_PROBE_LOGIC:
+                                       signal = shared_ptr<view::Signal>(
+                                               new view::LogicSignal(
+                                                       probe->name,
+                                                       _logic_data,
+                                                       probe->index));
+                                       break;
+
+                               case SR_PROBE_ANALOG:
+                                       signal = shared_ptr<view::Signal>(
+                                               new view::AnalogSignal(
+                                                       probe->name,
+                                                       _analog_data,
+                                                       probe->index));
+                                       break;
+                               }
+
+                               _signals.push_back(signal);
+                       }
+               }
+       }
+
+       signals_changed();
+}
+
 void SigSession::load_thread_proc(const string name,
        function<void (const QString)> error_handler)
 {
@@ -320,28 +407,8 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
 
 void SigSession::feed_in_header(const sr_dev_inst *sdi)
 {
-       shared_ptr<view::Signal> signal;
        GVariant *gvar;
        uint64_t sample_rate = 0;
-       unsigned int logic_probe_count = 0;
-       unsigned int analog_probe_count = 0;
-
-       // Detect what data types we will receive
-       for (const GSList *l = sdi->probes; l; l = l->next) {
-               const sr_probe *const probe = (const sr_probe *)l->data;
-               if (!probe->enabled)
-                       continue;
-
-               switch(probe->type) {
-               case SR_PROBE_LOGIC:
-                       logic_probe_count++;
-                       break;
-
-               case SR_PROBE_ANALOG:
-                       analog_probe_count++;
-                       break;
-               }
-       }
 
        // Read out the sample rate
        if(sdi->driver)
@@ -357,54 +424,10 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi)
                g_variant_unref(gvar);
        }
 
-       // Create data containers for the coming data snapshots
-       {
-               lock_guard<mutex> data_lock(_data_mutex);
-
-               if (logic_probe_count != 0) {
-                       _logic_data.reset(new data::Logic(
-                               logic_probe_count, sample_rate));
-                       assert(_logic_data);
-               }
-
-               if (analog_probe_count != 0) {
-                       _analog_data.reset(new data::Analog(sample_rate));
-                       assert(_analog_data);
-               }
-       }
-
-       // Make the logic probe list
-       {
-               lock_guard<mutex> lock(_signals_mutex);
-
-               _signals.clear();
-
-               for (const GSList *l = sdi->probes; l; l = l->next) {
-                       const sr_probe *const probe =
-                               (const sr_probe *)l->data;
-                       assert(probe);
-                       if (!probe->enabled)
-                               continue;
-
-                       switch(probe->type) {
-                       case SR_PROBE_LOGIC:
-                               signal = shared_ptr<view::Signal>(
-                                       new view::LogicSignal(probe->name,
-                                               _logic_data, probe->index));
-                               break;
-
-                       case SR_PROBE_ANALOG:
-                               signal = shared_ptr<view::Signal>(
-                                       new view::AnalogSignal(probe->name,
-                                               _analog_data, probe->index));
-                               break;
-                       }
-
-                       _signals.push_back(signal);
-               }
-
-               signals_changed();
-       }
+       if(_analog_data)
+               _analog_data->set_samplerate(sample_rate);
+       if(_logic_data)
+               _logic_data->set_samplerate(sample_rate);
 }
 
 void SigSession::feed_in_meta(const sr_dev_inst *sdi,
index 1638db838f91ecc89623002adc3ab8a41c741e55..f4e3d4af34d70b21cebe96992fc8f755797fb8a1 100644 (file)
@@ -91,6 +91,8 @@ public:
 private:
        void set_capture_state(capture_state state);
 
+       void update_signals();
+
 private:
        /**
         * Attempts to autodetect the format. Failing that