]> sigrok.org Git - pulseview.git/blobdiff - pv/dialogs/connect.cpp
Connect dialog: Fix constructor initialization order
[pulseview.git] / pv / dialogs / connect.cpp
index f7b0fc76004b9bf7e95b09aff53371b0f7deb5ac..f878d4997293bb47bb1d8cb348ed5fbc4e72d49f 100644 (file)
 
 #include <cassert>
 
-#include <libsigrok/libsigrok.hpp>
+#include <libsigrokcxx/libsigrokcxx.hpp>
+
+#include <QLabel>
 
 #include "connect.hpp"
 
-#include "pv/devicemanager.hpp"
+#include <pv/devicemanager.hpp>
+#include <pv/devices/hardwaredevice.hpp>
 
 using std::list;
 using std::map;
@@ -38,7 +41,8 @@ using Glib::VariantBase;
 using sigrok::ConfigKey;
 using sigrok::Driver;
 using sigrok::Error;
-using sigrok::HardwareDevice;
+
+using pv::devices::HardwareDevice;
 
 namespace pv {
 namespace dialogs {
@@ -50,8 +54,12 @@ Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
        form_(this),
        form_layout_(&form_),
        drivers_(&form_),
-       serial_device_(&form_),
-       scan_button_(tr("Scan for Devices"), this),
+       serial_devices_(&form_),
+       tcp_endpoint_(&form_),
+       tcp_endpoint_layout_(&tcp_endpoint_),
+       tcp_host_(&tcp_endpoint_),
+       tcp_port_(&tcp_endpoint_),
+       scan_button_(tr("&Scan for devices using driver above"), this),
        device_list_(this),
        button_box_(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
                Qt::Horizontal, this)
@@ -66,9 +74,19 @@ Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
                this, SLOT(device_selected(int)));
 
        form_.setLayout(&form_layout_);
-       form_layout_.addRow(tr("Driver"), &drivers_);
+       form_layout_.addRow(tr("&Driver"), &drivers_);
 
-       form_layout_.addRow(tr("Serial Port"), &serial_device_);
+       form_layout_.addRow(tr("Serial &Port"), &serial_devices_);
+       serial_devices_.setEditable(true);
+
+       tcp_host_.setPlaceholderText("192.168.1.100");
+       tcp_endpoint_layout_.addWidget(&tcp_host_);
+       tcp_endpoint_layout_.addWidget(new QLabel(":"));
+       tcp_port_.setRange(1, 65535);
+       tcp_port_.setValue(5555);
+       tcp_endpoint_layout_.addWidget(&tcp_port_);
+       tcp_endpoint_layout_.setContentsMargins(0, 0, 0, 0);
+       form_layout_.addRow(tr("TCP &Endpoint"), &tcp_endpoint_);
 
        unset_connection();
 
@@ -103,30 +121,50 @@ void Connect::populate_drivers()
                 * @todo Add support for non-monotonic devices i.e. DMMs
                 * and sensors.
                 */
-               bool supported_device = driver->config_check(
-                       ConfigKey::LOGIC_ANALYZER, ConfigKey::DEVICE_OPTIONS) |
-                                       driver->config_check(
-                       ConfigKey::OSCILLOSCOPE, ConfigKey::DEVICE_OPTIONS);
+               const auto keys = driver->config_keys();
+
+               bool supported_device = keys.count(ConfigKey::LOGIC_ANALYZER) |
+                       keys.count(ConfigKey::OSCILLOSCOPE);
 
                if (supported_device)
                        drivers_.addItem(QString("%1 (%2)").arg(
-                               driver->long_name().c_str()).arg(name.c_str()),
+                               driver->long_name().c_str()name.c_str()),
                                qVariantFromValue(driver));
        }
 }
 
+void Connect::populate_serials(shared_ptr<Driver> driver)
+{
+       serial_devices_.clear();
+       for (auto serial : device_manager_.context()->serials(driver))
+               serial_devices_.addItem(QString("%1 (%2)").arg(
+                       serial.first.c_str(), serial.second.c_str()),
+                       QString::fromStdString(serial.first));
+}
+
 void Connect::unset_connection()
 {
        device_list_.clear();
-       serial_device_.hide();
-       form_layout_.labelForField(&serial_device_)->hide();
+       serial_devices_.hide();
+       form_layout_.labelForField(&serial_devices_)->hide();
+       tcp_endpoint_.hide();
+       form_layout_.labelForField(&tcp_endpoint_)->hide();
        button_box_.button(QDialogButtonBox::Ok)->setDisabled(true);
 }
 
-void Connect::set_serial_connection()
+void Connect::set_serial_connection(shared_ptr<Driver> driver)
 {
-       serial_device_.show();
-       form_layout_.labelForField(&serial_device_)->show();
+       populate_serials(driver);
+       serial_devices_.show();
+       form_layout_.labelForField(&serial_devices_)->show();
+}
+
+void Connect::set_tcp_connection(shared_ptr<Driver> driver)
+{
+       (void)driver;
+
+       tcp_endpoint_.show();
+       form_layout_.labelForField(&tcp_endpoint_)->show();
 }
 
 void Connect::scan_pressed()
@@ -144,20 +182,38 @@ void Connect::scan_pressed()
 
        map<const ConfigKey *, VariantBase> drvopts;
 
-       if (serial_device_.isVisible())
+       if (serial_devices_.isVisible()) {
+               QString serial;
+               const int index = serial_devices_.currentIndex();
+               if (index >= 0 && index < serial_devices_.count() &&
+                   serial_devices_.currentText() == serial_devices_.itemText(index))
+                       serial = serial_devices_.itemData(index).value<QString>();
+               else
+                       serial = serial_devices_.currentText();
                drvopts[ConfigKey::CONN] = Variant<ustring>::create(
-                       serial_device_.text().toUtf8().constData());
+                       serial.toUtf8().constData());
+       }
 
-       list< shared_ptr<HardwareDevice> > devices =
+       if (tcp_endpoint_.isVisible()) {
+               QString host = tcp_host_.text();
+               QString port = tcp_port_.text();
+               if(!host.isEmpty()) {
+                       QString conn = QString("tcp-raw/%1/%2").arg(host, port);
+                       drvopts[ConfigKey::CONN] = Variant<ustring>::create(
+                               conn.toUtf8().constData());
+               }
+       }
+
+       const list< shared_ptr<HardwareDevice> > devices =
                device_manager_.driver_scan(driver, drvopts);
 
-       for (shared_ptr<HardwareDevice> device : devices)
-       {
+       for (shared_ptr<HardwareDevice> device : devices) {
                assert(device);
 
                QString text = QString::fromStdString(
-                       device_manager_.get_display_name(device));
-               text += QString(" with %1 channels").arg(device->channels().size());
+                       device->display_name(device_manager_));
+               text += QString(" with %1 channels").arg(
+                       device->device()->channels().size());
 
                QListWidgetItem *const item = new QListWidgetItem(text,
                        &device_list_);
@@ -176,8 +232,11 @@ void Connect::device_selected(int index)
 
        unset_connection();
 
-       if (driver->config_check(ConfigKey::SERIALCOMM, ConfigKey::SCAN_OPTIONS))
-                       set_serial_connection();
+       if (driver->scan_options().count(ConfigKey::SERIALCOMM))
+               set_serial_connection(driver);
+
+       if (driver->name() == "rigol-ds") // NBNB
+               set_tcp_connection(driver);
 }
 
 } // namespace dialogs