]> sigrok.org Git - pulseview.git/commitdiff
Added session file open support
authorJoel Holdsworth <redacted>
Sun, 13 May 2012 21:26:02 +0000 (22:26 +0100)
committerJoel Holdsworth <redacted>
Mon, 3 Sep 2012 12:49:39 +0000 (13:49 +0100)
CMakeLists.txt
mainwindow.cpp
mainwindow.h
mainwindow.ui
sigsession.cpp [new file with mode: 0644]
sigsession.h [new file with mode: 0644]

index fd932a2926de718d2b06bc3a4220e942fb3719ec..3b2df47b4b914786582847aa5cb3ef09e1277fb5 100644 (file)
@@ -17,12 +17,14 @@ set(sigrok-qt2_SOURCES
        about.cpp
        main.cpp
        mainwindow.cpp
+       sigsession.cpp
        sigview.cpp
 )
 
 set(sigrok-qt2_HEADERS
        about.h
        mainwindow.h
+       sigsession.h
        sigview.h
 )
 
index 45d415dd16114ffefa38735a95f82b37b9d7ccf6..d85c0a40e46e0604690cb62ab6ea5eefec04d11a 100644 (file)
@@ -22,6 +22,8 @@ extern "C" {
 #include <sigrokdecode.h>
 }
 
+#include <QFileDialog>
+
 #include "about.h"
 
 #include "mainwindow.h"
@@ -49,6 +51,14 @@ MainWindow::~MainWindow()
        delete ui;
 }
 
+void MainWindow::on_actionOpen_triggered()
+{
+       QString fileName = QFileDialog::getOpenFileName(
+               this, tr("Open File"), "",
+               tr("Sigrok Sessions (*.sr)"));
+       session.loadFile(fileName.toStdString());
+}
+
 void MainWindow::on_actionAbout_triggered()
 {
        About dlg(this);
index cef253cff9b77400aeffff35ca38ede899349a3f..34fb1b92e969e120a5ae6f1ed18364e52be3e487 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <QMainWindow>
 
+#include "sigsession.h"
+
 namespace Ui {
 class MainWindow;
 }
@@ -37,8 +39,12 @@ public:
 
 private:
        Ui::MainWindow *ui;
+       SigSession session;
 
 private slots:
+
+       void on_actionOpen_triggered();
+
        void on_actionAbout_triggered();
 };
 
index 5f11fb2a94b1c1c201455a4141527ce0d6947d9c..5cf32c6dfe889ec52445244586edb12513aa0b54 100644 (file)
     </property>
     <addaction name="actionAbout"/>
    </widget>
+   <widget class="QMenu" name="menu_File">
+    <property name="title">
+     <string>&amp;File</string>
+    </property>
+    <addaction name="actionOpen"/>
+   </widget>
+   <addaction name="menu_File"/>
    <addaction name="menu_Help"/>
   </widget>
   <widget class="QWidget" name="centralWidget">
     <string>&amp;About...</string>
    </property>
   </action>
+  <action name="actionOpen">
+   <property name="text">
+    <string>&amp;Open...</string>
+   </property>
+  </action>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
  <customwidgets>
diff --git a/sigsession.cpp b/sigsession.cpp
new file mode 100644 (file)
index 0000000..2df6a15
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "sigsession.h"
+
+#include <assert.h>
+
+// TODO: This should not be necessary
+SigSession* SigSession::session = NULL;
+
+SigSession::SigSession()
+{
+       // TODO: This should not be necessary
+       session = this;
+}
+
+SigSession::~SigSession()
+{
+       // TODO: This should not be necessary
+       session = NULL;
+}
+
+void SigSession::loadFile(const std::string &name)
+{
+       if (sr_session_load(name.c_str()) == SR_OK) {
+               /* sigrok session file */
+               sr_session_datafeed_callback_add(dataFeedInProc);
+               sr_session_start();
+               sr_session_run();
+               sr_session_stop();
+       }
+}
+
+void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
+       struct sr_datafeed_packet *packet)
+{
+       assert(sdi);
+       assert(packet);
+
+       switch (packet->type) {
+       case SR_DF_META_LOGIC:
+               {
+                       const sr_datafeed_meta_logic *meta_logic =
+                               (sr_datafeed_meta_logic*)packet->payload;
+                       int num_enabled_probes = 0;
+
+                       for (int i = 0; i < meta_logic->num_probes; i++) {
+                               const sr_probe *probe =
+                                       (sr_probe *)g_slist_nth_data(sdi->probes, i);
+                               if (probe->enabled) {
+                                       probeList[num_enabled_probes++] = probe->index;
+                               }
+                       }
+               }
+               break;
+
+       case SR_DF_END:
+               break;
+       }
+}
+
+void SigSession::dataFeedInProc(const struct sr_dev_inst *sdi,
+       struct sr_datafeed_packet *packet)
+{
+       assert(session);
+       session->dataFeedIn(sdi, packet);
+}
diff --git a/sigsession.h b/sigsession.h
new file mode 100644 (file)
index 0000000..47f37a1
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#ifndef SIGSESSION_H
+#define SIGSESSION_H
+
+extern "C" {
+#include <libsigrok/libsigrok.h>
+}
+
+#include <string>
+
+class SigSession
+{
+public:
+       SigSession();
+
+       ~SigSession();
+
+       void loadFile(const std::string &name);
+
+private:
+       void dataFeedIn(const struct sr_dev_inst *sdi,
+               struct sr_datafeed_packet *packet);
+
+       static void dataFeedInProc(const struct sr_dev_inst *sdi,
+               struct sr_datafeed_packet *packet);
+
+private:
+       int probeList[SR_MAX_NUM_PROBES + 1];
+
+private:
+       // TODO: This should not be necessary. Multiple concurrent
+       // sessions should should be supported and it should be
+       // possible to associate a pointer with a sr_session.
+       static SigSession *session;
+};
+
+#endif // SIGSESSION_H