Android 的字符串 UsbDevice.getVersion() 如何从 Word bcdDevice 编码?
How is Android's String UsbDevice.getVersion() encoded from Word bcdDevice?
我的 USB 设备 bcdDevice = 262 (word). In Android according UsbDevice.getVersion()
shows "1.16" (String) as it's String。通常第一个字节是设备major版本,第二个字节是minor版本,相应地应该是“1”和“6”:
devInfo->version.major = (dev_desc->bcdDevice >> 8) & 0xFF;
devInfo->version.minor = dev_desc->bcdDevice & 0xFF;
Android 如何从 word
bcdDevice 编码 String
设备版本?我需要做相反的事情 - 使用 Android "version".
获取 "bcdDevice" 值
显然“1.16”不能用下面的方式解析:
"major version before ""as int, 其余为次版本" 因为次版本为16,但实际上是6。
更新 1
Mac USB 设备信息显示为“1.06”(正确):
$system_profiler SPUSBDataType
USB:
USB 3.0 Bus:
Host Controller Driver: AppleUSBXHCISPTLP
PCI Device ID: 0x9d2f
PCI Revision ID: 0x0021
PCI Vendor ID: 0x8086
Vendor-Specific Device:
Product ID: 0x0753
Vendor ID: 0x16d0
Version: 1.06
Speed: Up to 1.5 Mb/sec
Location ID: 0x14400000 / 19
Current Available (mA): 500
Extra Operating Current (mA): 0
该函数不适用于 return bcdDevice。它创建一个基于 usb 文件系统的唯一 ID。如果您尝试 getDeviceName() 并与 getDeviceId() 进行比较,您将看到设备 ID 是 getDeviceName() 中最后两个路径条目的组合。
11-27 19:56:31.380 24948-24948/com.cirrus.cirruslogic D/com.cirrus.cirruslogic.MainActivity: getDeviceName: /dev/bus/usb/001/002
11-27 19:56:31.380 24948-24948/com.cirrus.cirruslogic D/com.cirrus.cirruslogic.MainActivity: getDeviceId: 1002
从 https://developer.android.com/reference/android/hardware/usb/UsbDevice.html#getDeviceId() -
getDeviceId"Returns a unique integer ID for the device. This is a convenience for clients that want to use an integer to represent the device, rather than the device name. IDs are not persistent across USB disconnects."
我也在尝试读取 bcdDevice。还没找到解决方法
-- 更新--
看来 getRawDescriptors() https://developer.android.com/reference/android/hardware/usb/UsbDeviceConnection.html#getRawDescriptors() 会做你需要的。
"Returns the raw USB descriptors for the device. This can be used to access descriptors not supported directly via the higher level APIs." 字节 12-13 应该是 bcdDevice
没有高电平Android API到return USB bcdDevice
值。
UsbDevice.getVersion()
的值实际上是bcdUSB
的值,意思是USB设备规格版本。
有两种方法(据我所知)可以在 Android 上获得 bcdDevice
:
- 正如 ddATC 所指出的 -> 使用
UsbDeviceConnection.getRawDescriptors()
bcdDevice
的值是字节 12 和 13。
- 手动执行
controlTransfer
动作读取设备描述符:示例代码:https://github.com/androidthings/sample-usbenum
更多 USB 规格信息:
- http://www.usbmadesimple.co.uk/ums_4.htm(包含
controlTransfer
可以接受的参数的详细信息)
- https://www-user.tu-chemnitz.de/~heha/viewchm.php/hs/usb.chm/usb5.htm#DeviceDescriptors(
GET_DESCRIPTOR - 0x06
命令的响应)
p.s。
我个人使用 UsbDeviceConnection.getRawDescriptors()
来读取 bcdDevice
值。
我的 USB 设备 bcdDevice = 262 (word). In Android according UsbDevice.getVersion()
shows "1.16" (String) as it's String。通常第一个字节是设备major版本,第二个字节是minor版本,相应地应该是“1”和“6”:
devInfo->version.major = (dev_desc->bcdDevice >> 8) & 0xFF;
devInfo->version.minor = dev_desc->bcdDevice & 0xFF;
Android 如何从 word
bcdDevice 编码 String
设备版本?我需要做相反的事情 - 使用 Android "version".
显然“1.16”不能用下面的方式解析: "major version before ""as int, 其余为次版本" 因为次版本为16,但实际上是6。
更新 1 Mac USB 设备信息显示为“1.06”(正确):
$system_profiler SPUSBDataType
USB:
USB 3.0 Bus:
Host Controller Driver: AppleUSBXHCISPTLP
PCI Device ID: 0x9d2f
PCI Revision ID: 0x0021
PCI Vendor ID: 0x8086
Vendor-Specific Device:
Product ID: 0x0753
Vendor ID: 0x16d0
Version: 1.06
Speed: Up to 1.5 Mb/sec
Location ID: 0x14400000 / 19
Current Available (mA): 500
Extra Operating Current (mA): 0
该函数不适用于 return bcdDevice。它创建一个基于 usb 文件系统的唯一 ID。如果您尝试 getDeviceName() 并与 getDeviceId() 进行比较,您将看到设备 ID 是 getDeviceName() 中最后两个路径条目的组合。
11-27 19:56:31.380 24948-24948/com.cirrus.cirruslogic D/com.cirrus.cirruslogic.MainActivity: getDeviceName: /dev/bus/usb/001/002
11-27 19:56:31.380 24948-24948/com.cirrus.cirruslogic D/com.cirrus.cirruslogic.MainActivity: getDeviceId: 1002
从 https://developer.android.com/reference/android/hardware/usb/UsbDevice.html#getDeviceId() -
getDeviceId"Returns a unique integer ID for the device. This is a convenience for clients that want to use an integer to represent the device, rather than the device name. IDs are not persistent across USB disconnects."
我也在尝试读取 bcdDevice。还没找到解决方法
-- 更新-- 看来 getRawDescriptors() https://developer.android.com/reference/android/hardware/usb/UsbDeviceConnection.html#getRawDescriptors() 会做你需要的。 "Returns the raw USB descriptors for the device. This can be used to access descriptors not supported directly via the higher level APIs." 字节 12-13 应该是 bcdDevice
没有高电平Android API到return USB bcdDevice
值。
UsbDevice.getVersion()
的值实际上是bcdUSB
的值,意思是USB设备规格版本。
有两种方法(据我所知)可以在 Android 上获得 bcdDevice
:
- 正如 ddATC 所指出的 -> 使用
UsbDeviceConnection.getRawDescriptors()
bcdDevice
的值是字节 12 和 13。 - 手动执行
controlTransfer
动作读取设备描述符:示例代码:https://github.com/androidthings/sample-usbenum
更多 USB 规格信息:
- http://www.usbmadesimple.co.uk/ums_4.htm(包含
controlTransfer
可以接受的参数的详细信息) - https://www-user.tu-chemnitz.de/~heha/viewchm.php/hs/usb.chm/usb5.htm#DeviceDescriptors(
GET_DESCRIPTOR - 0x06
命令的响应)
p.s。
我个人使用 UsbDeviceConnection.getRawDescriptors()
来读取 bcdDevice
值。