From ebfc45e55010c11f03e811e0194da5bbe4ef00e7 Mon Sep 17 00:00:00 2001 From: Martin Guenther Date: Wed, 21 Dec 2016 17:51:26 +0100 Subject: [PATCH 1/2] Don't connect to any device if URI cannot be resolved Fixes #35. --- src/openni2_driver.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/openni2_driver.cpp b/src/openni2_driver.cpp index 6e1d62c..02d2f89 100644 --- a/src/openni2_driver.cpp +++ b/src/openni2_driver.cpp @@ -716,10 +716,11 @@ std::string OpenNI2Driver::resolveDeviceURI(const std::string& device_id) throw( } } } - return matched_uri; + if (match_found) + return matched_uri; + else + return "INVALID"; } - - return "INVALID"; } void OpenNI2Driver::initDevice() From 6666fdb682d4eb101fc51b284866baea3ba7f223 Mon Sep 17 00:00:00 2001 From: Martin Guenther Date: Wed, 21 Dec 2016 17:52:10 +0100 Subject: [PATCH 2/2] Make @ device_id format work Without this patch, things like `device_id = '2@0'` worked (meaning any device on bus 2), but `device_id = '2@8'` (meaning device number 8 on bus 2) didn't. --- src/openni2_driver.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/openni2_driver.cpp b/src/openni2_driver.cpp index 02d2f89..dc9392d 100644 --- a/src/openni2_driver.cpp +++ b/src/openni2_driver.cpp @@ -652,7 +652,7 @@ std::string OpenNI2Driver::resolveDeviceURI(const std::string& device_id) throw( if (index >= device_id.size() - 1) { THROW_OPENNI_EXCEPTION( - "%s is not a valid device URI, you must give a number after the @, specify 0 for first device", + "%s is not a valid device URI, you must give the device number after the @, specify 0 for any device on this bus", device_id.c_str()); } @@ -671,8 +671,9 @@ std::string OpenNI2Driver::resolveDeviceURI(const std::string& device_id) throw( if (s.find(bus) != std::string::npos) { // this matches our bus, check device number - --device_number; - if (device_number <= 0) + std::ostringstream ss; + ss << bus << '/' << device_number; + if (device_number == 0 || s.find(ss.str()) != std::string::npos) return s; } }