pv/data/signaldata.cpp
pv/data/snapshot.cpp
pv/device/device.cpp
+ pv/device/file.cpp
pv/device/devinst.cpp
+ pv/device/inputfile.cpp
+ pv/device/sessionfile.cpp
pv/dialogs/about.cpp
pv/dialogs/connect.cpp
pv/dialogs/storeprogress.cpp
return _sdi;
}
+void Device::use(SigSession *owner) throw(QString)
+{
+ DevInst::use(owner);
+
+ sr_session_new();
+
+ assert(_sdi);
+ sr_dev_open(_sdi);
+ if (sr_session_dev_add(_sdi) != SR_OK)
+ throw QString(tr("Failed to use device."));
+}
+
+void Device::release()
+{
+ if (_owner) {
+ DevInst::release();
+ sr_session_destroy();
+ }
+
+ sr_dev_close(_sdi);
+}
+
std::string Device::format_device_title() const
{
ostringstream s;
sr_dev_inst* dev_inst() const;
+ void use(SigSession *owner) throw(QString);
+
+ void release();
+
std::string format_device_title() const;
bool is_trigger_enabled() const;
{
}
-void DevInst::use(SigSession *owner)
+void DevInst::use(SigSession *owner) throw(QString)
{
assert(owner);
assert(!_owner);
_owner = owner;
- sr_dev_open(dev_inst());
}
void DevInst::release()
if (_owner) {
_owner->release_device(this);
_owner = NULL;
- sr_dev_close(dev_inst());
}
}
GVariant* DevInst::get_config(const sr_probe_group *group, int key)
{
GVariant *data = NULL;
+ assert(_owner);
sr_dev_inst *const sdi = dev_inst();
assert(sdi);
if (sr_config_get(sdi->driver, sdi, group, key, &data) != SR_OK)
bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data)
{
+ assert(_owner);
sr_dev_inst *const sdi = dev_inst();
assert(sdi);
if(sr_config_set(sdi, group, key, data) == SR_OK) {
GVariant* DevInst::list_config(const sr_probe_group *group, int key)
{
GVariant *data = NULL;
+ assert(_owner);
sr_dev_inst *const sdi = dev_inst();
assert(sdi);
if (sr_config_list(sdi->driver, sdi, group, key, &data) != SR_OK)
void DevInst::enable_probe(const sr_probe *probe, bool enable)
{
+ assert(_owner);
sr_dev_inst *const sdi = dev_inst();
assert(sdi);
for (const GSList *p = sdi->probes; p; p = p->next)
return false;
}
+void DevInst::start()
+{
+ if (sr_session_start() != SR_OK)
+ throw tr("Failed to start session.");
+}
+
+void DevInst::run()
+{
+ sr_session_run();
+}
+
} // device
} // pv
public:
virtual sr_dev_inst* dev_inst() const = 0;
- void use(SigSession *owner);
+ virtual void use(SigSession *owner) throw(QString);
- void release();
+ virtual void release();
SigSession* owner() const;
virtual bool is_trigger_enabled() const;
+public:
+ virtual void start();
+
+ virtual void run();
+
signals:
void config_changed();
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 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 "file.h"
+#include "inputfile.h"
+#include "sessionfile.h"
+
+#include <libsigrok/libsigrok.h>
+
+using std::string;
+
+namespace pv {
+namespace device {
+
+File::File(const std::string path) :
+ _path(path)
+{
+}
+
+std::string File::format_device_title() const
+{
+ return _path;
+}
+
+File* File::create(const string &name)
+{
+ if (sr_session_load(name.c_str()) == SR_OK) {
+ GSList *devlist = NULL;
+ sr_session_dev_list(&devlist);
+ sr_session_destroy();
+
+ if (devlist) {
+ sr_dev_inst *const sdi = (sr_dev_inst*)devlist->data;
+ g_slist_free(devlist);
+ if (sdi) {
+ sr_dev_close(sdi);
+ sr_dev_clear(sdi->driver);
+ return new SessionFile(name);
+ }
+ }
+ }
+
+ return new InputFile(name);
+}
+
+} // device
+} // pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 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 PULSEVIEW_PV_DEVICE_FILE_H
+#define PULSEVIEW_PV_DEVICE_FILE_H
+
+#include <string>
+
+#include "devinst.h"
+
+namespace pv {
+namespace device {
+
+class File : public DevInst
+{
+protected:
+ File(const std::string path);
+
+public:
+ static File* create(const std::string &name);
+
+public:
+ std::string format_device_title() const;
+
+protected:
+ const std::string _path;
+};
+
+} // device
+} // pv
+
+#endif // PULSEVIEW_PV_DEVICE_FILE_H
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 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 <cassert>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "inputfile.h"
+
+#include <libsigrok/libsigrok.h>
+
+using std::string;
+
+namespace pv {
+namespace device {
+
+InputFile::InputFile(const std::string &path) :
+ File(path),
+ _input(NULL)
+{
+}
+
+sr_dev_inst* InputFile::dev_inst() const
+{
+ assert(_input);
+ return _input->sdi;
+}
+
+void InputFile::use(SigSession *owner) throw(QString)
+{
+ assert(!_input);
+
+ _input = load_input_file_format(_path, NULL);
+ File::use(owner);
+
+ sr_session_new();
+
+ if (sr_session_dev_add(_input->sdi) != SR_OK)
+ throw tr("Failed to add session device.");
+}
+
+void InputFile::release()
+{
+ if (!_owner)
+ return;
+
+ assert(_input);
+ File::release();
+ sr_dev_close(_input->sdi);
+ sr_session_destroy();
+ _input = NULL;
+}
+
+sr_input_format* InputFile::determine_input_file_format(
+ const string &filename)
+{
+ int i;
+
+ /* If there are no input formats, return NULL right away. */
+ sr_input_format *const *const inputs = sr_input_list();
+ if (!inputs) {
+ g_critical("No supported input formats available.");
+ return NULL;
+ }
+
+ /* Otherwise, try to find an input module that can handle this file. */
+ for (i = 0; inputs[i]; i++) {
+ if (inputs[i]->format_match(filename.c_str()))
+ break;
+ }
+
+ /* Return NULL if no input module wanted to touch this. */
+ if (!inputs[i]) {
+ g_critical("Error: no matching input module found.");
+ return NULL;
+ }
+
+ return inputs[i];
+}
+
+sr_input* InputFile::load_input_file_format(const string &filename,
+ sr_input_format *format)
+{
+ struct stat st;
+ sr_input *in;
+
+ if (!format && !(format =
+ determine_input_file_format(filename.c_str()))) {
+ /* The exact cause was already logged. */
+ throw tr("Failed to load file");
+ }
+
+ if (stat(filename.c_str(), &st) == -1)
+ throw tr("Failed to load file");
+
+ /* Initialize the input module. */
+ if (!(in = new sr_input)) {
+ throw tr("Failed to allocate input module.");
+ }
+
+ in->format = format;
+ in->param = NULL;
+ if (in->format->init &&
+ in->format->init(in, filename.c_str()) != SR_OK) {
+ throw tr("Failed to load file");
+ }
+
+ return in;
+}
+
+void InputFile::start()
+{
+}
+
+void InputFile::run()
+{
+ assert(_input);
+ assert(_input->format);
+ assert(_input->format->loadfile);
+ _input->format->loadfile(_input, _path.c_str());
+}
+
+} // device
+} // pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 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 PULSEVIEW_PV_DEVICE_INPUTFILE_H
+#define PULSEVIEW_PV_DEVICE_INPUTFILE_H
+
+#include "file.h"
+
+#include <string>
+
+struct sr_input;
+struct sr_input_format;
+
+namespace pv {
+namespace device {
+
+class InputFile : public File
+{
+public:
+ InputFile(const std::string &path);
+
+ sr_dev_inst* dev_inst() const;
+
+ virtual void use(SigSession *owner) throw(QString);
+
+ virtual void release();
+
+ virtual void start();
+
+ virtual void run();
+
+private:
+ /**
+ * Attempts to autodetect the format. Failing that
+ * @param filename The filename of the input file.
+ * @return A pointer to the 'struct sr_input_format' that should be used,
+ * or NULL if no input format was selected or auto-detected.
+ */
+ static sr_input_format* determine_input_file_format(
+ const std::string &filename);
+
+ static sr_input* load_input_file_format(const std::string &filename,
+ sr_input_format *format);
+private:
+ sr_input *_input;
+};
+
+} // device
+} // pv
+
+#endif // PULSEVIEW_PV_DEVICE_INPUTFILE_H
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 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 "sessionfile.h"
+
+#include <libsigrok/libsigrok.h>
+
+namespace pv {
+namespace device {
+
+SessionFile::SessionFile(const std::string &path) :
+ File(path),
+ _sdi(NULL)
+{
+}
+
+sr_dev_inst* SessionFile::dev_inst() const
+{
+ return _sdi;
+}
+
+void SessionFile::use(SigSession *owner) throw(QString)
+{
+ assert(!_sdi);
+
+ if (sr_session_load(_path.c_str()) != SR_OK)
+ throw tr("Failed to open file.\n");
+
+ GSList *devlist = NULL;
+ sr_session_dev_list(&devlist);
+
+ if (!devlist || !devlist->data) {
+ if (devlist)
+ g_slist_free(devlist);
+ throw tr("Failed to start session.");
+ }
+
+ _sdi = (sr_dev_inst*)devlist->data;
+ g_slist_free(devlist);
+
+ File::use(owner);
+}
+
+void SessionFile::release()
+{
+ if (!_owner)
+ return;
+
+ assert(_sdi);
+ File::release();
+ sr_dev_close(_sdi);
+ sr_dev_clear(_sdi->driver);
+ sr_session_destroy();
+ _sdi = NULL;
+}
+
+} // device
+} // pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 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 PULSEVIEW_PV_DEVICE_SESSIONFILE_H
+#define PULSEVIEW_PV_DEVICE_SESSIONFILE_H
+
+#include "file.h"
+
+namespace pv {
+namespace device {
+
+class SessionFile : public File
+{
+public:
+ SessionFile(const std::string &path);
+
+ sr_dev_inst* dev_inst() const;
+
+ virtual void use(SigSession *owner) throw(QString);
+
+ virtual void release();
+
+private:
+ sr_dev_inst *_sdi;
+};
+
+} // device
+} // pv
+
+#endif // PULSEVIEW_PV_DEVICE_SESSIONFILE_H
const QString errorMessage(
QString("Failed to load file %1").arg(file_name));
const QString infoMessage;
- _session.load_file(file_name.toStdString(),
- boost::bind(&MainWindow::session_error, this,
- errorMessage, infoMessage));
+
+ try {
+ _session.set_file(file_name.toStdString());
+ } catch(QString e) {
+ show_session_error(tr("Failed to load ") + file_name, e);
+ }
+
+ _session.start_capture(boost::bind(&MainWindow::session_error, this,
+ errorMessage, infoMessage));
}
void MainWindow::show_session_error(
#include "devicemanager.h"
#include "device/device.h"
+#include "device/file.h"
#include "data/analog.h"
#include "data/analogsnapshot.h"
return _dev_inst;
}
-void SigSession::set_device(shared_ptr<device::DevInst> dev_inst)
+void SigSession::set_device(
+ shared_ptr<device::DevInst> dev_inst) throw(QString)
{
using pv::device::Device;
// Ensure we are not capturing before setting the device
stop_capture();
- if (_dev_inst)
+ if (_dev_inst) {
+ sr_session_datafeed_callback_remove_all();
_dev_inst->release();
+ }
+
+ _dev_inst = dev_inst;
+ _decode_traces.clear();
- if (dev_inst)
+ if (dev_inst) {
dev_inst->use(this);
+ sr_session_datafeed_callback_add(data_feed_in_proc, NULL);
+ update_signals(dev_inst);
+ }
+}
- _dev_inst = dev_inst;
- update_signals(dev_inst);
+void SigSession::set_file(const string &name) throw(QString)
+{
+ // Deslect the old device, because file type detection in File::create
+ // destorys the old session inside libsigrok.
+ set_device(shared_ptr<device::DevInst>());
+ set_device(shared_ptr<device::DevInst>(device::File::create(name)));
}
void SigSession::release_device(device::DevInst *dev_inst)
_dev_inst = shared_ptr<device::DevInst>();
}
-void SigSession::load_file(const string &name,
- function<void (const QString)> error_handler)
-{
- stop_capture();
-
- if (sr_session_load(name.c_str()) == SR_OK) {
- GSList *devlist = NULL;
- sr_session_dev_list(&devlist);
-
- if (!devlist || !devlist->data ||
- sr_session_start() != SR_OK) {
- error_handler(tr("Failed to start session."));
- return;
- }
-
- shared_ptr<device::DevInst> dev_inst(
- new device::Device((sr_dev_inst*)devlist->data));
- g_slist_free(devlist);
-
- _decode_traces.clear();
- update_signals(dev_inst);
- read_sample_rate(dev_inst->dev_inst());
-
- _sampling_thread = boost::thread(
- &SigSession::load_session_thread_proc, this,
- error_handler);
-
- } else {
- sr_input *in = NULL;
-
- if (!(in = load_input_file_format(name.c_str(),
- error_handler)))
- return;
-
- _decode_traces.clear();
- update_signals(shared_ptr<device::DevInst>(
- new device::Device(in->sdi)));
- read_sample_rate(in->sdi);
-
- _sampling_thread = boost::thread(
- &SigSession::load_input_thread_proc, this,
- name, in, error_handler);
- }
-}
-
SigSession::capture_state SigSession::get_capture_state() const
{
lock_guard<mutex> lock(_sampling_mutex);
capture_state_changed(state);
}
-/**
- * Attempts to autodetect the format. Failing that
- * @param filename The filename of the input file.
- * @return A pointer to the 'struct sr_input_format' that should be used,
- * or NULL if no input format was selected or auto-detected.
- */
-sr_input_format* SigSession::determine_input_file_format(
- const string &filename)
-{
- int i;
-
- /* If there are no input formats, return NULL right away. */
- sr_input_format *const *const inputs = sr_input_list();
- if (!inputs) {
- g_critical("No supported input formats available.");
- return NULL;
- }
-
- /* Otherwise, try to find an input module that can handle this file. */
- for (i = 0; inputs[i]; i++) {
- if (inputs[i]->format_match(filename.c_str()))
- break;
- }
-
- /* Return NULL if no input module wanted to touch this. */
- if (!inputs[i]) {
- g_critical("Error: no matching input module found.");
- return NULL;
- }
-
- return inputs[i];
-}
-
-sr_input* SigSession::load_input_file_format(const string &filename,
- function<void (const QString)> error_handler,
- sr_input_format *format)
-{
- struct stat st;
- sr_input *in;
-
- if (!format && !(format =
- determine_input_file_format(filename.c_str()))) {
- /* The exact cause was already logged. */
- return NULL;
- }
-
- if (stat(filename.c_str(), &st) == -1) {
- error_handler(tr("Failed to load file"));
- return NULL;
- }
-
- /* Initialize the input module. */
- if (!(in = new sr_input)) {
- qDebug("Failed to allocate input module.\n");
- return NULL;
- }
-
- in->format = format;
- in->param = NULL;
- if (in->format->init &&
- in->format->init(in, filename.c_str()) != SR_OK) {
- qDebug("Input format init failed.\n");
- return NULL;
- }
-
- sr_session_new();
-
- if (sr_session_dev_add(in->sdi) != SR_OK) {
- qDebug("Failed to use device.\n");
- sr_session_destroy();
- return NULL;
- }
-
- return in;
-}
-
void SigSession::update_signals(shared_ptr<device::DevInst> dev_inst)
{
assert(dev_inst);
}
}
-void SigSession::load_session_thread_proc(
- function<void (const QString)> error_handler)
-{
- (void)error_handler;
-
- sr_session_datafeed_callback_add(data_feed_in_proc, NULL);
-
- set_capture_state(Running);
-
- sr_session_run();
-
- sr_session_destroy();
- set_capture_state(Stopped);
-
- // Confirm that SR_DF_END was received
- assert(!_cur_logic_snapshot);
- assert(_cur_analog_snapshots.empty());
-}
-
-void SigSession::load_input_thread_proc(const string name,
- sr_input *in, function<void (const QString)> error_handler)
-{
- (void)error_handler;
-
- assert(in);
- assert(in->format);
-
- sr_session_datafeed_callback_add(data_feed_in_proc, NULL);
-
- set_capture_state(Running);
-
- in->format->loadfile(in, name.c_str());
-
- sr_session_destroy();
- set_capture_state(Stopped);
-
- // Confirm that SR_DF_END was received
- assert(!_cur_logic_snapshot);
- assert(_cur_analog_snapshots.empty());
-
- delete in;
-}
-
void SigSession::sample_thread_proc(shared_ptr<device::DevInst> dev_inst,
function<void (const QString)> error_handler)
{
assert(dev_inst->dev_inst());
assert(error_handler);
- sr_session_new();
- sr_session_datafeed_callback_add(data_feed_in_proc, NULL);
+ read_sample_rate(dev_inst->dev_inst());
- if (sr_session_dev_add(dev_inst->dev_inst()) != SR_OK) {
- error_handler(tr("Failed to use device."));
- sr_session_destroy();
- return;
- }
-
- if (sr_session_start() != SR_OK) {
- error_handler(tr("Failed to start session."));
+ try {
+ dev_inst->start();
+ } catch(const QString e) {
+ error_handler(e);
return;
}
set_capture_state(dev_inst->is_trigger_enabled() ?
AwaitingTrigger : Running);
- sr_session_run();
- sr_session_destroy();
-
+ dev_inst->run();
set_capture_state(Stopped);
// Confirm that SR_DF_END was received
/**
* Sets device instance that will be used in the next capture session.
*/
- void set_device(boost::shared_ptr<device::DevInst> dev_inst);
+ void set_device(boost::shared_ptr<device::DevInst> dev_inst)
+ throw(QString);
- void release_device(device::DevInst *dev_inst);
+ void set_file(const std::string &name)
+ throw(QString);
- void load_file(const std::string &name,
- boost::function<void (const QString)> error_handler);
+ void release_device(device::DevInst *dev_inst);
capture_state get_capture_state() const;
boost::function<void (const QString)> error_handler,
sr_input_format *format = NULL);
- void load_session_thread_proc(
- boost::function<void (const QString)> error_handler);
-
- void load_input_thread_proc(const std::string name, sr_input *in,
- boost::function<void (const QString)> error_handler);
-
void sample_thread_proc(boost::shared_ptr<device::DevInst> dev_inst,
boost::function<void (const QString)> error_handler);
${PROJECT_SOURCE_DIR}/pv/data/signaldata.cpp
${PROJECT_SOURCE_DIR}/pv/device/device.cpp
${PROJECT_SOURCE_DIR}/pv/device/devinst.cpp
+ ${PROJECT_SOURCE_DIR}/pv/device/file.cpp
+ ${PROJECT_SOURCE_DIR}/pv/device/inputfile.cpp
+ ${PROJECT_SOURCE_DIR}/pv/device/sessionfile.cpp
${PROJECT_SOURCE_DIR}/pv/prop/int.cpp
${PROJECT_SOURCE_DIR}/pv/prop/property.cpp
${PROJECT_SOURCE_DIR}/pv/prop/string.cpp