From: Joel Holdsworth Date: Sun, 27 Jan 2013 11:10:19 +0000 (+0000) Subject: Ported sampling to new sigrok API X-Git-Tag: pulseview-0.1.0~135 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=be73bdfa788fcc62bda3187cb1ba04fed2b9d721;p=pulseview.git Ported sampling to new sigrok API --- diff --git a/pv/data/analog.cpp b/pv/data/analog.cpp index 8245186b..c8497027 100644 --- a/pv/data/analog.cpp +++ b/pv/data/analog.cpp @@ -27,8 +27,7 @@ using namespace std; namespace pv { namespace data { -Analog::Analog(const sr_datafeed_meta_analog&, - uint64_t samplerate) : +Analog::Analog(uint64_t samplerate) : SignalData(samplerate) { } diff --git a/pv/data/analog.h b/pv/data/analog.h index 2e2ade69..c8ec04f1 100644 --- a/pv/data/analog.h +++ b/pv/data/analog.h @@ -26,10 +26,6 @@ #include #include -extern "C" { -#include -} - namespace pv { namespace data { @@ -38,8 +34,7 @@ class AnalogSnapshot; class Analog : public SignalData { public: - Analog(const sr_datafeed_meta_analog &meta, - uint64_t samplerate); + Analog(uint64_t samplerate); void push_snapshot( boost::shared_ptr &snapshot); diff --git a/pv/data/logic.cpp b/pv/data/logic.cpp index 7b42e474..4d225442 100644 --- a/pv/data/logic.cpp +++ b/pv/data/logic.cpp @@ -27,11 +27,11 @@ using namespace std; namespace pv { namespace data { -Logic::Logic(const sr_datafeed_meta_logic &meta, - uint64_t samplerate) : +Logic::Logic(unsigned int num_probes, uint64_t samplerate) : SignalData(samplerate), - _num_probes(meta.num_probes) + _num_probes(num_probes) { + assert(_num_probes > 0); } int Logic::get_num_probes() const diff --git a/pv/data/logic.h b/pv/data/logic.h index 4b70b8f9..e29427a6 100644 --- a/pv/data/logic.h +++ b/pv/data/logic.h @@ -26,10 +26,6 @@ #include #include -extern "C" { -#include -} - namespace pv { namespace data { @@ -38,7 +34,7 @@ class LogicSnapshot; class Logic : public SignalData { public: - Logic(const sr_datafeed_meta_logic &meta, uint64_t samplerate); + Logic(unsigned int num_probes, uint64_t samplerate); int get_num_probes() const; @@ -49,7 +45,7 @@ public: get_snapshots(); private: - const int _num_probes; + const unsigned int _num_probes; std::deque< boost::shared_ptr > _snapshots; }; diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 7a0c49e5..348d40c1 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -140,6 +140,12 @@ void SigSession::load_thread_proc(const string name) void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, uint64_t record_length) { + shared_ptr signal; + unsigned int logic_probe_count = 0; + unsigned int analog_probe_count = 0; + + assert(sdi); + sr_session_new(); sr_session_datafeed_callback_add(data_feed_in_proc); @@ -149,16 +155,18 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, return; } - if (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_SAMPLES, + // Set the sample limit + if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES, &record_length) != SR_OK) { qDebug() << "Failed to configure time-based sample limit."; sr_session_destroy(); return; } + // Set the samplerate { lock_guard lock(_sampling_mutex); - if (sr_dev_config_set(sdi, SR_HWCAP_SAMPLERATE, + if (sr_config_set(sdi, SR_CONF_SAMPLERATE, &_sample_rate) != SR_OK) { qDebug() << "Failed to configure samplerate."; sr_session_destroy(); @@ -166,81 +174,100 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, } } - if (sr_session_start() != SR_OK) { - qDebug() << "Failed to start session."; - return; - } + // 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; - set_capture_state(Running); + switch(probe->type) { + case SR_PROBE_LOGIC: + logic_probe_count++; + break; - sr_session_run(); - sr_session_destroy(); - - set_capture_state(Stopped); -} - -void SigSession::feed_in_meta_logic(const struct sr_dev_inst *sdi, - const sr_datafeed_meta_logic &meta_logic) -{ - using view::LogicSignal; + case SR_PROBE_ANALOG: + analog_probe_count++; + break; + } + } + // Create data containers for the coming data snapshots { lock_guard data_lock(_data_mutex); lock_guard sampling_lock(_sampling_mutex); - // Create an empty data::Logic for coming data snapshots - _logic_data.reset(new data::Logic(meta_logic, _sample_rate)); - assert(_logic_data); - if (!_logic_data) - return; + 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); - // Add the signals - for (int i = 0; i < meta_logic.num_probes; i++) { + _signals.clear(); + + for (const GSList *l = sdi->probes; l; l = l->next) { const sr_probe *const probe = - (const sr_probe*)g_slist_nth_data( - sdi->probes, i); - if (probe->enabled) { - shared_ptr signal( - new LogicSignal(probe->name, + (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)); - _signals.push_back(signal); + break; + + case SR_PROBE_ANALOG: + signal = shared_ptr( + new view::AnalogSignal(probe->name, + _analog_data)); + break; } + + _signals.push_back(signal); } signals_changed(); } -} - -void SigSession::feed_in_meta_analog(const struct sr_dev_inst*, - const sr_datafeed_meta_analog &meta_analog) -{ - using view::AnalogSignal; - - { - lock_guard data_lock(_data_mutex); - lock_guard sampling_lock(_sampling_mutex); - // Create an empty data::Analog for coming data snapshots - _analog_data.reset(new data::Analog( - meta_analog, _sample_rate)); - assert(_analog_data); - if (!_analog_data) - return; + if (sr_session_start() != SR_OK) { + qDebug() << "Failed to start session."; + return; } - { - lock_guard lock(_signals_mutex); + set_capture_state(Running); - // Add the signals - shared_ptr signal( - new AnalogSignal(QString("???"), _analog_data)); - _signals.push_back(signal); + sr_session_run(); + sr_session_destroy(); - signals_changed(); + set_capture_state(Stopped); +} + +void SigSession::feed_in_meta(const sr_dev_inst *sdi, + const sr_datafeed_meta &meta) +{ + for (const GSList *l = meta.config; l; l = l->next) { + const sr_config *const src = (const sr_config*)l->data; + switch (src->key) { + case SR_CONF_SAMPLERATE: + /// @todo handle samplerate changes + /// samplerate = (uint64_t *)src->value; + break; + default: + // Unknown metadata is not an error. + break; + } } } @@ -249,6 +276,8 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) lock_guard lock(_data_mutex); if (!_cur_logic_snapshot) { + assert(_logic_data); + // Create a new data snapshot _cur_logic_snapshot = shared_ptr( new data::LogicSnapshot(logic)); @@ -268,6 +297,8 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog) lock_guard lock(_data_mutex); if (!_cur_analog_snapshot) { + assert(_analog_data); + // Create a new data snapshot _cur_analog_snapshot = shared_ptr( new data::AnalogSnapshot(analog)); @@ -290,22 +321,12 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, switch (packet->type) { case SR_DF_HEADER: - { - lock_guard lock(_signals_mutex); - _signals.clear(); - break; - } - - case SR_DF_META_LOGIC: - assert(packet->payload); - feed_in_meta_logic(sdi, - *(const sr_datafeed_meta_logic*)packet->payload); break; - case SR_DF_META_ANALOG: + case SR_DF_META: assert(packet->payload); - feed_in_meta_analog(sdi, - *(const sr_datafeed_meta_analog*)packet->payload); + feed_in_meta(sdi, + *(const sr_datafeed_meta*)packet->payload); break; case SR_DF_LOGIC: diff --git a/pv/sigsession.h b/pv/sigsession.h index d5ec200a..177e47c9 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -85,11 +85,8 @@ private: void sample_thread_proc(struct sr_dev_inst *sdi, uint64_t record_length); - void feed_in_meta_logic(const struct sr_dev_inst *sdi, - const sr_datafeed_meta_logic &meta_logic); - - void feed_in_meta_analog(const struct sr_dev_inst *sdi, - const sr_datafeed_meta_analog &meta_analog); + void feed_in_meta(const sr_dev_inst *sdi, + const sr_datafeed_meta &meta); void feed_in_logic(const sr_datafeed_logic &logic);