@@ -109,7 +109,8 @@ void OBCameraNodeDriver::onDeviceConnected(const std::shared_ptr<ob::DeviceList>
109109 pthread_mutex_lock (orb_device_lock_);
110110 std::shared_ptr<int > lock_holder (nullptr ,
111111 [this ](int *) { pthread_mutex_unlock (orb_device_lock_); });
112- RCLCPP_INFO_STREAM_THROTTLE (logger_, *get_clock (), 1000 , " device list count " << device_list->deviceCount ());
112+ RCLCPP_INFO_STREAM_THROTTLE (logger_, *get_clock (), 1000 ,
113+ " device list count " << device_list->deviceCount ());
113114 if (!device_) {
114115 try {
115116 startDevice (device_list);
@@ -275,38 +276,17 @@ std::shared_ptr<ob::Device> OBCameraNodeDriver::selectDeviceBySerialNumber(
275276
276277std::shared_ptr<ob::Device> OBCameraNodeDriver::selectDeviceByUSBPort (
277278 const std::shared_ptr<ob::DeviceList> &list, const std::string &usb_port) {
278- for (size_t i = 0 ; i < list->deviceCount (); i++) {
279- try {
280- auto pid = list->pid (i);
281- if (isOpenNIDevice (pid)) {
282- // openNI device
283- auto dev = list->getDevice (i);
284- auto device_info = dev->getDeviceInfo ();
285- std::string uid = device_info->uid ();
286- auto port_id = parseUsbPort (uid);
287- if (port_id == usb_port) {
288- RCLCPP_INFO_STREAM_THROTTLE (logger_, *get_clock (), 1000 ,
289- " Device port id " << port_id << " matched" );
290- return dev;
291- }
292- } else {
293- std::string uid = list->uid (i);
294- auto port_id = parseUsbPort (uid);
295- RCLCPP_ERROR_STREAM_THROTTLE (logger_, *get_clock (), 1000 , " Device usb port: " << uid);
296- if (port_id == usb_port) {
297- RCLCPP_INFO_STREAM_THROTTLE (logger_, *get_clock (), 1000 ,
298- " Device usb port " << uid << " matched" );
299- return list->getDevice (i);
300- }
301- }
302- } catch (ob::Error &e) {
303- RCLCPP_ERROR_STREAM (logger_, " Failed to get device info " << e.getMessage ());
304- } catch (std::exception &e) {
305- RCLCPP_ERROR_STREAM (logger_, " Failed to get device info " << e.what ());
306- } catch (...) {
307- RCLCPP_ERROR_STREAM (logger_, " Failed to get device info" );
308- }
279+ try {
280+ auto device = list->getDeviceByUid (usb_port.c_str ());
281+ return device;
282+ } catch (ob::Error &e) {
283+ RCLCPP_ERROR_STREAM (logger_, " Failed to get device info " << e.getMessage ());
284+ } catch (std::exception &e) {
285+ RCLCPP_ERROR_STREAM (logger_, " Failed to get device info " << e.what ());
286+ } catch (...) {
287+ RCLCPP_ERROR_STREAM (logger_, " Failed to get device info" );
309288 }
289+
310290 return nullptr ;
311291}
312292
0 commit comments