about.cpp
main.cpp
mainwindow.cpp
+ sigsession.cpp
sigview.cpp
)
set(sigrok-qt2_HEADERS
about.h
mainwindow.h
+ sigsession.h
sigview.h
)
#include <sigrokdecode.h>
}
+#include <QFileDialog>
+
#include "about.h"
#include "mainwindow.h"
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);
#include <QMainWindow>
+#include "sigsession.h"
+
namespace Ui {
class MainWindow;
}
private:
Ui::MainWindow *ui;
+ SigSession session;
private slots:
+
+ void on_actionOpen_triggered();
+
void on_actionAbout_triggered();
};
</property>
<addaction name="actionAbout"/>
</widget>
+ <widget class="QMenu" name="menu_File">
+ <property name="title">
+ <string>&File</string>
+ </property>
+ <addaction name="actionOpen"/>
+ </widget>
+ <addaction name="menu_File"/>
<addaction name="menu_Help"/>
</widget>
<widget class="QWidget" name="centralWidget">
<string>&About...</string>
</property>
</action>
+ <action name="actionOpen">
+ <property name="text">
+ <string>&Open...</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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