Move dump methods from simple descriptors into DumpUtils
This commit is contained in:
parent
7f85e27e12
commit
94ae441189
@ -10,6 +10,8 @@ import javax.usb.UsbConfigurationDescriptor;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
import de.ailis.usb4java.utils.DumpUtils;
|
||||
|
||||
/**
|
||||
* Simple USB configuration descriptor.
|
||||
*
|
||||
@ -166,22 +168,6 @@ public final class SimpleUsbConfigurationDescriptor extends SimpleUsbDescriptor
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("Configuration Descriptor:%n"
|
||||
+ " bLength %18d%n"
|
||||
+ " bDescriptorType %10d%n"
|
||||
+ " wTotalLength %13d%n"
|
||||
+ " bNumInterfaces %11d%n"
|
||||
+ " bConfigurationValue %6d%n"
|
||||
+ " iConfiguration %11d%n"
|
||||
+ " bmAttributes %13s%n"
|
||||
+ " bMaxPower %16smA%n",
|
||||
bLength(),
|
||||
bDescriptorType(),
|
||||
this.wTotalLength & 0xffff,
|
||||
this.bNumInterfaces & 0xff,
|
||||
this.bConfigurationValue & 0xff,
|
||||
this.iConfiguration & 0xff,
|
||||
String.format("0x%02x", this.bmAttributes & 0xff),
|
||||
(this.bMaxPower & 0xff) * 2);
|
||||
return DumpUtils.dump(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ import javax.usb.UsbDeviceDescriptor;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
import de.ailis.usb4java.utils.DumpUtils;
|
||||
|
||||
/**
|
||||
* Simple USB device descriptor.
|
||||
*
|
||||
@ -256,34 +258,6 @@ public final class SimpleUsbDeviceDescriptor extends SimpleUsbDescriptor
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("Device Descriptor:%n"
|
||||
+ " bLength %18d%n"
|
||||
+ " bDescriptorType %10d%n"
|
||||
+ " bcdDevice %13x.%02x%n"
|
||||
+ " bDeviceClass %13d%n"
|
||||
+ " bDeviceSubClass %10d%n"
|
||||
+ " bDeviceProtocol %10d%n"
|
||||
+ " bMaxPacketSize0 %10d%n"
|
||||
+ " idVendor %17s%n"
|
||||
+ " idProduct %16s%n"
|
||||
+ " bcdDevice %13x.%02x%n"
|
||||
+ " iManufacturer %12d%n"
|
||||
+ " iProduct %17d%n"
|
||||
+ " iSerial %18d%n"
|
||||
+ " bNumConfigurations %7d%n",
|
||||
bLength(),
|
||||
bDescriptorType(),
|
||||
(this.bcdUSB & 0xff00) >> 8, this.bcdUSB & 0xff,
|
||||
this.bDeviceClass & 0xff,
|
||||
this.bDeviceSubClass & 0xff,
|
||||
this.bDeviceProtocol & 0xff,
|
||||
this.bMaxPacketSize0 & 0xff,
|
||||
String.format("0x%04x", this.idVendor & 0xffff),
|
||||
String.format("0x%04x", this.idProduct & 0xffff),
|
||||
(this.bcdDevice & 0xff00) >> 8, this.bcdDevice & 0xff,
|
||||
this.iManufacturer & 0xff,
|
||||
this.iProduct & 0xff,
|
||||
this.iSerialNumber & 0xff,
|
||||
this.bNumConfigurations & 0xff);
|
||||
return DumpUtils.dump(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ import javax.usb.UsbEndpointDescriptor;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
import de.ailis.usb4java.utils.DumpUtils;
|
||||
|
||||
/**
|
||||
* Simple USB endpoint descriptor.
|
||||
*
|
||||
@ -134,18 +136,6 @@ public final class SimpleUsbEndpointDescriptor extends SimpleUsbDescriptor
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("Endpoint Descriptor:%n"
|
||||
+ " bLength %18d%n"
|
||||
+ " bDescriptorType %10d%n"
|
||||
+ " bEndpointAddress %9s%n"
|
||||
+ " bmAttributes %13d%n"
|
||||
+ " wMaxPacketSize %11d%n"
|
||||
+ " bInterval %16d%n",
|
||||
bLength(),
|
||||
bDescriptorType(),
|
||||
String.format("0x%02x", this.bEndpointAddress & 0xff),
|
||||
this.bmAttributes & 0xff,
|
||||
this.wMaxPacketSize & 0xffff,
|
||||
this.bInterval & 0xff);
|
||||
return DumpUtils.dump(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ import javax.usb.UsbInterfaceDescriptor;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
import de.ailis.usb4java.utils.DumpUtils;
|
||||
|
||||
/**
|
||||
* Simple USB interface descriptor.
|
||||
*
|
||||
@ -180,24 +182,6 @@ public final class SimpleUsbInterfaceDescriptor extends SimpleUsbDescriptor
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("Interface Descriptor:%n"
|
||||
+ " bLength %18d%n"
|
||||
+ " bDescriptorType %10d%n"
|
||||
+ " bInterfaceNumber %9d%n"
|
||||
+ " bAlternateSetting %8d%n"
|
||||
+ " bNumEndpoints %12d%n"
|
||||
+ " bInterfaceClass %10d%n"
|
||||
+ " bInterfaceSubClass %7d%n"
|
||||
+ " bInterfaceProtocol %7d%n"
|
||||
+ " iInterface %15d%n",
|
||||
bLength(),
|
||||
bDescriptorType(),
|
||||
this.bInterfaceNumber & 0xff,
|
||||
this.bAlternateSetting & 0xff,
|
||||
this.bNumEndpoints & 0xff,
|
||||
this.bInterfaceClass & 0xff,
|
||||
this.bInterfaceSubClass & 0xff,
|
||||
this.bInterfaceProtocol & 0xff,
|
||||
this.iInterface & 0xff);
|
||||
return DumpUtils.dump(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,11 @@ import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.usb.UsbConfigurationDescriptor;
|
||||
import javax.usb.UsbDeviceDescriptor;
|
||||
import javax.usb.UsbEndpointDescriptor;
|
||||
import javax.usb.UsbInterfaceDescriptor;
|
||||
|
||||
import de.ailis.usb4java.libusb.LibUSB;
|
||||
|
||||
/**
|
||||
@ -77,7 +82,7 @@ public final class DumpUtils
|
||||
*/
|
||||
public static String decodeBCD(final int bcd)
|
||||
{
|
||||
return String.format("%x.%02x", bcd >> Byte.SIZE, bcd & 0xff);
|
||||
return String.format("%x.%02x", (bcd & 0xff00) >> 8, bcd & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,6 +110,132 @@ public final class DumpUtils
|
||||
if (i % columns != 0) builder.append(String.format("%n"));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the specified USB device descriptor into a string and
|
||||
* returns it.
|
||||
*
|
||||
* @param descriptor
|
||||
* The USB device descriptor to dump.
|
||||
* @return The descriptor dump.
|
||||
*/
|
||||
public static String dump(final UsbDeviceDescriptor descriptor)
|
||||
{
|
||||
return String.format("Device Descriptor:%n"
|
||||
+ " bLength %18d%n"
|
||||
+ " bDescriptorType %10d%n"
|
||||
+ " bcdDevice %16s%n"
|
||||
+ " bDeviceClass %13d%n"
|
||||
+ " bDeviceSubClass %10d%n"
|
||||
+ " bDeviceProtocol %10d%n"
|
||||
+ " bMaxPacketSize0 %10d%n"
|
||||
+ " idVendor %17s%n"
|
||||
+ " idProduct %16s%n"
|
||||
+ " bcdDevice %16s%n"
|
||||
+ " iManufacturer %12d%n"
|
||||
+ " iProduct %17d%n"
|
||||
+ " iSerial %18d%n"
|
||||
+ " bNumConfigurations %7d",
|
||||
descriptor.bLength(),
|
||||
descriptor.bDescriptorType(),
|
||||
decodeBCD(descriptor.bcdUSB()),
|
||||
descriptor.bDeviceClass() & 0xff,
|
||||
descriptor.bDeviceSubClass() & 0xff,
|
||||
descriptor.bDeviceProtocol() & 0xff,
|
||||
descriptor.bMaxPacketSize0() & 0xff,
|
||||
String.format("0x%04x", descriptor.idVendor() & 0xffff),
|
||||
String.format("0x%04x", descriptor.idProduct() & 0xffff),
|
||||
decodeBCD(descriptor.bcdDevice()),
|
||||
descriptor.iManufacturer() & 0xff,
|
||||
descriptor.iProduct() & 0xff,
|
||||
descriptor.iSerialNumber() & 0xff,
|
||||
descriptor.bNumConfigurations() & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the specified USB configuration descriptor into a string and
|
||||
* returns it.
|
||||
*
|
||||
* @param descriptor
|
||||
* The USB configuration descriptor to dump.
|
||||
* @return The descriptor dump.
|
||||
*/
|
||||
public static String dump(final UsbConfigurationDescriptor descriptor)
|
||||
{
|
||||
return String.format("Configuration Descriptor:%n"
|
||||
+ " bLength %18d%n"
|
||||
+ " bDescriptorType %10d%n"
|
||||
+ " wTotalLength %13d%n"
|
||||
+ " bNumInterfaces %11d%n"
|
||||
+ " bConfigurationValue %6d%n"
|
||||
+ " iConfiguration %11d%n"
|
||||
+ " bmAttributes %13s%n"
|
||||
+ " bMaxPower %16smA",
|
||||
descriptor.bLength(),
|
||||
descriptor.bDescriptorType(),
|
||||
descriptor.wTotalLength() & 0xffff,
|
||||
descriptor.bNumInterfaces() & 0xff,
|
||||
descriptor.bConfigurationValue() & 0xff,
|
||||
descriptor.iConfiguration() & 0xff,
|
||||
String.format("0x%02x", descriptor.bmAttributes() & 0xff),
|
||||
(descriptor.bMaxPower() & 0xff) * 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the specified USB interface descriptor into a string and
|
||||
* returns it.
|
||||
*
|
||||
* @param descriptor
|
||||
* The USB interface descriptor to dump.
|
||||
* @return The descriptor dump.
|
||||
*/
|
||||
public static String dump(final UsbInterfaceDescriptor descriptor)
|
||||
{
|
||||
return String.format("Interface Descriptor:%n"
|
||||
+ " bLength %18d%n"
|
||||
+ " bDescriptorType %10d%n"
|
||||
+ " bInterfaceNumber %9d%n"
|
||||
+ " bAlternateSetting %8d%n"
|
||||
+ " bNumEndpoints %12d%n"
|
||||
+ " bInterfaceClass %10d%n"
|
||||
+ " bInterfaceSubClass %7d%n"
|
||||
+ " bInterfaceProtocol %7d%n"
|
||||
+ " iInterface %15d%n",
|
||||
descriptor.bLength(),
|
||||
descriptor.bDescriptorType(),
|
||||
descriptor.bInterfaceNumber() & 0xff,
|
||||
descriptor.bAlternateSetting() & 0xff,
|
||||
descriptor.bNumEndpoints() & 0xff,
|
||||
descriptor.bInterfaceClass() & 0xff,
|
||||
descriptor.bInterfaceSubClass() & 0xff,
|
||||
descriptor.bInterfaceProtocol() & 0xff,
|
||||
descriptor.iInterface() & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the specified USB endpoint descriptor into a string and
|
||||
* returns it.
|
||||
*
|
||||
* @param descriptor
|
||||
* The USB endpoint descriptor to dump.
|
||||
* @return The descriptor dump.
|
||||
*/
|
||||
public static String dump(final UsbEndpointDescriptor descriptor)
|
||||
{
|
||||
return String.format("Endpoint Descriptor:%n"
|
||||
+ " bLength %18d%n"
|
||||
+ " bDescriptorType %10d%n"
|
||||
+ " bEndpointAddress %9s%n"
|
||||
+ " bmAttributes %13d%n"
|
||||
+ " wMaxPacketSize %11d%n"
|
||||
+ " bInterval %16d%n",
|
||||
descriptor.bLength(),
|
||||
descriptor.bDescriptorType(),
|
||||
String.format("0x%02x", descriptor.bEndpointAddress() & 0xff),
|
||||
descriptor.bmAttributes() & 0xff,
|
||||
descriptor.wMaxPacketSize() & 0xffff,
|
||||
descriptor.bInterval() & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name for the specified speed number.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user