From: Joel Holdsworth Date: Sat, 4 May 2013 07:44:17 +0000 (+0100) Subject: Create signals when device is selected X-Git-Tag: pulseview-0.2.0~361 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b087ba7fd88610cbf54f6371367c7b9f9829dc63;p=pulseview.git Create signals when device is selected --- diff --git a/pv/data/analog.cpp b/pv/data/analog.cpp index c8497027..fadd5c69 100644 --- a/pv/data/analog.cpp +++ b/pv/data/analog.cpp @@ -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 >& Analog::get_snapshots() return _snapshots; } +void Analog::clear_snapshots() +{ + _snapshots.clear(); +} + } // namespace data } // namespace pv diff --git a/pv/data/analog.h b/pv/data/analog.h index c8ec04f1..3a755159 100644 --- a/pv/data/analog.h +++ b/pv/data/analog.h @@ -34,7 +34,7 @@ class AnalogSnapshot; class Analog : public SignalData { public: - Analog(uint64_t samplerate); + Analog(); void push_snapshot( boost::shared_ptr &snapshot); @@ -42,6 +42,8 @@ public: std::deque< boost::shared_ptr >& get_snapshots(); + void clear_snapshots(); + private: std::deque< boost::shared_ptr > _snapshots; }; diff --git a/pv/data/logic.cpp b/pv/data/logic.cpp index 4d225442..c62a2f2e 100644 --- a/pv/data/logic.cpp +++ b/pv/data/logic.cpp @@ -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 >& Logic::get_snapshots() return _snapshots; } +void Logic::clear_snapshots() +{ + _snapshots.clear(); +} + } // namespace data } // namespace pv diff --git a/pv/data/logic.h b/pv/data/logic.h index e29427a6..4fe4c42e 100644 --- a/pv/data/logic.h +++ b/pv/data/logic.h @@ -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 >& get_snapshots(); + void clear_snapshots(); + private: const unsigned int _num_probes; std::deque< boost::shared_ptr > _snapshots; diff --git a/pv/data/signaldata.cpp b/pv/data/signaldata.cpp index 2c6e3c66..78e5e91d 100644 --- a/pv/data/signaldata.cpp +++ b/pv/data/signaldata.cpp @@ -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; diff --git a/pv/data/signaldata.h b/pv/data/signaldata.h index 7f64bdb4..c43b7a37 100644 --- a/pv/data/signaldata.h +++ b/pv/data/signaldata.h @@ -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 diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 80802e5c..bda4b0d3 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -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 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 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 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( + new view::LogicSignal( + probe->name, + _logic_data, + probe->index)); + break; + + case SR_PROBE_ANALOG: + signal = shared_ptr( + 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 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 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 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 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( - new view::LogicSignal(probe->name, - _logic_data, probe->index)); - break; - - case SR_PROBE_ANALOG: - signal = shared_ptr( - 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, diff --git a/pv/sigsession.h b/pv/sigsession.h index 1638db83..f4e3d4af 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -91,6 +91,8 @@ public: private: void set_capture_state(capture_state state); + void update_signals(); + private: /** * Attempts to autodetect the format. Failing that