usb.core
Class Descriptor

java.lang.Object
  |
  +--usb.core.Descriptor
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Configuration, DeviceDescriptor, Endpoint, Hub, Interface

public abstract class Descriptor
extends java.lang.Object
implements java.io.Serializable

This is a base class for entities with USB typed descriptors. It encapsulates raw descriptor data (byte arrays) and provides parsed access to that data. It is intended to be subclassed; subclasses will know how to parse the data after the first two bytes that this base class parses.

Descriptors are discussed in sections 9.5 and 9.6 of the USB 1.1 specification.

See Also:
Serialized Form

Field Summary
static byte CLASS_APP_SPECIFIC
          Identifier for application-specific interfaces.
static byte CLASS_AUDIO
          Identifier for audio class interfaces.
static byte CLASS_COMM
          Identifier for communications control class interfaces.
static byte CLASS_DATA
          Identifier for communications data class interfaces.
static byte CLASS_HID
          Identifier for Human Interaction Device (HID) class interfaces.
static byte CLASS_HUB
          Identifier for hub class interfaces.
static byte CLASS_MASS_STORAGE
          Identifier for mass storage class interfaces.
static byte CLASS_PRINTER
          Identifier for printer class interfaces.
static byte CLASS_VENDOR_SPECIFIC
          Identifier for vendor-specific interfaces.
static byte TYPE_CONFIGURATION
          Indicates a configuration descriptor
static byte TYPE_DEVICE
          Indicates a device descriptor
static byte TYPE_DEVICE_QUALIFIER
          Indicates a USB 2.0 "device qualifier"
static byte TYPE_ENDPOINT
          Indicates an endpoint descriptor
static byte TYPE_HID
          Indicates a hid class descriptor
static byte TYPE_HUB
          Indicates a hub class descriptor
static byte TYPE_INTERFACE
          Indicates an interface descriptor
static byte TYPE_INTERFACE_POWER
          Indicates interface power consumption
static byte TYPE_OTHER_SPEED
          Indicates a USB 2.0 "other speed configuration"
static byte TYPE_PHYSICAL
           
static byte TYPE_REPORT
           
static byte TYPE_STRING
          Indicates a string descriptor
 
Constructor Summary
protected Descriptor()
          Used when deserializing.
protected Descriptor(byte[] raw)
          Creates and initializes a descriptor
 
Method Summary
 java.lang.String getBCD(int offset)
          Returns the two byte BCD string at the specified offset.
static java.lang.String getClassName(int klass, java.lang.String zeroValue)
          Returns the name corresponding to an interface class code.
 int getDescriptorType()
          Returns the descriptor type.
 java.lang.String getDescriptorTypeName()
          Returns a name for the type of descriptor (such as "device")
abstract  Device getDevice()
          Returns the device with which this USB object is associated.
 int getLength()
          Returns the length of the descriptor.
 int getU16(int index)
          Returns a sixteen bit unsigned integer value, as encoded in the descriptor at the specified byte offset.
 int getU32(int index)
          Returns a thirty-two bit integer value, as encoded in the descriptor at the specified byte offset.
 int getU8(int index)
          Returns an eight bit unsigned integer value, as encoded in the descriptor at the specified byte offset.
 Descriptor nextDescriptor()
          Provides successive access to all the descriptors in a block such a complete configuration descriptor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_DEVICE

public static final byte TYPE_DEVICE
Indicates a device descriptor

TYPE_CONFIGURATION

public static final byte TYPE_CONFIGURATION
Indicates a configuration descriptor

TYPE_STRING

public static final byte TYPE_STRING
Indicates a string descriptor

TYPE_INTERFACE

public static final byte TYPE_INTERFACE
Indicates an interface descriptor

TYPE_ENDPOINT

public static final byte TYPE_ENDPOINT
Indicates an endpoint descriptor

TYPE_DEVICE_QUALIFIER

public static final byte TYPE_DEVICE_QUALIFIER
Indicates a USB 2.0 "device qualifier"

TYPE_OTHER_SPEED

public static final byte TYPE_OTHER_SPEED
Indicates a USB 2.0 "other speed configuration"

TYPE_INTERFACE_POWER

public static final byte TYPE_INTERFACE_POWER
Indicates interface power consumption

TYPE_HID

public static final byte TYPE_HID
Indicates a hid class descriptor

TYPE_REPORT

public static final byte TYPE_REPORT

TYPE_PHYSICAL

public static final byte TYPE_PHYSICAL

TYPE_HUB

public static final byte TYPE_HUB
Indicates a hub class descriptor

CLASS_AUDIO

public static final byte CLASS_AUDIO
Identifier for audio class interfaces.

CLASS_COMM

public static final byte CLASS_COMM
Identifier for communications control class interfaces.

CLASS_HID

public static final byte CLASS_HID
Identifier for Human Interaction Device (HID) class interfaces.

CLASS_PRINTER

public static final byte CLASS_PRINTER
Identifier for printer class interfaces.

CLASS_MASS_STORAGE

public static final byte CLASS_MASS_STORAGE
Identifier for mass storage class interfaces.

CLASS_HUB

public static final byte CLASS_HUB
Identifier for hub class interfaces.

CLASS_DATA

public static final byte CLASS_DATA
Identifier for communications data class interfaces.

CLASS_APP_SPECIFIC

public static final byte CLASS_APP_SPECIFIC
Identifier for application-specific interfaces. Subclass codes are used to indicate facilities such as firmware update or an IrDA/USB bridge.

CLASS_VENDOR_SPECIFIC

public static final byte CLASS_VENDOR_SPECIFIC
Identifier for vendor-specific interfaces.
Constructor Detail

Descriptor

protected Descriptor()
Used when deserializing.

Descriptor

protected Descriptor(byte[] raw)
Creates and initializes a descriptor
Method Detail

getDevice

public abstract Device getDevice()
Returns the device with which this USB object is associated.

getLength

public final int getLength()
Returns the length of the descriptor.

getDescriptorType

public final int getDescriptorType()
Returns the descriptor type.

getDescriptorTypeName

public java.lang.String getDescriptorTypeName()
Returns a name for the type of descriptor (such as "device")

getClassName

public static java.lang.String getClassName(int klass,
                                            java.lang.String zeroValue)
Returns the name corresponding to an interface class code. Device class codes are not quite identical to these.

getU8

public final int getU8(int index)
Returns an eight bit unsigned integer value, as encoded in the descriptor at the specified byte offset.

getU16

public final int getU16(int index)
Returns a sixteen bit unsigned integer value, as encoded in the descriptor at the specified byte offset.

getU32

public final int getU32(int index)
Returns a thirty-two bit integer value, as encoded in the descriptor at the specified byte offset. Be careful with sign interpretation.

getBCD

public java.lang.String getBCD(int offset)
Returns the two byte BCD string at the specified offset.

nextDescriptor

public final Descriptor nextDescriptor()
Provides successive access to all the descriptors in a block such a complete configuration descriptor. This returns a "generic" descriptor. Use methods on configurations and interfaces to get Interface and Endpoint descriptor objects. Then if you use this method and see that the type of the resulting descriptor is neither TYPE_INTERFACE nor TYPE_ENDPOINT, you will know that you have some other kind of descriptor, such as a device-specific one.
Returns:
null when no more descriptors are available


Associated source code is licenced under the LGPL.
See http://jusb.sourceforge.net
This documentation was derived from that source code on 24-Jul-2002.