📄 descriptorpage.java
字号:
mainFrame.printError("",err);
} else {
int size = BufDesc.getBytesTransferred();
int pos = 0;
byte[] data;
while (pos < size) {
data = new byte[BufDesc.Buffer()[pos]];
System.arraycopy(BufDesc.Buffer(),pos,data,0,BufDesc.Buffer()[pos]);
switch(BufDesc.Buffer()[pos+1]) {
case UsbIo.USB_DEVICE_DESCRIPTOR_TYPE:
USB_DEVICE_DESCRIPTOR desc1 = new USB_DEVICE_DESCRIPTOR();
desc1.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc1);
break;
case UsbIo.USB_CONFIGURATION_DESCRIPTOR_TYPE:
USB_CONFIGURATION_DESCRIPTOR desc2 = new USB_CONFIGURATION_DESCRIPTOR();
desc2.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc2);
break;
case UsbIo.USB_STRING_DESCRIPTOR_TYPE:
USB_STRING_DESCRIPTOR desc3 = new USB_STRING_DESCRIPTOR();
desc3.parseByteArray(data,BufDesc.Buffer()[pos]);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc3);
break;
case UsbIo.USB_INTERFACE_DESCRIPTOR_TYPE:
USB_INTERFACE_DESCRIPTOR desc4 = new USB_INTERFACE_DESCRIPTOR();
desc4.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc4);
break;
case UsbIo.USB_ENDPOINT_DESCRIPTOR_TYPE:
USB_ENDPOINT_DESCRIPTOR desc5 = new USB_ENDPOINT_DESCRIPTOR();
desc5.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc5);
break;
case UsbIo.USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE:
USB_DEVICE_QUALIFIER_DESCRIPTOR desc6 = new USB_DEVICE_QUALIFIER_DESCRIPTOR();
desc6.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc6);
break;
case UsbIo.USB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR_TYPE:
USB_CONFIGURATION_DESCRIPTOR desc7 = new USB_CONFIGURATION_DESCRIPTOR();
desc7.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc7);
break;
case UsbIo.USB_HID_DESCRIPTOR_TYPE:
USB_HID_DESCRIPTOR desc8 = new USB_HID_DESCRIPTOR();
desc8.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc8);
break;
default:
mainFrame.printOutput("\n");
mainFrame.printOutput("Unknown Descriptor:\n");
}
pos = pos + BufDesc.Buffer()[pos];
}
}
}
catch (NumberFormatException ex) {
mainFrame.printOutput("Wrong input format.\n");
}
}
}
public class OnGetOtherSpeedConfDescButton implements ActionListener {
public void actionPerformed(ActionEvent event) {
try {
int index = Integer.decode(mConfDescIndexTF.getText()).intValue();
int err;
USBIO_DATA_BUFFER BufDesc = new USBIO_DATA_BUFFER(MAX_DESCRIPTOR_BUFFER_SIZE);
BufDesc.setNumberOfBytesToTransfer(MAX_DESCRIPTOR_BUFFER_SIZE);
// send command to driver
err = mainFrame.gUsbIo.getDescriptor(BufDesc,0,(byte)UsbIo.USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE,(byte)index);
if (err != 0) {
// print error message
mainFrame.printError("",err);
} else {
int size = BufDesc.getBytesTransferred();
int pos = 0;
byte[] data;
while (pos < size) {
data = new byte[BufDesc.Buffer()[pos]];
System.arraycopy(BufDesc.Buffer(),pos,data,0,BufDesc.Buffer()[pos]);
switch(BufDesc.Buffer()[pos+1]) {
case UsbIo.USB_DEVICE_DESCRIPTOR_TYPE:
USB_DEVICE_DESCRIPTOR desc1 = new USB_DEVICE_DESCRIPTOR();
desc1.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc1);
break;
case UsbIo.USB_CONFIGURATION_DESCRIPTOR_TYPE:
USB_CONFIGURATION_DESCRIPTOR desc2 = new USB_CONFIGURATION_DESCRIPTOR();
desc2.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc2);
break;
case UsbIo.USB_STRING_DESCRIPTOR_TYPE:
USB_STRING_DESCRIPTOR desc3 = new USB_STRING_DESCRIPTOR();
desc3.parseByteArray(data,BufDesc.Buffer()[pos]);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc3);
break;
case UsbIo.USB_INTERFACE_DESCRIPTOR_TYPE:
USB_INTERFACE_DESCRIPTOR desc4 = new USB_INTERFACE_DESCRIPTOR();
desc4.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc4);
break;
case UsbIo.USB_ENDPOINT_DESCRIPTOR_TYPE:
USB_ENDPOINT_DESCRIPTOR desc5 = new USB_ENDPOINT_DESCRIPTOR();
desc5.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc5);
break;
case UsbIo.USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE:
USB_DEVICE_QUALIFIER_DESCRIPTOR desc6 = new USB_DEVICE_QUALIFIER_DESCRIPTOR();
desc6.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc6);
break;
case UsbIo.USB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR_TYPE:
USB_CONFIGURATION_DESCRIPTOR desc7 = new USB_CONFIGURATION_DESCRIPTOR();
desc7.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc7);
break;
case UsbIo.USB_HID_DESCRIPTOR_TYPE:
USB_HID_DESCRIPTOR desc8 = new USB_HID_DESCRIPTOR();
desc8.parseByteArray(data);
dumpDescriptor((USB_COMMON_DESCRIPTOR)desc8);
break;
default:
mainFrame.printOutput("\n");
mainFrame.printOutput("Unknown Descriptor:\n");
}
pos = pos + BufDesc.Buffer()[pos];
}
}
}
catch (NumberFormatException ex) {
mainFrame.printOutput("Wrong input format.\n");
}
}
}
void
dumpDeviceDescriptor(
USB_DEVICE_DESCRIPTOR Desc
)
{
mainFrame.printOutput("\n");
mainFrame.printOutput("Device Descriptor:\n");
mainFrame.printOutput("bLength : " + Desc.bLength + "\n");
mainFrame.printOutput("bDescriptorType : 0x" + UsbIoApp.byteToString((byte)Desc.bDescriptorType) + "\n");
mainFrame.printOutput("bcdUSB : 0x" + UsbIoApp.shortToString((short)Desc.bcdUSB) + "\n");
mainFrame.printOutput("bDeviceClass : 0x" + UsbIoApp.byteToString((byte)Desc.bDeviceClass) + "\n");
mainFrame.printOutput("bDeviceSubClass : 0x" + UsbIoApp.byteToString((byte)Desc.bDeviceSubClass) + "\n");
mainFrame.printOutput("bDeviceProtocol : 0x" + UsbIoApp.byteToString((byte)Desc.bDeviceProtocol) + "\n");
mainFrame.printOutput("bMaxPacketSize0 : " + Desc.bMaxPacketSize0 + "\n");
mainFrame.printOutput("idVendor : 0x" + UsbIoApp.shortToString((short)Desc.idVendor) + "\n");
mainFrame.printOutput("idProduct : 0x" + UsbIoApp.shortToString((short)Desc.idProduct) + "\n");
mainFrame.printOutput("bcdDevice : 0x" + UsbIoApp.shortToString((short)Desc.bcdDevice) + "\n");
mainFrame.printOutput("iManufacturer : " + Desc.iManufacturer + "\n");
mainFrame.printOutput("iProduct : " + Desc.iProduct + "\n");
mainFrame.printOutput("iSerialNumber : " + Desc.iSerialNumber + "\n");
mainFrame.printOutput("bNumConfigurations : " + Desc.bNumConfigurations + "\n");
}
void
dumpConfigurationDescriptor(
USB_CONFIGURATION_DESCRIPTOR Desc
)
{
mainFrame.printOutput("\n");
mainFrame.printOutput("Configuration Descriptor:\n");
mainFrame.printOutput("bLength : " + Desc.bLength + "\n");
mainFrame.printOutput("bDescriptorType : 0x" + UsbIoApp.byteToString((byte)Desc.bDescriptorType) + "\n");
mainFrame.printOutput("wTotalLength : " + Desc.wTotalLength + "\n");
mainFrame.printOutput("bNumInterfaces : " + Desc.bNumInterfaces + "\n");
mainFrame.printOutput("bConfigurationValue: " + Desc.bConfigurationValue + "\n");
mainFrame.printOutput("iConfiguration : " + Desc.iConfiguration + "\n");
mainFrame.printOutput("bmAttributes : 0x" + UsbIoApp.byteToString((byte)Desc.bmAttributes) + "\n");
mainFrame.printOutput("MaxPower : " + UsbIoApp.byteToString((byte)Desc.MaxPower) + "\n");
}
void
dumpStringDescriptor(
USB_STRING_DESCRIPTOR Desc
)
{
mainFrame.printOutput("\n");
mainFrame.printOutput("String Descriptor:\n");
mainFrame.printOutput("bLength : " + Desc.bLength + "\n");
mainFrame.printOutput("bDescriptorType : 0x" + UsbIoApp.byteToString((byte)Desc.bDescriptorType) + "\n");
mainFrame.printOutput("DescriptorContents : " + Desc.Str + "\n");
}
void
dumpInterfaceDescriptor(
USB_INTERFACE_DESCRIPTOR Desc
)
{
mainFrame.printOutput("\n");
mainFrame.printOutput("Interface Descriptor:\n");
mainFrame.printOutput("bLength : " + Desc.bLength + "\n");
mainFrame.printOutput("bDescriptorType : 0x" + UsbIoApp.byteToString((byte)Desc.bDescriptorType) + "\n");
mainFrame.printOutput("bInterfaceNumber : " + Desc.bInterfaceNumber + "\n");
mainFrame.printOutput("bAlternateSetting : " + Desc.bAlternateSetting + "\n");
mainFrame.printOutput("bNumEndpoints : " + Desc.bNumEndpoints + "\n");
mainFrame.printOutput("bInterfaceClass : 0x" + UsbIoApp.byteToString((byte)Desc.bInterfaceClass) + "\n");
mainFrame.printOutput("bInterfaceSubClass : 0x" + UsbIoApp.byteToString((byte)Desc.bInterfaceSubClass) + "\n");
mainFrame.printOutput("bInterfaceProtocol : 0x" + UsbIoApp.byteToString((byte)Desc.bInterfaceProtocol) + "\n");
mainFrame.printOutput("iInterface : " + Desc.iInterface + "\n");
}
void
dumpHIDDescriptor(
USB_HID_DESCRIPTOR Desc
)
{
mainFrame.printOutput("\n");
mainFrame.printOutput("HID Descriptor:\n");
mainFrame.printOutput("bLength : " + Desc.bLength + "\n");
mainFrame.printOutput("bDescriptorType : 0x" + UsbIoApp.byteToString((byte)Desc.bDescriptorType) + "\n");
mainFrame.printOutput("bcdHID : 0x" + UsbIoApp.shortToString((short)Desc.bcdHID) + "\n");
mainFrame.printOutput("bCountryCode : 0x" + UsbIoApp.byteToString((byte)Desc.bCountryCode) + "\n");
mainFrame.printOutput("bNumDescriptors : 0x" + UsbIoApp.byteToString((byte)Desc.bNumDescriptors) + "\n");
mainFrame.printOutput("bDescriptorType : 0x" + UsbIoApp.byteToString((byte)Desc.bDescriptorType1) + "\n");
mainFrame.printOutput("wDescriptorLength : 0x" + UsbIoApp.shortToString((short)Desc.wDescriptorLength1) + "\n");
}
void
dumpEndpointDescriptor(
USB_ENDPOINT_DESCRIPTOR Desc
)
{
mainFrame.printOutput("\n");
mainFrame.printOutput("Endpoint Descriptor:\n");
mainFrame.printOutput("bLength : " + Desc.bLength + "\n");
mainFrame.printOutput("bDescriptorType : 0x" + UsbIoApp.byteToString((byte)Desc.bDescriptorType) + "\n");
mainFrame.printOutput("bEndpointAddress : 0x" + UsbIoApp.byteToString((byte)Desc.bEndpointAddress) + "\n");
mainFrame.printOutput("bmAttributes : 0x" + UsbIoApp.byteToString((byte)Desc.bmAttributes) + "\n");
mainFrame.printOutput("wMaxPacketSize : " + Desc.wMaxPacketSize + "\n");
mainFrame.printOutput("bInterval : " + Desc.bInterval + "\n");
}
void
dumpDeviceQualifierDescriptor(
USB_DEVICE_QUALIFIER_DESCRIPTOR Desc
)
{
mainFrame.printOutput("\n");
mainFrame.printOutput("Device Qualifier Descriptor:\n");
mainFrame.printOutput("bLength : " + Desc.bLength + "\n");
mainFrame.printOutput("bDescriptorType : 0x" + UsbIoApp.byteToString((byte)Desc.bDescriptorType) + "\n");
mainFrame.printOutput("bcdUSB : 0x" + UsbIoApp.shortToString((short)Desc.bcdUSB) + "\n");
mainFrame.printOutput("bDeviceClass : 0x" + UsbIoApp.byteToString((byte)Desc.bDeviceClass) + "\n");
mainFrame.printOutput("bDeviceSubClass : 0x" + UsbIoApp.byteToString((byte)Desc.bDeviceSubClass) + "\n");
mainFrame.printOutput("bDeviceProtocol : 0x" + UsbIoApp.byteToString((byte)Desc.bDeviceProtocol) + "\n");
mainFrame.printOutput("bMaxPacketSize0 : " + Desc.bMaxPacketSize0 + "\n");
mainFrame.printOutput("bNumConfigurations : " + Desc.bNumConfigurations + "\n");
mainFrame.printOutput("bReserved : " + Desc.bReserved + "\n");
}
public void dumpDescriptor(USB_COMMON_DESCRIPTOR Desc) {
int DescLength = Desc.bLength;
if (DescLength == 0) {
mainFrame.printOutput("Device returned a Zero packet (length=0) to the request.\n");
} else {
switch(Desc.bDescriptorType) {
case UsbIo.USB_DEVICE_DESCRIPTOR_TYPE:
dumpDeviceDescriptor((USB_DEVICE_DESCRIPTOR)Desc);
break;
case UsbIo.USB_CONFIGURATION_DESCRIPTOR_TYPE:
dumpConfigurationDescriptor((USB_CONFIGURATION_DESCRIPTOR)Desc);
break;
case UsbIo.USB_STRING_DESCRIPTOR_TYPE:
dumpStringDescriptor((USB_STRING_DESCRIPTOR)Desc);
break;
case UsbIo.USB_INTERFACE_DESCRIPTOR_TYPE:
dumpInterfaceDescriptor((USB_INTERFACE_DESCRIPTOR)Desc);
break;
case UsbIo.USB_ENDPOINT_DESCRIPTOR_TYPE:
dumpEndpointDescriptor((USB_ENDPOINT_DESCRIPTOR)Desc);
break;
case UsbIo.USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE:
dumpDeviceQualifierDescriptor((USB_DEVICE_QUALIFIER_DESCRIPTOR)Desc);
break;
case UsbIo.USB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR_TYPE:
dumpConfigurationDescriptor((USB_CONFIGURATION_DESCRIPTOR)Desc);
break;
case UsbIo.USB_HID_DESCRIPTOR_TYPE:
dumpHIDDescriptor((USB_HID_DESCRIPTOR)Desc);
break;
default:
mainFrame.printOutput("\n");
mainFrame.printOutput("Unknown Descriptor:\n");
mainFrame.printOutput("Descriptor length: " + DescLength + "\n");
mainFrame.printOutput("Descriptor Type: 0x" + UsbIoApp.byteToString((byte)Desc.bDescriptorType) + "\n");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -