- use getter methods to access Usb_xxx instance variables

git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@220 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c
This commit is contained in:
schlaepfer
2006-11-29 11:44:06 +00:00
parent 9ec7c3c53c
commit af40b52734
12 changed files with 670 additions and 297 deletions

View File

@@ -61,21 +61,20 @@ public class Device {
throw new USBException("LibusbWin.usb_get_busses(): " throw new USBException("LibusbWin.usb_get_busses(): "
+ LibusbJava.usb_strerror()); + LibusbJava.usb_strerror());
} }
return bus; return bus;
} }
private void updateMaxPacketSize(Usb_Device device) throws USBException { private void updateMaxPacketSize(Usb_Device device) throws USBException {
maxPacketSize = -1; maxPacketSize = -1;
Usb_Config_Descriptor[] confDesc = device.config; Usb_Config_Descriptor[] confDesc = device.getConfig();
for (int i = 0; i < confDesc.length; i++) { for (int i = 0; i < confDesc.length; i++) {
Usb_Interface[] int_ = confDesc[i].interface_; Usb_Interface[] int_ = confDesc[i].getInterface();
for (int j = 0; j < int_.length; j++) { for (int j = 0; j < int_.length; j++) {
Usb_Interface_Descriptor[] intDesc = int_[j].altsetting; Usb_Interface_Descriptor[] intDesc = int_[j].getAltsetting();
for (int k = 0; k < intDesc.length; k++) { for (int k = 0; k < intDesc.length; k++) {
Usb_Endpoint_Descriptor[] epDesc = intDesc[k].endpoint; Usb_Endpoint_Descriptor[] epDesc = intDesc[k].getEndpoint();
for (int l = 0; l < epDesc.length; l++) { for (int l = 0; l < epDesc.length; l++) {
maxPacketSize = Math.max(epDesc[l].wMaxPacketSize, maxPacketSize = Math.max(epDesc[l].getWMaxPacketSize(),
maxPacketSize); maxPacketSize);
} }
} }
@@ -93,18 +92,18 @@ public class Device {
Usb_Device device = null; Usb_Device device = null;
// search for device // search for device
while (bus != null) { while (bus != null) {
device = bus.devices; device = bus.getDevices();
while (device != null) { while (device != null) {
Usb_Device_Descriptor devDesc = device.descriptor; Usb_Device_Descriptor devDesc = device.getDescriptor();
if ((devDesc.idVendor == idVendor) if ((devDesc.getIdVendor() == idVendor)
&& (devDesc.idProduct == idProduct)) { && (devDesc.getIdProduct() == idProduct)) {
logger.info("Device found: " + device.filename); logger.info("Device found: " + device.getFilename());
updateMaxPacketSize(device); updateMaxPacketSize(device);
return device; return device;
} }
device = device.next; device = device.getNext();
} }
bus = bus.next; bus = bus.getNext();
} }
return null; return null;
} }
@@ -134,7 +133,7 @@ public class Device {
if (dev == null) { if (dev == null) {
return null; return null;
} }
return dev.descriptor; return dev.getDescriptor();
} }
/** /**
@@ -149,7 +148,7 @@ public class Device {
if (dev == null) { if (dev == null) {
return null; return null;
} }
return dev.config; return dev.getConfig();
} }
/** /**

View File

@@ -16,27 +16,69 @@ package ch.ntb.usb;
*/ */
public class Usb_Bus { public class Usb_Bus {
/** private Usb_Bus next, prev;
* The next and previous bus object
*/ private String dirname;
public Usb_Bus next, prev;
private Usb_Device devices;
private long location;
private Usb_Device root_dev;
/** /**
* Systems String representation of the bus * Get the first device ojects of the devices linked list.<br>
*
* @return the first device ojects of the devices linked list or null
*/ */
public String dirname; public Usb_Device getDevices() {
return devices;
}
/** /**
* Device objects attached to this bus * Returns the systems String representation of the bus.<br>
*
* @return the systems String representation of the bus
*/ */
public Usb_Device devices; public String getDirname() {
return dirname;
}
/** /**
* Location in the USB bus linked list * Returns the next bus object.<br>
*
* @return Returns the next bus object or null
*/ */
public long location; public Usb_Bus getNext() {
return next;
}
public Usb_Device root_dev; /**
* Returns the previous bus object.<br>
*
* @return Returns the previous bus object or null
*/
public Usb_Bus getPrev() {
return prev;
}
/**
* Get the root device of this bus.<br>
*
* @return the root device oject or null
*/
public Usb_Device getRootDev() {
return root_dev;
}
/**
* Returns the location in the USB bus linked list.<br>
*
* @return the location in the USB bus linked list
*/
public long getLocation() {
return location;
}
@Override @Override
public String toString() { public String toString() {

View File

@@ -20,62 +20,119 @@ package ch.ntb.usb;
public class Usb_Config_Descriptor extends Usb_Descriptor { public class Usb_Config_Descriptor extends Usb_Descriptor {
/** /**
* Maximum number of configuration per device * Maximum number of configurations per device
*/ */
public static final int USB_MAXCONFIG = 8; public static final int USB_MAXCONFIG = 8;
/** private short wTotalLength;
* Total length in bytes of data returned.<br>
* When the configuration descriptor is read, it returns the entire private byte bNumInterfaces;
* configuration hierarchy which includes all related interface and endpoint
* descriptors. The <code>wTotalLength</code> field reflects the number of private byte bConfigurationValue;
* bytes in the hierarchy.
*/ private byte iConfiguration;
public short wTotalLength;
private byte bmAttributes;
private byte MaxPower;
private Usb_Interface[] interface_;
private Usb_Config_Descriptor extra; /* Extra descriptors */
private int extralen;
/** /**
* Number of interfaces * Returns the value to use as an argument to select this configuration ({@link LibusbJava#usb_set_configuration(int, int)}).
*
* @return the value to use as an argument to select this configuration
*/ */
public byte bNumInterfaces; public byte getBConfigurationValue() {
return bConfigurationValue;
}
/** /**
* Value to use as an argument to select this configuration ({@link LibusbJava#usb_set_configuration(int, int)}). * Returns the power parameters for this configuration.<br>
*/
public byte bConfigurationValue;
/**
* Index of String descriptor describing this configuration
*/
public byte iConfiguration;
/**
* Specifies power parameters for this configuration<br>
* <br> * <br>
* Bit 7: Reserved, set to 1 (USB 1.0 Bus Powered)<br> * Bit 7: Reserved, set to 1 (USB 1.0 Bus Powered)<br>
* Bit 6: Self Powered<br> * Bit 6: Self Powered<br>
* Bit 5: Remote Wakeup<br> * Bit 5: Remote Wakeup<br>
* Bit 4..0: Reserved, set to 0 * Bit 4..0: Reserved, set to 0
*
* @return the power parameters for this configuration
*/ */
public byte bmAttributes; public byte getBmAttributes() {
return bmAttributes;
}
/** /**
* Maximum power consumption in 2mA units * Returns the number of interfaces.<br>
*
* @return the number of interfaces
*/ */
public byte MaxPower; public byte getBNumInterfaces() {
return bNumInterfaces;
/** }
* USB interface descriptors
*/
public Usb_Interface[] interface_;
/** /**
* Extra descriptors are currently not interpreted because of their unknown * Extra descriptors are currently not interpreted because of their unknown
* structure. * structure.
*
* @return null
*/ */
public Usb_Config_Descriptor extra; /* Extra descriptors */ // TODO: implementation
// TODO public Usb_Config_Descriptor getExtra() {
return extra;
}
public int extralen; /**
* Returns the number of bytes of the extra descriptor.<br>
*
* @return the number of bytes of the extra descriptor
*/
public int getExtralen() {
return extralen;
}
/**
* Returns the index of the String descriptor describing this configuration.<br>
*
* @return the index of the String descriptor
*/
public byte getIConfiguration() {
return iConfiguration;
}
/**
* Returns the USB interface descriptors.<br>
*
* @return the USB interface descriptors
*/
public Usb_Interface[] getInterface() {
return interface_;
}
/**
* Returns the maximum power consumption in 2mA units.<br>
*
* @return the maximum power consumption in 2mA units
*/
public byte getMaxPower() {
return MaxPower;
}
/**
* Returns the total length in bytes of all descriptors.<br>
* When the configuration descriptor is read, it returns the entire
* configuration hierarchy which includes all related interface and endpoint
* descriptors. The <code>wTotalLength</code> field reflects the number of
* bytes in the hierarchy.
*
* @return the total length in bytes of all descriptors
*/
public short getWTotalLength() {
return wTotalLength;
}
@Override @Override
public String toString() { public String toString() {

View File

@@ -35,14 +35,26 @@ public class Usb_Descriptor {
USB_DT_ENDPOINT_AUDIO_SIZE = 9 /* Audio extension */, USB_DT_ENDPOINT_AUDIO_SIZE = 9 /* Audio extension */,
USB_DT_HUB_NONVAR_SIZE = 7; USB_DT_HUB_NONVAR_SIZE = 7;
/** private byte bLength;
* Size of descriptor in bytes
*/ private byte bDescriptorType;
public byte bLength;
/** /**
* Type of descriptor * Get the type of this descriptor.<br>
*
* @return the type of this descriptor
*/ */
public byte bDescriptorType; public byte getBDescriptorType() {
return bDescriptorType;
}
/**
* Get the size of this descriptor in bytes.<br>
*
* @return the size of this descriptor in bytes
*/
public byte getBLength() {
return bLength;
}
} }

View File

@@ -16,49 +16,105 @@ package ch.ntb.usb;
*/ */
public class Usb_Device { public class Usb_Device {
/** private Usb_Device next, prev;
* Pointers to the next and previous device
*/ private String filename;
public Usb_Device next, prev;
private Usb_Bus bus;
private Usb_Device_Descriptor descriptor;
private Usb_Config_Descriptor[] config;
private byte devnum;
private byte num_children;
private Usb_Device children;
/** /**
* Systems String representation * Returns the reference to the bus to which this device is connected.<br>
*
* @return the reference to the bus to which this device is connected
*/ */
public String filename; public Usb_Bus getBus() {
return bus;
}
/** /**
* Reference to the bus to which this device is connected * Returns a reference to the first child.<br>
*
* @return a reference to the first child
*/ */
public Usb_Bus bus; public Usb_Device getChildren() {
return children;
}
/** /**
* USB device descriptor * Returns the USB config descriptors.<br>
*
* @return the USB config descriptors
*/ */
public Usb_Device_Descriptor descriptor; public Usb_Config_Descriptor[] getConfig() {
return config;
}
/** /**
* USB config descriptors * Returns the USB device descriptor.<br>
*
* @return the USB device descriptor
*/ */
public Usb_Config_Descriptor[] config; public Usb_Device_Descriptor getDescriptor() {
return descriptor;
}
/** /**
* Number assigned to this device * Returns the number assigned to this device.<br>
*
* @return the number assigned to this device
*/ */
public byte devnum; public byte getDevnum() {
return devnum;
}
/** /**
* Number of children of this device * Returns the systems String representation.<br>
*
* @return the systems String representation
*/ */
public byte num_children; public String getFilename() {
return filename;
}
/** /**
* Reference to the first child * Returns the pointer to the next device.<br>
*
* @return the pointer to the next device or null
*/ */
public Usb_Device children; public Usb_Device getNext() {
return next;
}
/**
* Returns the number of children of this device.<br>
*
* @return the number of children of this device
*/
public byte getNumChildren() {
return num_children;
}
/**
* Returns the pointer to the previous device.<br>
*
* @return the pointer to the previous device or null
*/
public Usb_Device getPrev() {
return prev;
}
@Override @Override
public String toString() { public String toString() {
return "Usb_Device " + filename; return "Usb_Device " + filename;
} }
} }

View File

@@ -27,79 +27,158 @@ public class Usb_Device_Descriptor extends Usb_Descriptor {
USB_CLASS_MASS_STORAGE = 8, USB_CLASS_HUB = 9, USB_CLASS_DATA = 10, USB_CLASS_MASS_STORAGE = 8, USB_CLASS_HUB = 9, USB_CLASS_DATA = 10,
USB_CLASS_VENDOR_SPEC = 0xff; USB_CLASS_VENDOR_SPEC = 0xff;
private short bcdUSB;
private byte bDeviceClass;
private byte bDeviceSubClass;
private byte bDeviceProtocol;
private byte bMaxPacketSize0;
private short idVendor;
private short idProduct;
private short bcdDevice;
private byte iManufacturer;
private byte iProduct;
private byte iSerialNumber;
private byte bNumConfigurations;
/** /**
* USB Specification number to which the device complies to.<br> * Returns the device release number.<br>
* Assigned by the manufacturer of the device.
*
* @return the device release number
*/
public short getBcdDevice() {
return bcdDevice;
}
/**
* Returns the USB specification number to which the device complies to.<br>
* This field reports the highest version of USB the device supports. The * This field reports the highest version of USB the device supports. The
* value is in binary coded decimal with a format of 0xJJMN where JJ is the * value is in binary coded decimal with a format of 0xJJMN where JJ is the
* major version number, M is the minor version number and N is the sub * major version number, M is the minor version number and N is the sub
* minor version number.<br> * minor version number.<br>
* Examples: USB 2.0 is reported as 0x0200, USB 1.1 as 0x0110 and USB 1.0 as * Examples: USB 2.0 is reported as 0x0200, USB 1.1 as 0x0110 and USB 1.0 as
* 0x100 * 0x100
*
* @return the USB specification number to which the device complies to
*/ */
public short bcdUSB; public short getBcdUSB() {
return bcdUSB;
}
/** /**
* Class code (Assigned by <a href="http://www.usb.org">www.usb.org</a>)<br> * Returns the class code (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
* If equal to zero, each interface specifies it's own class code. If equal * If equal to zero, each interface specifies it's own class code. If equal
* to 0xFF, the class code is vendor specified. Otherwise the field is a * to 0xFF, the class code is vendor specified. Otherwise the field is a
* valid class code. * valid class code.
*
* @return the class code
*/ */
public byte bDeviceClass; public byte getBDeviceClass() {
return bDeviceClass;
}
/** /**
* Subclass code (Assigned by <a href="http://www.usb.org">www.usb.org</a>)<br> * Returns the protocol code (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the protocol code
*/ */
public byte bDeviceSubClass; public byte getBDeviceProtocol() {
return bDeviceProtocol;
}
/** /**
* Protocol code (Assigned by <a href="http://www.usb.org">www.usb.org</a>)<br> * Returns the subclass code (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the subclass code
*/ */
public byte bDeviceProtocol; public byte getBDeviceSubClass() {
return bDeviceSubClass;
}
/** /**
* Maximum packet size for endpoint zero. <br> * Returns the maximum packet size for endpoint zero.<br>
* Valid sizes are 8, 16, 32, 64. * Valid sizes are 8, 16, 32, 64.
*
* @return the maximum packet size for endpoint zero
*/ */
public byte bMaxPacketSize0; public byte getBMaxPacketSize0() {
return bMaxPacketSize0;
}
/** /**
* Vendor ID (Assigned by <a href="http://www.usb.org">www.usb.org</a>)<br> * Returns the number of possible configurations supported at its current
* speed.<br>
*
* @return the number of possible configurations supported at its current
* speed
*/ */
public short idVendor; public byte getBNumConfigurations() {
return bNumConfigurations;
}
/** /**
* Product ID (Assigned by <a href="http://www.usb.org">www.usb.org</a>)<br> * Returns the product ID (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the product ID
*/ */
public short idProduct; public short getIdProduct() {
return idProduct;
}
/** /**
* Device release number<br> * Returns the Vendor ID (Assigned by <a
* Assigned by the manufacturer of the device. * href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the Vendor ID
*/ */
public short bcdDevice; public short getIdVendor() {
return idVendor;
}
/** /**
* Index of manufacturer string descriptor<br> * Returns the index of the manufacturer string descriptor.<br>
* If this value is 0, no string descriptor is used. * If this value is 0, no string descriptor is used.
*
* @return the index of the manufacturer string descriptor
*/ */
public byte iManufacturer; public byte getIManufacturer() {
return iManufacturer;
}
/** /**
* Index of product string descriptor<br> * Returns the index of the product string descriptor.<br>
* If this value is 0, no string descriptor is used. * If this value is 0, no string descriptor is used.
*
* @return the index of the product string descriptor
*/ */
public byte iProduct; public byte getIProduct() {
return iProduct;
}
/** /**
* Index of serial number string descriptor<br> * Returns the index of serial number string descriptor.<br>
* If this value is 0, no string descriptor is used. * If this value is 0, no string descriptor is used.
*
* @return the index of serial number string descriptor
*/ */
public byte iSerialNumber; public byte getISerialNumber() {
return iSerialNumber;
/** }
* Number of possible configurations supported at its current speed
*/
public byte bNumConfigurations;
@Override @Override
public String toString() { public String toString() {

View File

@@ -7,7 +7,7 @@
package ch.ntb.usb; package ch.ntb.usb;
/** /**
* Represents the descriptor of a USB endpoint.<br> * Represents the descriptor of an USB endpoint.<br>
* Endpoint descriptors are used to describe endpoints other than endpoint zero. * Endpoint descriptors are used to describe endpoints other than endpoint zero.
* Endpoint zero is always assumed to be a control endpoint and is configured * Endpoint zero is always assumed to be a control endpoint and is configured
* before any descriptors are even requested. The host will use the information * before any descriptors are even requested. The host will use the information
@@ -46,60 +46,110 @@ public class Usb_Endpoint_Descriptor extends Usb_Descriptor {
USB_ENDPOINT_TYPE_ISOCHRONOUS = 1, USB_ENDPOINT_TYPE_BULK = 2, USB_ENDPOINT_TYPE_ISOCHRONOUS = 1, USB_ENDPOINT_TYPE_BULK = 2,
USB_ENDPOINT_TYPE_INTERRUPT = 3; USB_ENDPOINT_TYPE_INTERRUPT = 3;
private byte bEndpointAddress;
private byte bmAttributes;
private short wMaxPacketSize;
private byte bInterval;
private byte bRefresh;
private byte bSynchAddress;
private Usb_Endpoint_Descriptor extra; /* Extra descriptors */
private int extralen;
/** /**
* Endpoint Address<br> * Returns the endpoint address.<br>
* <br> * <br>
* Bits 3..0: Endpoint number <br> * Bits 3..0: Endpoint number <br>
* Bits 6..4: Reserved. Set to zero <br> * Bits 6..4: Reserved. Set to zero <br>
* Bit 7: Direction. 0 = Out, 1 = In (ignored for control endpoints)<br> * Bit 7: Direction. 0 = Out, 1 = In (ignored for control endpoints)<br>
*
* @return the endpoint address
*/ */
public byte bEndpointAddress; public byte getBEndpointAddress() {
return bEndpointAddress;
}
/** /**
* Returns the intervall for polling endpoint data transfers.<br>
* Value in frame counts. Ignored for Bulk & Control eEndpoints. Isochronous
* endpoints must equal 1 and field may range from 1 to 255 for interrupt
* endpoints.
*
* @return the intervall for polling endpoint data transfers
*/
public byte getBInterval() {
return bInterval;
}
/**
* Returns the attributes of this endpoint.<br>
*
* Bits 1..0: Transfer Type (see <i>USB_ENDPOINT_TYPE_XXX</i>).<br> * Bits 1..0: Transfer Type (see <i>USB_ENDPOINT_TYPE_XXX</i>).<br>
* Bits 7..2: Reserved.<br> * Bits 7..2: Reserved.<br>
* *
* <pre> * <pre>
* If isochronous endpoint: * If isochronous endpoint:
* Bits 3..2: Synchronisation type * Bits 3..2: Synchronisation type
* 00 = No synchronisation * 00 = No synchronisation
* 01 = Asynchronous * 01 = Asynchronous
* 10 = Adaptive * 10 = Adaptive
* 11 = Synchronous * 11 = Synchronous
* Bits 5..4: Usage Type * Bits 5..4: Usage Type
* 00 = Data endpoint * 00 = Data endpoint
* 01 = Feedback endpoint * 01 = Feedback endpoint
* 10 = Explicit feedback data endpoint * 10 = Explicit feedback data endpoint
* 11 = Reserved * 11 = Reserved
* </pre> * </pre>
*
* @return the attributes of this endpoint
*/ */
public byte bmAttributes; public byte getBmAttributes() {
return bmAttributes;
}
/** public byte getBRefresh() {
* Maximum packet size this endpoint is capable of sending or receiving return bRefresh;
*/ }
public short wMaxPacketSize;
/** public byte getBSynchAddress() {
* Intervall for polling endpoint data transfers.<br> return bSynchAddress;
* Value in frame counts. Ignored for Bulk & Control eEndpoints. Isochronous }
* endpoints must equal 1 and field may range from 1 to 255 for interrupt
* endpoints.
*/
public byte bInterval;
public byte bRefresh;
public byte bSynchAddress;
/** /**
* Extra descriptors are currently not interpreted because of their unknown * Extra descriptors are currently not interpreted because of their unknown
* structure. * structure.
*
* @return null
*/ */
public Usb_Endpoint_Descriptor extra; /* Extra descriptors */ // TODO: implementation
// TODO public Usb_Endpoint_Descriptor getExtra() {
return extra;
}
public int extralen; /**
* Returns the number of bytes of the extra descriptor.<br>
*
* @return the number of bytes of the extra descriptor
*/
public int getExtralen() {
return extralen;
}
/**
* Returns the maximum packet size of this endpoint is capable of sending or
* receiving.<br>
*
* @return the maximum packet size
*/
public short getWMaxPacketSize() {
return wMaxPacketSize;
}
@Override @Override
public String toString() { public String toString() {

View File

@@ -20,15 +20,9 @@ public class Usb_Interface {
*/ */
public static final int USB_MAXALTSETTING = 128; /* Hard limit */ public static final int USB_MAXALTSETTING = 128; /* Hard limit */
/** private Usb_Interface_Descriptor[] altsetting;
* Interface descriptors
*/
public Usb_Interface_Descriptor[] altsetting;
/** private int num_altsetting;
* Number of alternate settings
*/
public int num_altsetting;
@Override @Override
public String toString() { public String toString() {
@@ -36,4 +30,22 @@ public class Usb_Interface {
+ Integer.toHexString(num_altsetting); + Integer.toHexString(num_altsetting);
} }
/**
* Retuns an array of interface descriptors.<br>
*
* @return an array of interface descriptors
*/
public Usb_Interface_Descriptor[] getAltsetting() {
return altsetting;
}
/**
* Returns the number of alternate settings.<br>
*
* @return the number of alternate settings
*/
public int getNumAltsetting() {
return num_altsetting;
}
} }

View File

@@ -21,62 +21,128 @@ package ch.ntb.usb;
public class Usb_Interface_Descriptor extends Usb_Descriptor { public class Usb_Interface_Descriptor extends Usb_Descriptor {
/** /**
* Maximal number of interfaces * Maximum number of interfaces
*/ */
public static final int USB_MAXINTERFACES = 32; public static final int USB_MAXINTERFACES = 32;
/** private byte bInterfaceNumber;
* Number (identifier) of interface
*/
public byte bInterfaceNumber;
/** private byte bAlternateSetting;
* Value used to select alternate setting ({@link LibusbJava#usb_set_altinterface(int, int)}).
*/
public byte bAlternateSetting;
/** private byte bNumEndpoints;
* Number of Endpoints used for this interface
*/
public byte bNumEndpoints;
/** private byte bInterfaceClass;
* Class code (Assigned by <a href="http://www.usb.org">www.usb.org</a>)<br>
*/
public byte bInterfaceClass;
/** private byte bInterfaceSubClass;
* Subclass code (Assigned by <a href="http://www.usb.org">www.usb.org</a>)<br>
*/
public byte bInterfaceSubClass;
/** private byte bInterfaceProtocol;
* Protocol code (Assigned by <a href="http://www.usb.org">www.usb.org</a>)<br>
*/
public byte bInterfaceProtocol;
/** private byte iInterface;
* Index of String descriptor describing this interface
*/
public byte iInterface;
/** private Usb_Endpoint_Descriptor[] endpoint;
* Endpoint descriptors
*/
public Usb_Endpoint_Descriptor[] endpoint;
/** private Usb_Interface_Descriptor extra; /* Extra descriptors */
* Extra descriptors are currently not interpreted because of their unknown
* structure.
*/
public Usb_Interface_Descriptor extra; /* Extra descriptors */
// TODO
public int extralen; private int extralen;
@Override @Override
public String toString() { public String toString() {
return "Usb_Interface_Descriptor bNumEndpoints: 0x" return "Usb_Interface_Descriptor bNumEndpoints: 0x"
+ Integer.toHexString(bNumEndpoints); + Integer.toHexString(bNumEndpoints);
} }
/**
* Returns the value used to select the alternate setting ({@link LibusbJava#usb_set_altinterface(int, int)}).<br>
*
* @return the alternate setting
*/
public byte getBAlternateSetting() {
return bAlternateSetting;
}
/**
* Returns the class code (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>).<br>
*
* @return the class code
*/
public byte getBInterfaceClass() {
return bInterfaceClass;
}
/**
* Returns the number (identifier) of this interface.<br>
*
* @return the number (identifier) of this interface
*/
public byte getBInterfaceNumber() {
return bInterfaceNumber;
}
/**
* Returns the protocol code (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>).<br>
*
* @return the protocol code
*/
public byte getBInterfaceProtocol() {
return bInterfaceProtocol;
}
/**
* Returns the subclass code (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>).<br>
*
* @return the subclass code
*/
public byte getBInterfaceSubClass() {
return bInterfaceSubClass;
}
/**
* Returns the number of endpoints used for this interface.<br>
*
* @return the number of endpoints used for this interface
*/
public byte getBNumEndpoints() {
return bNumEndpoints;
}
/**
* Returns an array of endpoint descriptors.<br>
*
* @return an array of endpoint descriptors
*/
public Usb_Endpoint_Descriptor[] getEndpoint() {
return endpoint;
}
/**
* Extra descriptors are currently not interpreted because of their unknown
* structure.
*
* @return null
*/
// TODO: implementation
public Usb_Interface_Descriptor getExtra() {
return extra;
}
/**
* Returns the number of bytes of the extra descriptor.<br>
*
* @return the number of bytes of the extra descriptor
*/
public int getExtralen() {
return extralen;
}
/**
* Returns the index of the String descriptor describing this interface.<br>
*
* @return the index of the String descriptor
*/
public byte getIInterface() {
return iInterface;
}
} }

View File

@@ -12,26 +12,26 @@ public class Utils {
Usb_Bus usb_Bus = bus; Usb_Bus usb_Bus = bus;
while (usb_Bus != null) { while (usb_Bus != null) {
System.out.println(usb_Bus.toString()); System.out.println(usb_Bus.toString());
Usb_Device dev = usb_Bus.devices; Usb_Device dev = usb_Bus.getDevices();
while (dev != null) { while (dev != null) {
System.out.println("\t" + dev.toString()); System.out.println("\t" + dev.toString());
// Usb_Device_Descriptor // Usb_Device_Descriptor
Usb_Device_Descriptor defDesc = dev.descriptor; Usb_Device_Descriptor defDesc = dev.getDescriptor();
System.out.println("\t\t" + defDesc.toString()); System.out.println("\t\t" + defDesc.toString());
// Usb_Config_Descriptor // Usb_Config_Descriptor
Usb_Config_Descriptor[] confDesc = dev.config; Usb_Config_Descriptor[] confDesc = dev.getConfig();
for (int i = 0; i < confDesc.length; i++) { for (int i = 0; i < confDesc.length; i++) {
System.out.println("\t\t" + confDesc[i].toString()); System.out.println("\t\t" + confDesc[i].toString());
Usb_Interface[] int_ = confDesc[i].interface_; Usb_Interface[] int_ = confDesc[i].getInterface();
if (int_ != null) { if (int_ != null) {
for (int j = 0; j < int_.length; j++) { for (int j = 0; j < int_.length; j++) {
System.out.println("\t\t\t" + int_[j].toString()); System.out.println("\t\t\t" + int_[j].toString());
Usb_Interface_Descriptor[] intDesc = int_[j].altsetting; Usb_Interface_Descriptor[] intDesc = int_[j].getAltsetting();
if (intDesc != null) { if (intDesc != null) {
for (int k = 0; k < intDesc.length; k++) { for (int k = 0; k < intDesc.length; k++) {
System.out.println("\t\t\t\t" System.out.println("\t\t\t\t"
+ intDesc[k].toString()); + intDesc[k].toString());
Usb_Endpoint_Descriptor[] epDesc = intDesc[k].endpoint; Usb_Endpoint_Descriptor[] epDesc = intDesc[k].getEndpoint();
if (epDesc != null) { if (epDesc != null) {
for (int e = 0; e < epDesc.length; e++) { for (int e = 0; e < epDesc.length; e++) {
System.out.println("\t\t\t\t\t" System.out.println("\t\t\t\t\t"
@@ -43,9 +43,9 @@ public class Utils {
} }
} }
} }
dev = dev.next; dev = dev.getNext();
} }
usb_Bus = usb_Bus.next; usb_Bus = usb_Bus.getNext();
} }
} }
} }

View File

@@ -59,37 +59,37 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
*/ */
public Object getChild(Object parent, int index) { public Object getChild(Object parent, int index) {
if (parent instanceof Usb_Bus) { if (parent instanceof Usb_Bus) {
Usb_Device device = ((Usb_Bus) parent).devices; Usb_Device device = ((Usb_Bus) parent).getDevices();
int count = 0; int count = 0;
while (device != null) { while (device != null) {
if (count == index) if (count == index)
return device; return device;
count++; count++;
device = device.next; device = device.getNext();
} }
return null; return null;
} else if (parent instanceof Usb_Device) { } else if (parent instanceof Usb_Device) {
Usb_Device dev = (Usb_Device) parent; Usb_Device dev = (Usb_Device) parent;
// return the Usb_Device_Descriptor at index 0 // return the Usb_Device_Descriptor at index 0
if (index == 0) { if (index == 0) {
return dev.descriptor; return dev.getDescriptor();
} }
Usb_Config_Descriptor[] confDescs = dev.config; Usb_Config_Descriptor[] confDescs = dev.getConfig();
if (index >= confDescs.length + 1) if (index >= confDescs.length + 1)
return null; return null;
return confDescs[index - 1]; return confDescs[index - 1];
} else if (parent instanceof Usb_Config_Descriptor) { } else if (parent instanceof Usb_Config_Descriptor) {
Usb_Interface[] intDescs = ((Usb_Config_Descriptor) parent).interface_; Usb_Interface[] intDescs = ((Usb_Config_Descriptor) parent).getInterface();
if (index >= intDescs.length) if (index >= intDescs.length)
return null; return null;
return intDescs[index]; return intDescs[index];
} else if (parent instanceof Usb_Interface) { } else if (parent instanceof Usb_Interface) {
Usb_Interface_Descriptor[] altSettings = ((Usb_Interface) parent).altsetting; Usb_Interface_Descriptor[] altSettings = ((Usb_Interface) parent).getAltsetting();
if (index >= altSettings.length) if (index >= altSettings.length)
return null; return null;
return altSettings[index]; return altSettings[index];
} else if (parent instanceof Usb_Interface_Descriptor) { } else if (parent instanceof Usb_Interface_Descriptor) {
Usb_Endpoint_Descriptor[] endpoints = ((Usb_Interface_Descriptor) parent).endpoint; Usb_Endpoint_Descriptor[] endpoints = ((Usb_Interface_Descriptor) parent).getEndpoint();
if (index >= endpoints.length) if (index >= endpoints.length)
return null; return null;
return endpoints[index]; return endpoints[index];
@@ -102,22 +102,22 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
*/ */
public int getChildCount(Object parent) { public int getChildCount(Object parent) {
if (parent instanceof Usb_Bus) { if (parent instanceof Usb_Bus) {
Usb_Device device = ((Usb_Bus) parent).devices; Usb_Device device = ((Usb_Bus) parent).getDevices();
int count = 0; int count = 0;
while (device != null) { while (device != null) {
count++; count++;
device = device.next; device = device.getNext();
} }
return count; return count;
} else if (parent instanceof Usb_Device) { } else if (parent instanceof Usb_Device) {
// add the Usb_Device_Descriptor // add the Usb_Device_Descriptor
return ((Usb_Device) parent).config.length + 1; return ((Usb_Device) parent).getConfig().length + 1;
} else if (parent instanceof Usb_Config_Descriptor) { } else if (parent instanceof Usb_Config_Descriptor) {
return ((Usb_Config_Descriptor) parent).interface_.length; return ((Usb_Config_Descriptor) parent).getInterface().length;
} else if (parent instanceof Usb_Interface) { } else if (parent instanceof Usb_Interface) {
return ((Usb_Interface) parent).altsetting.length; return ((Usb_Interface) parent).getAltsetting().length;
} else if (parent instanceof Usb_Interface_Descriptor) { } else if (parent instanceof Usb_Interface_Descriptor) {
return ((Usb_Interface_Descriptor) parent).endpoint.length; return ((Usb_Interface_Descriptor) parent).getEndpoint().length;
} }
return 0; return 0;
} }
@@ -172,59 +172,59 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
if (component instanceof Usb_Bus) { if (component instanceof Usb_Bus) {
Usb_Bus bus = (Usb_Bus) component; Usb_Bus bus = (Usb_Bus) component;
StringBuffer sb = new StringBuffer("Usb_Bus\n"); StringBuffer sb = new StringBuffer("Usb_Bus\n");
sb.append("\tdirname: " + bus.dirname + "\n"); sb.append("\tdirname: " + bus.getDirname() + "\n");
sb.append("\tlocation: 0x" + Long.toHexString(bus.location) + "\n"); sb.append("\tlocation: 0x" + Long.toHexString(bus.getLocation()) + "\n");
textArea.setText(sb.toString()); textArea.setText(sb.toString());
} else if (component instanceof Usb_Device) { } else if (component instanceof Usb_Device) {
Usb_Device device = (Usb_Device) component; Usb_Device device = (Usb_Device) component;
StringBuffer sb = new StringBuffer("Usb_Device\n"); StringBuffer sb = new StringBuffer("Usb_Device\n");
sb.append("\tfilename: " + device.filename + "\n"); sb.append("\tfilename: " + device.getFilename() + "\n");
sb.append("\tdevnum: " + device.devnum + "\n"); sb.append("\tdevnum: " + device.getDevnum() + "\n");
sb.append("\tnum_children: " + device.num_children + "\n"); sb.append("\tnum_children: " + device.getNumChildren() + "\n");
textArea.setText(sb.toString()); textArea.setText(sb.toString());
} else if (component instanceof Usb_Device_Descriptor) { } else if (component instanceof Usb_Device_Descriptor) {
Usb_Device_Descriptor devDesc = (Usb_Device_Descriptor) component; Usb_Device_Descriptor devDesc = (Usb_Device_Descriptor) component;
StringBuffer sb = new StringBuffer("Usb_Device_Descriptor\n"); StringBuffer sb = new StringBuffer("Usb_Device_Descriptor\n");
sb.append("\tblenght: 0x" + Integer.toHexString(devDesc.bLength) sb.append("\tblenght: 0x" + Integer.toHexString(devDesc.getBLength())
+ "\n"); + "\n");
sb.append("\tbDescriptorType: 0x" sb.append("\tbDescriptorType: 0x"
+ Integer.toHexString(devDesc.bDescriptorType) + "\n"); + Integer.toHexString(devDesc.getBDescriptorType()) + "\n");
sb.append("\tbcdUSB: 0x" sb.append("\tbcdUSB: 0x"
+ Integer.toHexString(devDesc.bcdUSB & 0xFFFF) + "\n"); + Integer.toHexString(devDesc.getBcdUSB() & 0xFFFF) + "\n");
sb.append("\tbDeviceClass: 0x" sb.append("\tbDeviceClass: 0x"
+ Integer.toHexString(devDesc.bDeviceClass & 0xFF) + "\n"); + Integer.toHexString(devDesc.getBDeviceClass() & 0xFF) + "\n");
sb.append("\tbDeviceSubClass: 0x" sb.append("\tbDeviceSubClass: 0x"
+ Integer.toHexString(devDesc.bDeviceSubClass & 0xFF) + Integer.toHexString(devDesc.getBDeviceSubClass() & 0xFF)
+ "\n"); + "\n");
sb.append("\tbDeviceProtocol: 0x" sb.append("\tbDeviceProtocol: 0x"
+ Integer.toHexString(devDesc.bDeviceProtocol & 0xFF) + Integer.toHexString(devDesc.getBDeviceProtocol() & 0xFF)
+ "\n"); + "\n");
sb.append("\tbMaxPacketSize0: 0x" sb.append("\tbMaxPacketSize0: 0x"
+ Integer.toHexString(devDesc.bMaxPacketSize0 & 0xFF) + Integer.toHexString(devDesc.getBMaxPacketSize0() & 0xFF)
+ " (" + devDesc.bMaxPacketSize0 + ")\n"); + " (" + devDesc.getBMaxPacketSize0() + ")\n");
sb.append("\tidVendor: 0x" sb.append("\tidVendor: 0x"
+ Integer.toHexString(devDesc.idVendor & 0xFFFF) + "\n"); + Integer.toHexString(devDesc.getIdVendor() & 0xFFFF) + "\n");
sb.append("\tidProduct: 0x" sb.append("\tidProduct: 0x"
+ Integer.toHexString(devDesc.idProduct & 0xFFFF) + "\n"); + Integer.toHexString(devDesc.getIdProduct() & 0xFFFF) + "\n");
sb.append("\tbcdDevice: 0x" sb.append("\tbcdDevice: 0x"
+ Integer.toHexString(devDesc.bcdDevice) + "\n"); + Integer.toHexString(devDesc.getBcdDevice()) + "\n");
sb.append("\tiManufacturer: 0x" sb.append("\tiManufacturer: 0x"
+ Integer.toHexString(devDesc.iManufacturer) + "\n"); + Integer.toHexString(devDesc.getIManufacturer()) + "\n");
sb.append("\tiProduct: 0x" + Integer.toHexString(devDesc.iProduct) sb.append("\tiProduct: 0x" + Integer.toHexString(devDesc.getIProduct())
+ "\n"); + "\n");
sb.append("\tiSerialNumber: 0x" sb.append("\tiSerialNumber: 0x"
+ Integer.toHexString(devDesc.iSerialNumber) + "\n"); + Integer.toHexString(devDesc.getISerialNumber()) + "\n");
sb.append("\tbNumConfigurations: 0x" sb.append("\tbNumConfigurations: 0x"
+ Integer.toHexString(devDesc.bNumConfigurations) + "\n"); + Integer.toHexString(devDesc.getBNumConfigurations()) + "\n");
// get device handle to retrieve string descriptors // get device handle to retrieve string descriptors
Usb_Bus bus = rootBus; Usb_Bus bus = rootBus;
while (bus != null) { while (bus != null) {
Usb_Device dev = bus.devices; Usb_Device dev = bus.getDevices();
while (dev != null) { while (dev != null) {
Usb_Device_Descriptor tmpDevDesc = dev.descriptor; Usb_Device_Descriptor tmpDevDesc = dev.getDescriptor();
if ((dev.descriptor != null) if ((dev.getDescriptor() != null)
&& ((dev.descriptor.iManufacturer > 0) && ((dev.getDescriptor().getIManufacturer() > 0)
|| (dev.descriptor.iProduct > 0) || (dev.descriptor.iSerialNumber > 0))) { || (dev.getDescriptor().getIProduct() > 0) || (dev.getDescriptor().getISerialNumber() > 0))) {
if (tmpDevDesc.equals(devDesc)) { if (tmpDevDesc.equals(devDesc)) {
int handle = LibusbJava.usb_open(dev); int handle = LibusbJava.usb_open(dev);
sb.append("\nString descriptors\n"); sb.append("\nString descriptors\n");
@@ -232,27 +232,27 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
sb.append("\terror opening the device\n"); sb.append("\terror opening the device\n");
break; break;
} }
if (dev.descriptor.iManufacturer > 0) { if (dev.getDescriptor().getIManufacturer() > 0) {
String manufacturer = LibusbJava String manufacturer = LibusbJava
.usb_get_string_simple(handle, .usb_get_string_simple(handle,
devDesc.iManufacturer); devDesc.getIManufacturer());
if (manufacturer == null) if (manufacturer == null)
manufacturer = "unable to fetch manufacturer string"; manufacturer = "unable to fetch manufacturer string";
sb.append("\tiManufacturer: " + manufacturer sb.append("\tiManufacturer: " + manufacturer
+ "\n"); + "\n");
} }
if (dev.descriptor.iProduct > 0) { if (dev.getDescriptor().getIProduct() > 0) {
String product = LibusbJava String product = LibusbJava
.usb_get_string_simple(handle, .usb_get_string_simple(handle,
devDesc.iProduct); devDesc.getIProduct());
if (product == null) if (product == null)
product = "unable to fetch product string"; product = "unable to fetch product string";
sb.append("\tiProduct: " + product + "\n"); sb.append("\tiProduct: " + product + "\n");
} }
if (dev.descriptor.iSerialNumber > 0) { if (dev.getDescriptor().getISerialNumber() > 0) {
String serialNumber = LibusbJava String serialNumber = LibusbJava
.usb_get_string_simple(handle, .usb_get_string_simple(handle,
devDesc.iSerialNumber); devDesc.getISerialNumber());
if (serialNumber == null) if (serialNumber == null)
serialNumber = "unable to fetch serial number string"; serialNumber = "unable to fetch serial number string";
sb.append("\tiSerialNumber: " + serialNumber sb.append("\tiSerialNumber: " + serialNumber
@@ -261,41 +261,41 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
LibusbJava.usb_close(handle); LibusbJava.usb_close(handle);
} }
} }
dev = dev.next; dev = dev.getNext();
} }
bus = bus.next; bus = bus.getNext();
} }
textArea.setText(sb.toString()); textArea.setText(sb.toString());
} else if (component instanceof Usb_Config_Descriptor) { } else if (component instanceof Usb_Config_Descriptor) {
Usb_Config_Descriptor confDesc = (Usb_Config_Descriptor) component; Usb_Config_Descriptor confDesc = (Usb_Config_Descriptor) component;
StringBuffer sb = new StringBuffer("Usb_Config_Descriptor\n"); StringBuffer sb = new StringBuffer("Usb_Config_Descriptor\n");
sb.append("\tblenght: 0x" + Integer.toHexString(confDesc.bLength) sb.append("\tblenght: 0x" + Integer.toHexString(confDesc.getBLength())
+ "\n"); + "\n");
sb.append("\tbDescriptorType: 0x" sb.append("\tbDescriptorType: 0x"
+ Integer.toHexString(confDesc.bDescriptorType) + "\n"); + Integer.toHexString(confDesc.getBDescriptorType()) + "\n");
sb.append("\tbNumInterfaces: 0x" sb.append("\tbNumInterfaces: 0x"
+ Integer.toHexString(confDesc.bNumInterfaces) + "\n"); + Integer.toHexString(confDesc.getBNumInterfaces()) + "\n");
sb.append("\tbConfigurationValue: 0x" sb.append("\tbConfigurationValue: 0x"
+ Integer.toHexString(confDesc.bConfigurationValue) + "\n"); + Integer.toHexString(confDesc.getBConfigurationValue()) + "\n");
sb.append("\tiConfiguration: 0x" sb.append("\tiConfiguration: 0x"
+ Integer.toHexString(confDesc.iConfiguration) + "\n"); + Integer.toHexString(confDesc.getIConfiguration()) + "\n");
sb.append("\tbmAttributes: 0x" sb.append("\tbmAttributes: 0x"
+ Integer.toHexString(confDesc.bmAttributes & 0xFF) + "\n"); + Integer.toHexString(confDesc.getBmAttributes() & 0xFF) + "\n");
sb.append("\tMaxPower [mA]: 0x" sb.append("\tMaxPower [mA]: 0x"
+ Integer.toHexString(confDesc.MaxPower & 0xFF) + " (" + Integer.toHexString(confDesc.getMaxPower() & 0xFF) + " ("
+ confDesc.MaxPower + ")\n"); + confDesc.getMaxPower() + ")\n");
sb.append("\textralen: 0x" + Integer.toHexString(confDesc.extralen) sb.append("\textralen: 0x" + Integer.toHexString(confDesc.getExtralen())
+ "\n"); + "\n");
sb.append("\textra: " + confDesc.extra + "\n"); sb.append("\textra: " + confDesc.getExtra() + "\n");
// get device handle to retrieve string descriptors // get device handle to retrieve string descriptors
Usb_Bus bus = rootBus; Usb_Bus bus = rootBus;
while (bus != null) { while (bus != null) {
Usb_Device dev = bus.devices; Usb_Device dev = bus.getDevices();
while (dev != null) { while (dev != null) {
Usb_Config_Descriptor[] tmpConfDesc = dev.config; Usb_Config_Descriptor[] tmpConfDesc = dev.getConfig();
for (int i = 0; i < tmpConfDesc.length; i++) { for (int i = 0; i < tmpConfDesc.length; i++) {
if ((tmpConfDesc.equals(confDesc)) if ((tmpConfDesc.equals(confDesc))
&& (confDesc.iConfiguration > 0)) { && (confDesc.getIConfiguration() > 0)) {
int handle = LibusbJava.usb_open(dev); int handle = LibusbJava.usb_open(dev);
sb.append("\nString descriptors\n"); sb.append("\nString descriptors\n");
if (handle <= 0) { if (handle <= 0) {
@@ -304,7 +304,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
} }
String configuration = LibusbJava String configuration = LibusbJava
.usb_get_string_simple(handle, .usb_get_string_simple(handle,
confDesc.iConfiguration); confDesc.getIConfiguration());
if (configuration == null) if (configuration == null)
configuration = "unable to fetch configuration string"; configuration = "unable to fetch configuration string";
sb.append("\tiConfiguration: " + configuration sb.append("\tiConfiguration: " + configuration
@@ -314,58 +314,58 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
} }
} }
dev = dev.next; dev = dev.getNext();
} }
bus = bus.next; bus = bus.getNext();
} }
textArea.setText(sb.toString()); textArea.setText(sb.toString());
} else if (component instanceof Usb_Interface) { } else if (component instanceof Usb_Interface) {
Usb_Interface int_ = (Usb_Interface) component; Usb_Interface int_ = (Usb_Interface) component;
StringBuffer sb = new StringBuffer("Usb_Interface\n"); StringBuffer sb = new StringBuffer("Usb_Interface\n");
sb.append("\tnum_altsetting: 0x" sb.append("\tnum_altsetting: 0x"
+ Integer.toHexString(int_.num_altsetting) + "\n"); + Integer.toHexString(int_.getNumAltsetting()) + "\n");
sb.append("\taltsetting: " + int_.altsetting + "\n"); sb.append("\taltsetting: " + int_.getAltsetting() + "\n");
textArea.setText(sb.toString()); textArea.setText(sb.toString());
} else if (component instanceof Usb_Interface_Descriptor) { } else if (component instanceof Usb_Interface_Descriptor) {
Usb_Interface_Descriptor intDesc = (Usb_Interface_Descriptor) component; Usb_Interface_Descriptor intDesc = (Usb_Interface_Descriptor) component;
StringBuffer sb = new StringBuffer("Usb_Interface_Descriptor\n"); StringBuffer sb = new StringBuffer("Usb_Interface_Descriptor\n");
sb.append("\tblenght: 0x" + Integer.toHexString(intDesc.bLength) sb.append("\tblenght: 0x" + Integer.toHexString(intDesc.getBLength())
+ "\n"); + "\n");
sb.append("\tbDescriptorType: 0x" sb.append("\tbDescriptorType: 0x"
+ Integer.toHexString(intDesc.bDescriptorType) + "\n"); + Integer.toHexString(intDesc.getBDescriptorType()) + "\n");
sb.append("\tbInterfaceNumber: 0x" sb.append("\tbInterfaceNumber: 0x"
+ Integer.toHexString(intDesc.bInterfaceNumber) + "\n"); + Integer.toHexString(intDesc.getBInterfaceNumber()) + "\n");
sb.append("\tbAlternateSetting: 0x" sb.append("\tbAlternateSetting: 0x"
+ Integer.toHexString(intDesc.bAlternateSetting) + "\n"); + Integer.toHexString(intDesc.getBAlternateSetting()) + "\n");
sb.append("\tbNumEndpoints: 0x" sb.append("\tbNumEndpoints: 0x"
+ Integer.toHexString(intDesc.bNumEndpoints) + "\n"); + Integer.toHexString(intDesc.getBNumEndpoints()) + "\n");
sb.append("\tbInterfaceClass: 0x" sb.append("\tbInterfaceClass: 0x"
+ Integer.toHexString(intDesc.bInterfaceClass & 0xFF) + Integer.toHexString(intDesc.getBInterfaceClass() & 0xFF)
+ "\n"); + "\n");
sb.append("\tbInterfaceSubClass: 0x" sb.append("\tbInterfaceSubClass: 0x"
+ Integer.toHexString(intDesc.bInterfaceSubClass & 0xFF) + Integer.toHexString(intDesc.getBInterfaceSubClass() & 0xFF)
+ "\n"); + "\n");
sb.append("\tbInterfaceProtocol: 0x" sb.append("\tbInterfaceProtocol: 0x"
+ Integer.toHexString(intDesc.bInterfaceProtocol & 0xFF) + Integer.toHexString(intDesc.getBInterfaceProtocol() & 0xFF)
+ "\n"); + "\n");
sb.append("\tiInterface: 0x" sb.append("\tiInterface: 0x"
+ Integer.toHexString(intDesc.iInterface) + "\n"); + Integer.toHexString(intDesc.getIInterface()) + "\n");
sb.append("\textralen: 0x" + Integer.toHexString(intDesc.extralen) sb.append("\textralen: 0x" + Integer.toHexString(intDesc.getExtralen())
+ "\n"); + "\n");
sb.append("\textra: " + intDesc.extra + "\n"); sb.append("\textra: " + intDesc.getExtra() + "\n");
// get device handle to retrieve string descriptors // get device handle to retrieve string descriptors
Usb_Bus bus = rootBus; Usb_Bus bus = rootBus;
while (bus != null) { while (bus != null) {
Usb_Device dev = bus.devices; Usb_Device dev = bus.getDevices();
while (dev != null) { while (dev != null) {
Usb_Config_Descriptor[] confDescs = dev.config; Usb_Config_Descriptor[] confDescs = dev.getConfig();
for (int i = 0; i < confDescs.length; i++) { for (int i = 0; i < confDescs.length; i++) {
Usb_Interface[] ints = confDescs[i].interface_; Usb_Interface[] ints = confDescs[i].getInterface();
for (int j = 0; j < ints.length; j++) { for (int j = 0; j < ints.length; j++) {
Usb_Interface_Descriptor[] tmpIntDescs = ints[j].altsetting; Usb_Interface_Descriptor[] tmpIntDescs = ints[j].getAltsetting();
for (int k = 0; k < ints.length; k++) { for (int k = 0; k < ints.length; k++) {
if (tmpIntDescs[i].equals(intDesc) if (tmpIntDescs[i].equals(intDesc)
&& (intDesc.iInterface > 0)) { && (intDesc.getIInterface() > 0)) {
int handle = LibusbJava.usb_open(dev); int handle = LibusbJava.usb_open(dev);
sb.append("\nString descriptors\n"); sb.append("\nString descriptors\n");
if (handle <= 0) { if (handle <= 0) {
@@ -375,7 +375,7 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
} }
String interface_ = LibusbJava String interface_ = LibusbJava
.usb_get_string_simple(handle, .usb_get_string_simple(handle,
intDesc.iInterface); intDesc.getIInterface());
if (interface_ == null) if (interface_ == null)
interface_ = "unable to fetch interface string"; interface_ = "unable to fetch interface string";
sb.append("\tiInterface: " + interface_ sb.append("\tiInterface: " + interface_
@@ -385,35 +385,35 @@ public class UsbTreeModel implements TreeModel, TreeSelectionListener {
} }
} }
} }
dev = dev.next; dev = dev.getNext();
} }
bus = bus.next; bus = bus.getNext();
} }
textArea.setText(sb.toString()); textArea.setText(sb.toString());
} else if (component instanceof Usb_Endpoint_Descriptor) { } else if (component instanceof Usb_Endpoint_Descriptor) {
Usb_Endpoint_Descriptor epDesc = (Usb_Endpoint_Descriptor) component; Usb_Endpoint_Descriptor epDesc = (Usb_Endpoint_Descriptor) component;
StringBuffer sb = new StringBuffer("Usb_Endpoint_Descriptor\n"); StringBuffer sb = new StringBuffer("Usb_Endpoint_Descriptor\n");
sb.append("\tblenght: 0x" + Integer.toHexString(epDesc.bLength) sb.append("\tblenght: 0x" + Integer.toHexString(epDesc.getBLength())
+ "\n"); + "\n");
sb.append("\tbDescriptorType: 0x" sb.append("\tbDescriptorType: 0x"
+ Integer.toHexString(epDesc.bDescriptorType) + "\n"); + Integer.toHexString(epDesc.getBDescriptorType()) + "\n");
sb.append("\tbEndpointAddress: 0x" sb.append("\tbEndpointAddress: 0x"
+ Integer.toHexString(epDesc.bEndpointAddress & 0xFF) + Integer.toHexString(epDesc.getBEndpointAddress() & 0xFF)
+ "\n"); + "\n");
sb.append("\tbmAttributes: 0x" sb.append("\tbmAttributes: 0x"
+ Integer.toHexString(epDesc.bmAttributes & 0xFF) + "\n"); + Integer.toHexString(epDesc.getBmAttributes() & 0xFF) + "\n");
sb.append("\twMaxPacketSize: 0x" sb.append("\twMaxPacketSize: 0x"
+ Integer.toHexString(epDesc.wMaxPacketSize & 0xFFFF) + Integer.toHexString(epDesc.getWMaxPacketSize() & 0xFFFF)
+ " (" + epDesc.wMaxPacketSize + ")\n"); + " (" + epDesc.getWMaxPacketSize() + ")\n");
sb.append("\tbInterval: 0x" + Integer.toHexString(epDesc.bInterval) sb.append("\tbInterval: 0x" + Integer.toHexString(epDesc.getBInterval())
+ "\n"); + "\n");
sb.append("\tbRefresh: 0x" + Integer.toHexString(epDesc.bRefresh) sb.append("\tbRefresh: 0x" + Integer.toHexString(epDesc.getBRefresh())
+ "\n"); + "\n");
sb.append("\tbSynchAddress: 0x" sb.append("\tbSynchAddress: 0x"
+ Integer.toHexString(epDesc.bSynchAddress) + "\n"); + Integer.toHexString(epDesc.getBSynchAddress()) + "\n");
sb.append("\textralen: 0x" + Integer.toHexString(epDesc.extralen) sb.append("\textralen: 0x" + Integer.toHexString(epDesc.getExtralen())
+ "\n"); + "\n");
sb.append("\textra: " + epDesc.extra + "\n"); sb.append("\textra: " + epDesc.getExtra() + "\n");
textArea.setText(sb.toString()); textArea.setText(sb.toString());
} }
} }

View File

@@ -72,11 +72,11 @@ public class DeviceTest {
dev.updateDescriptors(); dev.updateDescriptors();
Usb_Device_Descriptor devDescriptor = dev.getDeviceDescriptor(); Usb_Device_Descriptor devDescriptor = dev.getDeviceDescriptor();
assertTrue(devDescriptor != null); assertTrue(devDescriptor != null);
assertEquals(devinfo.getIdProduct(), devDescriptor.idProduct); assertEquals(devinfo.getIdProduct(), devDescriptor.getIdProduct());
assertEquals(devinfo.getIdVendor(), devDescriptor.idVendor); assertEquals(devinfo.getIdVendor(), devDescriptor.getIdVendor());
Usb_Config_Descriptor confDescriptors[] = dev.getConfigDescriptors(); Usb_Config_Descriptor confDescriptors[] = dev.getConfigDescriptors();
assertTrue(confDescriptors != null); assertTrue(confDescriptors != null);
assertTrue(confDescriptors[0].interface_.length > 0); assertTrue(confDescriptors[0].getInterface().length > 0);
} }
@Test @Test