25 #define XSENS_VENDOR_ID 0x2639 26 #define ATMEL_VENDOR_ID 0x03eb // needed for old MTw 27 #define ATMEL_BORROWED_PRODUCT_ID 0x2307 // needed for old MTw 43 ULONG requiredLength = 0;
46 GUID guid = {0xfd51225c,
49 {0x99, 0x99, 0xb2, 0xd9, 0x3, 0x1b, 0x88, 0xed}};
52 SP_DEVICE_INTERFACE_DATA interfaceData;
53 PSP_DEVICE_INTERFACE_DETAIL_DATA_A detailData =
nullptr;
55 deviceInfo = SetupDiGetClassDevs(
56 &guid,
nullptr,
nullptr, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
59 interfaceData.cbSize =
sizeof(SP_INTERFACE_DEVICE_DATA);
61 for (DWORD dwIndex = 0; port == 0; ++dwIndex)
63 BOOL bRet = SetupDiEnumDeviceInterfaces(
64 deviceInfo,
nullptr, &guid, dwIndex, &interfaceData);
67 if (GetLastError() == ERROR_NO_MORE_ITEMS)
break;
71 if (!SetupDiGetDeviceInterfaceDetail(
72 deviceInfo, &interfaceData,
nullptr, 0, &requiredLength,
75 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
77 SetupDiDestroyDeviceInfoList(deviceInfo);
81 detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA_A)LocalAlloc(
82 LMEM_FIXED, requiredLength);
83 if (
nullptr == detailData)
85 SetupDiDestroyDeviceInfoList(deviceInfo);
89 detailData->cbSize =
sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
91 SP_DEVINFO_DATA DevInfoData;
92 DevInfoData.cbSize =
sizeof(SP_DEVINFO_DATA);
93 bResult = SetupDiGetDeviceInterfaceDetailA(
94 deviceInfo, &interfaceData, detailData,
length, &requiredLength,
99 LocalFree(detailData);
100 SetupDiDestroyDeviceInfoList(deviceInfo);
104 unsigned char serialNumber[256];
105 char *ptrEnd, *ptrStart = strchr(detailData->DevicePath,
'#');
106 if (!ptrStart)
continue;
107 ptrStart = strchr(ptrStart + 1,
'#');
108 if (!ptrStart)
continue;
109 ptrEnd = strchr(ptrStart + 1,
'#');
110 if (!ptrEnd)
continue;
112 strncpy((
char*)serialNumber, ptrStart + 1, ptrEnd - ptrStart - 1);
113 serialNumber[ptrEnd - ptrStart - 1] =
'\0';
115 current.setPortName(detailData->DevicePath);
118 sscanf((
const char*)serialNumber,
"%X", &
id);
121 ports.push_back(current);
125 SetupDiDestroyDeviceInfoList(deviceInfo);
129 libusb_context* context;
130 int result = libUsb.
init(&context);
131 if (result != LIBUSB_SUCCESS)
return false;
133 libusb_device** deviceList;
135 for (ssize_t i = 0; i < deviceCount; i++)
137 libusb_device* device = deviceList[i];
138 libusb_device_descriptor desc;
140 if (result != LIBUSB_SUCCESS)
continue;
146 libusb_device_handle* handle;
147 result = libUsb.
open(device, &handle);
148 if (result != LIBUSB_SUCCESS)
154 unsigned char serialNumber[256];
156 handle, desc.iSerialNumber, serialNumber, 256);
161 unsigned char productName[256];
163 handle, desc.iProduct, productName, 256);
165 if (strcmp(
"Xsens COM port", (
const char*)productName) != 0)
167 libUsb.
close(handle);
172 libusb_config_descriptor* configDesc;
174 if (result != LIBUSB_SUCCESS)
continue;
176 bool kernelActive =
false;
177 for (
uint8_t ifCount = 0; ifCount < configDesc->bNumInterfaces;
181 kernelActive |= (
res == 1);
192 current.setPortName(
name);
195 sscanf((
const char*)serialNumber,
"%d", &
id);
197 ports.push_back(current);
202 gJournal,
"Kernel driver active on USB" 207 libUsb.
close(handle);
210 libUsb.
exit(context);
libUSB_unref_device unref_device
libUSB_free_config_descriptor free_config_descriptor
#define ATMEL_BORROWED_PRODUCT_ID
libUSB_get_string_descriptor_ascii get_string_descriptor_ascii
libUSB_free_device_list free_device_list
bool xsEnumerateUsbDevices(XsPortInfoList &ports)
Enumerate Xsens USB devices.
libUSB_get_device_list get_device_list
libUSB_get_device_descriptor get_device_descriptor
libUSB_kernel_driver_active kernel_driver_active
GLuint GLsizei GLsizei * length
GLuint const GLchar * name
libUSB_get_device_address get_device_address
unsigned __int32 uint32_t
libUSB_get_bus_number get_bus_number
libUSB_get_active_config_descriptor get_active_config_descriptor
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...