26 #define XSENS_VENDOR_ID 0x2639 27 #define ATMEL_VENDOR_ID 0x03eb // needed for old MTw 28 #define ATMEL_BORROWED_PRODUCT_ID 0x2307 // needed for old MTw 44 ULONG requiredLength = 0;
47 GUID guid = {0xfd51225c,
50 {0x99, 0x99, 0xb2, 0xd9, 0x3, 0x1b, 0x88, 0xed}};
53 SP_DEVICE_INTERFACE_DATA interfaceData;
54 PSP_DEVICE_INTERFACE_DETAIL_DATA_A detailData =
nullptr;
56 deviceInfo = SetupDiGetClassDevs(
57 &guid,
nullptr,
nullptr, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
60 interfaceData.cbSize =
sizeof(SP_INTERFACE_DEVICE_DATA);
62 for (DWORD dwIndex = 0; port == 0; ++dwIndex)
64 BOOL bRet = SetupDiEnumDeviceInterfaces(
65 deviceInfo,
nullptr, &guid, dwIndex, &interfaceData);
68 if (GetLastError() == ERROR_NO_MORE_ITEMS)
break;
72 if (!SetupDiGetDeviceInterfaceDetail(
73 deviceInfo, &interfaceData,
nullptr, 0, &requiredLength,
76 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
78 SetupDiDestroyDeviceInfoList(deviceInfo);
82 detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA_A)LocalAlloc(
83 LMEM_FIXED, requiredLength);
84 if (
nullptr == detailData)
86 SetupDiDestroyDeviceInfoList(deviceInfo);
90 detailData->cbSize =
sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
92 SP_DEVINFO_DATA DevInfoData;
93 DevInfoData.cbSize =
sizeof(SP_DEVINFO_DATA);
94 bResult = SetupDiGetDeviceInterfaceDetailA(
95 deviceInfo, &interfaceData, detailData,
length, &requiredLength,
100 LocalFree(detailData);
101 SetupDiDestroyDeviceInfoList(deviceInfo);
105 unsigned char serialNumber[256];
106 char *ptrEnd, *ptrStart = strchr(detailData->DevicePath,
'#');
107 if (!ptrStart)
continue;
108 ptrStart = strchr(ptrStart + 1,
'#');
109 if (!ptrStart)
continue;
110 ptrEnd = strchr(ptrStart + 1,
'#');
111 if (!ptrEnd)
continue;
113 strncpy((
char*)serialNumber, ptrStart + 1, ptrEnd - ptrStart - 1);
114 serialNumber[ptrEnd - ptrStart - 1] =
'\0';
116 current.setPortName(detailData->DevicePath);
119 sscanf((
const char*)serialNumber,
"%X", &
id);
122 ports.push_back(current);
126 SetupDiDestroyDeviceInfoList(deviceInfo);
130 libusb_context* context;
131 int result = libUsb.
init(&context);
132 if (result != LIBUSB_SUCCESS)
return false;
134 libusb_device** deviceList;
136 for (ssize_t i = 0; i < deviceCount; i++)
138 libusb_device* device = deviceList[i];
139 libusb_device_descriptor desc;
141 if (result != LIBUSB_SUCCESS)
continue;
147 libusb_device_handle* handle;
148 result = libUsb.
open(device, &handle);
149 if (result != LIBUSB_SUCCESS)
155 unsigned char serialNumber[256];
157 handle, desc.iSerialNumber, serialNumber, 256);
162 unsigned char productName[256];
164 handle, desc.iProduct, productName, 256);
166 if (strcmp(
"Xsens COM port", (
const char*)productName) != 0)
168 libUsb.
close(handle);
173 libusb_config_descriptor* configDesc;
175 if (result != LIBUSB_SUCCESS)
continue;
177 bool kernelActive =
false;
178 for (
uint8_t ifCount = 0; ifCount < configDesc->bNumInterfaces;
182 kernelActive |= (
res == 1);
193 current.setPortName(
name);
196 sscanf((
const char*)serialNumber,
"%d", &
id);
198 ports.push_back(current);
203 gJournal,
"Kernel driver active on USB" 208 libUsb.
close(handle);
211 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...