From: Joel Holdsworth Date: Sun, 13 May 2012 21:26:02 +0000 (+0100) Subject: Added session file open support X-Git-Tag: pulseview-0.1.0~352 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=2953961c06ff9e758035ba3cd67220568bd01710 Added session file open support --- diff --git a/CMakeLists.txt b/CMakeLists.txt index fd932a29..3b2df47b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) diff --git a/mainwindow.cpp b/mainwindow.cpp index 45d415dd..d85c0a40 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -22,6 +22,8 @@ extern "C" { #include } +#include + #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); diff --git a/mainwindow.h b/mainwindow.h index cef253cf..34fb1b92 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -23,6 +23,8 @@ #include +#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(); }; diff --git a/mainwindow.ui b/mainwindow.ui index 5f11fb2a..5cf32c6d 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -32,6 +32,13 @@ + + + &File + + + + @@ -50,6 +57,11 @@ &About... + + + &Open... + + diff --git a/sigsession.cpp b/sigsession.cpp new file mode 100644 index 00000000..2df6a151 --- /dev/null +++ b/sigsession.cpp @@ -0,0 +1,84 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 + +// 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 index 00000000..47f37a10 --- /dev/null +++ b/sigsession.h @@ -0,0 +1,56 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 +} + +#include + +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