pv/data/logicsegment.cpp
pv/data/signaldata.cpp
pv/data/segment.cpp
+ pv/devices/device.cpp
+ pv/devices/hardwaredevice.cpp
+ pv/devices/sessionfile.cpp
pv/dialogs/about.cpp
pv/dialogs/connect.cpp
pv/dialogs/inputoutputoptions.cpp
#include <boost/algorithm/string/join.hpp>
#include <boost/filesystem.hpp>
+#include <pv/devices/hardwaredevice.hpp>
+
using boost::algorithm::join;
using std::dynamic_pointer_cast;
using sigrok::ConfigKey;
using sigrok::Context;
using sigrok::Driver;
-using sigrok::Device;
-using sigrok::HardwareDevice;
using sigrok::SessionDevice;
namespace pv {
return context_;
}
-const list< shared_ptr<HardwareDevice> >& DeviceManager::devices() const
+const list< shared_ptr<devices::HardwareDevice> >&
+DeviceManager::devices() const
{
return devices_;
}
-list< shared_ptr<HardwareDevice> > DeviceManager::driver_scan(
+list< shared_ptr<devices::HardwareDevice> >
+DeviceManager::driver_scan(
shared_ptr<Driver> driver, map<const ConfigKey *, VariantBase> drvopts)
{
- list< shared_ptr<HardwareDevice> > driver_devices;
+ list< shared_ptr<devices::HardwareDevice> > driver_devices;
assert(driver);
// Remove any device instances from this driver from the device
// list. They will not be valid after the scan.
- devices_.remove_if([&](shared_ptr<HardwareDevice> device) {
- return device->driver() == driver; });
+ devices_.remove_if([&](shared_ptr<devices::HardwareDevice> device) {
+ return device->hardware_device()->driver() == driver; });
// Do the scan
auto devices = driver->scan(drvopts);
- driver_devices.insert(driver_devices.end(), devices.begin(), devices.end());
// Add the scanned devices to the main list, set display names and sort.
- devices_.insert(devices_.end(), driver_devices.begin(),
- driver_devices.end());
-
- for (shared_ptr<Device> device : devices_)
- build_display_name(device);
-
- devices_.sort([&](shared_ptr<Device> a, shared_ptr<Device> b)
- { return compare_devices(a, b); });
+ for (shared_ptr<sigrok::HardwareDevice> device : devices) {
+ const shared_ptr<devices::HardwareDevice> d(
+ new devices::HardwareDevice(context_, device));
+ driver_devices.push_back(d);
+ }
- // As the display names depend on the complete devices_ list,
- // we need to recompute them. However, there is no need to
- // recomute all names of the devices_ list since only the
- // devices that use the given driver can be affected.
- for (shared_ptr<Device> device : driver_devices)
+ for (shared_ptr<devices::HardwareDevice> device : driver_devices)
build_display_name(device);
- driver_devices.sort([&](shared_ptr<Device> a, shared_ptr<Device> b)
+ devices_.insert(devices_.end(), driver_devices.begin(),
+ driver_devices.end());
+ devices_.sort([&](shared_ptr<devices::Device> a,
+ shared_ptr<devices::Device> b)
{ return compare_devices(a, b); });
return driver_devices;
}
const map<string, string> DeviceManager::get_device_info(
- shared_ptr<Device> device)
+ shared_ptr<devices::Device> device)
{
map<string, string> result;
assert(device);
- if (device->vendor().length() > 0)
- result["vendor"] = device->vendor();
- if (device->model().length() > 0)
- result["model"] = device->model();
- if (device->version().length() > 0)
- result["version"] = device->version();
- if (device->serial_number().length() > 0)
- result["serial_num"] = device->serial_number();
- if (device->connection_id().length() > 0)
- result["connection_id"] = device->connection_id();
+ const shared_ptr<sigrok::Device> sr_dev = device->device();
+ if (sr_dev->vendor().length() > 0)
+ result["vendor"] = sr_dev->vendor();
+ if (sr_dev->model().length() > 0)
+ result["model"] = sr_dev->model();
+ if (sr_dev->version().length() > 0)
+ result["version"] = sr_dev->version();
+ if (sr_dev->serial_number().length() > 0)
+ result["serial_num"] = sr_dev->serial_number();
+ if (sr_dev->connection_id().length() > 0)
+ result["connection_id"] = sr_dev->connection_id();
return result;
}
-const shared_ptr<HardwareDevice> DeviceManager::find_device_from_info(
+const shared_ptr<devices::HardwareDevice> DeviceManager::find_device_from_info(
const map<string, string> search_info)
{
- shared_ptr<HardwareDevice> last_resort_dev;
+ shared_ptr<devices::HardwareDevice> last_resort_dev;
map<string, string> dev_info;
- last_resort_dev = NULL;
-
- for (shared_ptr<HardwareDevice> dev : devices_) {
+ for (shared_ptr<devices::HardwareDevice> dev : devices_) {
assert(dev);
dev_info = get_device_info(dev);
return last_resort_dev;
}
-void DeviceManager::build_display_name(shared_ptr<Device> device)
+void DeviceManager::build_display_name(shared_ptr<devices::Device> device)
{
- auto session_device = dynamic_pointer_cast<SessionDevice>(device);
- auto hardware_device = dynamic_pointer_cast<HardwareDevice>(device);
+ const shared_ptr<sigrok::Device> sr_dev = device->device();
+ auto session_device = dynamic_pointer_cast<sigrok::SessionDevice>(sr_dev);
+ auto hardware_device = dynamic_pointer_cast<sigrok::HardwareDevice>(sr_dev);
if (session_device) {
full_names_[device] = display_names_[device] =
// First, build the device's full name. It always contains all
// possible information.
- vector<string> parts = {device->vendor(), device->model(),
- device->version(), device->serial_number()};
+ vector<string> parts = {sr_dev->vendor(), sr_dev->model(),
+ sr_dev->version(), sr_dev->serial_number()};
- if (device->connection_id().length() > 0)
- parts.push_back("("+device->connection_id()+")");
+ if (sr_dev->connection_id().length() > 0)
+ parts.push_back("("+sr_dev->connection_id()+")");
full_names_[device] = join(parts, " ");
// we have at least two such devices and need to distinguish them.
const bool multiple_dev = hardware_device && any_of(
devices_.begin(), devices_.end(),
- [&](shared_ptr<HardwareDevice> dev) {
- return (dev->vendor() == hardware_device->vendor() &&
- dev->model() == hardware_device->model()) &&
- dev != hardware_device;
+ [&](shared_ptr<devices::HardwareDevice> dev) {
+ return (dev->device()->vendor() == hardware_device->vendor() &&
+ dev->device()->model() == hardware_device->model()) &&
+ dev != device;
} );
- parts = {device->vendor(), device->model()};
+ parts = {sr_dev->vendor(), sr_dev->model()};
if (multiple_dev) {
- parts.push_back(device->version());
- parts.push_back(device->serial_number());
+ parts.push_back(sr_dev->version());
+ parts.push_back(sr_dev->serial_number());
- if ((device->serial_number().length() == 0) &&
- (device->connection_id().length() > 0))
- parts.push_back("("+device->connection_id()+")");
+ if ((sr_dev->serial_number().length() == 0) &&
+ (sr_dev->connection_id().length() > 0))
+ parts.push_back("("+sr_dev->connection_id()+")");
}
display_names_[device] = join(parts, " ");
}
-const std::string DeviceManager::get_display_name(std::shared_ptr<sigrok::Device> dev)
+const std::string DeviceManager::get_display_name(
+ std::shared_ptr<devices::Device> dev)
{
return display_names_[dev];
}
-const std::string DeviceManager::get_full_name(std::shared_ptr<sigrok::Device> dev)
+const std::string DeviceManager::get_full_name(
+ std::shared_ptr<devices::Device> dev)
{
return full_names_[dev];
}
-void DeviceManager::update_display_name(std::shared_ptr<sigrok::Device> dev)
+void DeviceManager::update_display_name(
+ std::shared_ptr<devices::Device> dev)
{
build_display_name(dev);
}
-bool DeviceManager::compare_devices(shared_ptr<Device> a,
- shared_ptr<Device> b)
+bool DeviceManager::compare_devices(
+ shared_ptr<devices::Device> a, shared_ptr<devices::Device> b)
{
assert(a);
assert(b);
class ConfigKey;
class Context;
class Driver;
-class Device;
-class HardwareDevice;
}
namespace pv {
+namespace devices {
+class Device;
+class HardwareDevice;
+}
+
class Session;
class DeviceManager
std::shared_ptr<sigrok::Context> context();
- const std::list< std::shared_ptr<sigrok::HardwareDevice> >&
+ const std::list< std::shared_ptr<devices::HardwareDevice> >&
devices() const;
- std::list< std::shared_ptr<sigrok::HardwareDevice> > driver_scan(
+ std::list< std::shared_ptr<devices::HardwareDevice> > driver_scan(
std::shared_ptr<sigrok::Driver> driver,
std::map<const sigrok::ConfigKey *, Glib::VariantBase> drvopts);
const std::map<std::string, std::string> get_device_info(
- const std::shared_ptr<sigrok::Device> device);
+ const std::shared_ptr<devices::Device> device);
- const std::shared_ptr<sigrok::HardwareDevice> find_device_from_info(
+ const std::shared_ptr<devices::HardwareDevice> find_device_from_info(
const std::map<std::string, std::string> search_info);
- void build_display_name(std::shared_ptr<sigrok::Device> device);
+ void build_display_name(std::shared_ptr<devices::Device> device);
- const std::string get_display_name(std::shared_ptr<sigrok::Device> dev);
+ const std::string get_display_name(
+ std::shared_ptr<devices::Device> dev);
- const std::string get_full_name(std::shared_ptr<sigrok::Device> dev);
+ const std::string get_full_name(std::shared_ptr<devices::Device> dev);
- void update_display_name(std::shared_ptr<sigrok::Device> dev);
+ void update_display_name(std::shared_ptr<devices::Device> dev);
private:
- bool compare_devices(std::shared_ptr<sigrok::Device> a,
- std::shared_ptr<sigrok::Device> b);
+ bool compare_devices(std::shared_ptr<devices::Device> a,
+ std::shared_ptr<devices::Device> b);
protected:
std::shared_ptr<sigrok::Context> context_;
- std::list< std::shared_ptr<sigrok::HardwareDevice> > devices_;
+ std::list< std::shared_ptr<devices::HardwareDevice> > devices_;
- std::map< std::shared_ptr<sigrok::Device>, std::string > display_names_;
- std::map< std::shared_ptr<sigrok::Device>, std::string > full_names_;
+ std::map< std::shared_ptr<devices::Device>, std::string > display_names_;
+ std::map< std::shared_ptr<devices::Device>, std::string > full_names_;
};
} // namespace pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2015 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 <libsigrokcxx/libsigrokcxx.hpp>
+
+#include "device.hpp"
+
+namespace pv {
+namespace devices {
+
+Device::Device() {
+}
+
+Device::~Device() {
+ if (session_)
+ session_->remove_datafeed_callbacks();
+}
+
+std::shared_ptr<sigrok::Session> Device::session() const {
+ return session_;
+}
+
+std::shared_ptr<sigrok::Device> Device::device() const {
+ return device_;
+}
+
+void Device::run() {
+ assert(device_);
+ assert(session_);
+ session_->run();
+}
+
+void Device::stop() {
+ assert(session_);
+ session_->stop();
+}
+
+} // namespace devices
+} // namespace pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2015 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_DEVICES_DEVICE_HPP
+#define PULSEVIEW_PV_DEVICES_DEVICE_HPP
+
+#include <memory>
+
+
+namespace sigrok {
+class Device;
+class Session;
+} // namespace sigrok
+
+namespace pv {
+namespace devices {
+
+class Device
+{
+protected:
+ Device();
+
+public:
+ virtual ~Device();
+
+ std::shared_ptr<sigrok::Session> session() const;
+
+ std::shared_ptr<sigrok::Device> device() const;
+
+ virtual void create() = 0;
+
+ virtual void run();
+
+ virtual void stop();
+
+protected:
+ std::shared_ptr<sigrok::Session> session_;
+ std::shared_ptr<sigrok::Device> device_;
+};
+
+} // namespace devices
+} // namespace pv
+
+#endif // PULSEVIEW_PV_DEVICES_DEVICE_HPP
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2015 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 <QString>
+
+#include <libsigrokcxx/libsigrokcxx.hpp>
+
+#include "hardwaredevice.hpp"
+
+using std::shared_ptr;
+using std::static_pointer_cast;
+
+namespace pv {
+namespace devices {
+
+HardwareDevice::HardwareDevice(const std::shared_ptr<sigrok::Context> &context,
+ std::shared_ptr<sigrok::HardwareDevice> device) :
+ context_(context) {
+ device_ = device;
+}
+
+HardwareDevice::~HardwareDevice() {
+ device_->close();
+ if (session_)
+ session_->remove_devices();
+}
+
+shared_ptr<sigrok::HardwareDevice> HardwareDevice::hardware_device() const {
+ return static_pointer_cast<sigrok::HardwareDevice>(device_);
+}
+
+void HardwareDevice::create() {
+ // Open the device
+ try {
+ device_->open();
+ } catch(const sigrok::Error &e) {
+ throw QString(e.what());
+ }
+
+ // Set up the session
+ session_ = context_->create_session();
+ session_->add_device(device_);
+}
+
+} // namespace devices
+} // namespace pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2015 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_DEVICES_HARDWAREDEVICE_HPP
+#define PULSEVIEW_PV_DEVICES_HARDWAREDEVICE_HPP
+
+#include "device.hpp"
+
+namespace sigrok {
+class Context;
+class HardwareDevice;
+} // sigrok
+
+namespace pv {
+namespace devices {
+
+class HardwareDevice final : public Device
+{
+public:
+ HardwareDevice(const std::shared_ptr<sigrok::Context> &context,
+ std::shared_ptr<sigrok::HardwareDevice> device);
+
+ ~HardwareDevice();
+
+ std::shared_ptr<sigrok::HardwareDevice> hardware_device() const;
+
+ void create();
+
+private:
+ const std::shared_ptr<sigrok::Context> context_;
+};
+
+} // namespace devices
+} // namespace pv
+
+#endif // PULSEVIEW_PV_DEVICES_HARDWAREDEVICE_HPP
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2015 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 <libsigrokcxx/libsigrokcxx.hpp>
+
+#include "sessionfile.hpp"
+
+namespace pv {
+namespace devices {
+
+SessionFile::SessionFile(const std::shared_ptr<sigrok::Context> &context,
+ const std::string &file_name) :
+ context_(context),
+ file_name_(file_name) {
+}
+
+void SessionFile::create() {
+ session_ = context_->load_session(file_name_);
+ device_ = session_->devices()[0];
+}
+
+} // namespace devices
+} // namespace pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2015 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_DEVICES_SESSIONFILE_HPP
+#define PULSEVIEW_PV_DEVICES_SESSIONFILE_HPP
+
+#include <string>
+#include <memory>
+
+#include "device.hpp"
+
+namespace sigrok {
+class Context;
+} // sigrok
+
+namespace pv {
+namespace devices {
+
+class SessionFile final : public Device
+{
+public:
+ SessionFile(const std::shared_ptr<sigrok::Context> &context,
+ const std::string &file_name);
+
+ void create();
+
+private:
+ const std::shared_ptr<sigrok::Context> &context_;
+ const std::string file_name_;
+};
+
+} // namespace devices
+} // namespace pv
+
+#endif // PULSEVIEW_PV_DEVICES_SESSIONFILE_HPP
#include "connect.hpp"
-#include "pv/devicemanager.hpp"
+#include <pv/devicemanager.hpp>
+#include <pv/devices/hardwaredevice.hpp>
using std::list;
using std::map;
using sigrok::ConfigKey;
using sigrok::Driver;
using sigrok::Error;
-using sigrok::HardwareDevice;
+
+using pv::devices::HardwareDevice;
namespace pv {
namespace dialogs {
serial.toUtf8().constData());
}
- list< shared_ptr<HardwareDevice> > devices =
+ const list< shared_ptr<HardwareDevice> > devices =
device_manager_.driver_scan(driver, drvopts);
for (shared_ptr<HardwareDevice> device : devices)
QString text = QString::fromStdString(
device_manager_.get_display_name(device));
- text += QString(" with %1 channels").arg(device->channels().size());
+ text += QString(" with %1 channels").arg(
+ device->device()->channels().size());
QListWidgetItem *const item = new QListWidgetItem(text,
&device_list_);
namespace sigrok {
class Driver;
+}
+
+namespace pv {
+namespace devices {
class HardwareDevice;
}
+}
Q_DECLARE_METATYPE(std::shared_ptr<sigrok::Driver>);
-Q_DECLARE_METATYPE(std::shared_ptr<sigrok::HardwareDevice>);
+Q_DECLARE_METATYPE(std::shared_ptr<pv::devices::HardwareDevice>);
namespace pv {
public:
Connect(QWidget *parent, pv::DeviceManager &device_manager);
- std::shared_ptr<sigrok::HardwareDevice> get_selected_device() const;
+ std::shared_ptr<devices::HardwareDevice> get_selected_device() const;
private:
void populate_drivers();
#include "mainwindow.hpp"
#include "devicemanager.hpp"
+#include "devices/hardwaredevice.hpp"
+#include "devices/sessionfile.hpp"
#include "dialogs/about.hpp"
#include "dialogs/connect.hpp"
#include "dialogs/inputoutputoptions.hpp"
using boost::algorithm::join;
-using sigrok::Device;
using sigrok::Error;
-using sigrok::HardwareDevice;
using sigrok::OutputFormat;
namespace pv {
}
}
-void MainWindow::select_device(shared_ptr<Device> device)
+void MainWindow::select_device(shared_ptr<devices::Device> device)
{
try {
session_.set_device(device);
{
QSettings settings;
- shared_ptr<HardwareDevice> device;
-
map<string, string> dev_info;
list<string> key_list;
string value;
dev_info.insert(std::make_pair(key, value));
}
- device = device_manager_.find_device_from_info(dev_info);
-
+ const shared_ptr<devices::HardwareDevice> device =
+ device_manager_.find_device_from_info(dev_info);
if (device) {
select_device(device);
update_device_list();
const QString infoMessage;
try {
- session_.set_session_file(file_name.toStdString());
+ session_.set_device(
+ shared_ptr<devices::Device>(new devices::SessionFile(
+ device_manager_.context(),
+ file_name.toStdString())));
} catch(Error e) {
show_session_error(tr("Failed to load ") + file_name, e.what());
session_.set_default_device();
void MainWindow::device_selected()
{
// Set the title to include the device/file name
- const shared_ptr<sigrok::Device> device = session_.device();
+ const shared_ptr<devices::Device> device = session_.device();
if (!device)
return;
class QVBoxLayout;
namespace sigrok {
-class Device;
class OutputFormat;
}
void run_stop();
- void select_device(std::shared_ptr<sigrok::Device> device);
+ void select_device(std::shared_ptr<devices::Device> device);
public Q_SLOTS:
void export_file(std::shared_ptr<sigrok::OutputFormat> format);
#include "channels.hpp"
#include <pv/binding/device.hpp>
+#include <pv/devices/device.hpp>
#include <pv/session.hpp>
#include <pv/view/signal.hpp>
// Create the layout
setLayout(&layout_);
- shared_ptr<sigrok::Device> device = session_.device();
+ const shared_ptr<sigrok::Device> device = session_.device()->device();
assert(device);
// Collect a set of signals
#include "data/logicsegment.hpp"
#include "data/decode/decoder.hpp"
+#include "devices/hardwaredevice.hpp"
+#include "devices/sessionfile.hpp"
+
#include "view/analogsignal.hpp"
#include "view/decodetrace.hpp"
#include "view/logicsignal.hpp"
using sigrok::ChannelType;
using sigrok::ConfigKey;
using sigrok::DatafeedCallbackFunction;
-using sigrok::Device;
using sigrok::Error;
-using sigrok::HardwareDevice;
using sigrok::Header;
using sigrok::Logic;
using sigrok::Meta;
namespace pv {
Session::Session(DeviceManager &device_manager) :
device_manager_(device_manager),
- session_(device_manager.context()->create_session()),
capture_state_(Stopped),
cur_samplerate_(0)
{
return device_manager_;
}
-const shared_ptr<sigrok::Session>& Session::session() const
+shared_ptr<sigrok::Session> Session::session() const
{
- return session_;
+ if (!device_)
+ return shared_ptr<sigrok::Session>();
+ return device_->session();
}
-shared_ptr<Device> Session::device() const
+shared_ptr<devices::Device> Session::device() const
{
return device_;
}
-void Session::set_device(shared_ptr<Device> device)
+void Session::set_device(shared_ptr<devices::Device> device)
{
+ assert(device);
+
// Ensure we are not capturing before setting the device
stop_capture();
- if (device_) {
- session_->remove_datafeed_callbacks();
-
- // Did we have a hardware device selected previously?
- if (!dynamic_pointer_cast<HardwareDevice>(device_)) {
- device_->close();
- session_->remove_devices();
- }
- }
+ device_ = std::move(device);
+ device_->create();
+ device_->session()->add_datafeed_callback([=]
+ (shared_ptr<sigrok::Device> device, shared_ptr<Packet> packet) {
+ data_feed_in(device, packet);
+ });
+ device_manager_.update_display_name(device_);
+ update_signals(device_);
decode_traces_.clear();
- if (device) {
- // Are we setting a session device?
- const auto session_device =
- dynamic_pointer_cast<SessionDevice>(device);
-
- if (session_device)
- session_ = session_device->parent();
- else {
- session_ = device_manager_.context()->create_session();
-
- try {
- device->open();
- } catch(const sigrok::Error &e) {
- throw QString(e.what());
- }
-
- session_->add_device(device);
- }
-
- device_ = device;
- session_->add_datafeed_callback([=]
- (shared_ptr<Device> device, shared_ptr<Packet> packet) {
- data_feed_in(device, packet);
- });
- device_manager_.update_display_name(device);
- update_signals(device);
- } else
- device_ = nullptr;
-
device_selected();
}
-void Session::set_session_file(const string &name)
-{
- const shared_ptr<sigrok::Session> session =
- device_manager_.context()->load_session(name);
- set_device(session->devices()[0]);
-}
-
void Session::set_default_device()
{
- shared_ptr<HardwareDevice> default_device;
- const list< shared_ptr<HardwareDevice> > &devices =
+ const list< shared_ptr<devices::HardwareDevice> > &devices =
device_manager_.devices();
- if (!devices.empty()) {
- // Fall back to the first device in the list.
- default_device = devices.front();
-
- // Try and find the demo device and select that by default
- for (shared_ptr<HardwareDevice> dev : devices)
- if (dev->driver()->name().compare("demo") == 0) {
- default_device = dev;
- break;
- }
+ if (devices.empty())
+ return;
- set_device(default_device);
- }
+ // Try and find the demo device and select that by default
+ const auto iter = std::find_if(devices.begin(), devices.end(),
+ [] (const shared_ptr<devices::HardwareDevice> &d) {
+ return d->hardware_device()->driver()->name() ==
+ "demo"; });
+ set_device((iter == devices.end()) ? devices.front() : *iter);
}
Session::capture_state Session::get_capture_state() const
{
stop_capture();
- // Check that a device instance has been selected.
- if (!device_) {
- qDebug() << "No device selected";
- return;
- }
-
// Check that at least one channel is enabled
- auto channels = device_->channels();
+ assert(device_);
+ const std::shared_ptr<sigrok::Device> device = device_->device();
+ assert(device);
+ auto channels = device->channels();
bool enabled = std::any_of(channels.begin(), channels.end(),
[](shared_ptr<Channel> channel) { return channel->enabled(); });
void Session::stop_capture()
{
if (get_capture_state() != Stopped)
- session_->stop();
+ device_->stop();
// Check that sampling stopped
if (sampling_thread_.joinable())
capture_state_changed(state);
}
-void Session::update_signals(shared_ptr<Device> device)
+void Session::update_signals(shared_ptr<devices::Device> device)
{
assert(device);
assert(capture_state_ == Stopped);
// Detect what data types we will receive
- auto channels = device->channels();
+ auto channels = device->device()->channels();
unsigned int logic_channel_count = std::count_if(
channels.begin(), channels.end(),
[] (shared_ptr<Channel> channel) {
unordered_set< shared_ptr<view::Signal> > prev_sigs(signals_);
signals_.clear();
- for (auto channel : device->channels()) {
+ for (auto channel : device->device()->channels()) {
shared_ptr<view::Signal> signal;
// Find the channel in the old signals
return shared_ptr<view::Signal>();
}
-void Session::read_sample_rate(shared_ptr<Device> device)
+void Session::read_sample_rate(shared_ptr<sigrok::Device> device)
{
- const auto keys = device_->config_keys(ConfigKey::DEVICE_OPTIONS);
+ assert(device);
+ const auto keys = device->config_keys(ConfigKey::DEVICE_OPTIONS);
const auto iter = keys.find(ConfigKey::SAMPLERATE);
cur_samplerate_ = (iter != keys.end() &&
(*iter).second.find(sigrok::GET) != (*iter).second.end()) ?
device->config_get(ConfigKey::SAMPLERATE)).get() : 0;
}
-void Session::sample_thread_proc(shared_ptr<Device> device,
+void Session::sample_thread_proc(shared_ptr<devices::Device> device,
function<void (const QString)> error_handler)
{
assert(device);
assert(error_handler);
- read_sample_rate(device);
+ const std::shared_ptr<sigrok::Device> sr_dev = device->device();
+ assert(sr_dev);
+ read_sample_rate(sr_dev);
try {
- session_->start();
+ device_->session()->start();
} catch(Error e) {
error_handler(e.what());
return;
}
- set_capture_state(session_->trigger() ?
+ set_capture_state(device_->session()->trigger() ?
AwaitingTrigger : Running);
- session_->run();
+ device_->run();
set_capture_state(Stopped);
// Confirm that SR_DF_END was received
}
}
-void Session::feed_in_header(shared_ptr<Device> device)
+void Session::feed_in_header()
{
- read_sample_rate(device);
+ read_sample_rate(device_->device());
}
-void Session::feed_in_meta(shared_ptr<Device> device,
- shared_ptr<Meta> meta)
+void Session::feed_in_meta(shared_ptr<Meta> meta)
{
- (void)device;
-
for (auto entry : meta->config()) {
switch (entry.first->id()) {
case SR_CONF_SAMPLERATE:
set_capture_state(Running);
// Get sample limit.
- const auto keys = device_->config_keys(
+ assert(device_);
+ const std::shared_ptr<sigrok::Device> device =
+ device_->device();
+ assert(device);
+ const auto keys = device->config_keys(
ConfigKey::DEVICE_OPTIONS);
const auto iter = keys.find(ConfigKey::LIMIT_SAMPLES);
const uint64_t sample_limit = (iter != keys.end() &&
(*iter).second.find(sigrok::GET) !=
(*iter).second.end()) ?
VariantBase::cast_dynamic<Variant<guint64>>(
- device_->config_get(ConfigKey::LIMIT_SAMPLES)).get() : 0;
+ device->config_get(ConfigKey::LIMIT_SAMPLES)).get() : 0;
// Create a new data segment
cur_logic_segment_ = shared_ptr<data::LogicSegment>(
// Get sample limit.
uint64_t sample_limit;
try {
+ assert(device_);
+ const std::shared_ptr<sigrok::Device> device =
+ device_->device();
+ assert(device);
sample_limit = VariantBase::cast_dynamic<Variant<guint64>>(
- device_->config_get(ConfigKey::LIMIT_SAMPLES)).get();
+ device->config_get(ConfigKey::LIMIT_SAMPLES)).get();
} catch (Error) {
sample_limit = 0;
}
data_received();
}
-void Session::data_feed_in(shared_ptr<Device> device, shared_ptr<Packet> packet)
+void Session::data_feed_in(shared_ptr<sigrok::Device> device,
+ shared_ptr<Packet> packet)
{
+ (void)device;
+
assert(device);
+ assert(device == device_->device());
assert(packet);
switch (packet->type()->id()) {
case SR_DF_HEADER:
- feed_in_header(device);
+ feed_in_header();
break;
case SR_DF_META:
- feed_in_meta(device, dynamic_pointer_cast<Meta>(packet->payload()));
+ feed_in_meta(dynamic_pointer_cast<Meta>(packet->payload()));
break;
case SR_DF_FRAME_BEGIN:
class SignalData;
}
+namespace devices {
+class Device;
+}
+
namespace view {
class DecodeTrace;
class LogicSignal;
const DeviceManager& device_manager() const;
- const std::shared_ptr<sigrok::Session>& session() const;
+ std::shared_ptr<sigrok::Session> session() const;
- std::shared_ptr<sigrok::Device> device() const;
+ std::shared_ptr<devices::Device> device() const;
/**
* Sets device instance that will be used in the next capture session.
*/
- void set_device(std::shared_ptr<sigrok::Device> device);
-
- /**
- * Sets a sigrok session file as the capture device.
- * @param name the path to the file.
- */
- void set_session_file(const std::string &name);
+ void set_device(std::shared_ptr<devices::Device> device);
void set_default_device();
private:
void set_capture_state(capture_state state);
- void update_signals(std::shared_ptr<sigrok::Device> device);
+ void update_signals(std::shared_ptr<devices::Device> device);
std::shared_ptr<view::Signal> signal_from_channel(
std::shared_ptr<sigrok::Channel> channel) const;
- void read_sample_rate(std::shared_ptr<sigrok::Device>);
+ void read_sample_rate(std::shared_ptr<sigrok::Device> device);
private:
- void sample_thread_proc(std::shared_ptr<sigrok::Device> device,
+ void sample_thread_proc(std::shared_ptr<devices::Device> device,
std::function<void (const QString)> error_handler);
- void feed_in_header(std::shared_ptr<sigrok::Device> device);
+ void feed_in_header();
- void feed_in_meta(std::shared_ptr<sigrok::Device> device,
- std::shared_ptr<sigrok::Meta> meta);
+ void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
void feed_in_frame_begin();
private:
DeviceManager &device_manager_;
- std::shared_ptr<sigrok::Session> session_;
-
- /**
- * The device instance that will be used in the next capture session.
- */
- std::shared_ptr<sigrok::Device> device_;
+ std::shared_ptr<devices::Device> device_;
std::vector< std::shared_ptr<view::DecodeTrace> > decode_traces_;
#include <pv/session.hpp>
#include <pv/data/logic.hpp>
#include <pv/data/logicsegment.hpp>
+#include <pv/devices/device.hpp>
#include <pv/view/signal.hpp>
#include <libsigrokcxx/libsigrokcxx.hpp>
// Begin storing
try {
const auto context = session_.device_manager().context();
- auto device = session_.device();
+ auto device = session_.device()->device();
map<string, Glib::VariantBase> options = options_;
#include "mainbar.hpp"
#include <pv/devicemanager.hpp>
+#include <pv/devices/hardwaredevice.hpp>
#include <pv/mainwindow.hpp>
#include <pv/popups/deviceoptions.hpp>
#include <pv/popups/channels.hpp>
using sigrok::Capability;
using sigrok::ConfigKey;
-using sigrok::Device;
using sigrok::Error;
namespace pv {
void MainBar::update_device_list()
{
DeviceManager &mgr = session_.device_manager();
- shared_ptr<Device> selected_device = session_.device();
- list< shared_ptr<Device> > devs;
+ shared_ptr<devices::Device> selected_device = session_.device();
+ list< shared_ptr<devices::Device> > devs;
copy(mgr.devices().begin(), mgr.devices().end(), back_inserter(devs));
if (updating_sample_rate_)
return;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> device =
+ device_selector_.selected_device();
if (!device)
return;
assert(!updating_sample_rate_);
updating_sample_rate_ = true;
- const auto keys = device->config_keys(ConfigKey::DEVICE_OPTIONS);
+ const shared_ptr<sigrok::Device> sr_dev = device->device();
+ const auto keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS);
const auto iter = keys.find(ConfigKey::SAMPLERATE);
if (iter != keys.end() &&
(*iter).second.find(sigrok::LIST) != (*iter).second.end()) {
try {
- gvar_dict = device->config_list(ConfigKey::SAMPLERATE);
+ gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
} catch(const sigrok::Error &e) {
// Failed to enunmerate samplerate
(void)e;
if (updating_sample_rate_)
return;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> device =
+ device_selector_.selected_device();
if (!device)
return;
try {
- auto gvar = device->config_get(ConfigKey::SAMPLERATE);
+ auto gvar = device->device()->config_get(ConfigKey::SAMPLERATE);
uint64_t samplerate =
Glib::VariantBase::cast_dynamic<Glib::Variant<guint64>>(gvar).get();
assert(!updating_sample_rate_);
if (updating_sample_count_)
return;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> device =
+ device_selector_.selected_device();
if (!device)
return;
+ const shared_ptr<sigrok::Device> sr_dev = device->device();
+
assert(!updating_sample_count_);
updating_sample_count_ = true;
if (sample_count == 0)
sample_count = DefaultSampleCount;
- const auto keys = device->config_keys(ConfigKey::DEVICE_OPTIONS);
+ const auto keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS);
const auto iter = keys.find(ConfigKey::LIMIT_SAMPLES);
if (iter != keys.end() &&
(*iter).second.find(sigrok::LIST) != (*iter).second.end()) {
try {
auto gvar =
- device->config_list(ConfigKey::LIMIT_SAMPLES);
+ sr_dev->config_list(ConfigKey::LIMIT_SAMPLES);
if (gvar.gobj())
g_variant_get(gvar.gobj(), "(tt)",
&min_sample_count, &max_sample_count);
min_sample_count, max_sample_count);
try {
- auto gvar = device->config_get(ConfigKey::LIMIT_SAMPLES);
+ auto gvar = sr_dev->config_get(ConfigKey::LIMIT_SAMPLES);
sample_count = g_variant_get_uint64(gvar.gobj());
if (sample_count == 0)
sample_count = DefaultSampleCount;
{
using namespace pv::popups;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> device =
+ device_selector_.selected_device();
if (!device)
return;
+ const shared_ptr<sigrok::Device> sr_dev = device->device();
+ if (!sr_dev)
+ return;
+
// Update the configure popup
- DeviceOptions *const opts = new DeviceOptions(device, this);
+ DeviceOptions *const opts = new DeviceOptions(sr_dev, this);
configure_button_action_->setVisible(
!opts->binding().properties().empty());
configure_button_.set_popup(opts);
sample_count_supported_ = false;
try {
- for (auto entry : device->config_keys(ConfigKey::DEVICE_OPTIONS))
+ for (auto entry : sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS))
{
auto key = entry.first;
auto capabilities = entry.second;
case SR_CONF_LIMIT_FRAMES:
if (capabilities.count(Capability::SET))
{
- device->config_set(ConfigKey::LIMIT_FRAMES,
+ sr_dev->config_set(ConfigKey::LIMIT_FRAMES,
Glib::Variant<guint64>::create(1));
on_config_changed();
}
if (updating_sample_count_)
return;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> device =
+ device_selector_.selected_device();
if (!device)
return;
+ const shared_ptr<sigrok::Device> sr_dev = device->device();
+
sample_count = sample_count_.value();
// Set the sample count
if (sample_count_supported_)
{
try {
- device->config_set(ConfigKey::LIMIT_SAMPLES,
+ sr_dev->config_set(ConfigKey::LIMIT_SAMPLES,
Glib::Variant<guint64>::create(sample_count));
on_config_changed();
} catch (Error error) {
if (updating_sample_rate_)
return;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> device =
+ device_selector_.selected_device();
if (!device)
return;
+ const shared_ptr<sigrok::Device> sr_dev = device->device();
+
sample_rate = sample_rate_.value();
if (sample_rate == 0)
return;
assert(!updating_sample_rate_);
updating_sample_rate_ = true;
try {
- device->config_set(ConfigKey::SAMPLERATE,
+ sr_dev->config_set(ConfigKey::SAMPLERATE,
Glib::Variant<guint64>::create(sample_rate));
on_config_changed();
} catch (Error error) {
void MainBar::on_device_selected()
{
- shared_ptr<Device> device = device_selector_.selected_device();
+ shared_ptr<devices::Device> device = device_selector_.selected_device();
if (!device)
return;
#include <pv/session.hpp>
#include <pv/devicemanager.hpp>
+#include <pv/devices/device.hpp>
#include <pv/data/logic.hpp>
#include <pv/data/logicsegment.hpp>
#include <pv/view/view.hpp>
using sigrok::Channel;
using sigrok::ConfigKey;
-using sigrok::Device;
using sigrok::Error;
using sigrok::Trigger;
using sigrok::TriggerStage;
LogicSignal::LogicSignal(
pv::Session &session,
- shared_ptr<Device> device,
+ shared_ptr<devices::Device> device,
shared_ptr<Channel> channel,
shared_ptr<data::Logic> data) :
Signal(session, channel),
const vector<int32_t> LogicSignal::get_trigger_types() const
{
- const auto keys = device_->config_keys(ConfigKey::DEVICE_OPTIONS);
+ const auto sr_dev = device_->device();
+ const auto keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS);
const auto iter = keys.find(ConfigKey::TRIGGER_MATCH);
if (iter != keys.end() &&
(*iter).second.find(sigrok::LIST) != (*iter).second.end()) {
try {
const Glib::VariantContainerBase gvar =
- device_->config_list(ConfigKey::TRIGGER_MATCH);
+ sr_dev->config_list(ConfigKey::TRIGGER_MATCH);
return Glib::VariantBase::cast_dynamic<
Glib::Variant<vector<int32_t>>>(gvar).get();
} catch (Error e) {
class QToolBar;
namespace sigrok {
-class Device;
class TriggerMatchType;
}
namespace pv {
+namespace devices {
+class Device;
+}
+
namespace data {
class Logic;
}
public:
LogicSignal(pv::Session &session,
- std::shared_ptr<sigrok::Device> device,
+ std::shared_ptr<devices::Device> device,
std::shared_ptr<sigrok::Channel> channel,
std::shared_ptr<pv::data::Logic> data);
void on_trigger();
private:
- std::shared_ptr<sigrok::Device> device_;
+ std::shared_ptr<pv::devices::Device> device_;
std::shared_ptr<pv::data::Logic> data_;
const sigrok::TriggerMatchType *trigger_match_;
#include "viewport.hpp"
#include "pv/session.hpp"
+#include "pv/devices/device.hpp"
#include "pv/data/logic.hpp"
#include "pv/data/logicsegment.hpp"
#include "pv/util.hpp"
// Populate the traces
clear_child_items();
- shared_ptr<sigrok::Device> device = session_.device();
+ shared_ptr<sigrok::Device> device = session_.device()->device();
assert(device);
// Collect a set of signals
#include <libsigrokcxx/libsigrokcxx.hpp>
#include <pv/devicemanager.hpp>
+#include <pv/devices/device.hpp>
#include "devicetoolbutton.hpp"
using std::weak_ptr;
using std::vector;
-using sigrok::Device;
+using pv::devices::Device;
namespace pv {
namespace widgets {
struct srd_decoder;
-namespace sigrok {
-class Device;
-}
-
namespace pv {
class DeviceManager;
+namespace devices {
+class Device;
+}
+
namespace widgets {
class DeviceToolButton : public QToolButton
/**
* Returns a reference to the selected device.
*/
- std::shared_ptr<sigrok::Device> selected_device();
+ std::shared_ptr<devices::Device> selected_device();
/**
* Sets the current list of devices.
* @param selected_device the currently active device.
*/
void set_device_list(
- const std::list< std::shared_ptr<sigrok::Device> > &devices,
- std::shared_ptr<sigrok::Device> selected);
+ const std::list< std::shared_ptr<devices::Device> > &devices,
+ std::shared_ptr<devices::Device> selected);
private:
/**
QMenu menu_;
QSignalMapper mapper_;
- std::shared_ptr<sigrok::Device> selected_device_;
- std::vector< std::weak_ptr<sigrok::Device> > devices_;
+ std::shared_ptr<devices::Device> selected_device_;
+ std::vector< std::weak_ptr<devices::Device> > devices_;
QString device_tooltip_;
};