]> sigrok.org Git - pulseview.git/commitdiff
Connect dialog: Add support for connecting to raw-tcp devices
authorwhitequark <redacted>
Thu, 9 Jun 2016 03:02:52 +0000 (05:02 +0200)
committerUwe Hermann <redacted>
Sun, 26 Jun 2016 17:10:23 +0000 (19:10 +0200)
This fixes bug #769.

pv/dialogs/connect.cpp
pv/dialogs/connect.hpp

index 997234be76dc1815f229dd54ae56a7559eab730d..af01b6cf6e47e6f07ae251b5104d90d7d3e6b599 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
+#include <QLabel>
+
 #include "connect.hpp"
 
 #include <pv/devicemanager.hpp>
@@ -47,6 +49,10 @@ namespace dialogs {
 
 Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
        QDialog(parent),
+       tcp_endpoint_(&form_),
+       tcp_endpoint_layout_(&tcp_endpoint_),
+       tcp_host_(&tcp_endpoint_),
+       tcp_port_(&tcp_endpoint_),
        device_manager_(device_manager),
        layout_(this),
        form_(this),
@@ -73,6 +79,15 @@ Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) :
        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();
 
        connect(&scan_button_, SIGNAL(pressed()),
@@ -132,6 +147,8 @@ void Connect::unset_connection()
        device_list_.clear();
        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);
 }
 
@@ -142,6 +159,14 @@ void Connect::set_serial_connection(shared_ptr<Driver> driver)
        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()
 {
        device_list_.clear();
@@ -169,6 +194,16 @@ void Connect::scan_pressed()
                        serial.toUtf8().constData());
        }
 
+       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);
 
@@ -199,6 +234,9 @@ void Connect::device_selected(int index)
 
        if (driver->scan_options().count(ConfigKey::SERIALCOMM))
                set_serial_connection(driver);
+
+       if (driver->name() == "rigol-ds") // NBNB
+               set_tcp_connection(driver);
 }
 
 } // namespace dialogs
index a8f793ac1dc3e8f4b73ee9b9f86ead60c19343c6..0cb50fbff060edd6bcb6c4c5e554a19ca18fb0fd 100644 (file)
@@ -27,7 +27,9 @@
 #include <QDialog>
 #include <QDialogButtonBox>
 #include <QFormLayout>
+#include <QHBoxLayout>
 #include <QLineEdit>
+#include <QSpinBox>
 #include <QListWidget>
 #include <QPushButton>
 #include <QVBoxLayout>
@@ -68,6 +70,7 @@ private:
        void unset_connection();
 
        void set_serial_connection(std::shared_ptr<sigrok::Driver> driver);
+       void set_tcp_connection(std::shared_ptr<sigrok::Driver> driver);
 
 private Q_SLOTS:
        void device_selected(int index);
@@ -86,6 +89,11 @@ private:
 
        QComboBox serial_devices_;
 
+       QWidget tcp_endpoint_;
+       QHBoxLayout tcp_endpoint_layout_;
+       QLineEdit tcp_host_;
+       QSpinBox tcp_port_;
+
        QPushButton scan_button_;
        QListWidget device_list_;