Completed the general data structures.
This commit is contained in:
parent
cc18ce7446
commit
5d7ae9ba1c
@ -5,6 +5,8 @@
|
||||
|
||||
package de.ailis.usb4java;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
||||
/**
|
||||
* This is the main class of the usb4java JNI wrapper. It wraps the global
|
||||
@ -22,36 +24,91 @@ package de.ailis.usb4java;
|
||||
|
||||
public class USB
|
||||
{
|
||||
/** USB_CLASS_PER_INTERFACE constant. */
|
||||
// === USB class constants ===============================================
|
||||
|
||||
/** Per interface class. */
|
||||
public static final short USB_CLASS_PER_INTERFACE = 0;
|
||||
|
||||
/** USB_CLASS_AUDIO constant. */
|
||||
/** Audio class. */
|
||||
public static final short USB_CLASS_AUDIO = 1;
|
||||
|
||||
/** USB_CLASS_COMM constant. */
|
||||
/** Comm class. */
|
||||
public static final short USB_CLASS_COMM = 2;
|
||||
|
||||
/** USB_CLASS_HID constant. */
|
||||
/** HID class. */
|
||||
public static final short USB_CLASS_HID = 3;
|
||||
|
||||
/** USB_CLASS_PRINTER constant. */
|
||||
/** Printer class. */
|
||||
public static final short USB_CLASS_PRINTER = 7;
|
||||
|
||||
/** USB_CLASS_PTP constant. */
|
||||
/** PTP class. */
|
||||
public static final short USB_CLASS_PTP = 6;
|
||||
|
||||
/** USB_CLASS_MASS_STORAGE constant. */
|
||||
/** Mass storage class. */
|
||||
public static final short USB_CLASS_MASS_STORAGE = 8;
|
||||
|
||||
/** USB_CLASS_HUB constant. */
|
||||
/** HUB class. */
|
||||
public static final short USB_CLASS_HUB = 9;
|
||||
|
||||
/** USB_CLASS_DATA constant. */
|
||||
/** Data class. */
|
||||
public static final short USB_CLASS_DATA = 10;
|
||||
|
||||
/** USB_CLASS_VENDOR_SPEC constant. */
|
||||
/** Vendor specific class. */
|
||||
public static final short USB_CLASS_VENDOR_SPEC = 0xff;
|
||||
|
||||
|
||||
// === Device descriptor type constants ==================================
|
||||
|
||||
|
||||
/** Device descriptor type. */
|
||||
public static final short USB_DT_DEVICE = 0x01;
|
||||
|
||||
/** Config descriptor type. */
|
||||
public static final short USB_DT_CONFIG = 0x02;
|
||||
|
||||
/** String descriptor type. */
|
||||
public static final short USB_DT_STRING = 0x03;
|
||||
|
||||
/** Interface descriptor type. */
|
||||
public static final short USB_DT_INTERFACE = 0x04;
|
||||
|
||||
/** Endpoint descriptor type. */
|
||||
public static final short USB_DT_ENDPOINT = 0x05;
|
||||
|
||||
/** HID descriptor type. */
|
||||
public static final short USB_DT_HID = 0x21;
|
||||
|
||||
/** Report descriptor type. */
|
||||
public static final short USB_DT_REPORT = 0x22;
|
||||
|
||||
/** Physical descriptor type. */
|
||||
public static final short USB_DT_PHYSICAL = 0x23;
|
||||
|
||||
/** Hub descriptor type. */
|
||||
public static final short USB_DT_HUB = 0x29;
|
||||
|
||||
|
||||
// === Descriptor sizes per descriptor type ==============================
|
||||
|
||||
/** Device type descriptor size. */
|
||||
public static final short USB_DT_DEVICE_SIZE = 18;
|
||||
|
||||
/** Config type descriptor size. */
|
||||
public static final short USB_DT_CONFIG_SIZE = 9;
|
||||
|
||||
/** Interface type descriptor size. */
|
||||
public static final short USB_DT_INTERFACE_SIZE = 9;
|
||||
|
||||
/** Endpoint type descriptor size. */
|
||||
public static final short USB_DT_ENDPOINT_SIZE = 7;
|
||||
|
||||
/** Audio endpoint type descriptor size. */
|
||||
public static final short USB_DT_ENDPOINT_AUDIO_SIZE = 9;
|
||||
|
||||
/** Hub Non-Var type descriptor size. */
|
||||
public static final short USB_DT_HUB_NONVAR_SIZE = 7;
|
||||
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
@ -127,7 +184,7 @@ public class USB
|
||||
* @return The USB device handle.
|
||||
*/
|
||||
|
||||
public static native USB_Handle usb_open(USB_Device device);
|
||||
public static native USB_Dev_Handle usb_open(USB_Device device);
|
||||
|
||||
|
||||
/**
|
||||
@ -142,7 +199,7 @@ public class USB
|
||||
* @return 0 on success or < 0 on error.
|
||||
*/
|
||||
|
||||
public static native int usb_close(USB_Handle handle);
|
||||
public static native int usb_close(USB_Dev_Handle handle);
|
||||
|
||||
|
||||
/**
|
||||
@ -166,10 +223,41 @@ public class USB
|
||||
* @return The number of bytes read or < 0 on error.
|
||||
*/
|
||||
|
||||
public static native int usb_get_string(USB_Handle handle,
|
||||
public static native int usb_get_string(USB_Dev_Handle handle,
|
||||
int index, int langid, byte[] buffer, int buflen);
|
||||
|
||||
|
||||
/**
|
||||
* Returns a string descriptor from a device.
|
||||
*
|
||||
* @param handle
|
||||
* The USB device handle.
|
||||
* @param index
|
||||
* The string description index.
|
||||
* @param langid
|
||||
* The language id.
|
||||
* @param size
|
||||
* The maximum number of bytes to read.
|
||||
* @return The string or null if an error occurred.
|
||||
*/
|
||||
|
||||
public static String usb_get_string(final USB_Dev_Handle handle,
|
||||
final int index, final int langid, final int size)
|
||||
{
|
||||
final byte[] buffer = new byte[size];
|
||||
final int len = usb_get_string(handle, index, langid, buffer, size);
|
||||
if (len < 0) return null;
|
||||
try
|
||||
{
|
||||
return new String(buffer, 0, size, "UTF-8");
|
||||
}
|
||||
catch (final UnsupportedEncodingException e)
|
||||
{
|
||||
return new String(buffer, 0, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a string descriptor from a device using the first language.
|
||||
*
|
||||
@ -189,6 +277,35 @@ public class USB
|
||||
* @return The number of bytes read or < 0 on error.
|
||||
*/
|
||||
|
||||
public static native int usb_get_string_simple(USB_Handle handle,
|
||||
public static native int usb_get_string_simple(USB_Dev_Handle handle,
|
||||
int index, byte[] buffer, int buflen);
|
||||
|
||||
|
||||
/**
|
||||
* Returns a string descriptor from a device using the first language.
|
||||
*
|
||||
* @param handle
|
||||
* The USB device handle.
|
||||
* @param index
|
||||
* The string description index.
|
||||
* @param size
|
||||
* The maximum number of bytes to read.
|
||||
* @return The string or null if an error occurred.
|
||||
*/
|
||||
|
||||
public static String usb_get_string_simple(final USB_Dev_Handle handle,
|
||||
final int index, final int size)
|
||||
{
|
||||
final byte[] buffer = new byte[size];
|
||||
final int len = usb_get_string_simple(handle, index, buffer, size);
|
||||
if (len < 0) return null;
|
||||
try
|
||||
{
|
||||
return new String(buffer, 0, size, "UTF-8");
|
||||
}
|
||||
catch (final UnsupportedEncodingException e)
|
||||
{
|
||||
return new String(buffer, 0, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ package de.ailis.usb4java;
|
||||
|
||||
|
||||
/**
|
||||
* USB Bus.
|
||||
* The low-level USB Bus.
|
||||
*
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
@ -17,6 +17,7 @@ public class USB_Bus
|
||||
/** Pointer to low-level C structure. */
|
||||
final long pointer;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@ -31,9 +32,9 @@ public class USB_Bus
|
||||
|
||||
|
||||
/**
|
||||
* Returns the dirname.
|
||||
* Returns the directory name of the USB bus.
|
||||
*
|
||||
* @return The dirname.
|
||||
* @return The directory name. Never null.
|
||||
*/
|
||||
|
||||
public native String dirname();
|
||||
@ -58,18 +59,23 @@ public class USB_Bus
|
||||
|
||||
|
||||
/**
|
||||
* Returns the location.
|
||||
* Returns the location. The original datatype for this information is
|
||||
* an unsigned 32 bit integer. To avoid problems with values larger than
|
||||
* 0x7fffffff the wrapper returns a long integer instead.
|
||||
*
|
||||
* @return The location.
|
||||
* @return The location (32 bit unsigned integer).
|
||||
*/
|
||||
|
||||
public native long location();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the USB devices.
|
||||
* Returns the USB devices. Actually this returns the first USB device and
|
||||
* you can use the {@link USB_Device#next()} and {@link USB_Device#prev()}
|
||||
* methods to navigate to the other devices. When no USB device was found
|
||||
* then null is returned.
|
||||
*
|
||||
* @return The USB devices or null if none.
|
||||
* @return The first USB device or null if none.
|
||||
*/
|
||||
|
||||
public native USB_Device devices();
|
||||
|
||||
@ -7,7 +7,8 @@ package de.ailis.usb4java;
|
||||
|
||||
|
||||
/**
|
||||
* USB config descriptor.
|
||||
* THe USB configuration descriptor describes information about a specific USB
|
||||
* device configuration.
|
||||
*
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
@ -30,25 +31,132 @@ public class USB_Config_Descriptor
|
||||
this.pointer = pointer;
|
||||
}
|
||||
|
||||
public native byte bLength();
|
||||
/**
|
||||
* The size of the descriptor in bytes.
|
||||
*
|
||||
* @return The descriptor size in bytes (unsigned byte).
|
||||
*/
|
||||
|
||||
public native byte bDescriptorType();
|
||||
public native short bLength();
|
||||
|
||||
public native short wTotalLength();
|
||||
|
||||
public native byte bNumInterfaces();
|
||||
/**
|
||||
* Returns the configuration descriptor type.
|
||||
*
|
||||
* @return The configuration descriptor type (unsigned byte).
|
||||
*/
|
||||
|
||||
public native byte bConfigurationValue();
|
||||
public native short bDescriptorType();
|
||||
|
||||
public native byte iConfiguration();
|
||||
|
||||
public native byte bmAttributes();
|
||||
/**
|
||||
* Returns the total size of the data returned for this configuration
|
||||
* including the length of all descriptors returned for this configuration
|
||||
*
|
||||
* @return The total length of all configuration data (unsigned short).
|
||||
*/
|
||||
|
||||
public native byte MaxPower();
|
||||
public native int wTotalLength();
|
||||
|
||||
public native short extralen();
|
||||
|
||||
/**
|
||||
* Returns the number of supported interfaces.
|
||||
*
|
||||
* @return The number of supported interfaces (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bNumInterfaces();
|
||||
|
||||
|
||||
/**
|
||||
* The value to be used for usb_set_configuration() to select this
|
||||
* configuration.
|
||||
*
|
||||
* @return The configuration value (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bConfigurationValue();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the index of the string descriptor describing this configuation.
|
||||
*
|
||||
* @return The index of the string descriptor describing this configuation
|
||||
* (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short iConfiguration();
|
||||
|
||||
|
||||
/**
|
||||
* Returns a bitmap with configuration attributes.
|
||||
* <ul>
|
||||
* <li>Bit 7: Reserved.</li>
|
||||
* <li>Bit 6: Self-powered.</li>
|
||||
* <li>Bit 5: Remote wakeup.</li>
|
||||
* <li>Bit 4: Reserved.</li>
|
||||
* <li>Bit 3: Reserved.</li>
|
||||
* <li>Bit 2: Reserved.</li>
|
||||
* <li>Bit 1: Reserved.</li>
|
||||
* <li>Bit 0: Reserved.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return A bitmap with configuration attributes (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bmAttributes();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the maximum power consumption of the device when this
|
||||
* configuration is active and the device is fully operational. The power
|
||||
* is expressed in 2 maA units (50 means 100mA for example).
|
||||
*
|
||||
* @return The maximum power consumption in 2mA units (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bMaxPower();
|
||||
|
||||
|
||||
/**
|
||||
* @see USB_Config_Descriptor#bMaxPower
|
||||
*
|
||||
* @return The maximum power consumption in 2mA units (unsigned byte).
|
||||
* @deprecated Use {@link USB_Config_Descriptor#bMaxPower()} instead.
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
public short MaxPower()
|
||||
{
|
||||
return bMaxPower();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the length of the extra data block in bytes.
|
||||
*
|
||||
* @return The length of the extra data block in bytes.
|
||||
*/
|
||||
|
||||
public native int extralen();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the extra data block.
|
||||
*
|
||||
* @return The extra data block.
|
||||
*/
|
||||
|
||||
public native byte[] extra();
|
||||
|
||||
public native USB_Interface[] interface_();
|
||||
|
||||
/**
|
||||
* Returns the interfaces of this USB configuration. The original method
|
||||
* is named "interface" but this can't be used in Java because it is a
|
||||
* reserved word.
|
||||
*
|
||||
* @return The interfaces of this USB configuration.
|
||||
*/
|
||||
|
||||
public native USB_Interface[] iface();
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ package de.ailis.usb4java;
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
|
||||
public class USB_Handle
|
||||
public class USB_Dev_Handle
|
||||
{
|
||||
/** The low-level pointer to the C structure. */
|
||||
final long pointer;
|
||||
@ -25,7 +25,7 @@ public class USB_Handle
|
||||
* The low-level pointer to the C structure.
|
||||
*/
|
||||
|
||||
USB_Handle(final long pointer)
|
||||
USB_Dev_Handle(final long pointer)
|
||||
{
|
||||
this.pointer = pointer;
|
||||
}
|
||||
@ -68,18 +68,22 @@ public class USB_Device
|
||||
|
||||
|
||||
/**
|
||||
* Returns the device number.
|
||||
* Returns the device number. The original data type for this
|
||||
* information is an unsigned byte. This wrapper returns a short int
|
||||
* instead to avoid problems with values larger then 127.
|
||||
*
|
||||
* @return The device number.
|
||||
* @return The device number (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short devnum();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of child devices.
|
||||
* Returns the number of child devices. The original data type for this
|
||||
* information is an unsigned byte. This wrapper returns a short int
|
||||
* instead to avoid problems with values larger then 127.
|
||||
*
|
||||
* @return The number of child devices.
|
||||
* @return The number of child devices (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short num_children();
|
||||
|
||||
@ -7,7 +7,9 @@ package de.ailis.usb4java;
|
||||
|
||||
|
||||
/**
|
||||
* USB device descriptor.
|
||||
* The USB device descriptor contains global information about a USB device and
|
||||
* all its configurations. A USB device can only have a single device
|
||||
* descriptor.
|
||||
*
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
@ -30,31 +32,163 @@ public class USB_Device_Descriptor
|
||||
this.pointer = pointer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the descriptor size in bytes.
|
||||
*
|
||||
* @return The descriptor size in bytes (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bLength();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the device descriptor type.
|
||||
*
|
||||
* @return The device descriptor type (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bDescriptorType();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the release number of the USB specification with which the device
|
||||
* and its descriptors are compliant. The number is returned as a
|
||||
* Binary-Coded Decimal. For example 1.51 is decoded as 0x0151.
|
||||
*
|
||||
* @return The USB specification release number (unsigned short).
|
||||
*/
|
||||
|
||||
public native int bcdUSB();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the device class code as assigned by the USB-IF.
|
||||
*
|
||||
* If the code is set to 0x00 then each interface within a configuration
|
||||
* operate independently and specifies its own class information.
|
||||
*
|
||||
* If the code is between 0x01 and 0xfe then the device supports different
|
||||
* class specifications or different interfaces and the interfaces may not
|
||||
* operate independently. The code identifies the class definition used for
|
||||
* the aggregate interfaces.
|
||||
*
|
||||
* If the code is set to 0xff then the device class is vendor-specific.
|
||||
*
|
||||
* @return The device class code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bDeviceClass();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the device sub class code as assigned by the USB-IF.
|
||||
*
|
||||
* The codes are qualified by the value of the
|
||||
* {@link USB_Device_Descriptor#bDeviceClass} field.
|
||||
*
|
||||
* If the bDeviceClass field is set to zero then this field must also be set
|
||||
* to zero.
|
||||
*
|
||||
* If the bDeviceClass field is not set to 0xff, all values are reserved for
|
||||
* assignment by the USB-IF.
|
||||
*
|
||||
* @return The device subclass code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bDeviceSubClass();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the device protocol code as assigned by the USB-IF.
|
||||
*
|
||||
* The codes are qualified by the value of the
|
||||
* {@link USB_Device_Descriptor#bDeviceClass} and the bDeviceSubClass
|
||||
* fields. If a device supports class-specific protocols on a device basis
|
||||
* as opposed to an interface basis then this code identifies the protocols
|
||||
* that the device uses as defined by the specification of the device class.
|
||||
*
|
||||
* If set to zero then the device does not use class-specific protocols on a
|
||||
* device basis but may use class-specific protocols on an interface basis.
|
||||
*
|
||||
* If set to 0xff then the device uses a vendor-specific protocol on a
|
||||
* device basis.
|
||||
*
|
||||
* @return The device protocol code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bDeviceProtocol();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the maximum packet size for endpoint zero. Only sizes of 8, 16,
|
||||
* 32, or 64 are valid.
|
||||
*
|
||||
* @return The maximum packet size for endpoint zero (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bMaxPacketSize0();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the vendor ID as assigned by the USB-IF.
|
||||
*
|
||||
* @return The vendor ID (unsigned short).
|
||||
*/
|
||||
|
||||
public native int idVendor();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the product ID as assigned by the manufacturer.
|
||||
*
|
||||
* @return The product ID (unsigned short).
|
||||
*/
|
||||
|
||||
public native int idProduct();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the device release number in binary-coded decimal.
|
||||
*
|
||||
* @return THe device release number (unsigned short).
|
||||
*/
|
||||
|
||||
public native int bcdDevice();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the index of the manufacturer string descriptor.
|
||||
*
|
||||
* @return The index of the manufacturer string descriptor (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short iManufacturer();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the index of the product string descriptor.
|
||||
*
|
||||
* @return The index of the product string descriptor (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short iProduct();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the index of the serial number string descriptor.
|
||||
*
|
||||
* @return The index of the serial number string descriptor (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short iSerialNumber();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of configurations.
|
||||
*
|
||||
* @return The number of configurations (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bNumConfigurations();
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ package de.ailis.usb4java;
|
||||
|
||||
|
||||
/**
|
||||
* USB endport descriptor.
|
||||
* This descriptor contains information about an endpoint.
|
||||
*
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
@ -30,23 +30,117 @@ public class USB_Endpoint_Descriptor
|
||||
this.pointer = pointer;
|
||||
}
|
||||
|
||||
public native byte bLength();
|
||||
|
||||
public native byte bDescriptorType();
|
||||
/**
|
||||
* Returns the descriptor size in bytes.
|
||||
*
|
||||
* @return The descriptor size in bytes (unsigned byte).
|
||||
*/
|
||||
|
||||
public native byte bEndpointAddress();
|
||||
public native short bLength();
|
||||
|
||||
public native byte bmAttributes();
|
||||
|
||||
public native short wMaxPacketSize();
|
||||
/**
|
||||
* Returns the descriptor type.
|
||||
*
|
||||
* @return The descriptor type (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bDescriptorType();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the endpoint address. THe address is encoded as follos:
|
||||
* <ul>
|
||||
* <li>Bit 7: The direction (ignored by control endpoints), 0=OUT, 1=IN</li>
|
||||
* <li>Bit 6-4: Reserved</li>
|
||||
* <li>Bit 3-0: The endpoint number.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return The endpoint address (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bEndpointAddress();
|
||||
|
||||
/**
|
||||
* Returns the endpoint attributes. This is a bitmask with the following
|
||||
* meaning:
|
||||
* <ul>
|
||||
* <li>Bit 7-6: Reserved</li>
|
||||
* <li>Bit 5-4: Usage type (00=Data endpoint, 01=Feedback endpoint,
|
||||
* 10=Implicit feedback data endpoint, 11=Reserved)</li>
|
||||
* <li>Bit 3-2: Synchronization type (00=No synchronization,
|
||||
* 01=Asynchronous, 10=Adaptive, 11=Synchronous)</li>
|
||||
* <li>Bit 1-0: Transfer type
|
||||
* (00=Control,01=Isochronous,10=Bulk,11=Interrupt)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return The endpoint attributes bitmask (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bmAttributes();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the maximum packet size the endpoint is capable of sending or
|
||||
* receiving when this configuration is selected.
|
||||
*
|
||||
* For all endpoints this maximum packet size is located in bits 10-0.
|
||||
*
|
||||
* Bits 12-11 specify the number of additional opportunities per microframe:
|
||||
* 00=None (1 Transaction per microframe), 01=1 additional (2 per
|
||||
* microframe), 10=2 additional (3 per microframe), 11=Reserved.
|
||||
*
|
||||
* Bits 15-13 are reserved.
|
||||
*
|
||||
* @return The maximum packet size of the endpoint (unsigned short).
|
||||
*/
|
||||
|
||||
public native int wMaxPacketSize();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the interval for polling endpoint for data transfers in frames
|
||||
* or microframes depending on the device operating speed.
|
||||
*
|
||||
* @return The interval for polling endpoint (unsigned byte).
|
||||
*/
|
||||
|
||||
public native byte bInterval();
|
||||
|
||||
public native byte bRefresh();
|
||||
|
||||
public native byte bSynchAddress();
|
||||
/**
|
||||
* Returns the refresh information.
|
||||
*
|
||||
* @return The refresh information (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bRefresh();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the synch address.
|
||||
*
|
||||
* @return The synch address (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bSynchAddress();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the extra descriptor data.
|
||||
*
|
||||
* @return The extra descriptor data.
|
||||
*/
|
||||
|
||||
public native byte[] extra();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size of the extra descriptor data in bytes.
|
||||
*
|
||||
* @return The extra descriptor size.
|
||||
*/
|
||||
|
||||
public native int extralen();
|
||||
}
|
||||
|
||||
@ -30,7 +30,21 @@ public class USB_Interface
|
||||
this.pointer = pointer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the array with all available interface descriptors.
|
||||
*
|
||||
* @return The array with the interface descriptors.
|
||||
*/
|
||||
|
||||
public native USB_Interface_Descriptor[] altsetting();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of available interface descriptors.
|
||||
*
|
||||
* @return The number of available interface descriptors.
|
||||
*/
|
||||
|
||||
public native int num_altsetting();
|
||||
}
|
||||
|
||||
@ -7,7 +7,8 @@ package de.ailis.usb4java;
|
||||
|
||||
|
||||
/**
|
||||
* USB interface descriptor.
|
||||
* The interface descriptor describes a specific interface of a USB
|
||||
* configuration.
|
||||
*
|
||||
* @author Klaus Reimer (k@ailis.de)
|
||||
*/
|
||||
@ -30,27 +31,124 @@ public class USB_Interface_Descriptor
|
||||
this.pointer = pointer;
|
||||
}
|
||||
|
||||
public native byte bLength();
|
||||
|
||||
public native byte bDescriptorType();
|
||||
/**
|
||||
* Returns the size of the descriptor in bytes.
|
||||
*
|
||||
* @return The size of the descriptor in bytes (unsigned byte).
|
||||
*/
|
||||
|
||||
public native byte bInterfaceNumber();
|
||||
public native short bLength();
|
||||
|
||||
public native byte bAlternateSetting();
|
||||
|
||||
public native byte bNumEndpoints();
|
||||
/**
|
||||
* Returns the interface descriptor type.
|
||||
*
|
||||
* @return The interface descriptor type (unsigned byte).
|
||||
*/
|
||||
|
||||
public native byte bInterfaceClass();
|
||||
public native short bDescriptorType();
|
||||
|
||||
public native byte bInterfaceSubClass();
|
||||
|
||||
public native byte bInterfaceProtocol();
|
||||
/**
|
||||
* Returns the zero-based interface number.
|
||||
*
|
||||
* @return The interface number (unsigned byte).
|
||||
*/
|
||||
|
||||
public native byte iInterface();
|
||||
public native short bInterfaceNumber();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value used to select this alternate setting for the
|
||||
* interface.
|
||||
*
|
||||
* @return The value used to select this alternate setting (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bAlternateSetting();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of endpoints.
|
||||
*
|
||||
* @return The number of endpoints (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bNumEndpoints();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the interface class code as assigned by the USB-IF. Class 0 is
|
||||
* reserved for future standardization. Class 0xff means that the interface
|
||||
* class is vendor-specific. All other values are reserved for assignment by
|
||||
* the USB_IF.
|
||||
*
|
||||
* @return The interface class code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bInterfaceClass();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the interface sub class code as assigned by the USB-IF. These
|
||||
* codes are qualified by the interface class. If bInterfaceClass is 0 then
|
||||
* the sub class is also 0. If class is not 0xff then all sub classes are
|
||||
* reserved by the USB-IF.
|
||||
*
|
||||
* @return The interface sub class code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bInterfaceSubClass();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the protocol code as assigned by the USB-IF. These codes are
|
||||
* qualified by the interface class and sub class. If an interface supports
|
||||
* class-specific requests, this code identifies the protocols that the
|
||||
* device uses as defined by the specification of the device class. If this
|
||||
* field is set to zero then the device does not use a class-specific
|
||||
* protocol on this interface. If this field is set to 0xff then the device
|
||||
* uses a vendor-specific protocol for this interface.
|
||||
*
|
||||
* @return The protocol code (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short bInterfaceProtocol();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the index of the string descriptor describing this interface.
|
||||
*
|
||||
* @return The string descriptor index (unsigned byte).
|
||||
*/
|
||||
|
||||
public native short iInterface();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the array with endpoints.
|
||||
*
|
||||
* @return The array with endpoints.
|
||||
*/
|
||||
|
||||
public native USB_Endpoint_Descriptor[] endpoint();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the extra descriptor data.
|
||||
*
|
||||
* @return The extra descriptor data.
|
||||
*/
|
||||
|
||||
public native byte[] extra();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size of the extra data in bytes.
|
||||
*
|
||||
* @return The size of the extra data in bytes.
|
||||
*/
|
||||
|
||||
public native int extralen();
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ public class Dump
|
||||
indent(); System.out.format("bInterval: 0x%02x\n", descriptor.bInterval());
|
||||
indent(); System.out.format("bRefresh: 0x%02x\n", descriptor.bRefresh());
|
||||
indent(); System.out.format("bSynchAddress: 0x%02x\n", descriptor.bSynchAddress());
|
||||
indent(); System.out.format("extralen: 0x%04x\n", descriptor.extralen());
|
||||
indent(); System.out.format("extralen: 0x%08x\n", descriptor.extralen());
|
||||
indent(); System.out.format("extra:");
|
||||
for (i = 0; i < descriptor.extralen(); i++)
|
||||
System.out.format(" %02x", descriptor.extra()[i]);
|
||||
@ -119,7 +119,7 @@ public class Dump
|
||||
indent(); System.out.format("bInterfaceSubClass: 0x%02x\n", descriptor.bInterfaceSubClass());
|
||||
indent(); System.out.format("bInterfaceProtocol: 0x%02x\n", descriptor.bInterfaceProtocol());
|
||||
indent(); System.out.format("iInterface: 0x%02x\n", descriptor.iInterface());
|
||||
indent(); System.out.format("extralen: 0x%04x\n", descriptor.extralen());
|
||||
indent(); System.out.format("extralen: 0x%08x\n", descriptor.extralen());
|
||||
indent(); System.out.format("extra:");
|
||||
for (i = 0; i < descriptor.extralen(); i++)
|
||||
System.out.format(" %02x", descriptor.extra()[i]);
|
||||
@ -146,7 +146,7 @@ public class Dump
|
||||
|
||||
indent(); System.out.format("Interface:\n");
|
||||
level++;
|
||||
indent(); System.out.format("num_altsetting: 0x%04x\n", iface.num_altsetting());
|
||||
indent(); System.out.format("num_altsetting: 0x%08x\n", iface.num_altsetting());
|
||||
indent(); System.out.format("altsetting:\n");
|
||||
level++;
|
||||
for (i = 0; i < iface.num_altsetting(); i++)
|
||||
@ -176,8 +176,8 @@ public class Dump
|
||||
indent(); System.out.format("bConfigurationValue: 0x%02x\n", config.bConfigurationValue());
|
||||
indent(); System.out.format("iConfiguration: 0x%02x\n", config.iConfiguration());
|
||||
indent(); System.out.format("bmAttributes: 0x%02x\n", config.bmAttributes());
|
||||
indent(); System.out.format("MaxPower: 0x%02x\n", config.MaxPower());
|
||||
indent(); System.out.format("extralen: 0x%04x\n", config.extralen());
|
||||
indent(); System.out.format("MaxPower: 0x%02x\n", config.bMaxPower());
|
||||
indent(); System.out.format("extralen: 0x%08x\n", config.extralen());
|
||||
indent(); System.out.format("extra:");
|
||||
for (i = 0; i < config.extralen(); i++)
|
||||
System.out.format(" %02x", config.extra()[i]);
|
||||
@ -185,7 +185,7 @@ public class Dump
|
||||
indent(); System.out.format("Interfaces:\n");
|
||||
level++;
|
||||
for (i = 0; i < config.bNumInterfaces(); i++)
|
||||
dump_interface(config.interface_()[i]);
|
||||
dump_interface(config.iface()[i]);
|
||||
level--;
|
||||
level--;
|
||||
}
|
||||
@ -207,20 +207,20 @@ public class Dump
|
||||
level++;
|
||||
indent(); System.out.format("filename: %s\n", device.filename());
|
||||
indent(); System.out.format("bus: %s\n", device.bus().dirname());
|
||||
indent(); System.out.format("devnum: %i\n", device.devnum());
|
||||
indent(); System.out.format("num_children: %i\n", device.num_children());
|
||||
indent(); System.out.format("devnum: %d\n", device.devnum());
|
||||
indent(); System.out.format("num_children: %d\n", device.num_children());
|
||||
indent(); System.out.format("descriptor:\n");
|
||||
level++;
|
||||
dump_device_descriptor(device.descriptor());
|
||||
level--;
|
||||
// Rename me to USBHandle
|
||||
final USB_Handle handle = usb_open(device);
|
||||
i = usb_get_string_simple(handle, device.descriptor().iManufacturer(), buffer, 255);
|
||||
indent(); System.out.format("Manufacturer: %s\n", i > 0 ? buffer : "Unknown");
|
||||
i = usb_get_string_simple(handle, device.descriptor().iProduct(), buffer, 255);
|
||||
indent(); System.out.format("Product: %s\n", i > 0 ? buffer : "Unknown");
|
||||
i = usb_get_string_simple(handle, device.descriptor().iSerialNumber(), buffer, 255);
|
||||
indent(); System.out.format("Serial: %s\n", i > 0 ? buffer : "Unknown");
|
||||
final USB_Dev_Handle handle = usb_open(device);
|
||||
final String manufacturer = usb_get_string_simple(handle, device.descriptor().iManufacturer(), 255);
|
||||
indent(); System.out.format("Manufacturer: %s\n", manufacturer != null ? manufacturer : "Unknown");
|
||||
final String product = usb_get_string_simple(handle, device.descriptor().iProduct(), 255);
|
||||
indent(); System.out.format("Product: %s\n", product != null ? product : "Unknown");
|
||||
final String serialNumber = usb_get_string_simple(handle, device.descriptor().iSerialNumber(), 255);
|
||||
indent(); System.out.format("Serial: %s\n", serialNumber != null ? serialNumber : "Unknown");
|
||||
usb_close(handle);
|
||||
indent(); System.out.format("config descriptors:\n");
|
||||
level++;
|
||||
@ -264,9 +264,9 @@ public class Dump
|
||||
{
|
||||
usb_init();
|
||||
final int bus_count = usb_find_busses();
|
||||
System.out.format("Found %i busses\n", bus_count);
|
||||
System.out.format("Found %d busses\n", bus_count);
|
||||
final int dev_count = usb_find_devices();
|
||||
System.out.format("Found %i devices\n", dev_count);
|
||||
System.out.format("Found %d devices\n", dev_count);
|
||||
|
||||
USB_Bus bus = usb_get_busses();
|
||||
while (bus != null)
|
||||
@ -274,7 +274,7 @@ public class Dump
|
||||
System.out.format("Bus:\n");
|
||||
level++;
|
||||
indent(); System.out.format("dirname: %s\n", bus.dirname());
|
||||
indent(); System.out.format("location: %i\n", bus.location());
|
||||
indent(); System.out.format("location: %d\n", bus.location());
|
||||
indent(); System.out.format("Root device: ");
|
||||
level++;
|
||||
if (bus.root_dev() != null)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user