Can be used instead of selecting the device via the dropdown menu.

Example:

pulseview -d "lecroy-xstream:vxi/10.12.27.210"

Signed-off-by: Sven Schnelle <sv...@stackframe.org>
---
 main.cpp             | 10 +++++++---
 pv/devicemanager.cpp | 24 ++++++++++++++++++++++++
 pv/devicemanager.hpp |  1 +
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/main.cpp b/main.cpp
index 0881c18..ceb18d1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
 {
        int ret = 0;
        std::shared_ptr<sigrok::Context> context;
-       std::string open_file, open_file_format;
+       std::string open_file, open_file_format, device;
 
        Application a(argc, argv);
 
@@ -88,11 +88,12 @@ int main(int argc, char *argv[])
                        {"loglevel", required_argument, nullptr, 'l'},
                        {"input-file", required_argument, nullptr, 'i'},
                        {"input-format", required_argument, nullptr, 'I'},
+                       {"device", required_argument, nullptr, 'd'},
                        {nullptr, 0, nullptr, 0}
                };
 
                const int c = getopt_long(argc, argv,
-                       "l:Vh?i:I:", long_options, nullptr);
+                       "l:Vh?i:I:d:", long_options, nullptr);
                if (c == -1)
                        break;
 
@@ -126,6 +127,9 @@ int main(int argc, char *argv[])
                case 'I':
                        open_file_format = optarg;
                        break;
+               case 'd':
+                       device = optarg;
+                       break;
                }
        }
 
@@ -156,7 +160,7 @@ int main(int argc, char *argv[])
 
                try {
                        // Create the device manager, initialise the drivers
-                       pv::DeviceManager device_manager(context);
+                       pv::DeviceManager device_manager(context, device);
 
                        // Initialise the main window
                        pv::MainWindow w(device_manager,
diff --git a/pv/devicemanager.cpp b/pv/devicemanager.cpp
index 9e3944b..b3d73ff 100644
--- a/pv/devicemanager.cpp
+++ b/pv/devicemanager.cpp
@@ -50,6 +50,9 @@ using std::vector;
 
 using Glib::VariantBase;
 
+using Glib::ustring;
+using Glib::Variant;
+
 using sigrok::ConfigKey;
 using sigrok::Context;
 using sigrok::Driver;
@@ -64,6 +67,27 @@ DeviceManager::DeviceManager(shared_ptr<Context> context) :
                driver_scan(entry.second, map<const ConfigKey *, 
VariantBase>());
 }
 
+DeviceManager::DeviceManager(shared_ptr<Context> context, std::string conn) :
+       context_(context)
+{
+       std::string driver_name = conn;
+       size_t npos = driver_name.find(":");
+       map<const ConfigKey *, VariantBase> drvopts;
+
+       if (npos != std::string::npos) {
+               driver_name.resize(npos);
+               drvopts[ConfigKey::CONN] = 
Variant<ustring>::create(conn.substr(npos+1));
+       }
+
+       for (auto entry : context->drivers()) {
+               shared_ptr<Driver> driver = entry.second;
+               if (!driver_name.empty() && driver->name() != driver_name)
+                       continue;
+
+               driver_scan(entry.second, drvopts);
+       }
+}
+
 const std::shared_ptr<sigrok::Context>& DeviceManager::context() const
 {
        return context_;
diff --git a/pv/devicemanager.hpp b/pv/devicemanager.hpp
index 145f9e8..bc03238 100644
--- a/pv/devicemanager.hpp
+++ b/pv/devicemanager.hpp
@@ -48,6 +48,7 @@ class DeviceManager
 {
 public:
        DeviceManager(std::shared_ptr<sigrok::Context> context);
+       DeviceManager(std::shared_ptr<sigrok::Context> context, std::string 
conn);
 
        ~DeviceManager() = default;
 
-- 
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to