| 491 | } |
| 492 | |
| 493 | void enumerateDevices() |
| 494 | { |
| 495 | if (!initialized) |
| 496 | return; |
| 497 | |
| 498 | LOG_INFO << "enumerating devices..."; |
| 499 | libusb_device **device_list; |
| 500 | int num_devices = libusb_get_device_list(usb_context_, &device_list); |
| 501 | |
| 502 | LOG_INFO << num_devices << " usb devices connected"; |
| 503 | |
| 504 | if(num_devices > 0) |
| 505 | { |
| 506 | for(int idx = 0; idx < num_devices; ++idx) |
| 507 | { |
| 508 | libusb_device *dev = device_list[idx]; |
| 509 | libusb_device_descriptor dev_desc; |
| 510 | |
| 511 | int r = libusb_get_device_descriptor(dev, &dev_desc); // this is always successful |
| 512 | |
| 513 | if(dev_desc.idVendor == Freenect2Device::VendorId && (dev_desc.idProduct == Freenect2Device::ProductId || dev_desc.idProduct == Freenect2Device::ProductIdPreview)) |
| 514 | { |
| 515 | Freenect2DeviceImpl *freenect2_dev; |
| 516 | |
| 517 | // prevent error if device is already open |
| 518 | if(tryGetDevice(dev, &freenect2_dev)) |
| 519 | { |
| 520 | UsbDeviceWithSerial dev_with_serial; |
| 521 | dev_with_serial.dev = dev; |
| 522 | dev_with_serial.serial = freenect2_dev->getSerialNumber(); |
| 523 | |
| 524 | enumerated_devices_.push_back(dev_with_serial); |
| 525 | continue; |
| 526 | } |
| 527 | else |
| 528 | { |
| 529 | libusb_device_handle *dev_handle; |
| 530 | r = libusb_open(dev, &dev_handle); |
| 531 | |
| 532 | if(r == LIBUSB_SUCCESS) |
| 533 | { |
| 534 | unsigned char buffer[1024]; |
| 535 | r = libusb_get_string_descriptor_ascii(dev_handle, dev_desc.iSerialNumber, buffer, sizeof(buffer)); |
| 536 | // keep the ref until determined not kinect |
| 537 | libusb_ref_device(dev); |
| 538 | libusb_close(dev_handle); |
| 539 | |
| 540 | if(r > LIBUSB_SUCCESS) |
| 541 | { |
| 542 | UsbDeviceWithSerial dev_with_serial; |
| 543 | dev_with_serial.dev = dev; |
| 544 | dev_with_serial.serial = std::string(reinterpret_cast<char *>(buffer), size_t(r)); |
| 545 | |
| 546 | LOG_INFO << "found valid Kinect v2 " << PrintBusAndDevice(dev) << " with serial " << dev_with_serial.serial; |
| 547 | // valid Kinect v2 |
| 548 | enumerated_devices_.push_back(dev_with_serial); |
| 549 | continue; |
| 550 | } |
nothing calls this directly
no test coverage detected