]> sigrok.org Git - pulseview.git/blobdiff - sigsession.cpp
Replaced mainwindow.ui XML with code
[pulseview.git] / sigsession.cpp
index 9b9798e0577b65b4b64c0de854a82fb203426539..16b84f1487348871fa6af367278a2284433a998d 100644 (file)
 
 #include "logicdata.h"
 #include "logicdatasnapshot.h"
+#include "logicsignal.h"
 
 #include <QDebug>
 
 #include <assert.h>
 
 using namespace boost;
+using namespace std;
 
 // TODO: This should not be necessary
-SigSession* SigSession::session = NULL;
+SigSession* SigSession::_session = NULL;
 
 SigSession::SigSession()
 {
        // TODO: This should not be necessary
-       session = this;
+       _session = this;
 }
 
 SigSession::~SigSession()
 {
        // TODO: This should not be necessary
-       session = NULL;
+       _session = NULL;
 }
 
-void SigSession::loadFile(const std::string &name)
+void SigSession::load_file(const std::string &name)
 {
        if (sr_session_load(name.c_str()) == SR_OK) {
                /* sigrok session file */
-               sr_session_datafeed_callback_add(dataFeedInProc);
+               sr_session_datafeed_callback_add(data_feed_in_proc);
                sr_session_start();
                sr_session_run();
                sr_session_stop();
        }
 }
 
-void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
+void SigSession::start_capture(struct sr_dev_inst *sdi,
+       uint64_t record_length, uint64_t sample_rate)
+{
+       sr_session_new();
+       sr_session_datafeed_callback_add(data_feed_in_proc);
+
+       if (sr_session_dev_add(sdi) != SR_OK) {
+               qDebug() << "Failed to use device.";
+               sr_session_destroy();
+               return;
+       }
+
+       if (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_SAMPLES,
+               &record_length) != SR_OK) {
+               qDebug() << "Failed to configure time-based sample limit.";
+               sr_session_destroy();
+               return;
+       }
+
+       if (sr_dev_config_set(sdi, SR_HWCAP_SAMPLERATE,
+               &sample_rate) != SR_OK) {
+               qDebug() << "Failed to configure samplerate.";
+               sr_session_destroy();
+               return;
+       }
+
+       if (sr_session_start() != SR_OK) {
+               qDebug() << "Failed to start session.";
+               return;
+       }
+
+       sr_session_run();
+       sr_session_destroy();
+}
+
+vector< shared_ptr<Signal> >& SigSession::get_signals()
+{
+       return _signals;
+}
+
+void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
        struct sr_datafeed_packet *packet)
 {
        assert(sdi);
@@ -63,19 +105,38 @@ void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
 
        switch (packet->type) {
        case SR_DF_HEADER:
+               _signals.clear();
                break;
 
        case SR_DF_META_LOGIC:
                {
                        assert(packet->payload);
 
-                       _logic_data.reset(new LogicData(
-                               *(sr_datafeed_meta_logic*)packet->payload));
+                       const sr_datafeed_meta_logic &meta_logic =
+                               *(sr_datafeed_meta_logic*)packet->payload;
 
+                       // Create an empty LogiData for coming data snapshots
+                       _logic_data.reset(new LogicData(meta_logic));
                        assert(_logic_data);
                        if(!_logic_data)
                                break;
 
+                       // Add the signals
+                       for (int i = 0; i < meta_logic.num_probes; i++)
+                       {
+                               const sr_probe *const probe =
+                                       (const sr_probe*)g_slist_nth_data(
+                                               sdi->probes, i);
+                               if(probe->enabled)
+                               {
+                                       boost::shared_ptr<LogicSignal> signal(
+                                               new LogicSignal(probe->name,
+                                                       _logic_data,
+                                                       probe->index));
+                                       _signals.push_back(signal);
+                               }
+                       }
+
                        break;
                }
 
@@ -101,14 +162,14 @@ void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
 
        case SR_DF_END:
                _cur_logic_snapshot.reset();
-               dataUpdated();
+               data_updated();
                break;
        }
 }
 
-void SigSession::dataFeedInProc(const struct sr_dev_inst *sdi,
+void SigSession::data_feed_in_proc(const struct sr_dev_inst *sdi,
        struct sr_datafeed_packet *packet)
 {
-       assert(session);
-       session->dataFeedIn(sdi, packet);
+       assert(_session);
+       _session->data_feed_in(sdi, packet);
 }