Refactor device selection logic in OBCameraNodeDriver

This commit is contained in:
obyalian
2025-09-08 15:48:50 +08:00
parent 2ee4b200dd
commit 6735aee028
+3 -5
View File
@@ -275,11 +275,6 @@ void OBCameraNodeDriver::rebootDeviceCallback(
std::shared_ptr<ob::Device> OBCameraNodeDriver::selectDevice(
const std::shared_ptr<ob::DeviceList> &list) {
if (device_num_ == 1) {
RCLCPP_INFO_STREAM(logger_, "Connecting to the default device");
return list->getDevice(0);
}
std::shared_ptr<ob::Device> device = nullptr;
if (!serial_number_.empty()) {
RCLCPP_INFO_STREAM(logger_, "Connecting to device with serial number: " << serial_number_);
@@ -287,6 +282,9 @@ std::shared_ptr<ob::Device> OBCameraNodeDriver::selectDevice(
} else if (!usb_port_.empty()) {
RCLCPP_INFO_STREAM(logger_, "Connecting to device with usb port: " << usb_port_);
device = selectDeviceByUSBPort(list, usb_port_);
} else if (device_num_ == 1) {
RCLCPP_INFO_STREAM(logger_, "Connecting to the default device");
return list->getDevice(0);
}
if (device == nullptr) {
RCLCPP_WARN_THROTTLE(logger_, *get_clock(), 1000, "Device with serial number %s not found",