]> sigrok.org Git - pulseview.git/commitdiff
Ported sampling to new sigrok API
authorJoel Holdsworth <redacted>
Sun, 27 Jan 2013 11:10:19 +0000 (11:10 +0000)
committerJoel Holdsworth <redacted>
Mon, 28 Jan 2013 20:36:00 +0000 (20:36 +0000)
pv/data/analog.cpp
pv/data/analog.h
pv/data/logic.cpp
pv/data/logic.h
pv/sigsession.cpp
pv/sigsession.h

index 8245186b97ab21af6b89d8d9f54e4137bbd519a6..c8497027c5c2d68c5935cbe5295c561352a9e9f4 100644 (file)
@@ -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)
 {
 }
index 2e2ade69bfde31d961de628083c05454be7c35c3..c8ec04f175d55215346c11c8d29a14102d36b9f4 100644 (file)
 #include <boost/shared_ptr.hpp>
 #include <deque>
 
-extern "C" {
-#include <libsigrok/libsigrok.h>
-}
-
 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<AnalogSnapshot> &snapshot);
index 7b42e47497054c3fc6d359bf3ac860bb577fc09f..4d2254428dee22f44a9ca1bd1efd5a8d25103458 100644 (file)
@@ -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
index 4b70b8f98bdb8028d09f0744e8db94ce0c81cc5b..e29427a6f3669ab889cc8e3b727d9202ed821b94 100644 (file)
 #include <boost/shared_ptr.hpp>
 #include <deque>
 
-extern "C" {
-#include <libsigrok/libsigrok.h>
-}
-
 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<LogicSnapshot> > _snapshots;
 };
 
index 7a0c49e5479f5a899db3d14090f89b022ca608da..348d40c1e5b3b09da676184fb12f49ce48b6c566 100644 (file)
@@ -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<view::Signal> 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<mutex> 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<mutex> data_lock(_data_mutex);
                lock_guard<mutex> 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<mutex> 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<LogicSignal> 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<view::Signal>(
+                                       new view::LogicSignal(probe->name,
                                                _logic_data, probe->index));
-                               _signals.push_back(signal);
+                               break;
+
+                       case SR_PROBE_ANALOG:
+                               signal = shared_ptr<view::Signal>(
+                                       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<mutex> data_lock(_data_mutex);
-               lock_guard<mutex> 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<mutex> lock(_signals_mutex);
+       set_capture_state(Running);
 
-               // Add the signals
-               shared_ptr<AnalogSignal> 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<mutex> lock(_data_mutex);
        if (!_cur_logic_snapshot)
        {
+               assert(_logic_data);
+
                // Create a new data snapshot
                _cur_logic_snapshot = shared_ptr<data::LogicSnapshot>(
                        new data::LogicSnapshot(logic));
@@ -268,6 +297,8 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog)
        lock_guard<mutex> lock(_data_mutex);
        if (!_cur_analog_snapshot)
        {
+               assert(_analog_data);
+
                // Create a new data snapshot
                _cur_analog_snapshot = shared_ptr<data::AnalogSnapshot>(
                        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<mutex> 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:
index d5ec200a6498a9233e47be0fc4ac1d65389b2657..177e47c9b0ccc1d3cc20385f16b9d5e1e75426d9 100644 (file)
@@ -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);