Replace tabs with spaces

This commit is contained in:
2015-09-01 13:17:55 +01:00
parent a86b4d35ed
commit e7bf70ef9f
38 changed files with 7816 additions and 7816 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -32,345 +32,345 @@ import com.github.boukefalos.jlibloader.Native;
*/
public class LibusbJava {
/**
* System error codes.<br>
* This list is not complete! For more error codes see the file 'errorno.h'
* on your system.
*/
public static int ERROR_SUCCESS, ERROR_BAD_FILE_DESCRIPTOR,
ERROR_NO_SUCH_DEVICE_OR_ADDRESS, ERROR_BUSY,
ERROR_INVALID_PARAMETER, ERROR_TIMEDOUT, ERROR_IO_ERROR,
ERROR_NOT_ENOUGH_MEMORY;;
/**
* System error codes.<br>
* This list is not complete! For more error codes see the file 'errorno.h'
* on your system.
*/
public static int ERROR_SUCCESS, ERROR_BAD_FILE_DESCRIPTOR,
ERROR_NO_SUCH_DEVICE_OR_ADDRESS, ERROR_BUSY,
ERROR_INVALID_PARAMETER, ERROR_TIMEDOUT, ERROR_IO_ERROR,
ERROR_NOT_ENOUGH_MEMORY;;
/**
* Sets the debugging level of libusb.<br>
*
* The range is from 0 to 255, where 0 disables debug output and 255 enables
* all output. On application start, debugging is disabled (0).
*
* @param level
* 0 to 255
*/
public static native void usb_set_debug(int level);
/**
* Sets the debugging level of libusb.<br>
*
* The range is from 0 to 255, where 0 disables debug output and 255 enables
* all output. On application start, debugging is disabled (0).
*
* @param level
* 0 to 255
*/
public static native void usb_set_debug(int level);
// Core
/**
* Just like the name implies, <code>usb_init</code> sets up some internal
* structures. <code>usb_init</code> must be called before any other
* libusb functions.
*/
public static native void usb_init();
// Core
/**
* Just like the name implies, <code>usb_init</code> sets up some internal
* structures. <code>usb_init</code> must be called before any other
* libusb functions.
*/
public static native void usb_init();
/**
* <code>usb_find_busses</code> will find all of the busses on the system.
*
* @return the number of changes since previous call to this function (total
* of new busses and busses removed).
*/
public static native int usb_find_busses();
/**
* <code>usb_find_busses</code> will find all of the busses on the system.
*
* @return the number of changes since previous call to this function (total
* of new busses and busses removed).
*/
public static native int usb_find_busses();
/**
* <code>usb_find_devices</code> will find all of the devices on each bus.
* This should be called after <code>usb_find_busses</code>.
*
* @return the number of changes since the previous call to this function
* (total of new device and devices removed).
*/
public static native int usb_find_devices();
/**
* <code>usb_find_devices</code> will find all of the devices on each bus.
* This should be called after <code>usb_find_busses</code>.
*
* @return the number of changes since the previous call to this function
* (total of new device and devices removed).
*/
public static native int usb_find_devices();
/**
* <code>usb_get_busses</code> returns a tree of descriptor objects.<br>
* The tree represents the bus structure with devices, configurations,
* interfaces and endpoints. Note that this is only a copy. To refresh the
* information, <code>usb_get_busses()</code> must be called again.<br>
* The name of the objects contained in the tree is starting with
* <code>Usb_</code>.
*
* @return the structure of all busses and devices. <code>Note:</code> The
* java objects are copies of the C structs.
*/
public static native Usb_Bus usb_get_busses();
/**
* <code>usb_get_busses</code> returns a tree of descriptor objects.<br>
* The tree represents the bus structure with devices, configurations,
* interfaces and endpoints. Note that this is only a copy. To refresh the
* information, <code>usb_get_busses()</code> must be called again.<br>
* The name of the objects contained in the tree is starting with
* <code>Usb_</code>.
*
* @return the structure of all busses and devices. <code>Note:</code> The
* java objects are copies of the C structs.
*/
public static native Usb_Bus usb_get_busses();
// Device Operations
/**
* <code>usb_open</code> is to be used to open up a device for use.
* <code>usb_open</code> must be called before attempting to perform any
* operations to the device.
*
* @param dev
* The device to open.
* @return a handle used in future communication with the device. 0 if an
* error has occurred.
*/
public static native long usb_open(Usb_Device dev);
// Device Operations
/**
* <code>usb_open</code> is to be used to open up a device for use.
* <code>usb_open</code> must be called before attempting to perform any
* operations to the device.
*
* @param dev
* The device to open.
* @return a handle used in future communication with the device. 0 if an
* error has occurred.
*/
public static native long usb_open(Usb_Device dev);
/**
* <code>usb_close</code> closes a device opened with
* <code>usb_open</code>.
*
* @param dev_handle
* The handle to the device.
* @return 0 on success or < 0 on error.
*/
public static native int usb_close(long dev_handle);
/**
* <code>usb_close</code> closes a device opened with
* <code>usb_open</code>.
*
* @param dev_handle
* The handle to the device.
* @return 0 on success or < 0 on error.
*/
public static native int usb_close(long dev_handle);
/**
* Sets the active configuration of a device
*
* @param dev_handle
* The handle to the device.
* @param configuration
* The value as specified in the descriptor field
* bConfigurationValue.
* @return 0 on success or < 0 on error.
*/
public static native int usb_set_configuration(long dev_handle,
int configuration);
/**
* Sets the active configuration of a device
*
* @param dev_handle
* The handle to the device.
* @param configuration
* The value as specified in the descriptor field
* bConfigurationValue.
* @return 0 on success or < 0 on error.
*/
public static native int usb_set_configuration(long dev_handle,
int configuration);
/**
* Sets the active alternate setting of the current interface
*
* @param dev_handle
* The handle to the device.
* @param alternate
* The value as specified in the descriptor field
* bAlternateSetting.
* @return 0 on success or < 0 on error.
*/
public static native int usb_set_altinterface(long dev_handle, int alternate);
/**
* Sets the active alternate setting of the current interface
*
* @param dev_handle
* The handle to the device.
* @param alternate
* The value as specified in the descriptor field
* bAlternateSetting.
* @return 0 on success or < 0 on error.
*/
public static native int usb_set_altinterface(long dev_handle, int alternate);
/**
* Clears any halt status on an endpoint.
*
* @param dev_handle
* The handle to the device.
* @param ep
* The value specified in the descriptor field bEndpointAddress.
* @return 0 on success or < 0 on error.
*/
public static native int usb_clear_halt(long dev_handle, int ep);
/**
* Clears any halt status on an endpoint.
*
* @param dev_handle
* The handle to the device.
* @param ep
* The value specified in the descriptor field bEndpointAddress.
* @return 0 on success or < 0 on error.
*/
public static native int usb_clear_halt(long dev_handle, int ep);
/**
* Resets a device by sending a RESET down the port it is connected to.<br>
* <br>
* <b>Causes re-enumeration:</b> After calling <code>usb_reset</code>,
* the device will need to re-enumerate and thusly, requires you to find the
* new device and open a new handle. The handle used to call
* <code>usb_reset</code> will no longer work.
*
* @param dev_handle
* The handle to the device.
* @return 0 on success or < 0 on error.
*/
public static native int usb_reset(long dev_handle);
/**
* Resets a device by sending a RESET down the port it is connected to.<br>
* <br>
* <b>Causes re-enumeration:</b> After calling <code>usb_reset</code>,
* the device will need to re-enumerate and thusly, requires you to find the
* new device and open a new handle. The handle used to call
* <code>usb_reset</code> will no longer work.
*
* @param dev_handle
* The handle to the device.
* @return 0 on success or < 0 on error.
*/
public static native int usb_reset(long dev_handle);
/**
* Claim an interface of a device.<br>
* <br>
* <b>Must be called!:</b> <code>usb_claim_interface</code> must be
* called before you perform any operations related to this interface (like
* <code>usb_set_altinterface, usb_bulk_write</code>, etc).
*
* @param dev_handle
* The handle to the device.
* @param interface_
* The value as specified in the descriptor field
* bInterfaceNumber.
* @return 0 on success or < 0 on error.
*/
public static native int usb_claim_interface(long dev_handle, int interface_);
/**
* Claim an interface of a device.<br>
* <br>
* <b>Must be called!:</b> <code>usb_claim_interface</code> must be
* called before you perform any operations related to this interface (like
* <code>usb_set_altinterface, usb_bulk_write</code>, etc).
*
* @param dev_handle
* The handle to the device.
* @param interface_
* The value as specified in the descriptor field
* bInterfaceNumber.
* @return 0 on success or < 0 on error.
*/
public static native int usb_claim_interface(long dev_handle, int interface_);
/**
* Releases a previously claimed interface
*
* @param dev_handle
* The handle to the device.
* @param interface_
* The value as specified in the descriptor field
* bInterfaceNumber.
* @return 0 on success or < 0 on error.
*/
public static native int usb_release_interface(long dev_handle,
int interface_);
/**
* Releases a previously claimed interface
*
* @param dev_handle
* The handle to the device.
* @param interface_
* The value as specified in the descriptor field
* bInterfaceNumber.
* @return 0 on success or < 0 on error.
*/
public static native int usb_release_interface(long dev_handle,
int interface_);
// Control Transfers
/**
* Performs a control request to the default control pipe on a device. The
* parameters mirror the types of the same name in the USB specification.
*
* @param dev_handle
* The handle to the device.
* @param requesttype
* @param request
* @param value
* @param index
* @param bytes
* @param size
* @param timeout
* @return the number of bytes written/read or < 0 on error.
*/
public static native int usb_control_msg(long dev_handle, int requesttype,
int request, int value, int index, byte[] bytes, int size,
int timeout);
// Control Transfers
/**
* Performs a control request to the default control pipe on a device. The
* parameters mirror the types of the same name in the USB specification.
*
* @param dev_handle
* The handle to the device.
* @param requesttype
* @param request
* @param value
* @param index
* @param bytes
* @param size
* @param timeout
* @return the number of bytes written/read or < 0 on error.
*/
public static native int usb_control_msg(long dev_handle, int requesttype,
int request, int value, int index, byte[] bytes, int size,
int timeout);
/**
* Retrieves the string descriptor specified by index and langid from a
* device.
*
* @param dev_handle
* The handle to the device.
* @param index
* @param langid
* @return the descriptor String or null
*/
public static native String usb_get_string(long dev_handle, int index,
int langid);
/**
* Retrieves the string descriptor specified by index and langid from a
* device.
*
* @param dev_handle
* The handle to the device.
* @param index
* @param langid
* @return the descriptor String or null
*/
public static native String usb_get_string(long dev_handle, int index,
int langid);
/**
* <code>usb_get_string_simple</code> is a wrapper around
* <code>usb_get_string</code> that retrieves the string description
* specified by index in the first language for the descriptor.
*
* @param dev_handle
* The handle to the device.
* @param index
* @return the descriptor String or null
*/
public static native String usb_get_string_simple(long dev_handle, int index);
/**
* <code>usb_get_string_simple</code> is a wrapper around
* <code>usb_get_string</code> that retrieves the string description
* specified by index in the first language for the descriptor.
*
* @param dev_handle
* The handle to the device.
* @param index
* @return the descriptor String or null
*/
public static native String usb_get_string_simple(long dev_handle, int index);
/**
* Retrieves a descriptor from the device identified by the type and index
* of the descriptor from the default control pipe.<br>
* <br>
* See {@link #usb_get_descriptor_by_endpoint(long, int, byte, byte, int)}
* for a function that allows the control endpoint to be specified.
*
* @param dev_handle
* The handle to the device.
* @param type
* @param index
* @param size
* number of charactes which will be retrieved (the length of the
* resulting String)
* @return the descriptor String or null
*/
public static native String usb_get_descriptor(long dev_handle, byte type,
byte index, int size);
/**
* Retrieves a descriptor from the device identified by the type and index
* of the descriptor from the default control pipe.<br>
* <br>
* See {@link #usb_get_descriptor_by_endpoint(long, int, byte, byte, int)}
* for a function that allows the control endpoint to be specified.
*
* @param dev_handle
* The handle to the device.
* @param type
* @param index
* @param size
* number of charactes which will be retrieved (the length of the
* resulting String)
* @return the descriptor String or null
*/
public static native String usb_get_descriptor(long dev_handle, byte type,
byte index, int size);
/**
* Retrieves a descriptor from the device identified by the type and index
* of the descriptor from the control pipe identified by ep.
*
* @param dev_handle
* The handle to the device.
* @param ep
* @param type
* @param index
* @param size
* number of charactes which will be retrieved (the length of the
* resulting String)
* @return the descriptor String or null
*/
public static native String usb_get_descriptor_by_endpoint(long dev_handle,
int ep, byte type, byte index, int size);
/**
* Retrieves a descriptor from the device identified by the type and index
* of the descriptor from the control pipe identified by ep.
*
* @param dev_handle
* The handle to the device.
* @param ep
* @param type
* @param index
* @param size
* number of charactes which will be retrieved (the length of the
* resulting String)
* @return the descriptor String or null
*/
public static native String usb_get_descriptor_by_endpoint(long dev_handle,
int ep, byte type, byte index, int size);
// Bulk Transfers
/**
* Performs a bulk write request to the endpoint specified by ep.
*
* @param dev_handle
* The handle to the device.
* @param ep
* @param bytes
* @param size
* @param timeout
* @return the number of bytes written on success or < 0 on error.
*/
public static native int usb_bulk_write(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
// Bulk Transfers
/**
* Performs a bulk write request to the endpoint specified by ep.
*
* @param dev_handle
* The handle to the device.
* @param ep
* @param bytes
* @param size
* @param timeout
* @return the number of bytes written on success or < 0 on error.
*/
public static native int usb_bulk_write(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
/**
* Performs a bulk read request to the endpoint specified by ep.
*
* @param dev_handle
* The handle to the device.
* @param ep
* @param bytes
* @param size
* @param timeout
* @return the number of bytes read on success or < 0 on error.
*/
public static native int usb_bulk_read(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
/**
* Performs a bulk read request to the endpoint specified by ep.
*
* @param dev_handle
* The handle to the device.
* @param ep
* @param bytes
* @param size
* @param timeout
* @return the number of bytes read on success or < 0 on error.
*/
public static native int usb_bulk_read(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
// Interrupt Transfers
/**
* Performs an interrupt write request to the endpoint specified by ep.
*
* @param dev_handle
* The handle to the device.
* @param ep
* @param bytes
* @param size
* @param timeout
* @return the number of bytes written on success or < 0 on error.
*/
public static native int usb_interrupt_write(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
// Interrupt Transfers
/**
* Performs an interrupt write request to the endpoint specified by ep.
*
* @param dev_handle
* The handle to the device.
* @param ep
* @param bytes
* @param size
* @param timeout
* @return the number of bytes written on success or < 0 on error.
*/
public static native int usb_interrupt_write(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
/**
* Performs a interrupt read request to the endpoint specified by ep.
*
* @param dev_handle
* The handle to the device.
* @param ep
* @param bytes
* @param size
* @param timeout
* @return the number of bytes read on success or < 0 on error.
*/
public static native int usb_interrupt_read(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
/**
* Performs a interrupt read request to the endpoint specified by ep.
*
* @param dev_handle
* The handle to the device.
* @param ep
* @param bytes
* @param size
* @param timeout
* @return the number of bytes read on success or < 0 on error.
*/
public static native int usb_interrupt_read(long dev_handle, int ep,
byte[] bytes, int size, int timeout);
/**
* Returns the error string after an error occured.
*
* @return the last error sring.
*/
public static native String usb_strerror();
/**
* Returns the error string after an error occured.
*
* @return the last error sring.
*/
public static native String usb_strerror();
/** **************************************************************** */
/** **************************************************************** */
/**
* Maps the Java error code to the system error code.<br>
* <br>
* Note that not all error codes are be mapped by this method. For more
* error codes see the file 'errno.h' on your system.<br>
* <br>
* 1: EBADF: Bad file descriptor.<br>
* 2: ENXIO: No such device or address.<br>
* 3: EBUSY: Device or resource busy.<br>
* 4: EINVAL: Invalid argument.<br>
* 5: ETIMEDOUT: Connection timed out.<br>
* 6: EIO: I/O error.<br>
* 7: ENOMEM: Not enough memory.<br>
*
*
* @return the system error code or 100000 if no mapping has been found.
*/
private static native int usb_error_no(int value);
/**
* Maps the Java error code to the system error code.<br>
* <br>
* Note that not all error codes are be mapped by this method. For more
* error codes see the file 'errno.h' on your system.<br>
* <br>
* 1: EBADF: Bad file descriptor.<br>
* 2: ENXIO: No such device or address.<br>
* 3: EBUSY: Device or resource busy.<br>
* 4: EINVAL: Invalid argument.<br>
* 5: ETIMEDOUT: Connection timed out.<br>
* 6: EIO: I/O error.<br>
* 7: ENOMEM: Not enough memory.<br>
*
*
* @return the system error code or 100000 if no mapping has been found.
*/
private static native int usb_error_no(int value);
static {
Native.load("com.github.boukefalos", "jlibusb");
static {
Native.load("com.github.boukefalos", "jlibusb");
// define the error codes
ERROR_SUCCESS = 0;
ERROR_BAD_FILE_DESCRIPTOR = -usb_error_no(1);
ERROR_NO_SUCH_DEVICE_OR_ADDRESS = -usb_error_no(2);
ERROR_BUSY = -usb_error_no(3);
ERROR_INVALID_PARAMETER = -usb_error_no(4);
ERROR_TIMEDOUT = -usb_error_no(5);
ERROR_IO_ERROR = -usb_error_no(6);
ERROR_NOT_ENOUGH_MEMORY = -usb_error_no(7);
}
// define the error codes
ERROR_SUCCESS = 0;
ERROR_BAD_FILE_DESCRIPTOR = -usb_error_no(1);
ERROR_NO_SUCH_DEVICE_OR_ADDRESS = -usb_error_no(2);
ERROR_BUSY = -usb_error_no(3);
ERROR_INVALID_PARAMETER = -usb_error_no(4);
ERROR_TIMEDOUT = -usb_error_no(5);
ERROR_IO_ERROR = -usb_error_no(6);
ERROR_NOT_ENOUGH_MEMORY = -usb_error_no(7);
}
}

View File

@@ -19,300 +19,300 @@ import ch.ntb.usb.logger.LogUtil;
*/
public class USB {
// Standard requests (USB spec 9.4)
/**
* This request returns status for the specified recipient (USB spec 9.4.5).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_GET_STATUS = 0x00;
/**
* This request is used to clear or disable a specific feature (USB spec
* 9.4.1).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_CLEAR_FEATURE = 0x01;
// 0x02 is reserved
/**
* This request is used to set or enable a specific feature (USB spec
* 9.4.9).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SET_FEATURE = 0x03;
// 0x04 is reserved
/**
* This request sets the device address for all future device accesses (USB
* spec 9.4.6).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SET_ADDRESS = 0x05;
/**
* This request returns the specified descriptor if the descriptor exists
* (USB spec 9.4.3).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_GET_DESCRIPTOR = 0x06;
/**
* This request is optional and may be used to update existing descriptors
* or new descriptors may be added (USB spec 9.4.8).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SET_DESCRIPTOR = 0x07;
/**
* This request returns the current device configuration value (USB spec
* 9.4.2).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_GET_CONFIGURATION = 0x08;
/**
* This request sets the device configuration (USB spec 9.4.7).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SET_CONFIGURATION = 0x09;
/**
* This request returns the selected alternate setting for the specified
* interface (USB spec 9.4.4).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_GET_INTERFACE = 0x0A;
/**
* This request allows the host to select an alternate setting for the
* specified interface (USB spec 9.4.10).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SET_INTERFACE = 0x0B;
/**
* This request is used to set and then report an endpoint<6E>s synchronization
* frame (USB spec 9.4.11).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SYNCH_FRAME = 0x0C;
// Standard requests (USB spec 9.4)
/**
* This request returns status for the specified recipient (USB spec 9.4.5).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_GET_STATUS = 0x00;
/**
* This request is used to clear or disable a specific feature (USB spec
* 9.4.1).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_CLEAR_FEATURE = 0x01;
// 0x02 is reserved
/**
* This request is used to set or enable a specific feature (USB spec
* 9.4.9).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SET_FEATURE = 0x03;
// 0x04 is reserved
/**
* This request sets the device address for all future device accesses (USB
* spec 9.4.6).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SET_ADDRESS = 0x05;
/**
* This request returns the specified descriptor if the descriptor exists
* (USB spec 9.4.3).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_GET_DESCRIPTOR = 0x06;
/**
* This request is optional and may be used to update existing descriptors
* or new descriptors may be added (USB spec 9.4.8).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SET_DESCRIPTOR = 0x07;
/**
* This request returns the current device configuration value (USB spec
* 9.4.2).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_GET_CONFIGURATION = 0x08;
/**
* This request sets the device configuration (USB spec 9.4.7).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SET_CONFIGURATION = 0x09;
/**
* This request returns the selected alternate setting for the specified
* interface (USB spec 9.4.4).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_GET_INTERFACE = 0x0A;
/**
* This request allows the host to select an alternate setting for the
* specified interface (USB spec 9.4.10).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SET_INTERFACE = 0x0B;
/**
* This request is used to set and then report an endpoint<6E>s synchronization
* frame (USB spec 9.4.11).
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_SYNCH_FRAME = 0x0C;
// data transfer direction (USB spec 9.3)
/**
* Identifies the direction of data transfer in the second phase of the
* control transfer.<br>
* The state of the Direction bit is ignored if the wLength field is zero,
* signifying there is no Data stage.<br>
* Specifies bit 7 of bmRequestType.
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_TYPE_DIR_HOST_TO_DEVICE = (0x00 << 7),
REQ_TYPE_DIR_DEVICE_TO_HOST = (0x01 << 7);
// data transfer direction (USB spec 9.3)
/**
* Identifies the direction of data transfer in the second phase of the
* control transfer.<br>
* The state of the Direction bit is ignored if the wLength field is zero,
* signifying there is no Data stage.<br>
* Specifies bit 7 of bmRequestType.
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_TYPE_DIR_HOST_TO_DEVICE = (0x00 << 7),
REQ_TYPE_DIR_DEVICE_TO_HOST = (0x01 << 7);
// request types (USB spec 9.3)
/**
* Specifies the type of the request.<br>
* Specifies bits 6..5 of bmRequestType.
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_TYPE_TYPE_STANDARD = (0x00 << 5),
REQ_TYPE_TYPE_CLASS = (0x01 << 5),
REQ_TYPE_TYPE_VENDOR = (0x02 << 5),
REQ_TYPE_TYPE_RESERVED = (0x03 << 5);
// request types (USB spec 9.3)
/**
* Specifies the type of the request.<br>
* Specifies bits 6..5 of bmRequestType.
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_TYPE_TYPE_STANDARD = (0x00 << 5),
REQ_TYPE_TYPE_CLASS = (0x01 << 5),
REQ_TYPE_TYPE_VENDOR = (0x02 << 5),
REQ_TYPE_TYPE_RESERVED = (0x03 << 5);
// request recipient (USB spec 9.3)
/**
* Specifies the intended recipient of the request.<br>
* Requests may be directed to the device, an interface on the device, or a
* specific endpoint on a device. When an interface or endpoint is
* specified, the wIndex field identifies the interface or endpoint.<br>
* Specifies bits 4..0 of bmRequestType.
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_TYPE_RECIP_DEVICE = 0x00,
REQ_TYPE_RECIP_INTERFACE = 0x01, REQ_TYPE_RECIP_ENDPOINT = 0x02,
REQ_TYPE_RECIP_OTHER = 0x03;
// request recipient (USB spec 9.3)
/**
* Specifies the intended recipient of the request.<br>
* Requests may be directed to the device, an interface on the device, or a
* specific endpoint on a device. When an interface or endpoint is
* specified, the wIndex field identifies the interface or endpoint.<br>
* Specifies bits 4..0 of bmRequestType.
*
* @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int,
* boolean)
*/
public static final int REQ_TYPE_RECIP_DEVICE = 0x00,
REQ_TYPE_RECIP_INTERFACE = 0x01, REQ_TYPE_RECIP_ENDPOINT = 0x02,
REQ_TYPE_RECIP_OTHER = 0x03;
/**
* The maximum packet size of a bulk transfer when operating in highspeed
* (480 MB/s) mode.
*/
public static int HIGHSPEED_MAX_BULK_PACKET_SIZE = 512;
/**
* The maximum packet size of a bulk transfer when operating in highspeed
* (480 MB/s) mode.
*/
public static int HIGHSPEED_MAX_BULK_PACKET_SIZE = 512;
/**
* The maximum packet size of a bulk transfer when operating in fullspeed
* (12 MB/s) mode.
*/
public static int FULLSPEED_MAX_BULK_PACKET_SIZE = 64;
/**
* The maximum packet size of a bulk transfer when operating in fullspeed
* (12 MB/s) mode.
*/
public static int FULLSPEED_MAX_BULK_PACKET_SIZE = 64;
private static final Logger logger = LogUtil.getLogger("ch.ntb.usb");
private static final Logger logger = LogUtil.getLogger("ch.ntb.usb");
private static LinkedList<Device> devices = new LinkedList<Device>();
private static LinkedList<Device> devices = new LinkedList<Device>();
private static boolean initUSBDone = false;
private static boolean initUSBDone = false;
/**
* Create a new device an register it in a device list. If the device is
* already registered, a reference to it will be returned.<br>
* After resetting or re-attaching a device the busName and filename may
* change. You can unregister the current device instance (see
* {@link #unregisterDevice(Device)}) and get a new instance with the
* updated bus and filename.
*
* @param idVendor
* the vendor id of the USB device
* @param idProduct
* the product id of the USB device
* @param busName
* optional name of the bus which can be used to distinguish
* multiple devices with the same vendor and product id.<br>
* see {@link Usb_Bus#getDirname()}
* @param filename
* optional filename which can be used to distinguish multiple
* devices with the same vendor and product id.<br>
* see {@link Usb_Device#getFilename()}
* @return a newly created device or an already registered device
*/
public static Device getDevice(short idVendor, short idProduct,
String busName, String filename) {
/**
* Create a new device an register it in a device list. If the device is
* already registered, a reference to it will be returned.<br>
* After resetting or re-attaching a device the busName and filename may
* change. You can unregister the current device instance (see
* {@link #unregisterDevice(Device)}) and get a new instance with the
* updated bus and filename.
*
* @param idVendor
* the vendor id of the USB device
* @param idProduct
* the product id of the USB device
* @param busName
* optional name of the bus which can be used to distinguish
* multiple devices with the same vendor and product id.<br>
* see {@link Usb_Bus#getDirname()}
* @param filename
* optional filename which can be used to distinguish multiple
* devices with the same vendor and product id.<br>
* see {@link Usb_Device#getFilename()}
* @return a newly created device or an already registered device
*/
public static Device getDevice(short idVendor, short idProduct,
String busName, String filename) {
// check if this device is already registered
Device dev = getRegisteredDevice(idVendor, idProduct, busName, filename);
if (dev != null) {
logger.info("return already registered device: " + dev);
return dev;
}
dev = new Device(idVendor, idProduct, busName, filename);
logger.info("create new device: " + dev);
devices.add(dev);
return dev;
}
// check if this device is already registered
Device dev = getRegisteredDevice(idVendor, idProduct, busName, filename);
if (dev != null) {
logger.info("return already registered device: " + dev);
return dev;
}
dev = new Device(idVendor, idProduct, busName, filename);
logger.info("create new device: " + dev);
devices.add(dev);
return dev;
}
/**
* See {@link #getDevice(short, short, String, String)}. The parameter
* <code>filename</code> and <code>busName</code>is set to null.
*
* @param idVendor
* @param idProduct
* @return a newly created device or an already registered device
*/
public static Device getDevice(short idVendor, short idProduct) {
return getDevice(idVendor, idProduct, null, null);
}
/**
* See {@link #getDevice(short, short, String, String)}. The parameter
* <code>filename</code> and <code>busName</code>is set to null.
*
* @param idVendor
* @param idProduct
* @return a newly created device or an already registered device
*/
public static Device getDevice(short idVendor, short idProduct) {
return getDevice(idVendor, idProduct, null, null);
}
/**
* Unregister a registered device.
*
* @param dev
* the device to unregister
* @return true if the device has been removed, else false
*/
public static boolean unregisterDevice(Device dev) {
return devices.remove(dev);
}
/**
* Unregister a registered device.
*
* @param dev
* the device to unregister
* @return true if the device has been removed, else false
*/
public static boolean unregisterDevice(Device dev) {
return devices.remove(dev);
}
/**
* Get an already registered device or null if the device does not exist.<br>
* To uniquely identify a device bus and filename should be set. If only one
* of those is set the first device matching the criteria is returned.
*
* @param idVendor
* the vendor id of the USB device
* @param idProduct
* the product id of the USB device
* @param busName
* the name of the bus which can be used to distinguish multiple
* devices with the same vendor and product id.<br>
* see {@link Usb_Bus#getDirname()}
* @param filename
* an optional filename which can be used to distinguish multiple
* devices with the same vendor and product id. see
* {@link Usb_Device#getFilename()}
*
* @return the device or null
*/
private static Device getRegisteredDevice(short idVendor, short idProduct,
String busName, String filename) {
for (Iterator<Device> iter = devices.iterator(); iter.hasNext();) {
Device dev = iter.next();
// bus and filename
if (busName != null && filename != null) {
if (busName.compareTo(dev.getBusName() == null ? "" : dev
.getBusName()) == 0
&& filename.compareTo(dev.getFilename() == null ? ""
: dev.getFilename()) == 0
&& dev.getIdVendor() == idVendor
&& dev.getIdProduct() == idProduct) {
return dev;
}
} else if (filename != null) {
if (filename.compareTo(dev.getFilename() == null ? "" : dev
.getFilename()) == 0
&& dev.getIdVendor() == idVendor
&& dev.getIdProduct() == idProduct) {
return dev;
}
} else if (busName != null) {
if (busName.compareTo(dev.getBusName() == null ? "" : dev
.getBusName()) == 0
&& dev.getIdVendor() == idVendor
&& dev.getIdProduct() == idProduct) {
return dev;
}
} else if (dev.getIdVendor() == idVendor
&& dev.getIdProduct() == idProduct) {
return dev;
}
}
return null;
}
/**
* Get an already registered device or null if the device does not exist.<br>
* To uniquely identify a device bus and filename should be set. If only one
* of those is set the first device matching the criteria is returned.
*
* @param idVendor
* the vendor id of the USB device
* @param idProduct
* the product id of the USB device
* @param busName
* the name of the bus which can be used to distinguish multiple
* devices with the same vendor and product id.<br>
* see {@link Usb_Bus#getDirname()}
* @param filename
* an optional filename which can be used to distinguish multiple
* devices with the same vendor and product id. see
* {@link Usb_Device#getFilename()}
*
* @return the device or null
*/
private static Device getRegisteredDevice(short idVendor, short idProduct,
String busName, String filename) {
for (Iterator<Device> iter = devices.iterator(); iter.hasNext();) {
Device dev = iter.next();
// bus and filename
if (busName != null && filename != null) {
if (busName.compareTo(dev.getBusName() == null ? "" : dev
.getBusName()) == 0
&& filename.compareTo(dev.getFilename() == null ? ""
: dev.getFilename()) == 0
&& dev.getIdVendor() == idVendor
&& dev.getIdProduct() == idProduct) {
return dev;
}
} else if (filename != null) {
if (filename.compareTo(dev.getFilename() == null ? "" : dev
.getFilename()) == 0
&& dev.getIdVendor() == idVendor
&& dev.getIdProduct() == idProduct) {
return dev;
}
} else if (busName != null) {
if (busName.compareTo(dev.getBusName() == null ? "" : dev
.getBusName()) == 0
&& dev.getIdVendor() == idVendor
&& dev.getIdProduct() == idProduct) {
return dev;
}
} else if (dev.getIdVendor() == idVendor
&& dev.getIdProduct() == idProduct) {
return dev;
}
}
return null;
}
/**
* Returns the root {@link Usb_Bus} element.
*
* @return the root {@link Usb_Bus} element
* @throws USBException
*/
public static Usb_Bus getBus() throws USBException {
if (!initUSBDone) {
init();
}
LibusbJava.usb_find_busses();
LibusbJava.usb_find_devices();
/**
* Returns the root {@link Usb_Bus} element.
*
* @return the root {@link Usb_Bus} element
* @throws USBException
*/
public static Usb_Bus getBus() throws USBException {
if (!initUSBDone) {
init();
}
LibusbJava.usb_find_busses();
LibusbJava.usb_find_devices();
Usb_Bus bus = LibusbJava.usb_get_busses();
if (bus == null) {
throw new USBException("LibusbJava.usb_get_busses(): "
+ LibusbJava.usb_strerror());
}
return bus;
}
Usb_Bus bus = LibusbJava.usb_get_busses();
if (bus == null) {
throw new USBException("LibusbJava.usb_get_busses(): "
+ LibusbJava.usb_strerror());
}
return bus;
}
/**
* Explicitly calls {@link LibusbJava#usb_init()}. Note that you don't need
* to call this procedure as it is called implicitly when creating a new
* device with {@link USB#getDevice(short, short, String, String)}.
*/
public static void init() {
LibusbJava.usb_init();
initUSBDone = true;
}
/**
* Explicitly calls {@link LibusbJava#usb_init()}. Note that you don't need
* to call this procedure as it is called implicitly when creating a new
* device with {@link USB#getDevice(short, short, String, String)}.
*/
public static void init() {
LibusbJava.usb_init();
initUSBDone = true;
}
}

View File

@@ -11,13 +11,13 @@ import java.io.IOException;
public class USBException extends IOException {
public USBException(String string) {
super(string);
}
public USBException(String string) {
super(string);
}
/**
*
*/
private static final long serialVersionUID = 1690857437804284710L;
/**
*
*/
private static final long serialVersionUID = 1690857437804284710L;
}

View File

@@ -9,13 +9,13 @@ package ch.ntb.usb;
public class USBTimeoutException extends USBException {
public USBTimeoutException(String string) {
super(string);
}
public USBTimeoutException(String string) {
super(string);
}
/**
*
*/
private static final long serialVersionUID = -1065328371159778249L;
/**
*
*/
private static final long serialVersionUID = -1065328371159778249L;
}

View File

@@ -15,72 +15,72 @@ package ch.ntb.usb;
*/
public class Usb_Bus {
private Usb_Bus next, prev;
private Usb_Bus next, prev;
private String dirname;
private String dirname;
private Usb_Device devices;
private Usb_Device devices;
private long location;
private long location;
private Usb_Device root_dev;
private Usb_Device root_dev;
/**
* Get the first device ojects of the devices linked list.<br>
*
* @return the first device ojects of the devices linked list or null
*/
public Usb_Device getDevices() {
return devices;
}
/**
* Get the first device ojects of the devices linked list.<br>
*
* @return the first device ojects of the devices linked list or null
*/
public Usb_Device getDevices() {
return devices;
}
/**
* Returns the systems String representation of the bus.<br>
*
* @return the systems String representation of the bus
*/
public String getDirname() {
return dirname;
}
/**
* Returns the systems String representation of the bus.<br>
*
* @return the systems String representation of the bus
*/
public String getDirname() {
return dirname;
}
/**
* Returns the next bus object.<br>
*
* @return Returns the next bus object or null
*/
public Usb_Bus getNext() {
return next;
}
/**
* Returns the next bus object.<br>
*
* @return Returns the next bus object or null
*/
public Usb_Bus getNext() {
return next;
}
/**
* Returns the previous bus object.<br>
*
* @return Returns the previous bus object or null
*/
public Usb_Bus getPrev() {
return prev;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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
public String toString() {
return "Usb_Bus " + dirname;
}
@Override
public String toString() {
return "Usb_Bus " + dirname;
}
}

View File

@@ -18,122 +18,122 @@ package ch.ntb.usb;
*/
public class Usb_Config_Descriptor extends Usb_Descriptor {
/**
* Maximum number of configurations per device
*/
public static final int USB_MAXCONFIG = 8;
/**
* Maximum number of configurations per device
*/
public static final int USB_MAXCONFIG = 8;
private short wTotalLength;
private short wTotalLength;
private byte bNumInterfaces;
private byte bNumInterfaces;
private byte bConfigurationValue;
private byte bConfigurationValue;
private byte iConfiguration;
private byte iConfiguration;
private byte bmAttributes;
private byte bmAttributes;
private byte MaxPower;
private byte MaxPower;
private Usb_Interface[] interface_;
private Usb_Interface[] interface_;
private byte[] extra; /* Extra descriptors */
private byte[] extra; /* Extra descriptors */
private int extralen;
private int extralen;
/**
* Returns the value to use as an argument to select this configuration ({@link LibusbJava#usb_set_configuration(long, int)}).
*
* @return the value to use as an argument to select this configuration
*/
public byte getBConfigurationValue() {
return bConfigurationValue;
}
/**
* Returns the value to use as an argument to select this configuration ({@link LibusbJava#usb_set_configuration(long, int)}).
*
* @return the value to use as an argument to select this configuration
*/
public byte getBConfigurationValue() {
return bConfigurationValue;
}
/**
* Returns the power parameters for this configuration.<br>
* <br>
* Bit 7: Reserved, set to 1 (USB 1.0 Bus Powered)<br>
* Bit 6: Self Powered<br>
* Bit 5: Remote Wakeup<br>
* Bit 4..0: Reserved, set to 0
*
* @return the power parameters for this configuration
*/
public byte getBmAttributes() {
return bmAttributes;
}
/**
* Returns the power parameters for this configuration.<br>
* <br>
* Bit 7: Reserved, set to 1 (USB 1.0 Bus Powered)<br>
* Bit 6: Self Powered<br>
* Bit 5: Remote Wakeup<br>
* Bit 4..0: Reserved, set to 0
*
* @return the power parameters for this configuration
*/
public byte getBmAttributes() {
return bmAttributes;
}
/**
* Returns the number of interfaces.<br>
*
* @return the number of interfaces
*/
public byte getBNumInterfaces() {
return bNumInterfaces;
}
/**
* Returns the number of interfaces.<br>
*
* @return the number of interfaces
*/
public byte getBNumInterfaces() {
return bNumInterfaces;
}
/**
* Returns the data of extra descriptor(s) if available.<br>
*
* @return null or a byte array with the extra descriptor data
*/
public byte[] getExtra() {
return extra;
}
/**
* Returns the data of extra descriptor(s) if available.<br>
*
* @return null or a byte array with the extra descriptor data
*/
public byte[] 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 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 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 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 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;
}
/**
* 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
public String toString() {
return "Usb_Config_Descriptor bNumInterfaces: 0x"
+ Integer.toHexString(bNumInterfaces);
}
@Override
public String toString() {
return "Usb_Config_Descriptor bNumInterfaces: 0x"
+ Integer.toHexString(bNumInterfaces);
}
}

View File

@@ -13,47 +13,47 @@ package ch.ntb.usb;
*/
public class Usb_Descriptor {
/**
* Descriptor types ({@link #bDescriptorType}).
*/
public static final int USB_DT_DEVICE = 0x01, USB_DT_CONFIG = 0x02,
USB_DT_STRING = 0x03, USB_DT_INTERFACE = 0x04,
USB_DT_ENDPOINT = 0x05;
/**
* Descriptor types ({@link #bDescriptorType}).
*/
public static final int USB_DT_DEVICE = 0x01, USB_DT_CONFIG = 0x02,
USB_DT_STRING = 0x03, USB_DT_INTERFACE = 0x04,
USB_DT_ENDPOINT = 0x05;
/**
* Descriptor types ({@link #bDescriptorType}).
*/
public static final int USB_DT_HID = 0x21, USB_DT_REPORT = 0x22,
USB_DT_PHYSICAL = 0x23, USB_DT_HUB = 0x29;
/**
* Descriptor types ({@link #bDescriptorType}).
*/
public static final int USB_DT_HID = 0x21, USB_DT_REPORT = 0x22,
USB_DT_PHYSICAL = 0x23, USB_DT_HUB = 0x29;
/**
* Descriptor sizes per descriptor type ({@link #bLength}).
*/
public static final int USB_DT_DEVICE_SIZE = 18, USB_DT_CONFIG_SIZE = 9,
USB_DT_INTERFACE_SIZE = 9, USB_DT_ENDPOINT_SIZE = 7,
USB_DT_ENDPOINT_AUDIO_SIZE = 9 /* Audio extension */,
USB_DT_HUB_NONVAR_SIZE = 7;
/**
* Descriptor sizes per descriptor type ({@link #bLength}).
*/
public static final int USB_DT_DEVICE_SIZE = 18, USB_DT_CONFIG_SIZE = 9,
USB_DT_INTERFACE_SIZE = 9, USB_DT_ENDPOINT_SIZE = 7,
USB_DT_ENDPOINT_AUDIO_SIZE = 9 /* Audio extension */,
USB_DT_HUB_NONVAR_SIZE = 7;
private byte bLength;
private byte bLength;
private byte bDescriptorType;
private byte bDescriptorType;
/**
* Get the type of this descriptor.<br>
*
* @return the type of this descriptor
*/
public byte getBDescriptorType() {
return bDescriptorType;
}
/**
* Get the type of this descriptor.<br>
*
* @return the type of this descriptor
*/
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;
}
/**
* Get the size of this descriptor in bytes.<br>
*
* @return the size of this descriptor in bytes
*/
public byte getBLength() {
return bLength;
}
}

View File

@@ -15,111 +15,111 @@ package ch.ntb.usb;
*/
public class Usb_Device {
private Usb_Device next, prev;
private Usb_Device next, prev;
private String filename;
private String filename;
private Usb_Bus bus;
private Usb_Bus bus;
private Usb_Device_Descriptor descriptor;
private Usb_Device_Descriptor descriptor;
private Usb_Config_Descriptor[] config;
private Usb_Config_Descriptor[] config;
private byte devnum;
private byte devnum;
private byte num_children;
private byte num_children;
private Usb_Device children;
private Usb_Device children;
/**
* The address of the device structure to be passed to usb_open. This value
* is used only internally so we don't use getter or setter methods.
*/
public long devStructAddr;
/**
* The address of the device structure to be passed to usb_open. This value
* is used only internally so we don't use getter or setter methods.
*/
public long devStructAddr;
/**
* 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 Usb_Bus getBus() {
return bus;
}
/**
* 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 Usb_Bus getBus() {
return bus;
}
/**
* Returns a reference to the first child.<br>
*
* @return a reference to the first child
*/
public Usb_Device getChildren() {
return children;
}
/**
* Returns a reference to the first child.<br>
*
* @return a reference to the first child
*/
public Usb_Device getChildren() {
return children;
}
/**
* Returns the USB config descriptors.<br>
*
* @return the USB config descriptors
*/
public Usb_Config_Descriptor[] getConfig() {
return config;
}
/**
* Returns the USB config descriptors.<br>
*
* @return the USB config descriptors
*/
public Usb_Config_Descriptor[] getConfig() {
return config;
}
/**
* Returns the USB device descriptor.<br>
*
* @return the USB device descriptor
*/
public Usb_Device_Descriptor getDescriptor() {
return descriptor;
}
/**
* Returns the USB device descriptor.<br>
*
* @return the USB device descriptor
*/
public Usb_Device_Descriptor getDescriptor() {
return descriptor;
}
/**
* Returns the number assigned to this device.<br>
*
* @return the number assigned to this device
*/
public byte getDevnum() {
return devnum;
}
/**
* Returns the number assigned to this device.<br>
*
* @return the number assigned to this device
*/
public byte getDevnum() {
return devnum;
}
/**
* Returns the systems String representation.<br>
*
* @return the systems String representation
*/
public String getFilename() {
return filename;
}
/**
* Returns the systems String representation.<br>
*
* @return the systems String representation
*/
public String getFilename() {
return filename;
}
/**
* Returns the pointer to the next device.<br>
*
* @return the pointer to the next device or null
*/
public Usb_Device getNext() {
return next;
}
/**
* Returns the pointer to the next device.<br>
*
* @return the pointer to the next device or null
*/
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 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;
}
/**
* Returns the pointer to the previous device.<br>
*
* @return the pointer to the previous device or null
*/
public Usb_Device getPrev() {
return prev;
}
@Override
public String toString() {
return "Usb_Device " + filename;
}
@Override
public String toString() {
return "Usb_Device " + filename;
}
}

View File

@@ -18,173 +18,173 @@ package ch.ntb.usb;
*
*/
public class Usb_Device_Descriptor extends Usb_Descriptor {
/**
* Device and/or interface class codes.
*/
public static final int USB_CLASS_PER_INTERFACE = 0, USB_CLASS_AUDIO = 1,
USB_CLASS_COMM = 2, USB_CLASS_HID = 3, USB_CLASS_PRINTER = 7,
USB_CLASS_MASS_STORAGE = 8, USB_CLASS_HUB = 9, USB_CLASS_DATA = 10,
USB_CLASS_VENDOR_SPEC = 0xff;
/**
* Device and/or interface class codes.
*/
public static final int USB_CLASS_PER_INTERFACE = 0, USB_CLASS_AUDIO = 1,
USB_CLASS_COMM = 2, USB_CLASS_HID = 3, USB_CLASS_PRINTER = 7,
USB_CLASS_MASS_STORAGE = 8, USB_CLASS_HUB = 9, USB_CLASS_DATA = 10,
USB_CLASS_VENDOR_SPEC = 0xff;
private short bcdUSB;
private short bcdUSB;
private byte bDeviceClass;
private byte bDeviceClass;
private byte bDeviceSubClass;
private byte bDeviceSubClass;
private byte bDeviceProtocol;
private byte bDeviceProtocol;
private byte bMaxPacketSize0;
private byte bMaxPacketSize0;
private short idVendor;
private short idVendor;
private short idProduct;
private short idProduct;
private short bcdDevice;
private short bcdDevice;
private byte iManufacturer;
private byte iManufacturer;
private byte iProduct;
private byte iProduct;
private byte iSerialNumber;
private byte iSerialNumber;
private byte bNumConfigurations;
private byte bNumConfigurations;
/**
* 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 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
* 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
* minor version number.<br>
* Examples: USB 2.0 is reported as 0x0200, USB 1.1 as 0x0110 and USB 1.0 as
* 0x100
*
* @return the USB specification number to which the device complies to
*/
public short getBcdUSB() {
return bcdUSB;
}
/**
* Returns the USB specification number to which the device complies to.<br>
* 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
* major version number, M is the minor version number and N is the sub
* minor version number.<br>
* Examples: USB 2.0 is reported as 0x0200, USB 1.1 as 0x0110 and USB 1.0 as
* 0x100
*
* @return the USB specification number to which the device complies to
*/
public short getBcdUSB() {
return bcdUSB;
}
/**
* 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
* to 0xFF, the class code is vendor specified. Otherwise the field is a
* valid class code.
*
* @return the class code
*/
public byte getBDeviceClass() {
return bDeviceClass;
}
/**
* 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
* to 0xFF, the class code is vendor specified. Otherwise the field is a
* valid class code.
*
* @return the class code
*/
public byte getBDeviceClass() {
return bDeviceClass;
}
/**
* Returns the protocol code (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the protocol code
*/
public byte getBDeviceProtocol() {
return bDeviceProtocol;
}
/**
* Returns the protocol code (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the protocol code
*/
public byte getBDeviceProtocol() {
return bDeviceProtocol;
}
/**
* Returns the subclass code (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the subclass code
*/
public byte getBDeviceSubClass() {
return bDeviceSubClass;
}
/**
* Returns the subclass code (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the subclass code
*/
public byte getBDeviceSubClass() {
return bDeviceSubClass;
}
/**
* Returns the maximum packet size for endpoint zero.<br>
* Valid sizes are 8, 16, 32, 64.
*
* @return the maximum packet size for endpoint zero
*/
public byte getBMaxPacketSize0() {
return bMaxPacketSize0;
}
/**
* Returns the maximum packet size for endpoint zero.<br>
* Valid sizes are 8, 16, 32, 64.
*
* @return the maximum packet size for endpoint zero
*/
public byte getBMaxPacketSize0() {
return bMaxPacketSize0;
}
/**
* Returns the number of possible configurations supported at its current
* speed.<br>
*
* @return the number of possible configurations supported at its current
* speed
*/
public byte getBNumConfigurations() {
return bNumConfigurations;
}
/**
* Returns the number of possible configurations supported at its current
* speed.<br>
*
* @return the number of possible configurations supported at its current
* speed
*/
public byte getBNumConfigurations() {
return bNumConfigurations;
}
/**
* Returns the product ID (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the product ID
*/
public short getIdProduct() {
return idProduct;
}
/**
* Returns the product ID (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the product ID
*/
public short getIdProduct() {
return idProduct;
}
/**
* Returns the Vendor ID (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the Vendor ID
*/
public short getIdVendor() {
return idVendor;
}
/**
* Returns the Vendor ID (Assigned by <a
* href="http://www.usb.org">www.usb.org</a>)<br>
*
* @return the Vendor ID
*/
public short getIdVendor() {
return idVendor;
}
/**
* Returns the index of the manufacturer string descriptor.<br>
* If this value is 0, no string descriptor is used.
*
* @return the index of the manufacturer string descriptor
*/
public byte getIManufacturer() {
return iManufacturer;
}
/**
* Returns the index of the manufacturer string descriptor.<br>
* If this value is 0, no string descriptor is used.
*
* @return the index of the manufacturer string descriptor
*/
public byte getIManufacturer() {
return iManufacturer;
}
/**
* Returns the index of the product string descriptor.<br>
* If this value is 0, no string descriptor is used.
*
* @return the index of the product string descriptor
*/
public byte getIProduct() {
return iProduct;
}
/**
* Returns the index of the product string descriptor.<br>
* If this value is 0, no string descriptor is used.
*
* @return the index of the product string descriptor
*/
public byte getIProduct() {
return iProduct;
}
/**
* Returns the index of serial number string descriptor.<br>
* If this value is 0, no string descriptor is used.
*
* @return the index of serial number string descriptor
*/
public byte getISerialNumber() {
return iSerialNumber;
}
/**
* Returns the index of serial number string descriptor.<br>
* If this value is 0, no string descriptor is used.
*
* @return the index of serial number string descriptor
*/
public byte getISerialNumber() {
return iSerialNumber;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("Usb_Device_Descriptor idVendor: 0x"
+ Integer.toHexString(idVendor & 0xFFFF) + ", idProduct: 0x"
+ Integer.toHexString(idProduct & 0xFFFF));
return sb.toString();
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("Usb_Device_Descriptor idVendor: 0x"
+ Integer.toHexString(idVendor & 0xFFFF) + ", idProduct: 0x"
+ Integer.toHexString(idProduct & 0xFFFF));
return sb.toString();
}
}

View File

@@ -22,137 +22,137 @@ package ch.ntb.usb;
*/
public class Usb_Endpoint_Descriptor extends Usb_Descriptor {
/**
* Maximum number of endpoints
*/
public static final int USB_MAXENDPOINTS = 32;
/**
* Maximum number of endpoints
*/
public static final int USB_MAXENDPOINTS = 32;
/**
* Endpoint address mask (in bEndpointAddress).
*/
public static final int USB_ENDPOINT_ADDRESS_MASK = 0x0f,
USB_ENDPOINT_DIR_MASK = 0x80;
/**
* Endpoint address mask (in bEndpointAddress).
*/
public static final int USB_ENDPOINT_ADDRESS_MASK = 0x0f,
USB_ENDPOINT_DIR_MASK = 0x80;
/**
* Endpoint type mask (in bmAttributes).
*/
public static final int USB_ENDPOINT_TYPE_MASK = 0x03;
/**
* Endpoint type mask (in bmAttributes).
*/
public static final int USB_ENDPOINT_TYPE_MASK = 0x03;
/**
* Possible endpoint types (in bmAttributes).
*/
public static final int USB_ENDPOINT_TYPE_CONTROL = 0,
USB_ENDPOINT_TYPE_ISOCHRONOUS = 1, USB_ENDPOINT_TYPE_BULK = 2,
USB_ENDPOINT_TYPE_INTERRUPT = 3;
/**
* Possible endpoint types (in bmAttributes).
*/
public static final int USB_ENDPOINT_TYPE_CONTROL = 0,
USB_ENDPOINT_TYPE_ISOCHRONOUS = 1, USB_ENDPOINT_TYPE_BULK = 2,
USB_ENDPOINT_TYPE_INTERRUPT = 3;
private byte bEndpointAddress;
private byte bEndpointAddress;
private byte bmAttributes;
private byte bmAttributes;
private short wMaxPacketSize;
private short wMaxPacketSize;
private byte bInterval;
private byte bInterval;
private byte bRefresh;
private byte bRefresh;
private byte bSynchAddress;
private byte bSynchAddress;
private byte[] extra; /* Extra descriptors */
private byte[] extra; /* Extra descriptors */
private int extralen;
private int extralen;
/**
* Returns the endpoint address.<br>
* <br>
* Bits 3..0: Endpoint number <br>
* Bits 6..4: Reserved. Set to zero <br>
* Bit 7: Direction (host to device). 0 = OUT (send data from host to
* device), 1 = IN (host receives data from device). Note: these values are
* ignored for control endpoints.<br>
*
* @return the endpoint address
*/
public byte getBEndpointAddress() {
return bEndpointAddress;
}
/**
* Returns the endpoint address.<br>
* <br>
* Bits 3..0: Endpoint number <br>
* Bits 6..4: Reserved. Set to zero <br>
* Bit 7: Direction (host to device). 0 = OUT (send data from host to
* device), 1 = IN (host receives data from device). Note: these values are
* ignored for control endpoints.<br>
*
* @return the endpoint address
*/
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 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 7..2: Reserved.<br>
*
* <pre>
* If isochronous endpoint:
* Bits 3..2: Synchronisation type
* 00 = No synchronisation
* 01 = Asynchronous
* 10 = Adaptive
* 11 = Synchronous
* Bits 5..4: Usage Type
* 00 = Data endpoint
* 01 = Feedback endpoint
* 10 = Explicit feedback data endpoint
* 11 = Reserved
* </pre>
*
* @return the attributes of this endpoint
*/
public byte getBmAttributes() {
return bmAttributes;
}
/**
* Returns the attributes of this endpoint.<br>
*
* Bits 1..0: Transfer Type (see <i>USB_ENDPOINT_TYPE_XXX</i>).<br>
* Bits 7..2: Reserved.<br>
*
* <pre>
* If isochronous endpoint:
* Bits 3..2: Synchronisation type
* 00 = No synchronisation
* 01 = Asynchronous
* 10 = Adaptive
* 11 = Synchronous
* Bits 5..4: Usage Type
* 00 = Data endpoint
* 01 = Feedback endpoint
* 10 = Explicit feedback data endpoint
* 11 = Reserved
* </pre>
*
* @return the attributes of this endpoint
*/
public byte getBmAttributes() {
return bmAttributes;
}
public byte getBRefresh() {
return bRefresh;
}
public byte getBRefresh() {
return bRefresh;
}
public byte getBSynchAddress() {
return bSynchAddress;
}
public byte getBSynchAddress() {
return bSynchAddress;
}
/**
* Returns the data of extra descriptor(s) if available.<br>
*
* @return null or a byte array with the extra descriptor data
*/
public byte[] getExtra() {
return extra;
}
/**
* Returns the data of extra descriptor(s) if available.<br>
*
* @return null or a byte array with the extra descriptor data
*/
public byte[] 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 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;
}
/**
* 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
public String toString() {
return "Usb_Endpoint_Descriptor bEndpointAddress: 0x"
+ Integer.toHexString(bEndpointAddress & 0xFF);
}
@Override
public String toString() {
return "Usb_Endpoint_Descriptor bEndpointAddress: 0x"
+ Integer.toHexString(bEndpointAddress & 0xFF);
}
}

View File

@@ -14,37 +14,37 @@ package ch.ntb.usb;
*/
public class Usb_Interface {
/**
* Maximal number of alternate settings
*/
public static final int USB_MAXALTSETTING = 128; /* Hard limit */
/**
* Maximal number of alternate settings
*/
public static final int USB_MAXALTSETTING = 128; /* Hard limit */
private Usb_Interface_Descriptor[] altsetting;
private Usb_Interface_Descriptor[] altsetting;
private int num_altsetting;
private int num_altsetting;
@Override
public String toString() {
return "Usb_Interface num_altsetting: 0x"
+ Integer.toHexString(num_altsetting);
}
@Override
public String toString() {
return "Usb_Interface num_altsetting: 0x"
+ Integer.toHexString(num_altsetting);
}
/**
* Retuns an array of interface descriptors.<br>
*
* @return an array of interface descriptors
*/
public Usb_Interface_Descriptor[] getAltsetting() {
return 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;
}
/**
* Returns the number of alternate settings.<br>
*
* @return the number of alternate settings
*/
public int getNumAltsetting() {
return num_altsetting;
}
}

View File

@@ -19,127 +19,127 @@ package ch.ntb.usb;
*/
public class Usb_Interface_Descriptor extends Usb_Descriptor {
/**
* Maximum number of interfaces
*/
public static final int USB_MAXINTERFACES = 32;
/**
* Maximum number of interfaces
*/
public static final int USB_MAXINTERFACES = 32;
private byte bInterfaceNumber;
private byte bInterfaceNumber;
private byte bAlternateSetting;
private byte bAlternateSetting;
private byte bNumEndpoints;
private byte bNumEndpoints;
private byte bInterfaceClass;
private byte bInterfaceClass;
private byte bInterfaceSubClass;
private byte bInterfaceSubClass;
private byte bInterfaceProtocol;
private byte bInterfaceProtocol;
private byte iInterface;
private byte iInterface;
private Usb_Endpoint_Descriptor[] endpoint;
private Usb_Endpoint_Descriptor[] endpoint;
private byte[] extra; /* Extra descriptors */
private byte[] extra; /* Extra descriptors */
private int extralen;
private int extralen;
@Override
public String toString() {
return "Usb_Interface_Descriptor bNumEndpoints: 0x"
+ Integer.toHexString(bNumEndpoints);
}
@Override
public String toString() {
return "Usb_Interface_Descriptor bNumEndpoints: 0x"
+ Integer.toHexString(bNumEndpoints);
}
/**
* Returns the value used to select the alternate setting ({@link LibusbJava#usb_set_altinterface(long, int)}).<br>
*
* @return the alternate setting
*/
public byte getBAlternateSetting() {
return bAlternateSetting;
}
/**
* Returns the value used to select the alternate setting ({@link LibusbJava#usb_set_altinterface(long, 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 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 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 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 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 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;
}
/**
* Returns an array of endpoint descriptors.<br>
*
* @return an array of endpoint descriptors
*/
public Usb_Endpoint_Descriptor[] getEndpoint() {
return endpoint;
}
/**
* Returns the data of extra descriptor(s) if available.<br>
*
* @return null or a byte array with the extra descriptor data
*/
public byte[] getExtra() {
return extra;
}
/**
* Returns the data of extra descriptor(s) if available.<br>
*
* @return null or a byte array with the extra descriptor data
*/
public byte[] 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 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;
}
/**
* 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

@@ -11,50 +11,50 @@ import java.io.PrintStream;
public class Utils {
public static void logBus(Usb_Bus bus) {
logBus(bus, System.out);
}
public static void logBus(Usb_Bus bus) {
logBus(bus, System.out);
}
public static void logBus(Usb_Bus bus, PrintStream out) {
Usb_Bus usb_Bus = bus;
while (usb_Bus != null) {
out.println(usb_Bus.toString());
Usb_Device dev = usb_Bus.getDevices();
while (dev != null) {
out.println("\t" + dev.toString());
// Usb_Device_Descriptor
Usb_Device_Descriptor defDesc = dev.getDescriptor();
out.println("\t\t" + defDesc.toString());
// Usb_Config_Descriptor
Usb_Config_Descriptor[] confDesc = dev.getConfig();
for (int i = 0; i < confDesc.length; i++) {
out.println("\t\t" + confDesc[i].toString());
Usb_Interface[] int_ = confDesc[i].getInterface();
if (int_ != null) {
for (int j = 0; j < int_.length; j++) {
out.println("\t\t\t" + int_[j].toString());
Usb_Interface_Descriptor[] intDesc = int_[j]
.getAltsetting();
if (intDesc != null) {
for (int k = 0; k < intDesc.length; k++) {
out.println("\t\t\t\t"
+ intDesc[k].toString());
Usb_Endpoint_Descriptor[] epDesc = intDesc[k]
.getEndpoint();
if (epDesc != null) {
for (int e = 0; e < epDesc.length; e++) {
out.println("\t\t\t\t\t"
+ epDesc[e].toString());
}
}
}
}
}
}
}
dev = dev.getNext();
}
usb_Bus = usb_Bus.getNext();
}
}
public static void logBus(Usb_Bus bus, PrintStream out) {
Usb_Bus usb_Bus = bus;
while (usb_Bus != null) {
out.println(usb_Bus.toString());
Usb_Device dev = usb_Bus.getDevices();
while (dev != null) {
out.println("\t" + dev.toString());
// Usb_Device_Descriptor
Usb_Device_Descriptor defDesc = dev.getDescriptor();
out.println("\t\t" + defDesc.toString());
// Usb_Config_Descriptor
Usb_Config_Descriptor[] confDesc = dev.getConfig();
for (int i = 0; i < confDesc.length; i++) {
out.println("\t\t" + confDesc[i].toString());
Usb_Interface[] int_ = confDesc[i].getInterface();
if (int_ != null) {
for (int j = 0; j < int_.length; j++) {
out.println("\t\t\t" + int_[j].toString());
Usb_Interface_Descriptor[] intDesc = int_[j]
.getAltsetting();
if (intDesc != null) {
for (int k = 0; k < intDesc.length; k++) {
out.println("\t\t\t\t"
+ intDesc[k].toString());
Usb_Endpoint_Descriptor[] epDesc = intDesc[k]
.getEndpoint();
if (epDesc != null) {
for (int e = 0; e < epDesc.length; e++) {
out.println("\t\t\t\t\t"
+ epDesc[e].toString());
}
}
}
}
}
}
}
dev = dev.getNext();
}
usb_Bus = usb_Bus.getNext();
}
}
}

View File

@@ -17,119 +17,119 @@ import java.util.logging.Logger;
public class LogUtil {
// debug this class
private static final boolean debugLogUtil = false;
// debug this class
private static final boolean debugLogUtil = false;
private static final String PLUGIN_ID = "ch.ntb.usb";
private static final String PROPERTIES_FILE = ".configure";
private static final String LOGGER_WARNING = "Warning in class "
+ LogUtil.class.getName()
+ ": could not load the logger properties file " + PROPERTIES_FILE;
private static final String PLUGIN_ID = "ch.ntb.usb";
private static final String PROPERTIES_FILE = ".configure";
private static final String LOGGER_WARNING = "Warning in class "
+ LogUtil.class.getName()
+ ": could not load the logger properties file " + PROPERTIES_FILE;
private static boolean debugEnabled;
private static boolean debugEnabled;
static {
createLoggersFromProperties();
}
static {
createLoggersFromProperties();
}
private static void debugMsg(String method, String message) {
if (debugLogUtil) {
System.out.println(method + ": " + message);
}
}
private static void debugMsg(String method, String message) {
if (debugLogUtil) {
System.out.println(method + ": " + message);
}
}
public static void setLevel(Logger logger, Level loglevel) {
Handler[] h = logger.getHandlers();
for (int i = 0; i < h.length; i++) {
System.out.println("setLevel " + loglevel.toString());
h[i].setLevel(loglevel);
}
logger.setLevel(loglevel);
}
public static void setLevel(Logger logger, Level loglevel) {
Handler[] h = logger.getHandlers();
for (int i = 0; i < h.length; i++) {
System.out.println("setLevel " + loglevel.toString());
h[i].setLevel(loglevel);
}
logger.setLevel(loglevel);
}
public static Logger getLogger(String name) {
debugMsg("getLogger", name);
LogManager manager = LogManager.getLogManager();
// check if logger is already registered
Logger logger = manager.getLogger(name);
if (logger == null) {
logger = Logger.getLogger(name);
setLevel(logger, Level.OFF);
manager.addLogger(logger);
debugMsg("getLogger", "creating new logger");
}
if (logger.getLevel() == null) {
debugMsg("getLogger", "level == null -> setLevel to OFF ");
setLevel(logger, Level.OFF);
}
debugMsg("getLogger", "logLevel " + logger.getLevel().getName());
return logger;
}
public static Logger getLogger(String name) {
debugMsg("getLogger", name);
LogManager manager = LogManager.getLogManager();
// check if logger is already registered
Logger logger = manager.getLogger(name);
if (logger == null) {
logger = Logger.getLogger(name);
setLevel(logger, Level.OFF);
manager.addLogger(logger);
debugMsg("getLogger", "creating new logger");
}
if (logger.getLevel() == null) {
debugMsg("getLogger", "level == null -> setLevel to OFF ");
setLevel(logger, Level.OFF);
}
debugMsg("getLogger", "logLevel " + logger.getLevel().getName());
return logger;
}
private static void initLevel(Logger logger, Level loglevel) {
Handler[] h = logger.getHandlers();
for (int i = 0; i < h.length; i++) {
logger.removeHandler(h[i]);
}
Handler console = new ConsoleHandler();
console.setLevel(loglevel);
logger.addHandler(console);
logger.setLevel(loglevel);
logger.setUseParentHandlers(false);
}
private static void initLevel(Logger logger, Level loglevel) {
Handler[] h = logger.getHandlers();
for (int i = 0; i < h.length; i++) {
logger.removeHandler(h[i]);
}
Handler console = new ConsoleHandler();
console.setLevel(loglevel);
logger.addHandler(console);
logger.setLevel(loglevel);
logger.setUseParentHandlers(false);
}
private static void createLoggersFromProperties() {
try {
debugMsg(LogUtil.class.getName(), "createLoggersFromProperties");
InputStream is = LogUtil.class.getClassLoader()
.getResourceAsStream(PROPERTIES_FILE);
if (is == null) {
System.err.println(LOGGER_WARNING);
} else {
Properties prop = new Properties();
prop.load(is);
debugMsg("createLoggersFromProperties",
"properties file loaded: " + PROPERTIES_FILE);
debugMsg("createLoggersFromProperties", "file content:\n"
+ prop.toString());
// get global debug enable flag
debugEnabled = Boolean.parseBoolean(prop.getProperty(PLUGIN_ID
+ "/debug"));
debugMsg("createLoggersFromProperties", "debuging enabled: "
+ debugEnabled);
// get and configure loggers
boolean moreLoggers = true;
int loggerCount = 0;
while (moreLoggers) {
String loggerProp = prop.getProperty(PLUGIN_ID
+ "/debug/logger" + loggerCount);
loggerCount++;
if (loggerProp != null) {
// parse string and get logger name and log level
int slashIndex = loggerProp.indexOf('/');
String loggerName = loggerProp.substring(0, slashIndex)
.trim();
String logLevel = loggerProp.substring(slashIndex + 1,
loggerProp.length());
// register logger
Level level;
if (debugEnabled) {
level = Level.parse(logLevel);
} else {
level = Level.OFF;
}
Logger logger = getLogger(loggerName);
initLevel(logger, level);
debugMsg("createLoggersFromProperties",
"create logger " + loggerName + " with level "
+ level.toString());
} else {
moreLoggers = false;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static void createLoggersFromProperties() {
try {
debugMsg(LogUtil.class.getName(), "createLoggersFromProperties");
InputStream is = LogUtil.class.getClassLoader()
.getResourceAsStream(PROPERTIES_FILE);
if (is == null) {
System.err.println(LOGGER_WARNING);
} else {
Properties prop = new Properties();
prop.load(is);
debugMsg("createLoggersFromProperties",
"properties file loaded: " + PROPERTIES_FILE);
debugMsg("createLoggersFromProperties", "file content:\n"
+ prop.toString());
// get global debug enable flag
debugEnabled = Boolean.parseBoolean(prop.getProperty(PLUGIN_ID
+ "/debug"));
debugMsg("createLoggersFromProperties", "debuging enabled: "
+ debugEnabled);
// get and configure loggers
boolean moreLoggers = true;
int loggerCount = 0;
while (moreLoggers) {
String loggerProp = prop.getProperty(PLUGIN_ID
+ "/debug/logger" + loggerCount);
loggerCount++;
if (loggerProp != null) {
// parse string and get logger name and log level
int slashIndex = loggerProp.indexOf('/');
String loggerName = loggerProp.substring(0, slashIndex)
.trim();
String logLevel = loggerProp.substring(slashIndex + 1,
loggerProp.length());
// register logger
Level level;
if (debugEnabled) {
level = Level.parse(logLevel);
} else {
level = Level.OFF;
}
Logger logger = getLogger(loggerName);
initLevel(logger, level);
debugMsg("createLoggersFromProperties",
"create logger " + loggerName + " with level "
+ level.toString());
} else {
moreLoggers = false;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}