From d35f1df2aa446d39e8f02d0df66fbc3cf0ce6086 Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Sun, 30 Nov 2014 09:29:01 +0000 Subject: [PATCH] Revert to old java source from 519dac0002f6562f0092c9c2f24921431e146168 (svn r273) --- src/main/java/ch/ntb/usb.r273/Device.java | 816 ---------- src/main/java/ch/ntb/usb.r273/LibusbJava.java | 378 ----- src/main/java/ch/ntb/usb.r273/USB.java | 318 ---- .../java/ch/ntb/usb.r273/USBException.java | 23 - .../ch/ntb/usb.r273/USBTimeoutException.java | 21 - src/main/java/ch/ntb/usb.r273/Usb_Bus.java | 86 - .../ntb/usb.r273/Usb_Config_Descriptor.java | 139 -- .../java/ch/ntb/usb.r273/Usb_Descriptor.java | 59 - src/main/java/ch/ntb/usb.r273/Usb_Device.java | 125 -- .../ntb/usb.r273/Usb_Device_Descriptor.java | 190 --- .../ntb/usb.r273/Usb_Endpoint_Descriptor.java | 158 -- .../java/ch/ntb/usb.r273/Usb_Interface.java | 50 - .../usb.r273/Usb_Interface_Descriptor.java | 145 -- src/main/java/ch/ntb/usb.r273/Utils.java | 60 - .../java/ch/ntb/usb.r273/logger/LogUtil.java | 135 -- .../java/ch/ntb/usb.r273/logger/package.html | 16 - src/main/java/ch/ntb/usb.r273/package.html | 26 - .../ch/ntb/usb.r273/usbView/UsbTreeModel.java | 495 ------ .../java/ch/ntb/usb.r273/usbView/UsbView.java | 403 ----- .../java/ch/ntb/usb.r273/usbView/package.html | 17 - src/main/java/ch/ntb/usb/Device.java | 22 +- src/main/java/ch/ntb/usb/LibusbJava.java | 558 ++----- src/main/java/ch/ntb/usb/LibusbJava1.java | 1424 ----------------- src/main/java/ch/ntb/usb/Libusb_event.java | 19 - src/main/java/ch/ntb/usb/Libusb_pollfd.java | 7 - src/main/java/ch/ntb/usb/USB.java | 30 +- src/main/java/ch/ntb/usb/Usb_Bus.java | 21 - .../ch/ntb/usb/Usb_Config_Descriptor.java | 4 +- src/main/java/ch/ntb/usb/Usb_Descriptor.java | 4 +- src/main/java/ch/ntb/usb/Usb_Device.java | 40 - .../ch/ntb/usb/Usb_Device_Descriptor.java | 9 +- .../ch/ntb/usb/Usb_Endpoint_Descriptor.java | 29 +- .../ch/ntb/usb/Usb_Interface_Descriptor.java | 7 +- .../ch/ntb/usb/exceptions/LibusbError.java | 150 -- src/main/java/ch/ntb/usb/logger/LogUtil.java | 2 +- 35 files changed, 140 insertions(+), 5846 deletions(-) delete mode 100644 src/main/java/ch/ntb/usb.r273/Device.java delete mode 100644 src/main/java/ch/ntb/usb.r273/LibusbJava.java delete mode 100644 src/main/java/ch/ntb/usb.r273/USB.java delete mode 100644 src/main/java/ch/ntb/usb.r273/USBException.java delete mode 100644 src/main/java/ch/ntb/usb.r273/USBTimeoutException.java delete mode 100644 src/main/java/ch/ntb/usb.r273/Usb_Bus.java delete mode 100644 src/main/java/ch/ntb/usb.r273/Usb_Config_Descriptor.java delete mode 100644 src/main/java/ch/ntb/usb.r273/Usb_Descriptor.java delete mode 100644 src/main/java/ch/ntb/usb.r273/Usb_Device.java delete mode 100644 src/main/java/ch/ntb/usb.r273/Usb_Device_Descriptor.java delete mode 100644 src/main/java/ch/ntb/usb.r273/Usb_Endpoint_Descriptor.java delete mode 100644 src/main/java/ch/ntb/usb.r273/Usb_Interface.java delete mode 100644 src/main/java/ch/ntb/usb.r273/Usb_Interface_Descriptor.java delete mode 100644 src/main/java/ch/ntb/usb.r273/Utils.java delete mode 100644 src/main/java/ch/ntb/usb.r273/logger/LogUtil.java delete mode 100644 src/main/java/ch/ntb/usb.r273/logger/package.html delete mode 100644 src/main/java/ch/ntb/usb.r273/package.html delete mode 100644 src/main/java/ch/ntb/usb.r273/usbView/UsbTreeModel.java delete mode 100644 src/main/java/ch/ntb/usb.r273/usbView/UsbView.java delete mode 100644 src/main/java/ch/ntb/usb.r273/usbView/package.html delete mode 100644 src/main/java/ch/ntb/usb/LibusbJava1.java delete mode 100644 src/main/java/ch/ntb/usb/Libusb_event.java delete mode 100644 src/main/java/ch/ntb/usb/Libusb_pollfd.java delete mode 100644 src/main/java/ch/ntb/usb/exceptions/LibusbError.java diff --git a/src/main/java/ch/ntb/usb.r273/Device.java b/src/main/java/ch/ntb/usb.r273/Device.java deleted file mode 100644 index 7398295..0000000 --- a/src/main/java/ch/ntb/usb.r273/Device.java +++ /dev/null @@ -1,816 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import ch.ntb.usb.logger.LogUtil; - -/** - * This class represents an USB device.
- * To get an instance of an USB device use USB.getDevice(...). - * - */ -public class Device { - - private static final Logger logger = LogUtil.getLogger("ch.ntb.usb"); - - private int maxPacketSize; - - /** - * Mandatory identification values for the device. - */ - private int idVendor, idProduct; - - /** - * Optional identification value for the device (e.g. if there are multiple - * devices with the same vendor and product id). - */ - private String filename; - - /** - * Optional identification value for the device (e.g. if there are multiple - * devices with the same vendor and product id). - */ - private String busName; - - private int dev_configuration, dev_interface, dev_altinterface; - - private long usbDevHandle; - - private boolean resetOnFirstOpen, resetDone; - - private int resetTimeout = 2000; - - private Usb_Device dev; - - protected Device(short idVendor, short idProduct) { - resetOnFirstOpen = false; - resetDone = false; - maxPacketSize = -1; - this.idVendor = idVendor; - this.idProduct = idProduct; - this.filename = null; - } - - protected Device(short idVendor, short idProduct, String busName, - String filename) { - resetOnFirstOpen = false; - resetDone = false; - maxPacketSize = -1; - this.idVendor = idVendor; - this.idProduct = idProduct; - this.busName = busName; - this.filename = filename; - } - - private void updateMaxPacketSize(Usb_Device device) throws USBException { - maxPacketSize = -1; - Usb_Config_Descriptor[] confDesc = device.getConfig(); - for (int i = 0; i < confDesc.length; i++) { - Usb_Interface[] int_ = confDesc[i].getInterface(); - for (int j = 0; j < int_.length; j++) { - Usb_Interface_Descriptor[] intDesc = int_[j].getAltsetting(); - for (int k = 0; k < intDesc.length; k++) { - Usb_Endpoint_Descriptor[] epDesc = intDesc[k].getEndpoint(); - for (int l = 0; l < epDesc.length; l++) { - maxPacketSize = Math.max(epDesc[l].getWMaxPacketSize(), - maxPacketSize); - } - } - } - } - if (maxPacketSize <= 0) { - throw new USBException( - "No USB endpoints found. Check the device configuration"); - } - } - - /** - * Initializes the device. The parameters idVendor and - * idProduct are mandatory. The parameter filename - * is optional. - */ - private Usb_Device initDevice(int idVendorParam, int idProductParam, - String busName, String filename) throws USBException { - Usb_Bus bus = USB.getBus(); - - Usb_Device device = null; - // search for device - while (bus != null) { - device = bus.getDevices(); - while (device != null) { - Usb_Device_Descriptor devDesc = device.getDescriptor(); - if (busName != null && filename != null) { - if (busName.compareTo(bus.getDirname()) == 0 - && filename.compareTo(device.getFilename()) == 0 - && devDesc.getIdVendor() == idVendor - && devDesc.getIdProduct() == idProduct) { - logger.info("Device found. bus: " + bus.getDirname() - + ", filename: " + device.getFilename()); - updateMaxPacketSize(device); - return device; - } - } else if (filename != null) { - if (filename.compareTo(device.getFilename()) == 0 - && devDesc.getIdVendor() == idVendor - && devDesc.getIdProduct() == idProduct) { - logger.info("Device found. bus: " + bus.getDirname() - + ", filename: " + device.getFilename()); - updateMaxPacketSize(device); - return device; - } - } else if (busName != null) { - if (busName.compareTo(bus.getDirname()) == 0 - && devDesc.getIdVendor() == idVendor - && devDesc.getIdProduct() == idProduct) { - logger.info("Device found. bus: " + bus.getDirname() - + ", filename: " + device.getFilename()); - updateMaxPacketSize(device); - return device; - } - } else if (devDesc.getIdVendor() == idVendor - && devDesc.getIdProduct() == idProduct) { - logger.info("Device found. bus: " + bus.getDirname() - + ", filename: " + device.getFilename()); - updateMaxPacketSize(device); - return device; - } - device = device.getNext(); - } - bus = bus.getNext(); - } - return null; - } - - /** - * Updates the device and descriptor information from the bus.
- * The descriptors can be read with {@link #getDeviceDescriptor()} and - * {@link #getConfigDescriptors()}. - * - * @throws USBException - */ - public void updateDescriptors() throws USBException { - dev = initDevice(idVendor, idProduct, busName, filename); - } - - /** - * Returns the device descriptor associated with this device.
- * The descriptor is updated by calling {@link #updateDescriptors()} or - * {@link #open(int, int, int)}. - * - * @return the device descriptor associated with this device or - * null - */ - public Usb_Device_Descriptor getDeviceDescriptor() { - if (dev == null) { - return null; - } - return dev.getDescriptor(); - } - - /** - * Returns the configuration descriptors associated with this device.
- * The descriptors are updated by calling {@link #updateDescriptors()} or - * {@link #open(int, int, int)}. - * - * @return the configuration descriptors associated with this device or - * null - */ - public Usb_Config_Descriptor[] getConfigDescriptors() { - if (dev == null) { - return null; - } - return dev.getConfig(); - } - - /** - * Opens the device and claims the specified configuration, interface and - * altinterface.
- * First the bus is enumerated. If the device is found its descriptors are - * read and the maxPacketSize value is updated. If no endpoints - * are found in the descriptors an exception is thrown. - * - * @param configuration - * the configuration, see - * {@link Usb_Config_Descriptor#getBConfigurationValue()} - * @param interface_ - * the interface, see - * {@link Usb_Interface_Descriptor#getBInterfaceNumber()} - * @param altinterface - * the alternate interface, see - * {@link Usb_Interface_Descriptor#getBAlternateSetting()}. If no - * alternate interface must be set -1 can be used. - * @throws USBException - */ - public void open(int configuration, int interface_, int altinterface) - throws USBException { - this.dev_configuration = configuration; - this.dev_interface = interface_; - this.dev_altinterface = altinterface; - - if (usbDevHandle != 0) { - throw new USBException("device opened, close or reset first"); - } - - dev = initDevice(idVendor, idProduct, busName, filename); - - if (dev != null) { - long res = LibusbJava.usb_open(dev); - if (res == 0) { - throw new USBException("LibusbJava.usb_open: " - + LibusbJava.usb_strerror()); - } - usbDevHandle = res; - } - - if (dev == null || usbDevHandle == 0) { - throw new USBException("USB device with " + toString() - + " not found on USB"); - } - claim_interface(usbDevHandle, configuration, interface_, altinterface); - if (resetOnFirstOpen & !resetDone) { - logger.info("reset on first open"); - resetDone = true; - reset(); - try { - Thread.sleep(resetTimeout); - } catch (InterruptedException e) { - // - } - open(configuration, interface_, altinterface); - } - } - - /** - * Release the claimed interface and close the opened device.
- * - * @throws USBException - */ - public void close() throws USBException { - if (usbDevHandle == 0) { - throw new USBException("invalid device handle"); - } - release_interface(usbDevHandle, dev_interface); - if (LibusbJava.usb_close(usbDevHandle) < 0) { - usbDevHandle = 0; - throw new USBException("LibusbJava.usb_close: " - + LibusbJava.usb_strerror()); - } - usbDevHandle = 0; - maxPacketSize = -1; - logger.info("device closed"); - } - - /** - * Sends an USB reset to the device. The device handle will no longer be - * valid. To use the device again, {@link #open(int, int, int)} must be - * called.
- * Note that the device is re-attached to the USB which may cause the bus - * and filename to be changed. If the bus and filename parameters are used - * in {@link USB#getDevice(short, short, String, String)} unregister the - * device using {@link USB#unregisterDevice(Device)}, re-enumerate the bus - * and create a new device instance. If that is not done the device may not - * be found. - * - * @throws USBException - */ - public void reset() throws USBException { - if (usbDevHandle == 0) { - throw new USBException("invalid device handle"); - } - release_interface(usbDevHandle, dev_interface); - if (LibusbJava.usb_reset(usbDevHandle) < 0) { - usbDevHandle = 0; - throw new USBException("LibusbJava.usb_reset: " - + LibusbJava.usb_strerror()); - } - usbDevHandle = 0; - logger.info("device reset"); - } - - /** - * Write data to the device using a bulk transfer.
- * - * @param out_ep_address - * endpoint address to write to - * @param data - * data to write to this endpoint - * @param size - * size of the data - * @param timeout - * amount of time in ms the device will try to send the data - * until a timeout exception is thrown - * @param reopenOnTimeout - * if set to true, the device will try to open the connection and - * send the data again before a timeout exception is thrown - * @return the actual number of bytes written - * @throws USBException - */ - public int writeBulk(int out_ep_address, byte[] data, int size, - int timeout, boolean reopenOnTimeout) throws USBException { - if (usbDevHandle == 0) { - throw new USBException("invalid device handle"); - } - if (data == null) { - throw new USBException("data must not be null"); - } - if (size <= 0 || size > data.length) { - throw new ArrayIndexOutOfBoundsException("invalid size: " + size); - } - int lenWritten = LibusbJava.usb_bulk_write(usbDevHandle, - out_ep_address, data, size, timeout); - if (lenWritten < 0) { - if (lenWritten == LibusbJava.ERROR_TIMEDOUT) { - // try to reopen the device and send the data again - if (reopenOnTimeout) { - logger.info("try to reopen"); - reset(); - open(dev_configuration, dev_interface, dev_altinterface); - return writeBulk(out_ep_address, data, size, timeout, false); - } - throw new USBTimeoutException("LibusbJava.usb_bulk_write: " - + LibusbJava.usb_strerror()); - } - throw new USBException("LibusbJava.usb_bulk_write: " - + LibusbJava.usb_strerror()); - } - - logger.info("length written: " + lenWritten); - if (logger.isLoggable(Level.FINEST)) { - StringBuffer sb = new StringBuffer("bulkwrite, ep 0x" - + Integer.toHexString(out_ep_address) + ": " + lenWritten - + " Bytes sent: "); - for (int i = 0; i < lenWritten; i++) { - sb.append("0x" + String.format("%1$02X", data[i]) + " "); - } - logger.info(sb.toString()); - } - return lenWritten; - } - - /** - * Read data from the device using a bulk transfer.
- * - * @param in_ep_address - * endpoint address to read from - * @param data - * data buffer for the data to be read - * @param size - * the maximum requested data size - * @param timeout - * amount of time in ms the device will try to receive data until - * a timeout exception is thrown - * @param reopenOnTimeout - * if set to true, the device will try to open the connection and - * receive the data again before a timeout exception is thrown - * @return the actual number of bytes read - * @throws USBException - */ - public int readBulk(int in_ep_address, byte[] data, int size, int timeout, - boolean reopenOnTimeout) throws USBException { - if (usbDevHandle == 0) { - throw new USBException("invalid device handle"); - } - if (data == null) { - throw new USBException("data must not be null"); - } - if (size <= 0 || size > data.length) { - throw new ArrayIndexOutOfBoundsException("invalid size: " + size); - } - int lenRead = LibusbJava.usb_bulk_read(usbDevHandle, in_ep_address, - data, size, timeout); - if (lenRead < 0) { - if (lenRead == LibusbJava.ERROR_TIMEDOUT) { - // try to reopen the device and send the data again - if (reopenOnTimeout) { - logger.info("try to reopen"); - reset(); - open(dev_configuration, dev_interface, dev_altinterface); - return readBulk(in_ep_address, data, size, timeout, false); - } - throw new USBTimeoutException("LibusbJava.usb_bulk_read: " - + LibusbJava.usb_strerror()); - } - throw new USBException("LibusbJava.usb_bulk_read: " - + LibusbJava.usb_strerror()); - } - - logger.info("length read: " + lenRead); - if (logger.isLoggable(Level.FINEST)) { - StringBuffer sb = new StringBuffer("bulkread, ep 0x" - + Integer.toHexString(in_ep_address) + ": " + lenRead - + " Bytes received: "); - for (int i = 0; i < lenRead; i++) { - sb.append("0x" + String.format("%1$02X", data[i]) + " "); - } - logger.info(sb.toString()); - } - return lenRead; - } - - /** - * Write data to the device using a interrupt transfer.
- * - * @param out_ep_address - * endpoint address to write to - * @param data - * data to write to this endpoint - * @param size - * size of the data - * @param timeout - * amount of time in ms the device will try to send the data - * until a timeout exception is thrown - * @param reopenOnTimeout - * if set to true, the device will try to open the connection and - * send the data again before a timeout exception is thrown - * @return the actual number of bytes written - * @throws USBException - */ - public int writeInterrupt(int out_ep_address, byte[] data, int size, - int timeout, boolean reopenOnTimeout) throws USBException { - if (usbDevHandle == 0) { - throw new USBException("invalid device handle"); - } - if (data == null) { - throw new USBException("data must not be null"); - } - if (size <= 0 || size > data.length) { - throw new ArrayIndexOutOfBoundsException("invalid size: " + size); - } - int lenWritten = LibusbJava.usb_interrupt_write(usbDevHandle, - out_ep_address, data, size, timeout); - if (lenWritten < 0) { - if (lenWritten == LibusbJava.ERROR_TIMEDOUT) { - // try to reopen the device and send the data again - if (reopenOnTimeout) { - logger.info("try to reopen"); - reset(); - open(dev_configuration, dev_interface, dev_altinterface); - return writeInterrupt(out_ep_address, data, size, timeout, - false); - } - throw new USBTimeoutException( - "LibusbJava.usb_interrupt_write: " - + LibusbJava.usb_strerror()); - } - throw new USBException("LibusbJava.usb_interrupt_write: " - + LibusbJava.usb_strerror()); - } - - logger.info("length written: " + lenWritten); - if (logger.isLoggable(Level.FINEST)) { - StringBuffer sb = new StringBuffer("interruptwrite, ep 0x" - + Integer.toHexString(out_ep_address) + ": " + lenWritten - + " Bytes sent: "); - for (int i = 0; i < lenWritten; i++) { - sb.append("0x" + String.format("%1$02X", data[i]) + " "); - } - logger.info(sb.toString()); - } - return lenWritten; - } - - /** - * Read data from the device using a interrupt transfer.
- * - * @param in_ep_address - * endpoint address to read from - * @param data - * data buffer for the data to be read - * @param size - * the maximum requested data size - * @param timeout - * amount of time in ms the device will try to receive data until - * a timeout exception is thrown - * @param reopenOnTimeout - * if set to true, the device will try to open the connection and - * receive the data again before a timeout exception is thrown - * @return the actual number of bytes read - * @throws USBException - */ - public int readInterrupt(int in_ep_address, byte[] data, int size, - int timeout, boolean reopenOnTimeout) throws USBException { - if (usbDevHandle == 0) { - throw new USBException("invalid device handle"); - } - if (data == null) { - throw new USBException("data must not be null"); - } - if (size <= 0 || size > data.length) { - throw new ArrayIndexOutOfBoundsException("invalid size: " + size); - } - int lenRead = LibusbJava.usb_interrupt_read(usbDevHandle, - in_ep_address, data, size, timeout); - if (lenRead < 0) { - if (lenRead == LibusbJava.ERROR_TIMEDOUT) { - // try to reopen the device and send the data again - if (reopenOnTimeout) { - logger.info("try to reopen"); - reset(); - open(dev_configuration, dev_interface, dev_altinterface); - return readInterrupt(in_ep_address, data, size, timeout, - false); - } - throw new USBTimeoutException("LibusbJava.usb_interrupt_read: " - + LibusbJava.usb_strerror()); - } - throw new USBException("LibusbJava.usb_interrupt_read: " - + LibusbJava.usb_strerror()); - } - - logger.info("length read: " + lenRead); - if (logger.isLoggable(Level.FINEST)) { - StringBuffer sb = new StringBuffer("interrupt, ep 0x" - + Integer.toHexString(in_ep_address) + ": " + lenRead - + " Bytes received: "); - for (int i = 0; i < lenRead; i++) { - sb.append("0x" + String.format("%1$02X", data[i]) + " "); - } - logger.info(sb.toString()); - } - return lenRead; - } - - /** - * 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 requestType - * USB device request type (USB specification 9.3, - * bmRequestType). Use constants from {@link ch.ntb.usb.USB} - * (REQ_TYPE_xxx). - * @param request - * specific request (USB specification 9.4, bRequest). Use - * constants from {@link ch.ntb.usb.USB} (REQ_xxx). - * @param value - * field that varies according to request (USB specification 9.4, - * wValue) - * @param index - * field that varies according to request (USB specification 9.4, - * wIndex) - * @param data - * the send/receive buffer - * @param size - * the buffer size. 0 is a valid value, but there must still be a - * dummy data buffer provided. - * @param timeout - * amount of time in ms the device will try to send/receive data - * until a timeout exception is thrown - * @param reopenOnTimeout - * if set to true, the device will try to open the connection and - * send/receive the data again before a timeout exception is - * thrown - * @return the number of bytes written/read - * @throws USBException - */ - public int controlMsg(int requestType, int request, int value, int index, - byte[] data, int size, int timeout, boolean reopenOnTimeout) - throws USBException { - if (usbDevHandle == 0) { - throw new USBException("invalid device handle"); - } - if (data == null) { - throw new USBException("data must not be null"); - } - if (size < 0 || size > data.length) { - throw new ArrayIndexOutOfBoundsException("invalid size: " + size); - } - int len = LibusbJava.usb_control_msg(usbDevHandle, requestType, - request, value, index, data, size, timeout); - if (len < 0) { - if (len == LibusbJava.ERROR_TIMEDOUT) { - // try to reopen the device and send the data again - if (reopenOnTimeout) { - logger.info("try to reopen"); - reset(); - open(dev_configuration, dev_interface, dev_altinterface); - return controlMsg(requestType, request, value, index, data, - size, timeout, false); - } - throw new USBTimeoutException("LibusbJava.controlMsg: " - + LibusbJava.usb_strerror()); - } - throw new USBException("LibusbJava.controlMsg: " - + LibusbJava.usb_strerror()); - } - - logger.info("length read/written: " + len); - if (logger.isLoggable(Level.FINEST)) { - StringBuffer sb = new StringBuffer("controlMsg: " + len - + " Bytes received(written: "); - for (int i = 0; i < len; i++) { - sb.append("0x" + String.format("%1$02X", data[i]) + " "); - } - logger.info(sb.toString()); - } - return len; - } - - /** - * Claim an interface to send and receive USB data.
- * - * @param usb_dev_handle - * the handle of the device (MUST BE VALID) - * @param configuration - * the configuration to use - * @param interface_ - * the interface to claim - * @param altinterface - * the alternate interface to use. If no alternate interface must - * be set -1 can be used. - * @throws USBException - * throws an USBException if the action fails - */ - private void claim_interface(long usb_dev_handle, int configuration, - int interface_, int altinterface) throws USBException { - if (LibusbJava.usb_set_configuration(usb_dev_handle, configuration) < 0) { - usbDevHandle = 0; - throw new USBException("LibusbJava.usb_set_configuration: " - + LibusbJava.usb_strerror()); - } - if (LibusbJava.usb_claim_interface(usb_dev_handle, interface_) < 0) { - usbDevHandle = 0; - throw new USBException("LibusbJava.usb_claim_interface: " - + LibusbJava.usb_strerror()); - } - if (altinterface >= 0) { - if (LibusbJava.usb_set_altinterface(usb_dev_handle, altinterface) < 0) { - try { - release_interface(usb_dev_handle, interface_); - } catch (USBException e) { - // ignore - } - usbDevHandle = 0; - throw new USBException("LibusbJava.usb_set_altinterface: " - + LibusbJava.usb_strerror()); - } - } - logger.info("interface claimed"); - } - - /** - * Release a previously claimed interface.
- * - * @param dev_handle - * the handle of the device (MUST BE VALID) - * @param interface_ - * the interface to claim - * @throws USBException - * throws an USBException if the action fails - */ - private void release_interface(long dev_handle, int interface_) - throws USBException { - if (LibusbJava.usb_release_interface(dev_handle, interface_) < 0) { - usbDevHandle = 0; - throw new USBException("LibusbJava.usb_release_interface: " - + LibusbJava.usb_strerror()); - } - logger.info("interface released"); - } - - /** - * Returns the product ID of the device.
- * - * @return the product ID of the device. - */ - public int getIdProduct() { - return idProduct; - } - - /** - * Returns the vendor ID of the device.
- * - * @return the vendor ID of the device. - */ - public int getIdVendor() { - return idVendor; - } - - /** - * Returns the alternative interface.
- * This value is only valid after opening the device. - * - * @return the alternative interface. This value is only valid after opening - * the device. - */ - public int getAltinterface() { - return dev_altinterface; - } - - /** - * Returns the current configuration used.
- * This value is only valid after opening the device. - * - * @return the current configuration used. This value is only valid after - * opening the device. - */ - public int getConfiguration() { - return dev_configuration; - } - - /** - * Returns the current interface.
- * This value is only valid after opening the device. - * - * @return the current interface. This value is only valid after opening the - * device. - */ - public int getInterface() { - return dev_interface; - } - - /** - * Returns the maximum packet size in bytes which is allowed to be - * transmitted at once.
- * The value is determined by reading the endpoint descriptor(s) when - * opening the device. It is invalid before the device is opened! Note that - * if some endpoints use different packet sizes the maximum packet size is - * return. This value may be used to determine if a device is opened in - * fullspeed or highspeed mode. - * - * @return the maximum packet size - */ - public int getMaxPacketSize() { - return maxPacketSize; - } - - /** - * Check if the device is open.
- * This checks only for a valid device handle. It doesn't check if the - * device is still attached or working. - * - * @return true if the device is open - */ - public boolean isOpen() { - return usbDevHandle != 0; - } - - /** - * If enabled, the device is reset when first opened.
- * This will only happen once. When the application is started, the device - * state is unknown. If the device is not reset, read or write may result in - * a {@link USBTimeoutException}.
- *
- * This feature is disabled by default. - * - * @param enable - * true if the device should be reset when first opened - * @param timeout - * the timeout between the reset and the reopening - */ - public void setResetOnFirstOpen(boolean enable, int timeout) { - resetOnFirstOpen = enable; - resetTimeout = timeout; - } - - /** - * Returns the optional filename which is set when there are multiple - * devices with the same vendor and product id. See - * {@link USB#getDevice(short, short, String, String)}. Use - * {@link Usb_Device#getFilename()} to read the filename of a device. - * - * @return the filename or null - */ - protected String getFilename() { - return filename; - } - - /** - * Returns the optional bus name which is set when there are multiple - * devices with the same vendor and product id. See - * {@link USB#getDevice(short, short, String, String)}. Use - * {@link Usb_Bus#getDirname()} to read the name of a bus. - * - * @return the bus name or null - */ - protected String getBusName() { - return busName; - } - - /** - * Returns the Usb_Device instance associated with this device. This value - * is only valid after opening the device. - * - * @return the Usb_Device instance associated with this device. - */ - public Usb_Device getDevice() { - return dev; - } - - @Override - public String toString() { - return "idVendor: 0x" + Integer.toHexString(getIdVendor() & 0xffff) - + ", idProduct: 0x" - + Integer.toHexString(getIdProduct() & 0xffff) + ", busName: " - + getBusName() + ", filename: " + getFilename(); - } - -} diff --git a/src/main/java/ch/ntb/usb.r273/LibusbJava.java b/src/main/java/ch/ntb/usb.r273/LibusbJava.java deleted file mode 100644 index c976af2..0000000 --- a/src/main/java/ch/ntb/usb.r273/LibusbJava.java +++ /dev/null @@ -1,378 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -/** - * This class represents the Java Native Interface to the shared library which - * is (with some exceptions) a one-to-one representation of the libusb API.
- *
- *

Project Description

- * Java libusb is a Java wrapper for the libusb and libusb-win32 USB library. - * - * libusb aim is to create a - * library for use by user level applications to access USB devices regardless - * of OS.
- * Libusb-win32 is a port of - * the USB library libusb to the - * Windows operating systems. The library allows user space applications to - * access any USB device on Windows in a generic way without writing any line of - * kernel driver code.
- *
- * The API description of this class has been copied from the libusb documentation - * and adapted where neccessary.
- * - */ -public class LibusbJava { - - /** - * System error codes.
- * 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.
- * - * 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, usb_init sets up some internal - * structures. usb_init must be called before any other - * libusb functions. - */ - public static native void usb_init(); - - /** - * usb_find_busses 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(); - - /** - * usb_find_devices will find all of the devices on each bus. - * This should be called after usb_find_busses. - * - * @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(); - - /** - * usb_get_busses returns a tree of descriptor objects.
- * The tree represents the bus structure with devices, configurations, - * interfaces and endpoints. Note that this is only a copy. To refresh the - * information, usb_get_busses() must be called again.
- * The name of the objects contained in the tree is starting with - * Usb_. - * - * @return the structure of all busses and devices. Note: The - * java objects are copies of the C structs. - */ - public static native Usb_Bus usb_get_busses(); - - // Device Operations - /** - * usb_open is to be used to open up a device for use. - * usb_open 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); - - /** - * usb_close closes a device opened with - * usb_open. - * - * @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 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); - - /** - * Resets a device by sending a RESET down the port it is connected to.
- *
- * Causes re-enumeration: After calling usb_reset, - * 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 - * usb_reset 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.
- *
- * Must be called!: usb_claim_interface must be - * called before you perform any operations related to this interface (like - * usb_set_altinterface, usb_bulk_write, 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_); - - // 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); - - /** - * usb_get_string_simple is a wrapper around - * usb_get_string 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.
- *
- * 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); - - // 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); - - // 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); - - /** - * 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.
- *
- * Note that not all error codes are be mapped by this method. For more - * error codes see the file 'errno.h' on your system.
- *
- * 1: EBADF: Bad file descriptor.
- * 2: ENXIO: No such device or address.
- * 3: EBUSY: Device or resource busy.
- * 4: EINVAL: Invalid argument.
- * 5: ETIMEDOUT: Connection timed out.
- * 6: EIO: I/O error.
- * 7: ENOMEM: Not enough memory.
- * - * - * @return the system error code or 100000 if no mapping has been found. - */ - private static native int usb_error_no(int value); - - static { - String os = System.getProperty("os.name"); - if (os.contains("Windows")) { - System.loadLibrary("LibusbJava"); - } else { - System.loadLibrary("usbJava"); - } - // 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); - } -} \ No newline at end of file diff --git a/src/main/java/ch/ntb/usb.r273/USB.java b/src/main/java/ch/ntb/usb.r273/USB.java deleted file mode 100644 index f372ef3..0000000 --- a/src/main/java/ch/ntb/usb.r273/USB.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.logging.Logger; - -import ch.ntb.usb.logger.LogUtil; - -/** - * This class manages all USB devices and defines some USB specific constants.
- * - */ -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’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.
- * The state of the Direction bit is ignored if the wLength field is zero, - * signifying there is no Data stage.
- * 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.
- * 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.
- * 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.
- * 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 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 LinkedList devices = new LinkedList(); - - 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.
- * 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.
- * see {@link Usb_Bus#getDirname()} - * @param filename - * optional filename which can be used to distinguish multiple - * devices with the same vendor and product id.
- * 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; - } - - /** - * See {@link #getDevice(short, short, String, String)}. The parameter - * filename and busNameis 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); - } - - /** - * Get an already registered device or null if the device does not exist.
- * 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.
- * 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 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(); - - 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; - } -} diff --git a/src/main/java/ch/ntb/usb.r273/USBException.java b/src/main/java/ch/ntb/usb.r273/USBException.java deleted file mode 100644 index 21f1f5c..0000000 --- a/src/main/java/ch/ntb/usb.r273/USBException.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -import java.io.IOException; - -public class USBException extends IOException { - - public USBException(String string) { - super(string); - } - - /** - * - */ - private static final long serialVersionUID = 1690857437804284710L; - -} diff --git a/src/main/java/ch/ntb/usb.r273/USBTimeoutException.java b/src/main/java/ch/ntb/usb.r273/USBTimeoutException.java deleted file mode 100644 index 4b8c3c6..0000000 --- a/src/main/java/ch/ntb/usb.r273/USBTimeoutException.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -public class USBTimeoutException extends USBException { - - public USBTimeoutException(String string) { - super(string); - } - - /** - * - */ - private static final long serialVersionUID = -1065328371159778249L; - -} diff --git a/src/main/java/ch/ntb/usb.r273/Usb_Bus.java b/src/main/java/ch/ntb/usb.r273/Usb_Bus.java deleted file mode 100644 index a7c59fc..0000000 --- a/src/main/java/ch/ntb/usb.r273/Usb_Bus.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -/** - * Represents an USB bus.
- * This is the root class for the representation of the libusb USB structure. - * Zero or more devices may be connected to an USB bus. - * - */ -public class Usb_Bus { - - private Usb_Bus next, prev; - - private String dirname; - - private Usb_Device devices; - - private long location; - - private Usb_Device root_dev; - - /** - * Get the first device ojects of the devices linked list.
- * - * @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.
- * - * @return the systems String representation of the bus - */ - public String getDirname() { - return dirname; - } - - /** - * Returns the next bus object.
- * - * @return Returns the next bus object or null - */ - public Usb_Bus getNext() { - return next; - } - - /** - * Returns the previous bus object.
- * - * @return Returns the previous bus object or null - */ - public Usb_Bus getPrev() { - return prev; - } - - /** - * Get the root device of this bus.
- * - * @return the root device oject or null - */ - public Usb_Device getRootDev() { - return root_dev; - } - - /** - * Returns the location in the USB bus linked list.
- * - * @return the location in the USB bus linked list - */ - public long getLocation() { - return location; - } - - @Override - public String toString() { - return "Usb_Bus " + dirname; - } -} \ No newline at end of file diff --git a/src/main/java/ch/ntb/usb.r273/Usb_Config_Descriptor.java b/src/main/java/ch/ntb/usb.r273/Usb_Config_Descriptor.java deleted file mode 100644 index 9bf6ff5..0000000 --- a/src/main/java/ch/ntb/usb.r273/Usb_Config_Descriptor.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -/** - * Represents the descriptor of a USB configuration.
- * A USB device can have several different configuration.
- *
- * The length of the configuration descriptor is - * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_CONFIG_SIZE} and the type is - * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_CONFIG}. - * - */ -public class Usb_Config_Descriptor extends Usb_Descriptor { - - /** - * Maximum number of configurations per device - */ - public static final int USB_MAXCONFIG = 8; - - private short wTotalLength; - - private byte bNumInterfaces; - - private byte bConfigurationValue; - - private byte iConfiguration; - - private byte bmAttributes; - - private byte MaxPower; - - private Usb_Interface[] interface_; - - private byte[] extra; /* Extra descriptors */ - - 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 power parameters for this configuration.
- *
- * Bit 7: Reserved, set to 1 (USB 1.0 Bus Powered)
- * Bit 6: Self Powered
- * Bit 5: Remote Wakeup
- * Bit 4..0: Reserved, set to 0 - * - * @return the power parameters for this configuration - */ - public byte getBmAttributes() { - return bmAttributes; - } - - /** - * Returns the number of interfaces.
- * - * @return the number of interfaces - */ - public byte getBNumInterfaces() { - return bNumInterfaces; - } - - /** - * Returns the data of extra descriptor(s) if available.
- * - * @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.
- * - * @return the number of bytes of the extra descriptor - */ - public int getExtralen() { - return extralen; - } - - /** - * Returns the index of the String descriptor describing this configuration.
- * - * @return the index of the String descriptor - */ - public byte getIConfiguration() { - return iConfiguration; - } - - /** - * Returns the USB interface descriptors.
- * - * @return the USB interface descriptors - */ - public Usb_Interface[] getInterface() { - return interface_; - } - - /** - * Returns the maximum power consumption in 2mA units.
- * - * @return the maximum power consumption in 2mA units - */ - public byte getMaxPower() { - return MaxPower; - } - - /** - * Returns the total length in bytes of all descriptors.
- * When the configuration descriptor is read, it returns the entire - * configuration hierarchy which includes all related interface and endpoint - * descriptors. The wTotalLength 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); - } -} \ No newline at end of file diff --git a/src/main/java/ch/ntb/usb.r273/Usb_Descriptor.java b/src/main/java/ch/ntb/usb.r273/Usb_Descriptor.java deleted file mode 100644 index 6aee245..0000000 --- a/src/main/java/ch/ntb/usb.r273/Usb_Descriptor.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -/** - * Common USB descriptor values.
- * - */ -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_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; - - private byte bLength; - - private byte bDescriptorType; - - /** - * Get the type of this descriptor.
- * - * @return the type of this descriptor - */ - public byte getBDescriptorType() { - return bDescriptorType; - } - - /** - * Get the size of this descriptor in bytes.
- * - * @return the size of this descriptor in bytes - */ - public byte getBLength() { - return bLength; - } - -} diff --git a/src/main/java/ch/ntb/usb.r273/Usb_Device.java b/src/main/java/ch/ntb/usb.r273/Usb_Device.java deleted file mode 100644 index 5cb314a..0000000 --- a/src/main/java/ch/ntb/usb.r273/Usb_Device.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -/** - * Represents an USB device.
- * An USB device has one device descriptor and it may have multiple - * configuration descriptors. - * - */ -public class Usb_Device { - - private Usb_Device next, prev; - - private String filename; - - 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; - - /** - * 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.
- * - * @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.
- * - * @return a reference to the first child - */ - public Usb_Device getChildren() { - return children; - } - - /** - * Returns the USB config descriptors.
- * - * @return the USB config descriptors - */ - public Usb_Config_Descriptor[] getConfig() { - return config; - } - - /** - * Returns the USB device descriptor.
- * - * @return the USB device descriptor - */ - public Usb_Device_Descriptor getDescriptor() { - return descriptor; - } - - /** - * Returns the number assigned to this device.
- * - * @return the number assigned to this device - */ - public byte getDevnum() { - return devnum; - } - - /** - * Returns the systems String representation.
- * - * @return the systems String representation - */ - public String getFilename() { - return filename; - } - - /** - * Returns the pointer to the next device.
- * - * @return the pointer to the next device or null - */ - public Usb_Device getNext() { - return next; - } - - /** - * Returns the number of children of this device.
- * - * @return the number of children of this device - */ - public byte getNumChildren() { - return num_children; - } - - /** - * Returns the pointer to the previous device.
- * - * @return the pointer to the previous device or null - */ - public Usb_Device getPrev() { - return prev; - } - - @Override - public String toString() { - return "Usb_Device " + filename; - } -} \ No newline at end of file diff --git a/src/main/java/ch/ntb/usb.r273/Usb_Device_Descriptor.java b/src/main/java/ch/ntb/usb.r273/Usb_Device_Descriptor.java deleted file mode 100644 index 5cf30e9..0000000 --- a/src/main/java/ch/ntb/usb.r273/Usb_Device_Descriptor.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -/** - * Represents the descriptor of a USB device.
- * A USB device can only have one device descriptor. It specifies some basic, - * yet important information about the device.
- *
- * The length of the device descriptor is - * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_DEVICE_SIZE} and the type is - * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_DEVICE}. - * - */ -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; - - 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; - - /** - * Returns the device release number.
- * 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.
- * 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.
- * 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 www.usb.org)
- * 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 www.usb.org)
- * - * @return the protocol code - */ - public byte getBDeviceProtocol() { - return bDeviceProtocol; - } - - /** - * Returns the subclass code (Assigned by www.usb.org)
- * - * @return the subclass code - */ - public byte getBDeviceSubClass() { - return bDeviceSubClass; - } - - /** - * Returns the maximum packet size for endpoint zero.
- * 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.
- * - * @return the number of possible configurations supported at its current - * speed - */ - public byte getBNumConfigurations() { - return bNumConfigurations; - } - - /** - * Returns the product ID (Assigned by www.usb.org)
- * - * @return the product ID - */ - public short getIdProduct() { - return idProduct; - } - - /** - * Returns the Vendor ID (Assigned by www.usb.org)
- * - * @return the Vendor ID - */ - public short getIdVendor() { - return idVendor; - } - - /** - * Returns the index of the manufacturer string descriptor.
- * 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.
- * 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.
- * 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(); - } -} \ No newline at end of file diff --git a/src/main/java/ch/ntb/usb.r273/Usb_Endpoint_Descriptor.java b/src/main/java/ch/ntb/usb.r273/Usb_Endpoint_Descriptor.java deleted file mode 100644 index 00e4bbc..0000000 --- a/src/main/java/ch/ntb/usb.r273/Usb_Endpoint_Descriptor.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -/** - * Represents the descriptor of an USB endpoint.
- * Endpoint descriptors are used to describe endpoints other than endpoint zero. - * 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 - * returned from these descriptors to determine the bandwidth requirements of - * the bus.
- *
- * The length of the configuration descriptor is - * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_ENDPOINT_SIZE} and the type is - * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_ENDPOINT}. - * - */ -public class Usb_Endpoint_Descriptor extends Usb_Descriptor { - - /** - * 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 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; - - private byte bEndpointAddress; - - private byte bmAttributes; - - private short wMaxPacketSize; - - private byte bInterval; - - private byte bRefresh; - - private byte bSynchAddress; - - private byte[] extra; /* Extra descriptors */ - - private int extralen; - - /** - * Returns the endpoint address.
- *
- * Bits 3..0: Endpoint number
- * Bits 6..4: Reserved. Set to zero
- * 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.
- * - * @return the endpoint address - */ - public byte getBEndpointAddress() { - return bEndpointAddress; - } - - /** - * Returns the intervall for polling endpoint data transfers.
- * 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.
- * - * Bits 1..0: Transfer Type (see USB_ENDPOINT_TYPE_XXX).
- * Bits 7..2: Reserved.
- * - *
-	 * 	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
-	 * 
- * - * @return the attributes of this endpoint - */ - public byte getBmAttributes() { - return bmAttributes; - } - - public byte getBRefresh() { - return bRefresh; - } - - public byte getBSynchAddress() { - return bSynchAddress; - } - - /** - * Returns the data of extra descriptor(s) if available.
- * - * @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.
- * - * @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.
- * - * @return the maximum packet size - */ - public short getWMaxPacketSize() { - return wMaxPacketSize; - } - - @Override - public String toString() { - return "Usb_Endpoint_Descriptor bEndpointAddress: 0x" - + Integer.toHexString(bEndpointAddress & 0xFF); - } -} diff --git a/src/main/java/ch/ntb/usb.r273/Usb_Interface.java b/src/main/java/ch/ntb/usb.r273/Usb_Interface.java deleted file mode 100644 index a8bb6bc..0000000 --- a/src/main/java/ch/ntb/usb.r273/Usb_Interface.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -/** - * Represents an USB interface.
- * An interface is a group of alternate settings of a configuration.
- * - */ -public class Usb_Interface { - - /** - * Maximal number of alternate settings - */ - public static final int USB_MAXALTSETTING = 128; /* Hard limit */ - - private Usb_Interface_Descriptor[] altsetting; - - private int num_altsetting; - - @Override - public String toString() { - return "Usb_Interface num_altsetting: 0x" - + Integer.toHexString(num_altsetting); - } - - /** - * Retuns an array of interface descriptors.
- * - * @return an array of interface descriptors - */ - public Usb_Interface_Descriptor[] getAltsetting() { - return altsetting; - } - - /** - * Returns the number of alternate settings.
- * - * @return the number of alternate settings - */ - public int getNumAltsetting() { - return num_altsetting; - } - -} diff --git a/src/main/java/ch/ntb/usb.r273/Usb_Interface_Descriptor.java b/src/main/java/ch/ntb/usb.r273/Usb_Interface_Descriptor.java deleted file mode 100644 index a36d3ed..0000000 --- a/src/main/java/ch/ntb/usb.r273/Usb_Interface_Descriptor.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -/** - * Represents the descriptor of a USB interface.
- * The interface descriptor could be seen as a header or grouping of the - * endpoints into a functional group performing a single feature of the device.
- *
- * The length of the interface descriptor is - * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_INTERFACE_SIZE} and the type is - * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_INTERFACE}. - * - */ -public class Usb_Interface_Descriptor extends Usb_Descriptor { - - /** - * Maximum number of interfaces - */ - public static final int USB_MAXINTERFACES = 32; - - private byte bInterfaceNumber; - - private byte bAlternateSetting; - - private byte bNumEndpoints; - - private byte bInterfaceClass; - - private byte bInterfaceSubClass; - - private byte bInterfaceProtocol; - - private byte iInterface; - - private Usb_Endpoint_Descriptor[] endpoint; - - private byte[] extra; /* Extra descriptors */ - - private int extralen; - - @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)}).
- * - * @return the alternate setting - */ - public byte getBAlternateSetting() { - return bAlternateSetting; - } - - /** - * Returns the class code (Assigned by www.usb.org).
- * - * @return the class code - */ - public byte getBInterfaceClass() { - return bInterfaceClass; - } - - /** - * Returns the number (identifier) of this interface.
- * - * @return the number (identifier) of this interface - */ - public byte getBInterfaceNumber() { - return bInterfaceNumber; - } - - /** - * Returns the protocol code (Assigned by www.usb.org).
- * - * @return the protocol code - */ - public byte getBInterfaceProtocol() { - return bInterfaceProtocol; - } - - /** - * Returns the subclass code (Assigned by www.usb.org).
- * - * @return the subclass code - */ - public byte getBInterfaceSubClass() { - return bInterfaceSubClass; - } - - /** - * Returns the number of endpoints used for this interface.
- * - * @return the number of endpoints used for this interface - */ - public byte getBNumEndpoints() { - return bNumEndpoints; - } - - /** - * Returns an array of endpoint descriptors.
- * - * @return an array of endpoint descriptors - */ - public Usb_Endpoint_Descriptor[] getEndpoint() { - return endpoint; - } - - /** - * Returns the data of extra descriptor(s) if available.
- * - * @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.
- * - * @return the number of bytes of the extra descriptor - */ - public int getExtralen() { - return extralen; - } - - /** - * Returns the index of the String descriptor describing this interface.
- * - * @return the index of the String descriptor - */ - public byte getIInterface() { - return iInterface; - } -} diff --git a/src/main/java/ch/ntb/usb.r273/Utils.java b/src/main/java/ch/ntb/usb.r273/Utils.java deleted file mode 100644 index d13a5ba..0000000 --- a/src/main/java/ch/ntb/usb.r273/Utils.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -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, 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(); - } - } -} diff --git a/src/main/java/ch/ntb/usb.r273/logger/LogUtil.java b/src/main/java/ch/ntb/usb.r273/logger/LogUtil.java deleted file mode 100644 index 998b602..0000000 --- a/src/main/java/ch/ntb/usb.r273/logger/LogUtil.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb.logger; - -import java.io.InputStream; -import java.util.Properties; -import java.util.logging.ConsoleHandler; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogManager; -import java.util.logging.Logger; - -public class LogUtil { - - // 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 boolean debugEnabled; - - static { - createLoggersFromProperties(); - } - - 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 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 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(); - } - } -} diff --git a/src/main/java/ch/ntb/usb.r273/logger/package.html b/src/main/java/ch/ntb/usb.r273/logger/package.html deleted file mode 100644 index fe57a92..0000000 --- a/src/main/java/ch/ntb/usb.r273/logger/package.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - -Logging related classes. - -

Related Resources

- -For more information about this project visit -http://libusbjava.sourceforge.net -. - - - diff --git a/src/main/java/ch/ntb/usb.r273/package.html b/src/main/java/ch/ntb/usb.r273/package.html deleted file mode 100644 index 147866d..0000000 --- a/src/main/java/ch/ntb/usb.r273/package.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - -Includes the main classes for the Java libusb wrapper. -
-LibusbJava.java -is the JNI class to the -LibusbJava.dll -. Every class starting with -Usb_ -represents a descriptor of the bus structure which is retrieved by -calling -LibusbJava.usb_get_busses() -. - -

Related Resources

- -For more information about this project visit -http://libusbjava.sourceforge.net -. - - - diff --git a/src/main/java/ch/ntb/usb.r273/usbView/UsbTreeModel.java b/src/main/java/ch/ntb/usb.r273/usbView/UsbTreeModel.java deleted file mode 100644 index 8e4b1ca..0000000 --- a/src/main/java/ch/ntb/usb.r273/usbView/UsbTreeModel.java +++ /dev/null @@ -1,495 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb.usbView; - -import java.util.Vector; - -import javax.swing.JTextArea; -import javax.swing.JTree; -import javax.swing.event.TreeModelEvent; -import javax.swing.event.TreeModelListener; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.TreeModel; -import javax.swing.tree.TreePath; - -import ch.ntb.usb.LibusbJava; -import ch.ntb.usb.Usb_Bus; -import ch.ntb.usb.Usb_Config_Descriptor; -import ch.ntb.usb.Usb_Device; -import ch.ntb.usb.Usb_Device_Descriptor; -import ch.ntb.usb.Usb_Endpoint_Descriptor; -import ch.ntb.usb.Usb_Interface; -import ch.ntb.usb.Usb_Interface_Descriptor; - -public class UsbTreeModel implements TreeModel, TreeSelectionListener { - - private Usb_Bus rootBus; - - private static final String USB_ROOT = "USB"; - - private JTextArea textArea; - - private Vector treeModelListeners = new Vector(); - - /** - * Default constructor.
- * - * @param rootBus - * the root bus from which the data is read - * @param textArea - * the text area to which the data is written - */ - public UsbTreeModel(Usb_Bus rootBus, JTextArea textArea) { - this.rootBus = rootBus; - this.textArea = textArea; - } - - /** - * Returns the root of the tree. - */ - public Object getRoot() { - return USB_ROOT; - } - - /** - * Returns the child of parent at index index in the parent's child array. - */ - public Object getChild(Object parent, int index) { - - if (parent instanceof String && ((String) parent).compareTo(USB_ROOT) == 0) - { - Usb_Bus curBus = rootBus; - - for (int i = 0; curBus != null; curBus = curBus.getNext(), i++) - { - if (i == index) - return curBus; - } - } - - else if (parent instanceof Usb_Bus) { - Usb_Device device = ((Usb_Bus) parent).getDevices(); - int count = 0; - while (device != null) { - if (count == index) - return device; - count++; - device = device.getNext(); - } - return null; - } else if (parent instanceof Usb_Device) { - Usb_Device dev = (Usb_Device) parent; - // return the Usb_Device_Descriptor at index 0 - if (index == 0) { - return dev.getDescriptor(); - } - Usb_Config_Descriptor[] confDescs = dev.getConfig(); - if (index >= confDescs.length + 1) - return null; - return confDescs[index - 1]; - } else if (parent instanceof Usb_Config_Descriptor) { - Usb_Interface[] intDescs = ((Usb_Config_Descriptor) parent) - .getInterface(); - if (index >= intDescs.length) - return null; - return intDescs[index]; - } else if (parent instanceof Usb_Interface) { - Usb_Interface_Descriptor[] altSettings = ((Usb_Interface) parent) - .getAltsetting(); - if (index >= altSettings.length) - return null; - return altSettings[index]; - } else if (parent instanceof Usb_Interface_Descriptor) { - Usb_Endpoint_Descriptor[] endpoints = ((Usb_Interface_Descriptor) parent) - .getEndpoint(); - if (index >= endpoints.length) - return null; - return endpoints[index]; - } - return null; - } - - /** - * Returns the number of children of parent. - */ - public int getChildCount(Object parent) - { - if (parent instanceof String && ((String) parent).compareTo(USB_ROOT) == 0) - { - int count = 0; - - Usb_Bus curBus = rootBus; - - for (; curBus != null; curBus = curBus.getNext()) - { - count++; - } - - return count; - - } - else if (parent instanceof Usb_Bus) { - Usb_Device device = ((Usb_Bus) parent).getDevices(); - int count = 0; - while (device != null) { - count++; - device = device.getNext(); - } - return count; - } else if (parent instanceof Usb_Device) { - // add the Usb_Device_Descriptor - return ((Usb_Device) parent).getConfig().length + 1; - } else if (parent instanceof Usb_Config_Descriptor) { - return ((Usb_Config_Descriptor) parent).getInterface().length; - } else if (parent instanceof Usb_Interface) { - return ((Usb_Interface) parent).getAltsetting().length; - } else if (parent instanceof Usb_Interface_Descriptor) { - return ((Usb_Interface_Descriptor) parent).getEndpoint().length; - } - return 0; - } - - /** - * Returns true if node is a leaf. - */ - public boolean isLeaf(Object node) { - return false; - } - - /** - * Messaged when the user has altered the value for the item identified by - * path to newValue. Not used by this model. - */ - public void valueForPathChanged(TreePath path, Object newValue) { - System.out.println("*** valueForPathChanged : " + path + " --> " - + newValue); - } - - /** - * Returns the index of child in parent. - */ - public int getIndexOfChild(Object parent, Object child) { - return 0; - } - - public void addTreeModelListener(TreeModelListener l) { - treeModelListeners.addElement(l); - } - - public void removeTreeModelListener(TreeModelListener l) { - treeModelListeners.removeElement(l); - } - - /** - * The only event raised by this model is TreeStructureChanged with the root - * as path, i.e. the whole tree has changed. - */ - protected void fireTreeStructureChanged(Usb_Bus newRootBus) { - rootBus = newRootBus; - int len = treeModelListeners.size(); - TreeModelEvent e = new TreeModelEvent(this, new Object[] { newRootBus }); - for (int i = 0; i < len; i++) { - treeModelListeners.elementAt(i).treeStructureChanged(e); - } - } - - public void valueChanged(TreeSelectionEvent e) { - JTree tree = (JTree) e.getSource(); - Object component = tree.getLastSelectedPathComponent(); - if (component instanceof Usb_Bus) { - Usb_Bus bus = (Usb_Bus) component; - StringBuffer sb = new StringBuffer("Usb_Bus\n"); - sb.append("\tdirname: " + bus.getDirname() + "\n"); - sb.append("\tlocation: 0x" + Long.toHexString(bus.getLocation()) - + "\n"); - textArea.setText(sb.toString()); - } else if (component instanceof Usb_Device) { - Usb_Device device = (Usb_Device) component; - StringBuffer sb = new StringBuffer("Usb_Device\n"); - sb.append("\tfilename: " + device.getFilename() + "\n"); - sb.append("\tdevnum: " + device.getDevnum() + "\n"); - sb.append("\tnum_children: " + device.getNumChildren() + "\n"); - textArea.setText(sb.toString()); - } else if (component instanceof Usb_Device_Descriptor) { - Usb_Device_Descriptor devDesc = (Usb_Device_Descriptor) component; - StringBuffer sb = new StringBuffer("Usb_Device_Descriptor\n"); - sb.append("\tblenght: 0x" - + Integer.toHexString(devDesc.getBLength() & 0xFF) + "\n"); - sb.append("\tbDescriptorType: 0x" - + Integer.toHexString(devDesc.getBDescriptorType() & 0xFF) - + "\n"); - sb.append("\tbcdUSB: 0x" - + Integer.toHexString(devDesc.getBcdUSB() & 0xFFFF) + "\n"); - sb.append("\tbDeviceClass: 0x" - + Integer.toHexString(devDesc.getBDeviceClass() & 0xFF) - + "\n"); - sb.append("\tbDeviceSubClass: 0x" - + Integer.toHexString(devDesc.getBDeviceSubClass() & 0xFF) - + "\n"); - sb.append("\tbDeviceProtocol: 0x" - + Integer.toHexString(devDesc.getBDeviceProtocol() & 0xFF) - + "\n"); - sb.append("\tbMaxPacketSize0: 0x" - + Integer.toHexString(devDesc.getBMaxPacketSize0() & 0xFF) - + " (" + devDesc.getBMaxPacketSize0() + ")\n"); - sb.append("\tidVendor: 0x" - + Integer.toHexString(devDesc.getIdVendor() & 0xFFFF) - + "\n"); - sb.append("\tidProduct: 0x" - + Integer.toHexString(devDesc.getIdProduct() & 0xFFFF) - + "\n"); - sb - .append("\tbcdDevice: 0x" - + Integer - .toHexString(devDesc.getBcdDevice() & 0xFF) - + "\n"); - sb.append("\tiManufacturer: 0x" - + Integer.toHexString(devDesc.getIManufacturer() & 0xFF) - + "\n"); - sb.append("\tiProduct: 0x" - + Integer.toHexString(devDesc.getIProduct()) + "\n"); - sb.append("\tiSerialNumber: 0x" - + Integer.toHexString(devDesc.getISerialNumber() & 0xFF) - + "\n"); - sb - .append("\tbNumConfigurations: 0x" - + Integer.toHexString(devDesc - .getBNumConfigurations() & 0xFF) + "\n"); - // get device handle to retrieve string descriptors - Usb_Bus bus = rootBus; - while (bus != null) { - Usb_Device dev = bus.getDevices(); - while (dev != null) { - Usb_Device_Descriptor tmpDevDesc = dev.getDescriptor(); - if ((dev.getDescriptor() != null) - && ((dev.getDescriptor().getIManufacturer() > 0) - || (dev.getDescriptor().getIProduct() > 0) || (dev - .getDescriptor().getISerialNumber() > 0))) { - if (tmpDevDesc.equals(devDesc)) { - long handle = LibusbJava.usb_open(dev); - sb.append("\nString descriptors\n"); - if (handle <= 0) { - sb.append("\terror opening the device\n"); - break; - } - if (dev.getDescriptor().getIManufacturer() > 0) { - String manufacturer = LibusbJava - .usb_get_string_simple(handle, devDesc - .getIManufacturer()); - if (manufacturer == null) - manufacturer = "unable to fetch manufacturer string"; - sb.append("\tiManufacturer: " + manufacturer - + "\n"); - } - if (dev.getDescriptor().getIProduct() > 0) { - String product = LibusbJava - .usb_get_string_simple(handle, devDesc - .getIProduct()); - if (product == null) - product = "unable to fetch product string"; - sb.append("\tiProduct: " + product + "\n"); - } - if (dev.getDescriptor().getISerialNumber() > 0) { - String serialNumber = LibusbJava - .usb_get_string_simple(handle, devDesc - .getISerialNumber()); - if (serialNumber == null) - serialNumber = "unable to fetch serial number string"; - sb.append("\tiSerialNumber: " + serialNumber - + "\n"); - } - LibusbJava.usb_close(handle); - } - } - dev = dev.getNext(); - } - bus = bus.getNext(); - } - textArea.setText(sb.toString()); - } else if (component instanceof Usb_Config_Descriptor) { - Usb_Config_Descriptor confDesc = (Usb_Config_Descriptor) component; - StringBuffer sb = new StringBuffer("Usb_Config_Descriptor\n"); - sb.append("\tblenght: 0x" - + Integer.toHexString(confDesc.getBLength()) + "\n"); - sb.append("\tbDescriptorType: 0x" - + Integer.toHexString(confDesc.getBDescriptorType() & 0xFF) - + "\n"); - sb.append("\tbNumInterfaces: 0x" - + Integer.toHexString(confDesc.getBNumInterfaces() & 0xFF) - + "\n"); - sb - .append("\tbConfigurationValue: 0x" - + Integer.toHexString(confDesc - .getBConfigurationValue() & 0xFF) + "\n"); - sb.append("\tiConfiguration: 0x" - + Integer.toHexString(confDesc.getIConfiguration() & 0xFF) - + "\n"); - sb.append("\tbmAttributes: 0x" - + Integer.toHexString(confDesc.getBmAttributes() & 0xFF) - + "\n"); - sb.append("\tMaxPower [mA]: 0x" - + Integer.toHexString(confDesc.getMaxPower() & 0xFF) + " (" - + confDesc.getMaxPower() + ")\n"); - sb.append("\textralen: 0x" - + Integer.toHexString(confDesc.getExtralen()) + "\n"); - sb.append("\textra: " + extraDescriptorToString(confDesc.getExtra()) + "\n"); - // get device handle to retrieve string descriptors - Usb_Bus bus = rootBus; - while (bus != null) { - Usb_Device dev = bus.getDevices(); - while (dev != null) { - Usb_Config_Descriptor[] tmpConfDesc = dev.getConfig(); - for (int i = 0; i < tmpConfDesc.length; i++) { - if ((tmpConfDesc.equals(confDesc)) - && (confDesc.getIConfiguration() > 0)) { - long handle = LibusbJava.usb_open(dev); - sb.append("\nString descriptors\n"); - if (handle <= 0) { - sb.append("\terror opening the device\n"); - break; - } - String configuration = LibusbJava - .usb_get_string_simple(handle, confDesc - .getIConfiguration()); - if (configuration == null) - configuration = "unable to fetch configuration string"; - sb.append("\tiConfiguration: " + configuration - + "\n"); - - LibusbJava.usb_close(handle); - - } - } - dev = dev.getNext(); - } - bus = bus.getNext(); - } - textArea.setText(sb.toString()); - } else if (component instanceof Usb_Interface) { - Usb_Interface int_ = (Usb_Interface) component; - StringBuffer sb = new StringBuffer("Usb_Interface\n"); - sb.append("\tnum_altsetting: 0x" - + Integer.toHexString(int_.getNumAltsetting()) + "\n"); - sb.append("\taltsetting: " + int_.getAltsetting() + "\n"); - textArea.setText(sb.toString()); - } else if (component instanceof Usb_Interface_Descriptor) { - Usb_Interface_Descriptor intDesc = (Usb_Interface_Descriptor) component; - StringBuffer sb = new StringBuffer("Usb_Interface_Descriptor\n"); - sb.append("\tblenght: 0x" - + Integer.toHexString(intDesc.getBLength() & 0xFF) + "\n"); - sb.append("\tbDescriptorType: 0x" - + Integer.toHexString(intDesc.getBDescriptorType() & 0xFF) - + "\n"); - sb.append("\tbInterfaceNumber: 0x" - + Integer.toHexString(intDesc.getBInterfaceNumber() & 0xFF) - + "\n"); - sb.append("\tbAlternateSetting: 0x" - + Integer - .toHexString(intDesc.getBAlternateSetting() & 0xFF) - + "\n"); - sb.append("\tbNumEndpoints: 0x" - + Integer.toHexString(intDesc.getBNumEndpoints() & 0xFF) - + "\n"); - sb.append("\tbInterfaceClass: 0x" - + Integer.toHexString(intDesc.getBInterfaceClass() & 0xFF) - + "\n"); - sb - .append("\tbInterfaceSubClass: 0x" - + Integer.toHexString(intDesc - .getBInterfaceSubClass() & 0xFF) + "\n"); - sb - .append("\tbInterfaceProtocol: 0x" - + Integer.toHexString(intDesc - .getBInterfaceProtocol() & 0xFF) + "\n"); - sb.append("\tiInterface: 0x" - + Integer.toHexString(intDesc.getIInterface()) + "\n"); - sb.append("\textralen: 0x" - + Integer.toHexString(intDesc.getExtralen()) + "\n"); - sb.append("\textra: " + extraDescriptorToString(intDesc.getExtra()) + "\n"); - // get device handle to retrieve string descriptors - Usb_Bus bus = rootBus; - while (bus != null) { - Usb_Device dev = bus.getDevices(); - while (dev != null) { - Usb_Config_Descriptor[] confDescs = dev.getConfig(); - for (int i = 0; i < confDescs.length; i++) { - Usb_Interface[] ints = confDescs[i].getInterface(); - for (int j = 0; j < ints.length; j++) { - Usb_Interface_Descriptor[] tmpIntDescs = ints[j] - .getAltsetting(); - for (int k = 0; k < ints.length; k++) { - if (i < tmpIntDescs.length && tmpIntDescs[i].equals(intDesc) - && (intDesc.getIInterface() > 0)) { - long handle = LibusbJava.usb_open(dev); - sb.append("\nString descriptors\n"); - if (handle <= 0) { - sb - .append("\terror opening the device\n"); - break; - } - String interface_ = LibusbJava - .usb_get_string_simple(handle, - intDesc.getIInterface()); - if (interface_ == null) - interface_ = "unable to fetch interface string"; - sb.append("\tiInterface: " + interface_ - + "\n"); - LibusbJava.usb_close(handle); - } - } - } - } - dev = dev.getNext(); - } - bus = bus.getNext(); - } - textArea.setText(sb.toString()); - } else if (component instanceof Usb_Endpoint_Descriptor) { - Usb_Endpoint_Descriptor epDesc = (Usb_Endpoint_Descriptor) component; - StringBuffer sb = new StringBuffer("Usb_Endpoint_Descriptor\n"); - sb.append("\tblenght: 0x" - + Integer.toHexString(epDesc.getBLength() & 0xFF) + "\n"); - sb.append("\tbDescriptorType: 0x" - + Integer.toHexString(epDesc.getBDescriptorType() & 0xFF) - + "\n"); - sb.append("\tbEndpointAddress: 0x" - + Integer.toHexString(epDesc.getBEndpointAddress() & 0xFF) - + "\n"); - sb.append("\tbmAttributes: 0x" - + Integer.toHexString(epDesc.getBmAttributes() & 0xFF) - + "\n"); - sb.append("\twMaxPacketSize: 0x" - + Integer.toHexString(epDesc.getWMaxPacketSize() & 0xFFFF) - + " (" + epDesc.getWMaxPacketSize() + ")\n"); - sb.append("\tbInterval: 0x" - + Integer.toHexString(epDesc.getBInterval() & 0xFF) + "\n"); - sb.append("\tbRefresh: 0x" - + Integer.toHexString(epDesc.getBRefresh() & 0xFF) + "\n"); - sb.append("\tbSynchAddress: 0x" - + Integer.toHexString(epDesc.getBSynchAddress()) + "\n"); - sb.append("\textralen: 0x" - + Integer.toHexString(epDesc.getExtralen()) + "\n"); - sb.append("\textra: " + extraDescriptorToString(epDesc.getExtra()) + "\n"); - textArea.setText(sb.toString()); - } - } - - private String extraDescriptorToString(byte[] extra) { - if (extra != null) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < extra.length; i++) { - sb.append("0x"); - sb.append(Integer.toHexString(extra[i] & 0xff)); - sb.append(' '); - } - return sb.toString(); - } - return null; - } -} diff --git a/src/main/java/ch/ntb/usb.r273/usbView/UsbView.java b/src/main/java/ch/ntb/usb.r273/usbView/UsbView.java deleted file mode 100644 index c531812..0000000 --- a/src/main/java/ch/ntb/usb.r273/usbView/UsbView.java +++ /dev/null @@ -1,403 +0,0 @@ -/* - * Java libusb wrapper - * Copyright (c) 2005-2006 Andreas Schläpfer - * - * http://libusbjava.sourceforge.net - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb.usbView; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTextArea; -import javax.swing.JTree; -import javax.swing.KeyStroke; -import javax.swing.tree.TreePath; - -import ch.ntb.usb.LibusbJava; -import ch.ntb.usb.Usb_Bus; -import ch.ntb.usb.Usb_Config_Descriptor; -import ch.ntb.usb.Usb_Device; -import ch.ntb.usb.Usb_Device_Descriptor; -import ch.ntb.usb.Usb_Endpoint_Descriptor; -import ch.ntb.usb.Usb_Interface_Descriptor; -import ch.ntb.usb.testApp.TestApp; -import ch.ntb.usb.testApp.TestDevice; -import ch.ntb.usb.testApp.AbstractDeviceInfo.TransferMode; - -public class UsbView extends JFrame { - - private static final long serialVersionUID = 4693554326612734263L; - - private static final int APP_WIDTH = 600, APP_HIGHT = 800; - - private JPanel jContentPane = null; - private JMenuBar jJMenuBar = null; - private JMenu commandsMenu = null; - private JMenuItem exitMenuItem = null; - private JMenuItem updateMenuItem = null; - JTree usbTree = null; - private JSplitPane jSplitPane = null; - - private JTextArea jPropertiesArea = null; - - UsbTreeModel treeModel; - - JPopupMenu testAppPopup; - - protected JPopupMenu endpointPopup; - - /** - * This is the default constructor - */ - public UsbView() { - super(); - initialize(); - } - - /** - * This method initializes this - * - * @return void - */ - private void initialize() { - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - this.setJMenuBar(getJJMenuBar()); - this.setSize(APP_WIDTH, APP_HIGHT); - this.setContentPane(getJContentPane()); - this.setTitle("USB View"); - } - - /** - * This method initializes jContentPane - * - * @return javax.swing.JPanel - */ - private JPanel getJContentPane() { - if (jContentPane == null) { - jContentPane = new JPanel(); - jContentPane.setLayout(new BorderLayout()); - jContentPane.add(getJSplitPane(), java.awt.BorderLayout.CENTER); - } - return jContentPane; - } - - /** - * This method initializes jJMenuBar - * - * @return javax.swing.JMenuBar - */ - private JMenuBar getJJMenuBar() { - if (jJMenuBar == null) { - jJMenuBar = new JMenuBar(); - jJMenuBar.add(getFileMenu()); - } - return jJMenuBar; - } - - /** - * This method initializes jMenu - * - * @return javax.swing.JMenu - */ - private JMenu getFileMenu() { - if (commandsMenu == null) { - commandsMenu = new JMenu(); - commandsMenu.setText("Commands"); - commandsMenu.add(getUpdateMenuItem()); - commandsMenu.add(getExitMenuItem()); - } - return commandsMenu; - } - - /** - * This method initializes jMenuItem - * - * @return javax.swing.JMenuItem - */ - private JMenuItem getExitMenuItem() { - if (exitMenuItem == null) { - exitMenuItem = new JMenuItem(); - exitMenuItem.setText("Exit"); - exitMenuItem.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - System.exit(0); - } - }); - } - return exitMenuItem; - } - - /** - * This method initializes jMenuItem - * - * @return javax.swing.JMenuItem - */ - private JMenuItem getUpdateMenuItem() { - if (updateMenuItem == null) { - updateMenuItem = new JMenuItem(); - updateMenuItem.setText("Update"); - updateMenuItem.setAccelerator(KeyStroke.getKeyStroke( - KeyEvent.VK_F5, 0, true)); - updateMenuItem - .addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - // open bus - LibusbJava.usb_init(); - LibusbJava.usb_find_busses(); - LibusbJava.usb_find_devices(); - - Usb_Bus bus = LibusbJava.usb_get_busses(); - if (bus != null) { - treeModel.fireTreeStructureChanged(bus); - expandAll(usbTree); - } - } - }); - } - return updateMenuItem; - } - - /** - * This method initializes usbTree - * - * @return javax.swing.JTree - */ - private JTree getUsbTree() { - if (usbTree == null) { - // open bus - LibusbJava.usb_init(); - LibusbJava.usb_find_busses(); - LibusbJava.usb_find_devices(); - - Usb_Bus bus = LibusbJava.usb_get_busses(); - - treeModel = new UsbTreeModel(bus, jPropertiesArea); - usbTree = new JTree(treeModel); - expandAll(usbTree); - usbTree.addTreeSelectionListener(treeModel); - getJTestAppPopup(); - usbTree.addMouseListener(new MouseAdapter() { - - @Override - public void mousePressed(MouseEvent e) { - if (e.isPopupTrigger()) { - Object source = e.getSource(); - if (source instanceof JTree) { - JTree tree = (JTree) source; - TreePath path = tree.getPathForLocation(e.getX(), e - .getY()); - if (path != null - && (path.getLastPathComponent() instanceof Usb_Interface_Descriptor)) { - usbTree.setSelectionPath(path); - testAppPopup.show(tree, e.getX(), e.getY()); - } - } - } - } - - @Override - public void mouseReleased(MouseEvent e) { - if (e.isPopupTrigger()) { - if (e.isPopupTrigger()) { - Object source = e.getSource(); - if (source instanceof JTree) { - JTree tree = (JTree) source; - TreePath path = tree.getPathForLocation(e - .getX(), e.getY()); - if (path != null - && (path.getLastPathComponent() instanceof Usb_Interface_Descriptor)) { - usbTree.setSelectionPath(path); - testAppPopup.show(tree, e.getX(), e.getY()); - } - } - } - } - } - }); - } - return usbTree; - } - - private void getJTestAppPopup() { - // Create the popup menu. - testAppPopup = new JPopupMenu(); - endpointPopup = new JPopupMenu(); - JMenuItem menuItem = new JMenuItem( - "Start a test application using this interface"); - menuItem.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - initAndStartTestApp(); - } - - private void initAndStartTestApp() { - JTree tree = (JTree) testAppPopup.getInvoker(); - TreePath path = tree.getSelectionPath(); - TreePath parent = path; - Usb_Endpoint_Descriptor[] endpoints = null; - int altinterface = -1; - int interface_ = -1; - int configuration = -1; - short vendorId = -1; - short productId = -1; - while (parent != null - && !(parent.getLastPathComponent() instanceof Usb_Bus)) { - Object usbObj = parent.getLastPathComponent(); - if (usbObj instanceof Usb_Interface_Descriptor) { - Usb_Interface_Descriptor usbIntDesc = (Usb_Interface_Descriptor) usbObj; - endpoints = usbIntDesc.getEndpoint(); - interface_ = usbIntDesc.getBInterfaceNumber(); - altinterface = usbIntDesc.getBAlternateSetting(); - } else if (usbObj instanceof Usb_Config_Descriptor) { - configuration = ((Usb_Config_Descriptor) usbObj) - .getBConfigurationValue(); - } else if (usbObj instanceof Usb_Device) { - Usb_Device_Descriptor devDesc = ((Usb_Device) usbObj) - .getDescriptor(); - productId = devDesc.getIdProduct(); - vendorId = devDesc.getIdVendor(); - } - parent = parent.getParentPath(); - } - if (parent != null) { - // present a dialog to select in/out endpoint - // TODO: present dialog to select in/out endpoint - Usb_Endpoint_Descriptor[] outEPs = null; - int nofOutEPs = 0; - Usb_Endpoint_Descriptor[] inEPs = null; - int nofInEPs = 0; - - if (endpoints != null) { - outEPs = new Usb_Endpoint_Descriptor[endpoints.length]; - inEPs = new Usb_Endpoint_Descriptor[endpoints.length]; - for (int i = 0; i < endpoints.length; i++) { - int epAddr = endpoints[i].getBEndpointAddress() & 0xFF; - if ((epAddr & 0x80) > 0) { - // is IN endpoint - inEPs[nofInEPs++] = endpoints[i]; - } else { - // is OUT endpoint - outEPs[nofOutEPs++] = endpoints[i]; - } - } - } - // create a new TestDevice - TestDevice testDevice = new TestDevice(); - testDevice.setIdProduct(productId); - testDevice.setIdVendor(vendorId); - testDevice.setAltinterface(altinterface); - testDevice.setConfiguration(configuration); - testDevice.setInterface(interface_); - if (inEPs != null) { - for (int i = 0; i < nofInEPs; i++) { - int type = inEPs[i].getBmAttributes() & 0x03; - switch (type) { - case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_BULK: - testDevice.setInEPBulk(inEPs[i] - .getBEndpointAddress() & 0xff); - testDevice.setInMode(TransferMode.Bulk); - break; - case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_INTERRUPT: - testDevice.setInEPInt(inEPs[i] - .getBEndpointAddress() & 0xff); - testDevice.setInMode(TransferMode.Interrupt); - break; - default: - break; - } - } - } - if (outEPs != null) { - for (int i = 0; i < nofOutEPs; i++) { - int type = outEPs[i].getBmAttributes() & 0x03; - switch (type) { - case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_BULK: - testDevice.setOutEPBulk(outEPs[i] - .getBEndpointAddress() & 0xff); - testDevice.setOutMode(TransferMode.Bulk); - break; - case Usb_Endpoint_Descriptor.USB_ENDPOINT_TYPE_INTERRUPT: - testDevice.setOutEPInt(outEPs[i] - .getBEndpointAddress() & 0xff); - testDevice.setOutMode(TransferMode.Interrupt); - break; - default: - break; - } - } - } - // open a new testApp - TestApp app = new TestApp(testDevice); - app.setVisible(true); - } else { - System.out.println("error, could not find device node"); - // TODO: handle error - } - } - }); - testAppPopup.add(menuItem); - } - - /** - * This method initializes jSplitPane - * - * @return javax.swing.JSplitPane - */ - private JSplitPane getJSplitPane() { - if (jSplitPane == null) { - jSplitPane = new JSplitPane(); - jSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); - jSplitPane.setContinuousLayout(true); - jSplitPane.setDividerLocation(APP_HIGHT / 2); - jSplitPane - .setBottomComponent(createScrollPane(getJPropertiesArea())); - jSplitPane.setTopComponent(createScrollPane(getUsbTree())); - } - return jSplitPane; - } - - /** - * This method initializes jPropertiesArea - * - * @return javax.swing.JTextArea - */ - private JTextArea getJPropertiesArea() { - if (jPropertiesArea == null) { - jPropertiesArea = new JTextArea(); - } - return jPropertiesArea; - } - - private JScrollPane createScrollPane(Component view) { - JScrollPane scrollPane = new JScrollPane(view); - return scrollPane; - } - - /** - * Launches this application - */ - public static void main(String[] args) { - UsbView application = new UsbView(); - application.setVisible(true); - } - - void expandAll(JTree tree) { - for (int row = 0; row < tree.getRowCount(); row++) { - tree.expandRow(row); - } - } -} diff --git a/src/main/java/ch/ntb/usb.r273/usbView/package.html b/src/main/java/ch/ntb/usb.r273/usbView/package.html deleted file mode 100644 index 2a64b06..0000000 --- a/src/main/java/ch/ntb/usb.r273/usbView/package.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - -Displays the bus and device information of the currently attached -devices in a tree (based on Swing). - -

Related Resources

- -For more information about this project visit -http://libusbjava.sourceforge.net -. - - - diff --git a/src/main/java/ch/ntb/usb/Device.java b/src/main/java/ch/ntb/usb/Device.java index 823c9a5..7398295 100644 --- a/src/main/java/ch/ntb/usb/Device.java +++ b/src/main/java/ch/ntb/usb/Device.java @@ -19,7 +19,7 @@ import ch.ntb.usb.logger.LogUtil; */ public class Device { - private static final Logger logger = LogUtil.getLogger("ch.ntb.inf.libusbJava"); + private static final Logger logger = LogUtil.getLogger("ch.ntb.usb"); private int maxPacketSize; @@ -545,11 +545,11 @@ public class Device { * * @param requestType * USB device request type (USB specification 9.3, - * bmRequestType). Use constants from {@link ch.ntb.inf.libusbJava.USB} + * bmRequestType). Use constants from {@link ch.ntb.usb.USB} * (REQ_TYPE_xxx). * @param request * specific request (USB specification 9.4, bRequest). Use - * constants from {@link ch.ntb.inf.libusbJava.USB} (REQ_xxx). + * constants from {@link ch.ntb.usb.USB} (REQ_xxx). * @param value * field that varies according to request (USB specification 9.4, * wValue) @@ -743,20 +743,14 @@ public class Device { } /** - * Check if the device is open, attached and work.
+ * Check if the device is open.
+ * This checks only for a valid device handle. It doesn't check if the + * device is still attached or working. * - * @return true if the device is open and work. + * @return true if the device is open */ public boolean isOpen() { - if(usbDevHandle != 0){ - try { - updateDescriptors(); - } catch (USBException e) { - return false; - } - return dev != null; - } - return false; + return usbDevHandle != 0; } /** diff --git a/src/main/java/ch/ntb/usb/LibusbJava.java b/src/main/java/ch/ntb/usb/LibusbJava.java index a578118..58da3b8 100644 --- a/src/main/java/ch/ntb/usb/LibusbJava.java +++ b/src/main/java/ch/ntb/usb/LibusbJava.java @@ -4,38 +4,43 @@ * * http://libusbjava.sourceforge.net * This library is covered by the LGPL, read LGPL.txt for details. - * - * Changes: - * 12.04.2012 NTB / Ueli Niederer implemented exception handling - * 18.10.2010 NTB / Roger Millischer change from native interface to compatibility layer - * */ package ch.ntb.usb; -import ch.ntb.usb.exceptions.LibusbError; +import com.github.boukefalos.jlibloader.Native; /** - * This class is used as compatibility layer for libusb 0.1 projects. + * This class represents the Java Native Interface to the shared library which + * is (with some exceptions) a one-to-one representation of the libusb API.
+ *
+ *

Project Description

+ * Java libusb is a Java wrapper for the libusb and libusb-win32 USB library. + * + * libusb aim is to create a + * library for use by user level applications to access USB devices regardless + * of OS.
+ * Libusb-win32 is a port of + * the USB library libusb to the + * Windows operating systems. The library allows user space applications to + * access any USB device on Windows in a generic way without writing any line of + * kernel driver code.
+ *
+ * The API description of this class has been copied from the libusb documentation + * and adapted where neccessary.
* - * @deprecated This class will not be subject to test anymore. Be aware that possible - * modifications could always break the functionality. For new - * projects only use {@link LibusbJava1}. */ public class LibusbJava { - private static Usb_Bus busses = null; - private static long defaultCTX = 0; /** * System error codes.
* This list is not complete! For more error codes see the file 'errorno.h' * on your system. */ - public static final int ERROR_SUCCESS = LibusbError.ERROR_NONE; - public static final int ERROR_BUSY = LibusbError.ERROR_BUSY; - public static final int ERROR_INVALID_PARAMETER = LibusbError.ERROR_INVALID_PARAM; - public static final int ERROR_TIMEDOUT = LibusbError.ERROR_TIMEOUT; - public static final int ERROR_IO_ERROR = LibusbError.ERROR_IO; - public static final int ERROR_NOT_ENOUGH_MEMORY = LibusbError.ERROR_NO_MEM; + 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.
@@ -46,30 +51,15 @@ public class LibusbJava { * @param level * 0 to 255 */ - public static void usb_set_debug(int level) { - LibusbJava1.libusb_set_debug(0, level); - } + public static native void usb_set_debug(int level); // Core /** * Just like the name implies, usb_init sets up some internal - * structures. usb_init must be called before any other libusb - * functions. + * structures. usb_init must be called before any other + * libusb functions. */ - public static void usb_init() { - if (defaultCTX != 0) { - return; - } - /*try { - defaultCTX = LibusbJava1.libusb_init(); - } catch (LibusbError e) { - System.err.println("LibusbJava-1.0 init failed with errorcode: " - + e.getMessage()); - e.printStackTrace(); - defaultCTX = 0; - }*/ - LibusbJava1.libusb_set_debug(0, 0); - } + public static native void usb_init(); /** * usb_find_busses will find all of the busses on the system. @@ -77,107 +67,7 @@ public class LibusbJava { * @return the number of changes since previous call to this function (total * of new busses and busses removed). */ - public static int usb_find_busses() { - int changes = 0; - long tmpBusNumber; - Usb_Bus nbusses = null; - Usb_Bus bus = nbusses, tmp; - boolean found = false; - Usb_Device devices = null; - devices = LibusbJava1.libusb_get_device_list(0); - - // no busses - if (devices.getDevnum() == -1) { - while (busses != null) { - changes++; - busses = busses.getNext(); - } - return changes; - } - // find busses - while (devices != null) { - tmpBusNumber = (long) LibusbJava1.libusb_get_bus_number(devices); - while (bus != null) { - if (bus.getLocation() == tmpBusNumber) { - found = true; - break; - } - bus = bus.getNext(); - } - if (found) { - devices = devices.getNext(); - found = false; - continue; - } - if (nbusses == null) { - nbusses = new Usb_Bus(Long.toString(tmpBusNumber), tmpBusNumber); - } else { - tmp = new Usb_Bus(Long.toString(tmpBusNumber), tmpBusNumber); - bus = nbusses; - // append - while (bus.getNext() != null) { - bus = bus.getNext(); - } - tmp.setPrev(bus); - bus.setNext(tmp); - } - bus = nbusses; - devices = devices.getNext(); - } - // compare to existing bus-list - bus = busses; - tmp = nbusses; - found = false; - while (bus != null) { - tmpBusNumber = bus.getLocation(); - while (tmp != null) { - if (tmpBusNumber == tmp.getLocation()) { - found = true; - // remove from nbusses list - if (tmp.getPrev() != null) { - tmp.getPrev().setNext(tmp.getNext()); - } else { - nbusses = tmp.getNext(); - } - if (tmp.getNext() != null) { - tmp.getNext().setPrev(tmp.getPrev()); - } - break; - } - tmp = tmp.getNext(); - } - if (!found) { - // remove from busses an increment changes - if (bus.getPrev() != null) { - bus.getPrev().setNext(bus.getNext()); - } else { - busses = bus.getNext(); - } - if (bus.getNext() != null) { - bus.getNext().setPrev(bus.getPrev()); - } - changes++; - } - bus = bus.getNext(); - tmp = nbusses; - found = false; - } - // add new busses - bus = busses; - while (tmp != null) { - tmp = tmp.getNext(); - changes++; - } - if (busses != null) { - while (bus.getNext() != null) { - bus = bus.getNext(); - } - bus.setNext(nbusses); - } else { - busses = nbusses; - } - return changes; - } + public static native int usb_find_busses(); /** * usb_find_devices will find all of the devices on each bus. @@ -186,85 +76,7 @@ public class LibusbJava { * @return the number of changes since the previous call to this function * (total of new device and devices removed). */ - public static int usb_find_devices() { - int changes = 0; - byte tmpDevnum; - long tmpBusNumber; - Usb_Bus bus = busses; - boolean found = false; - Usb_Device devices, dev, ndev; - - devices = LibusbJava1.libusb_get_device_list(0); - // Compare to existing bus-structure and remove removed devices - while (bus != null) { - dev = bus.getDevices(); - while (dev != null) { - tmpDevnum = dev.getDevnum(); - ndev = devices; - while (ndev != null) { - // if dev already exist remove from ndev list - if (tmpDevnum == ndev.getDevnum()) { - found = true; - if (ndev.getPrev() != null) { - ndev.getPrev().setNext(ndev.getNext()); - } else { - devices = ndev.getNext(); - } - if (ndev.getNext() != null) { - ndev.getNext().setPrev(ndev.getPrev()); - } - break; - } - ndev = ndev.getNext(); - } - if (!found) { - // remove device from bus an increment changes - if (dev.getPrev() != null) { - dev.getPrev().setNext(dev.getNext()); - } else { - bus.setDevices(dev.getNext()); - } - if (dev.getNext() != null) { - dev.getNext().setPrev(dev.getPrev()); - } - changes++; - } else { - found = false; - } - dev = dev.getNext(); - } - bus = bus.getNext(); - } - // Add new Devices - bus = busses; - while (devices != null) { - ndev = devices.getNext(); - // find correct bus - tmpBusNumber = (long) LibusbJava1.libusb_get_bus_number(devices); - while (bus != null) { - if (bus.getLocation() == tmpBusNumber) { - break; - } - bus = bus.getNext(); - } - // insert device - if (bus != null) { - if (bus.getDevices() == null) { - devices.setNext(null); - } else { - devices.setNext(bus.getDevices()); - devices.getNext().setPrev(devices); - } - devices.setPrev(null); - bus.setDevices(devices); - devices.setBus(bus); - changes++; - } - devices = ndev; - bus = busses; - } - return changes; - } + public static native int usb_find_devices(); /** * usb_get_busses returns a tree of descriptor objects.
@@ -277,9 +89,7 @@ public class LibusbJava { * @return the structure of all busses and devices. Note: The * java objects are copies of the C structs. */ - public static Usb_Bus usb_get_busses() { - return busses; - } + public static native Usb_Bus usb_get_busses(); // Device Operations /** @@ -292,33 +102,17 @@ public class LibusbJava { * @return a handle used in future communication with the device. 0 if an * error has occurred. */ - public static long usb_open(Usb_Device dev) { - long handle = 0; - - try { - handle = LibusbJava1.libusb_open(dev); - } - catch (LibusbError e) { - System.err.println("LibusbJava-1.0 failed with errorcode: " - + e.getMessage()); - e.printStackTrace(); - handle = 0; - } - - return handle; - } + public static native long usb_open(Usb_Device dev); /** - * usb_close closes a device opened with usb_open. + * usb_close closes a device opened with + * usb_open. * * @param dev_handle * The handle to the device. - * @return 0 + * @return 0 on success or < 0 on error. */ - public static int usb_close(long dev_handle) { - LibusbJava1.libusb_close(dev_handle); - return 0; - } + public static native int usb_close(long dev_handle); /** * Sets the active configuration of a device @@ -330,17 +124,8 @@ public class LibusbJava { * bConfigurationValue. * @return 0 on success or < 0 on error. */ - public static int usb_set_configuration(long dev_handle, int configuration) { - int result = 0; - - try { - LibusbJava1.libusb_set_configuration(dev_handle, configuration); - } catch (LibusbError e) { - result = -1; - } - - return result; - } + public static native int usb_set_configuration(long dev_handle, + int configuration); /** * Sets the active alternate setting of the current interface @@ -352,42 +137,7 @@ public class LibusbJava { * bAlternateSetting. * @return 0 on success or < 0 on error. */ - public static int usb_set_altinterface(long dev_handle, int alternate) { - Usb_Device dev = LibusbJava1.libusb_get_device(dev_handle); - int nofInterfaces = LibusbJava1 - .libusb_get_active_config_descriptor(dev).getBNumInterfaces(); - int interface_number, success = 0; - for (interface_number = 0; interface_number < nofInterfaces; interface_number++) { - try - { - LibusbJava1.libusb_release_interface(dev_handle, interface_number); - - try - { - LibusbJava1.libusb_claim_interface(dev_handle, interface_number); - } - catch (LibusbError e) - { - return e.getErrorCode(); - } - break; - } - catch (LibusbError e) - { - /* Move ahead. */ - } - } - - try { - LibusbJava1.libusb_set_interface_alt_setting(dev_handle, interface_number, alternate); - success = 0; - } - catch (LibusbError e) { - success = -1; - } - - return success; - } + public static native int usb_set_altinterface(long dev_handle, int alternate); /** * Clears any halt status on an endpoint. @@ -398,56 +148,27 @@ public class LibusbJava { * The value specified in the descriptor field bEndpointAddress. * @return 0 on success or < 0 on error. */ - public static int usb_clear_halt(long dev_handle, int ep) { - int result = 0; - - try { - LibusbJava1.libusb_clear_halt(dev_handle, (short) ep); - } catch (LibusbError e) { - result = e.getErrorCode(); - } - - return result; - } + 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.
*
- * Causes re-enumeration: After calling usb_reset, 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 + * Causes re-enumeration: After calling usb_reset, + * 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 * usb_reset will no longer work. * * @param dev_handle * The handle to the device. * @return 0 on success or < 0 on error. */ - public static int usb_reset(long dev_handle) { - int res = 0; - - try { - LibusbJava1.libusb_claim_interface(dev_handle, 0); - try { - LibusbJava1.libusb_reset_device(dev_handle); - } - catch (LibusbError e) { - res = e.getErrorCode(); - } - LibusbJava1.libusb_release_interface(dev_handle, 0); - LibusbJava1.libusb_close(dev_handle); - } catch (LibusbError e) { - /* Ignore all errors of these calls */ - } - - return res; - - } + public static native int usb_reset(long dev_handle); /** * Claim an interface of a device.
*
- * Must be called!: usb_claim_interface must be called - * before you perform any operations related to this interface (like + * Must be called!: usb_claim_interface must be + * called before you perform any operations related to this interface (like * usb_set_altinterface, usb_bulk_write, etc). * * @param dev_handle @@ -457,17 +178,7 @@ public class LibusbJava { * bInterfaceNumber. * @return 0 on success or < 0 on error. */ - public static int usb_claim_interface(long dev_handle, int interface_) { - int result = 0; - - try { - LibusbJava1.libusb_claim_interface(dev_handle, interface_); - } catch (LibusbError e) { - result = e.getErrorCode(); - } - - return result; - } + public static native int usb_claim_interface(long dev_handle, int interface_); /** * Releases a previously claimed interface @@ -479,17 +190,8 @@ public class LibusbJava { * bInterfaceNumber. * @return 0 on success or < 0 on error. */ - public static int usb_release_interface(long dev_handle, int interface_) { - int result = 0; - - try { - LibusbJava1.libusb_release_interface(dev_handle, interface_); - } catch (LibusbError e) { - result = e.getErrorCode(); - } - - return result; - } + public static native int usb_release_interface(long dev_handle, + int interface_); // Control Transfers /** @@ -507,12 +209,9 @@ public class LibusbJava { * @param timeout * @return the number of bytes written/read or < 0 on error. */ - public static int usb_control_msg(long dev_handle, int requesttype, + public static native int usb_control_msg(long dev_handle, int requesttype, int request, int value, int index, byte[] bytes, int size, - int timeout) { - return LibusbJava1.libusb_control_transfer(dev_handle, requesttype, - request, value, index, bytes, size, timeout); - } + int timeout); /** * Retrieves the string descriptor specified by index and langid from a @@ -524,17 +223,8 @@ public class LibusbJava { * @param langid * @return the descriptor String or null */ - public static String usb_get_string(long dev_handle, int index, int langid) { - String result; - - try { - result = LibusbJava1.libusb_get_string_descriptor(dev_handle, (short) index, langid, 255); - } catch (LibusbError e) { - result = null; - } - - return result; - } + public static native String usb_get_string(long dev_handle, int index, + int langid); /** * usb_get_string_simple is a wrapper around @@ -546,17 +236,7 @@ public class LibusbJava { * @param index * @return the descriptor String or null */ - public static String usb_get_string_simple(long dev_handle, int index) { - String result = null; - - try { - result = LibusbJava1.libusb_get_string_descriptor_ascii(dev_handle,(short) index, 255); - } catch (LibusbError e) { - result = null; - } - - return result; - } + 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 @@ -574,18 +254,8 @@ public class LibusbJava { * resulting String) * @return the descriptor String or null */ - public static byte[] usb_get_descriptor(long dev_handle, byte type, - byte index, int size) { - byte[] result = null; - - try { - result = LibusbJava1.libusb_get_descriptor(dev_handle, type, index, size); - } catch (LibusbError e) { - e.printStackTrace(); - } - - return result; - } + 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 @@ -601,24 +271,8 @@ public class LibusbJava { * resulting String) * @return the descriptor String or null */ - public static String usb_get_descriptor_by_endpoint(long dev_handle, - int ep, byte type, byte index, int size) { - - // We just send a control message directly; - byte data[] = new byte[size]; - char string[] = new char[size]; - int transfered; - transfered = LibusbJava1.libusb_control_transfer(dev_handle, - 0x80 | (ep & 0xFF), 0x07, (type << 8) | index, 0, data, size, - 1000); - if (transfered > 0) { - for (int i = 0; i < transfered; i++) { - string[i] = (char) data[i]; - } - return String.valueOf(string); - } - return null; - } + public static native String usb_get_descriptor_by_endpoint(long dev_handle, + int ep, byte type, byte index, int size); // Bulk Transfers /** @@ -632,19 +286,8 @@ public class LibusbJava { * @param timeout * @return the number of bytes written on success or < 0 on error. */ - public static int usb_bulk_write(long dev_handle, int ep, byte[] bytes, - int size, int timeout) { - int result = LibusbError.ERROR_OTHER; - - try { - result = LibusbJava1.libusb_bulk_transfer(dev_handle, (byte) ep, - bytes, size, timeout); - } catch (LibusbError e) { - result = e.getErrorCode(); - } - - return result; - } + 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. @@ -657,19 +300,8 @@ public class LibusbJava { * @param timeout * @return the number of bytes read on success or < 0 on error. */ - public static int usb_bulk_read(long dev_handle, int ep, byte[] bytes, - int size, int timeout) { - int result = LibusbError.ERROR_OTHER; - - try { - result = LibusbJava1.libusb_bulk_transfer(dev_handle, (byte) ep, - bytes, size, timeout); - } catch (LibusbError e) { - result = e.getErrorCode(); - } - - return result; - } + public static native int usb_bulk_read(long dev_handle, int ep, + byte[] bytes, int size, int timeout); // Interrupt Transfers /** @@ -683,19 +315,8 @@ public class LibusbJava { * @param timeout * @return the number of bytes written on success or < 0 on error. */ - public static int usb_interrupt_write(long dev_handle, int ep, - byte[] bytes, int size, int timeout) { - int result = LibusbError.ERROR_OTHER; - - try { - result = LibusbJava1.libusb_interrupt_transfer(dev_handle, (byte) ep, - bytes, size, timeout); - } catch (LibusbError e) { - result = e.getErrorCode(); - } - - return result; - } + 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. @@ -708,27 +329,48 @@ public class LibusbJava { * @param timeout * @return the number of bytes read on success or < 0 on error. */ - public static int usb_interrupt_read(long dev_handle, int ep, byte[] bytes, - int size, int timeout) { - int result = LibusbError.ERROR_OTHER; - - try { - result = LibusbJava1.libusb_interrupt_transfer(dev_handle, (byte) ep, - bytes, size, timeout); - } catch (LibusbError e) { - result = e.getErrorCode(); - } - - return result; - } + 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 String usb_strerror() { - return LibusbJava1.libusb_strerror(); - } + public static native String usb_strerror(); + /** **************************************************************** */ + + /** + * Maps the Java error code to the system error code.
+ *
+ * Note that not all error codes are be mapped by this method. For more + * error codes see the file 'errno.h' on your system.
+ *
+ * 1: EBADF: Bad file descriptor.
+ * 2: ENXIO: No such device or address.
+ * 3: EBUSY: Device or resource busy.
+ * 4: EINVAL: Invalid argument.
+ * 5: ETIMEDOUT: Connection timed out.
+ * 6: EIO: I/O error.
+ * 7: ENOMEM: Not enough memory.
+ * + * + * @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"); + + // 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); + } } \ No newline at end of file diff --git a/src/main/java/ch/ntb/usb/LibusbJava1.java b/src/main/java/ch/ntb/usb/LibusbJava1.java deleted file mode 100644 index 8801245..0000000 --- a/src/main/java/ch/ntb/usb/LibusbJava1.java +++ /dev/null @@ -1,1424 +0,0 @@ -/** - * Java libusb1.0 wrapper - * Roger Millischer - * - * This library is covered by the LGPL, read LGPL.txt for details. - */ -package ch.ntb.usb; - -import ch.ntb.usb.exceptions.LibusbError; - -import com.github.boukefalos.jlibloader.Native; - -/** - * This class represents the Java Native Interface to the shared library which - * is (with some exceptions) a one-to-one representation of the libusb1.0 API.
- *
- *

Project Description

Java libusb1.0 is a Java wrapper for the - * libusb1.0 USB library. - * - * libusb aim is to create a library for - * use by user level applications to access USB devices regardless of OS.
- * Libusb-Windows - * backend aim of this project is to bring a Windows backend to the mainline - * libusb 1.0 branch, so that libusb 1.0 can easily be used on Windows - * platforms. The library allows user space applications to access any USB - * device on Windows in a generic way without writing any line of kernel driver - * code.
- *
- * The API description of this class has been copied from the libusb-1.0 API - * Reference and adapted where neccessary.
- * - */ -public class LibusbJava1 { - /** - * Set message verbosity. - *
    - *
  • Level 0: no messages ever printed by the library (default)
  • - *
  • Level 1: error messages are printed to stderr
  • - *
  • Level 2: warning and error messages are printed to stderr
  • - *
  • Level 3: informational messages are printed to stdout, warning and - * error messages are printed to stderr
  • - *
- * - * The default level is 0, which means no messages are ever printed. If you - * choose to increase the message verbosity level, ensure that your - * application does not close the stdout/stderr file descriptors.
- *
- * You are advised to set level 3. libusb is conservative with its message - * logging and most of the time, will only log messages that explain error - * conditions and other oddities. This will help you debug your software.
- *
- * If the LIBUSB_DEBUG environment variable was set when libusb was - * initialized, this function does nothing: the message verbosity is fixed - * to the value in the environment variable.
- *
- * If libusb was compiled without any message logging, this function does - * nothing: you'll never get any messages.
- *
- * If libusb was compiled with verbose debug message logging, this function - * does nothing: you'll always get messages from all levels.
- *
- * - * @param ctx - * the context to operate on, or NULL for the default context - * @param level - * debug level to set - */ - - public static native void libusb_set_debug(long ctx, int level); - - /** - * Initialize libusb.
- *
- * This function must be called before calling any other libusb function.
- *
- * - * @return a context to operate on - * @throws LibusbError - * if an error occured - */ - public static native long libusb_init() throws LibusbError; - - /** - * Deinitialize libusb.
- *
- * Should be called after closing all open devices and before your - * application terminates.
- *
- * - * @param ctx - * the context to deinitialize, or 0 if the default context has - * been used. - */ - public static native void libusb_exit(long ctx); - - /** - * Returns a list of USB devices currently attached to the system.
- *
- * This is your entry point into finding a USB device to operate.
- *
- * - * @param ctx - * the context to operate on, or NULL for the default context - * - * @return Usb_Devices currently attached to the system
- * if no device is attached the devnum of the returned device is set - * to -1
- * or NULL if an error occurs - */ - public static native Usb_Device libusb_get_device_list(long ctx); - - /** - * Get the number of the bus that a device is connected to. - * - * @param dev - * a device - * @return the bus number - */ - public static native short libusb_get_bus_number(Usb_Device dev); - - /** - * Calculate the maximum packet size which a specific endpoint is capable is - * sending or receiving in the duration of 1 microframe.
- *
- * Only the active configution is examined. The calculation is based on the - * wMaxPacketSize field in the endpoint descriptor as described in section - * 9.6.6 in the USB 2.0 specifications.
- *
- * If acting on an isochronous or interrupt endpoint, this function will - * multiply the value found in bits 0:10 by the number of transactions per - * microframe (determined by bits 11:12). Otherwise, this function just - * returns the numeric value found in bits 0:10.
- *
- * This function is useful for setting up isochronous transfers, for example - * you might pass the return value from this function to - * libusb_set_iso_packet_lengths() in order to set the length - * field of every isochronous packet in a transfer.
- *
- * Since libusb v1.0.3.
- *
- * This functionality is not available on Windows-Systems
- *
- * - * @param dev - * a device - * @param endpoint - * address of the endpoint in question - * @return the maximum packet size which can be sent/received on this - * endpoint
- * LIBUSB_ERROR_NOT_FOUND if the endpoint does not exist
- * LIBUSB_ERROR_OTHER on other failure
- * TODO wenn funktion impl. richtig verlinken @see - * libusb_set_iso_packet_lengths() - */ - - public static native int libusb_get_max_iso_packet_size(Usb_Device dev, - short endpoint); - - /** - * Increment the reference count of a device. - * - * @param dev - * the device to reference - * @return the same device - */ - public static native Usb_Device libusb_ref_device(Usb_Device dev); - - /** - * Decrement the reference count of a device.
- *
- * If the decrement operation causes the reference count to reach zero, the - * device shall be destroyed.
- *
- * - * @param dev - * the device to unreference - */ - - public static native void libusb_unref_device(Usb_Device dev); - - /** - * Open a device and obtain a device handle.
- *
- * A handle allows you to perform I/O on the device in question.
- *
- * Internally, this function adds a reference to the device and makes it - * available to you through libusb_get_device(). This reference - * is removed during libusb_close().
- *
- * This is a non-blocking function; no requests are sent over the bus.
- *
- * - * @param dev - * the device to open - * - * @return a device handle >= 0 - * - * @throws LibusbError - * in case of an error
- * Possible causes are:
- * - ERROR_NO_MEM on memory allocation failure
- * - ERROR_ACCESS if the user has insufficient permissions
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another ERROR code on other failure - * - * @see #libusb_get_device(long) - */ - public static native long libusb_open(Usb_Device dev) throws LibusbError; - - /** - * Convenience function for finding a device with a particular - * idVendor/idProduct combination.
- *
- * This function is intended for those scenarios where you are using libusb - * to knock up a quick test application - it allows you to avoid calling - * libusb_get_device_list() and worrying about - * traversing/freeing the list.
- *
- * This function has limitations and is hence not intended for use in real - * applications: if multiple devices have the same IDs it will only give you - * the first one, etc.
- * - * @param ctx - * the context to operate on, or NULL for the default context - * @param vendor_id - * the idVendor value to search for - * @param product_id - * the idProduct value to search for - * @return a handle for the first found device, or NULL on error or if the - * device could not be found. - * @see #libusb_get_device_list(long) - */ - public static native long libusb_open_device_with_vid_pid(long ctx, - int vendor_id, int product_id); - - /** - * Close a device handle.
- *
- * Should be called on all open handles before your application exits.
- *
- * Internally, this function destroys the reference that was added by - * libusb_open() on the given device.
- *
- * This is a non-blocking function; no requests are sent over the bus.
- *
- * - * @param dev_handle - * the handle to close - */ - public static native void libusb_close(long dev_handle); - - /** - * Get the underlying device for a handle.
- *
- * This function does not modify the reference count of the returned device, - * so do not feel compelled to unreference it when you are done.
- *
- * - * @param dev_handle - * a device handle - * @return the underlying {@link Usb_Device} - */ - public static native Usb_Device libusb_get_device(long dev_handle); - - /** - * Determine the bConfigurationValue of the currently active configuration.
- *
- * You could formulate your own control request to obtain this information, - * but this function has the advantage that it may be able to retrieve the - * information from operating system caches (no I/O involved).
- *
- * If the OS does not cache this information, then this function will block - * while a control transfer is submitted to retrieve the information.
- *
- * This function will return a value of 0 if the device is in unconfigured - * state.
- *
- * - * @param dev_handle - * a device handle - * @return bConfigurationValue of the currently active configuration - * @throws LibusbError - * in case of an error
- * Possible error causes are:
- * - ERROR_NO_DEVICE if the device has been disconnected - - * another ERROR code on other failure - */ - public static native int libusb_get_configuration(long dev_handle) - throws LibusbError; - - /** - * Set the active configuration for a device.
- *
- * The operating system may or may not have already set an active - * configuration on the device. It is up to your application to ensure the - * correct configuration is selected before you attempt to claim interfaces - * and perform other operations.
- *
- * If you call this function on a device already configured with the - * selected configuration, then this function will act as a lightweight - * device reset: it will issue a SET_CONFIGURATION request using the current - * configuration, causing most USB-related device state to be reset - * (altsetting reset to zero, endpoint halts cleared, toggles reset).
- *
- * You cannot change/reset configuration if your application has claimed - * interfaces - you should free them with - * {@link #libusb_release_interface(long, int)} first. You cannot - * change/reset configuration if other applications or drivers have claimed - * interfaces.
- *
- * A configuration value of -1 will put the device in unconfigured state. - * The USB specifications state that a configuration value of 0 does this, - * however buggy devices exist which actually have a configuration 0.
- *
- * You should always use this function rather than formulating your own - * SET_CONFIGURATION control request. This is because the underlying - * operating system needs to know when such changes happen.
- *
- * This is a blocking function.
- *
- * - * @param dev_handle - * a device handle - * @param configuration - * the bConfigurationValue of the configuration you wish to - * activate, or -1 if you wish to put the device in unconfigured - * state - * @throws LibusbError - * in case of an error
- * Possible error causes are:
- * - ERROR_NOT_FOUND if the requested configuration does not - * exist
- * - ERROR_BUSY if interfaces are currently claimed
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another LIBUSB_ERROR code on other failure
- */ - public static native void libusb_set_configuration(long dev_handle, - int configuration) throws LibusbError; - - /** - * Claim an interface on a given device handle.
- *
- * You must claim the interface you wish to use before you can perform I/O - * on any of its endpoints.
- *
- * It is legal to attempt to claim an already-claimed interface, in which - * case libusb just returns 0 without doing anything.
- *
- * Claiming of interfaces is a purely logical operation, it does not cause - * any requests to be sent over the bus. Interface claiming is used to - * instruct the underlying operating system that your application wishes to - * take ownership of the interface.
- *
- * This is a non-blocking function.
- *
- * - * @param dev_handle - * a device handle - * @param interface_number - * the bInterfaceNumber of the interface you wish to claim - * @throws LibusbError - * in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if the interface was not claimed
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - ERROR_BUSY if another program or driver has claimed the - * interface
- * - another LIBUSB_ERROR code on other failure
- */ - public static native void libusb_claim_interface(long dev_handle, - int interface_number) throws LibusbError; - - /** - * Release an interface previously claimed with - * {@link #libusb_claim_interface(long, int)}.
- *
- * You should release all claimed interfaces before closing a device handle.
- *
- * This is a blocking function. A SET_INTERFACE control request will be sent - * to the device, resetting interface state to the first alternate setting.
- *
- * - * @param dev_handle - * a device handle - * @param interface_number - * the bInterfaceNumber of the previously-claimed interface - * @throws LibusbError - * in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if the interface was not claimed
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another ERROR code on other failure
- */ - public static native void libusb_release_interface(long dev_handle, - int interface_number) throws LibusbError; - - /** - * Activate an alternate setting for an interface.
- *
- * The interface must have been previously claimed with - * {@link #libusb_claim_interface(long, int)}.
- *
- * You should always use this function rather than formulating your own - * SET_INTERFACE control request. This is because the underlying operating - * system needs to know when such changes happen.
- *
- * This is a blocking function.
- *
- * - * @param dev_handle - * a device handle - * @param interface_number - * the bInterfaceNumber of the previously-claimed interface - * @param alternate_setting - * the bAlternateSetting of the alternate setting to activate - * @throws LibusbError - * in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if the interface was not claimed, or the - * requested alternate setting does not exist
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another LIBUSB_ERROR code on other failure
- */ - public static native void libusb_set_interface_alt_setting(long dev_handle, - int interface_number, int alternate_setting) throws LibusbError; - - /** - * Clear the halt/stall condition for an endpoint.
- *
- * Endpoints with halt status are unable to receive or transmit data until - * the halt condition is stalled.
- *
- * You should cancel all pending transfers before attempting to clear the - * halt condition.
- *
- * This is a blocking function.
- *
- * - * @param dev_handle - * a device handle - * @param endpoint - * the endpoint to clear halt status - * @throws LibusbError - * in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if the endpoint does not exist
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another LIBUSB_ERROR code on other failure
- */ - public static native void libusb_clear_halt(long dev_handle, short endpoint) - throws LibusbError; - - /** - * Perform a USB port reset to reinitialize a device.
- *
- * The system will attempt to restore the previous configuration and - * alternate settings after the reset has completed.
- *
- * If the reset fails, the descriptors change, or the previous state cannot - * be restored, the device will appear to be disconnected and reconnected. - * This means that the device handle is no longer valid (you should close - * it) and rediscover the device. A return code of LIBUSB_ERROR_NOT_FOUND - * indicates when this is the case.
- *
- * This is a blocking function which usually incurs a noticeable delay.
- *
- * - * @param dev_handle - * a handle of the device to reset - * @throws LibusbError - * in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if re-enumeration is required, or if the - * device has been disconnected
- * - another LIBUSB_ERROR code on other failure
- */ - public static native void libusb_reset_device(long dev_handle) - throws LibusbError; - - /** - * Determine if a kernel driver is active on an interface.
- *
- * If a kernel driver is active, you cannot claim the interface, and libusb - * will be unable to perform I/O.
- *
- * - * @param dev_handle - * a device handle - * @param interface_number - * the interface to check - * @return 0 if no kernel driver is active
- * 1 if a kernel driver is active
- * @throws LibusbError - * in case of an error
- * Possible causes for errors are:
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another LIBUSB_ERROR code on other failure
- * @see #libusb_detach_kernel_driver(long, int) - */ - public static native int libusb_kernel_driver_active(long dev_handle, - int interface_number) throws LibusbError; - - /** - * Detach a kernel driver from an interface.
- *
- * If successful, you will then be able to claim the interface and perform - * I/O.
- *
- * - * @param dev_handle - * a device handle - * @param interface_number - * the interface to detach the driver from - * @throws LibusbError - * in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if no kernel driver was active
- * - ERROR_INVALID_PARAM if the interface does not exist
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another ERROR code on other failure
- * @see #libusb_kernel_driver_active(long, int) - */ - public static native void libusb_detach_kernel_driver(long dev_handle, - int interface_number) throws LibusbError; - - /** - * Re-attach an interface's kernel driver, which was previously detached - * using {@link #libusb_detach_kernel_driver(long, int)}.
- * - * @param dev_handle - * a device handle - * @param interface_number - * the interface to attach the driver from - * @throws LibusbError - * in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if no kernel driver was active
- * - ERROR_INVALID_PARAM if the interface does not exist
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - ERROR_BUSY if the driver cannot be attached because the - * interface is claimed by a program or driver
- * - another ERROR code on other failure
- * @see #libusb_kernel_driver_active(long, int) - */ - public static native void libusb_attach_kernel_driver(long dev_handle, - int interface_number) throws LibusbError; - - /** - * Get the USB configuration descriptor for the currently active - * configuration.
- *
- * This is a non-blocking function which does not involve any requests being - * sent to the device.
- *
- * - * @param dev - * a device - * @return {@link Usb_Config_Descriptor} - */ - public static native Usb_Config_Descriptor libusb_get_active_config_descriptor( - Usb_Device dev); - - /** - * Retrieve a string descriptor in C style ASCII.
- *
- * Wrapper around - * {@link #libusb_get_string_descriptor(long, short, int, int)}. Uses the - * first language supported by the device. - * - * @param dev_handle - * a device handle - * @param desc_index - * the index of the descriptor to retrieve - * @param size - * number of charactes which will be retrieved (the length of the - * resulting String) - * @return a string which contains the string descriptor - * @throws LibusbError - * in case of an error
- */ - public static native String libusb_get_string_descriptor_ascii( - long dev_handle, short desc_index, int size) throws LibusbError; - - /** - * Retrieve a descriptor from the default control pipe.
- *
- * This is a convenience function which formulates the appropriate control - * message to retrieve the descriptor. - * - * @param dev_handle - * a device handle - * @param desc_type - * the descriptor type - * @param desc_index - * the index of the descriptor to retrieve - * @param size - * number of bytes which will be retrieved (the length of the - * resulting byte[]) - * @return a byte[] which contains the descriptor or null on failure - * @throws LibusbError - * in case of an error
- * - */ - public static native byte[] libusb_get_descriptor(long dev_handle, - int desc_type, short desc_index, int size) throws LibusbError; - - /** - * Retrieve a descriptor from a device.
- *
- * This is a convenience function which formulates the appropriate control - * message to retrieve the descriptor. The string returned is Unicode, as - * detailed in the USB specifications. - * - * @param dev_handle - * a device handle - * @param desc_index - * the index of the descriptor to retrieve - * @param langid - * the language ID for the string descriptor - * @param size - * number of charactes which will be retrieved (the length of the - * resulting String) - * @return a string which contains the string descriptor - * @throws LibusbError - * in case of an error
- * @see #libusb_get_string_descriptor_ascii(long, short, int) - */ - public static native String libusb_get_string_descriptor(long dev_handle, - short desc_index, int langid, int size) throws LibusbError; - - /** - * Allocate a libusb transfer with a specified number of isochronous packet - * descriptors.
- * - * The returned transfer is pre-initialized for you. When the new transfer - * is no longer needed, it should be freed with - * libusb_free_transfer().
- *
- * Transfers intended for non-isochronous endpoints (e.g. control, bulk, - * interrupt) should specify an iso_packets count of zero.
- *
- * For transfers intended for isochronous endpoints, specify an appropriate - * number of packet descriptors to be allocated as part of the transfer. The - * returned transfer is not specially initialized for isochronous I/O you - * are still required to set the num_iso_packets and type - * fields accordingly.
- *
- * It is safe to allocate a transfer with some isochronous packets and then - * use it on a non-isochronous endpoint. If you do this, ensure that at time - * of submission, num_iso_packets is 0 and that type is set appropriately.
- * - * @param iso_packets - * number of isochronous packet descriptors to allocate - * @return a newly allocated transfernumber, or NULL on error - */ - public static native long libusb_alloc_transfer(int iso_packets); - - /** - * Free a transfer. - * - * This should be called for all transfers allocated with - * libusb_alloc_transfer().
- *
- * It is legal to call this function with a NULL transfer. In this case, the - * function will simply return safely.
- *
- * It is not legal to free an active transfer (one which has been submitted - * and has not yet completed).
- *
- * - * @param transfernumber - * the transfer to free - */ - public static native void libusb_free_transfer(long transfernumber); - - /** - * Submit a transfer.
- *
- * This function will fire off the USB transfer and then return immediately.
- *
- * - * @param transfernumber - * the transfer to submit - * @throws LibusbError - * in case of an error
- * Possible causes for errors are:
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - ERROR_BUSY if the transfer has already been submitted.
- * - another LIBUSB_ERROR code on other failure
- */ - public static native void libusb_submit_transfer(long transfernumber) - throws LibusbError; - - /** - * Asynchronously cancel a previously submitted transfer.
- *
- * This function returns immediately, but this does not indicate - * cancellation is complete. Libusb_event will be invoked at some later time - * to notify you. - * - * @param transfernumber - * a transfer - * @throws LibusbError - * in case of an error
- * Possible causes for errors are:
- * - ERROR_NOT_FOUND if the transfer is already complete or - * cancelled.
- * - a LIBUSB_ERROR code on failure
- */ - public static native void libusb_cancel_transfer(long transfernumber) - throws LibusbError; - - /** - * Get the data section of a control transfer.
- *
- * This convenience function is here to remind you that the data does not - * start until 8 bytes into the actual buffer, as the setup packet comes - * first.
- *
- * Calling this function only makes sense from a transfer event handler, or - * situations where you have already allocated a suitably sized buffer. - * - * @param transfernumber - * a transfer - * @return the data section from the transfer, null if the transfer number - * was invalid. - */ - public static native byte[] libusb_control_transfer_get_data( - long transfernumber); - - /** - * Get the control setup packet of a control transfer.
- *
- * This convenience function is here to remind you that the control setup - * occupies the first 8 bytes of the transfer data buffer.
- *
- * Calling this function only makes sense from a transfer event handler, or - * situations where you have already allocated a suitably sized buffer at - * transfer->buffer. - * - * @param transfernumber - * a transfer - * @return the setup packet from the transfer, null if the transfer number - * was invalid. - */ - public static native byte[] libusb_control_transfer_get_setup( - long transfernumber); - - /** - * Helper function to populate the setup packet (first 8 bytes of the data - * buffer) for a control transfer.
- * - * @param bmRequestType - * @param bRequest - * @param wValue - * @param wIndex - * @param wLength - * @return the setup packet - */ - public static native byte[] libusb_fill_control_setup(int bmRequestType, - int bRequest, int wValue, int wIndex, int wLength); - - /** - * Helper function to populate the required libusb_transfer fields for a - * control transfer.
- *
- * If you pass a transfer buffer to this function, the first 8 bytes will be - * interpreted as a control setup packet, and the wLength field will be used - * to automatically populate the length field of the transfer. Therefore the - * recommended approach is:
- *
- * 1. Call libusb_fill_control_setup()
- * 2. Allocate a suitably sized data buffer (including space for control - * setup)
- * 3. Put the retrieved setup packet into the firste 8 byte of the data - * buffer.
- * 4. If this is a host-to-device transfer with a data stage, put the data - * in place after the setup packet
- * 5. Call this function
- * 6. Call libusb_submit_transfer()
- *
- * It is also legal to pass a NULL buffer to this function, in which case - * this function will not attempt to populate the length field. Remember - * that you must then populate the buffer and length fields later. - * - * @param transfernumber - * transfer to populate - * @param dev_handle - * handle of the device that - * @param buffer - * data buffer. If provided, this function will interpret the - * first 8 bytes as a setup packet and infer the transfer length - * from that. - * @param timeout - * timeout for the transfer in milliseconds - */ - public static native void libusb_fill_control_transfer(long transfernumber, - long dev_handle, byte[] buffer, int timeout); - - /** - * Helper function to populate the required libusb_transfer fields for a - * bulk transfer. - * - * @param transfernumber - * the transfer to populate - * @param dev_handle - * handle of the device that will handle the transfer - * @param endpoint - * address of the endpoint where this transfer will be sent - * @param buffer - * data buffer - * @param length - * length of data buffer - * @param timeout - * timeout for the transfer in milliseconds - */ - public static native void libusb_fill_bulk_transfer(long transfernumber, - long dev_handle, byte endpoint, byte[] buffer, int length, - int timeout); - - /** - * Helper function to populate the required libusb_transfer fields for an - * interrupt transfer. - * - * @param transfernumber - * the transfer to populate - * @param dev_handle - * handle of the device that will handle the transfer - * @param endpoint - * address of the endpoint where this transfer will be sent - * @param buffer - * data buffer - * @param length - * length of data buffer - * @param timeout - * timeout for the transfer in milliseconds - */ - public static native void libusb_fill_interrupt_transfer( - long transfernumber, long dev_handle, byte endpoint, byte[] buffer, - int length, int timeout); - - /** - * Helper function to populate the required libusb_transfer fields for an - * isochronous transfer. - * - * @param transfernumber - * the transfer to populate - * @param dev_handle - * handle of the device that will handle the transfer - * @param endpoint - * address of the endpoint where this transfer will be sent - * @param buffer - * data buffer - * @param length - * length of data buffer - * @param num_iso_packets - * the number of isochronous packets - * @param timeout - * timeout for the transfer in milliseconds - */ - public static native void libusb_fill_iso_transfer(long transfernumber, - long dev_handle, byte endpoint, byte[] buffer, int length, - int num_iso_packets, int timeout); - - /** - * Convenience function to set the length of all packets in an isochronous - * transfer, based on the num_iso_packets field in the transfer structure. - * - * @param transfer - * a transfer - * @param length - * the length to set in each isochronous packet descriptor - */ - public static native void libusb_set_iso_packet_lengths(long transfer, - int length); - - /** - * Convenience function to locate the position of an isochronous packet - * within the buffer of an isochronous transfer.
- *
- * This is a thorough function which loops through all preceding packets, - * accumulating their lengths to find the position of the specified packet. - * Typically you will assign equal lengths to each packet in the transfer, - * and hence the above method is sub-optimal. You may wish to use - * libusb_get_iso_packet_buffer_simple() instead.
- *
- * - * @param transfer - * a transfer - * @param packet - * the packet to return - * @return the packet buffer inside the transfer buffer, or NULL if the - * packet does not exist - */ - public static native byte[] libusb_get_iso_packet_buffer(long transfer, - int packet); - - /** - * Convenience function to locate the position of an isochronous packet - * within the buffer of an isochronous transfer, for transfers where each - * packet is of identical size.
- *
- * This function relies on the assumption that every packet within the - * transfer is of identical size to the first packet. Calculating the - * location of the packet buffer is then just a simple calculation: buffer + - * (packet_size * packet)
- *
- * Do not use this function on transfers other than those that have - * identical packet lengths for each packet. - * - * @param transfernumber - * a transfer - * @param packet - * he packet to return - * @return the packet buffer inside the transfer buffer, or NULL if the - * packet does not exist. - */ - public static native byte[] libusb_get_iso_packet_buffer_simple( - long transfernumber, int packet); - - /** - * Attempt to acquire the event handling lock.
- *
- * This lock is used to ensure that only one thread is monitoring libusb - * event sources at any one time.
- *
- * You only need to use this lock if you are developing an application which - * calls poll() or select() on libusb's file descriptors directly. If you - * stick to libusb's event handling loop functions (e.g. - * libusb_handle_events()) then you do not need to be concerned - * with this locking.
- *
- * While holding this lock, you are trusted to actually be handling events. - * If you are no longer handling events, you must call - * libusb_unlock_events() as soon as possible. - * - * @param ctx - * the context to operate on, or NULL for the default context - * @return 0 if the lock was obtained successfully
- * 1 if the lock was not obtained (i.e. another thread holds the - * lock)
- */ - public static native int libusb_try_lock_events(long ctx); - - /** - * Acquire the event handling lock, blocking until successful acquisition if - * it is contended.
- *
- * This lock is used to ensure that only one thread is monitoring libusb - * event sources at any one time.
- *
- * You only need to use this lock if you are developing an application which - * calls poll() or select() on libusb's file descriptors directly. If you - * stick to libusb's event handling loop functions (e.g. - * libusb_handle_events()) then you do not need to be concerned - * with this locking.
- *
- * While holding this lock, you are trusted to actually be handling events. - * If you are no longer handling events, you must call - * libusb_unlock_events() as soon as possible. - * - * @param ctx - * the context to operate on, or NULL for the default context - */ - public static native void libusb_lock_events(long ctx); - - /** - * Release the lock previously acquired with - * libusb_try_lock_events() or - * libusb_lock_events().
- *
- * Releasing this lock will wake up any threads blocked on - * libusb_wait_for_event(). - * - * @param ctx - * the context to operate on, or NULL for the default context - */ - public static native void libusb_unlock_events(long ctx); - - /** - * Determine if it is still OK for this thread to be doing event handling.
- *
- * Sometimes, libusb needs to temporarily pause all event handlers, and this - * is the function you should use before polling file descriptors to see if - * this is the case.
- *
- * If this function instructs your thread to give up the events lock, you - * should just continue the usual logic. On the next iteration, your thread - * will fail to obtain the events lock, and will hence become an event - * waiter.
- *
- * This function should be called while the events lock is held: you don't - * need to worry about the results of this function if your thread is not - * the current event handler. - * - * @param ctx - * the context to operate on, or NULL for the default context - * @return 1 if event handling can start or continue
- * 0 if this thread must give up the events lock
- */ - public static native int libusb_event_handling_ok(long ctx); - - /** - * Determine if an active thread is handling events (i.e. if anyone is - * holding the event handling lock). - * - * @param ctx - * the context to operate on, or NULL for the default context - * @return 1 if a thread is handling events
- * 0 if there are no threads currently handling events
- */ - public static native int libusb_event_handler_active(long ctx); - - /** - * Acquire the event waiters lock.
- *
- * This lock is designed to be obtained under the situation where you want - * to be aware when events are completed, but some other thread is event - * handling so calling libusb_handle_events() is not allowed.
- *
- * You then obtain this lock, re-check that another thread is still handling - * events, then call libusb_wait_for_event().
- *
- * You only need to use this lock if you are developing an application which - * calls poll() or select() on libusb's file descriptors directly, and may - * potentially be handling events from 2 threads simultaenously. If you - * stick to libusb's event handling loop functions (e.g. - * libusb_handle_events()) then you do not need to be concerned - * with this locking. - * - * @param ctx - * the context to operate on, or NULL for the default context - */ - public static native void libusb_lock_event_waiters(long ctx); - - /** - * Release the event waiters lock. - * - * @param ctx - * the context to operate on, or NULL for the default context - */ - public static native void libusb_unlock_event_waiters(long ctx); - - /** - * Wait for another thread to signal completion of an event.
- *
- * Must be called with the event waiters lock held, see - * libusb_lock_event_waiters().
- *
- * This function will block until any of the following conditions are met:
- * - * 1. The timeout expires
- * 2. A transfer completes
- * 3. A thread releases the event handling lock through - * libusb_unlock_events()
- *
- * Condition 1 is obvious. Condition 2 unblocks your thread after the - * callback for the transfer has completed. Condition 3 is important because - * it means that the thread that was previously handling events is no longer - * doing so, so if any events are to complete, another thread needs to step - * up and start event handling.
- *
- * This function releases the event waiters lock before putting your thread - * to sleep, and reacquires the lock as it is being woken up. - * - * @param ctx - * the context to operate on, or NULL for the default context - * @param timeval - * maximum timeout in seconds for this blocking function. 0 - * seconds indicates unlimited timeout - * @return 0 after a transfer completes or another thread stops event - * handling
- * 1 if the timeout expired
- */ - public static native int libusb_wait_for_event(long ctx, long timeval); - - /** - * Handle any pending events.
- *
- * libusb determines "pending events" by checking if any timeouts have - * expired and by checking the set of file descriptors for activity.
- *
- * If a zero timeval is passed, this function will handle any - * already-pending events and then immediately return in non-blocking style.
- *
- * If a non-zero timeval is passed and no events are currently pending, this - * function will block waiting for events to handle up until the specified - * timeout. If an event arrives or a signal is raised, this function will - * return early. - * - * @param ctx - * the context to operate on, or NULL for the default context - * @param timeval - * the maximum time to block waiting for events, or zero for - * non-blocking mode - * @throws LibusbError - * in case of an error
- */ - public static native void libusb_handle_events_timeout(long ctx, - long timeval) throws LibusbError; - - /** - * Handle any pending events in blocking mode with a sensible timeout.
- *
- * This timeout is currently hardcoded at 2 seconds but we may change this - * if we decide other values are more sensible. For finer control over - * whether this function is blocking or non-blocking, or the maximum - * timeout, use libusb_handle_events_timeout() instead. - * - * @param ctx - * the context to operate on, or NULL for the default context - * @throws LibusbError - * in case of an error
- */ - public static native void libusb_handle_events(long ctx) throws LibusbError; - - /** - * Handle any pending events by polling file descriptors, without checking - * if any other threads are already doing so.
- *
- * Must be called with the event lock held, see - * libusb_lock_events().
- *
- * This function is designed to be called under the situation where you have - * taken the event lock and are calling poll()/select() directly on libusb's - * file descriptors (as opposed to using libusb_handle_events() - * or similar). You detect events on libusb's descriptors, so you then call - * this function with a zero timeout value (while still holding the event - * lock). - * - * @param ctx - * the context to operate on, or NULL for the default context - * @param timeval - * the maximum time in seconds to block waiting for events, or - * zero for non-blocking mode - * @throws LibusbError - * in case of an error
- */ - public static native void libusb_handle_events_locked(long ctx, long timeval) - throws LibusbError; - - /** - * Determines whether your application must apply special timing - * considerations when monitoring libusb's file descriptors.
- *
- * This function is only useful for applications which retrieve and poll - * libusb's file descriptors in their own main loop (The more advanced - * option).
- *
- * Ordinarily, libusb's event handler needs to be called into at specific - * moments in time (in addition to times when there is activity on the file - * descriptor set). The usual approach is to use - * libusb_get_next_timeout() to learn about when the next - * timeout occurs, and to adjust your poll()/select() timeout accordingly so - * that you can make a call into the library at that time.
- *
- * Some platforms supported by libusb do not come with this baggage - any - * events relevant to timing will be represented by activity on the file - * descriptor set, and libusb_get_next_timeout() will always - * return 0. This function allows you to detect whether you are running on - * such a platform.
- *
- * Since v1.0.5. - * - * @param ctx - * the context to operate on, or NULL for the default context - * @return 0 if you must call into libusb at times determined by - * libusb_get_next_timeout(), or 1 if all timeout - * events are handled internally or through regular activity on the - * file descriptors. - */ - public static native int libusb_pollfds_handle_timeouts(long ctx); - - /** - * Determine the next internal timeout that libusb needs to handle.
- *
- * You only need to use this function if you are calling poll() or select() - * or similar on libusb's file descriptors yourself - you do not need to use - * it if you are calling libusb_handle_events() or a variant directly.
- *
- * You should call this function in your main loop in order to determine how - * long to wait for select() or poll() to return results. libusb needs to be - * called into at this timeout, so you should use it as an upper bound on - * your select() or poll() call.
- *
- * When the timeout has expired, call into libusb_handle_events_timeout() - * (perhaps in non-blocking mode) so that libusb can handle the timeout.
- *
- * This function may return an zero timevalue. If this is the case, it - * indicates that libusb has a timeout that has already expired so you - * should call libusb_handle_events_timeout() or similar immediately. A - * return code of -1 indicates that there are no pending timeouts.
- *
- * On some platforms, this function will always returns -1 (no pending - * timeouts). - * - * @param ctx - * the context to operate on, or NULL for the default context - * @return time to next timeout
- * -1 if there are no pending timeouts
- * @throws LibusbError - * If an error is occured in libusb - */ - public static native int libusb_get_next_timeout(long ctx) - throws LibusbError; - - /** - * Register notification functions for file descriptor additions/removals.
- *
- * These functions will be invoked for every new or removed file descriptor - * that libusb uses as an event source.
- *
- * To remove notifiers, set remove TRUE.
- *
- * Note that file descriptors may have been added even before you register - * these notifiers (e.g. at libusb_init() time).
- *
- * Additionally, note that the removal notifier may be called during - * libusb_exit() (e.g. when it is closing file descriptors that - * were opened and added to the poll set at libusb_init() - * time).
- * If you don't want this, remove the notifiers immediately before calling - * libusb_exit(). - * - * @param ctx - * the context to operate on, or NULL for the default context - * @param remove - * select add or remove notifiers - */ - public static native void libusb_set_pollfd_notifiers(long ctx, - boolean remove); - - /** - * Retrieve a array of file descriptors that should be polled by your main - * loop as libusb event sources.
- *
- * - * The actual list contents must not be touched. - * - * @param ctx - * the context to operate on, or NULL for the default context - * @return array of Libusb_pollfd or NULL on error - */ - public static native Libusb_pollfd[] libusb_get_pollfds(long ctx); - - /** - * Perform a USB control transfer.
- *
- * The direction of the transfer is inferred from the bmRequestType field of - * the setup packet.
- *
- * The wValue, wIndex and wLength fields values should be given in - * host-endian byte order. - * - * @param dev_handle - * a handle for the device to communicate with - * @param bmRequestType - * the request type field for the setup packet - * @param bRequest - * the request field for the setup packet - * @param wValue - * the value field for the setup packet - * @param wIndex - * the index field for the setup packet - * @param data - * a suitably-sized data buffer for either input or output - * (depending on direction bits within bmRequestType) - * @param wLength - * the length field for the setup packet. The data buffer should - * be at least this size. - * @param timeout - * timeout (in millseconds) that this function should wait before - * giving up due to no response being received. For an unlimited - * timeout, use value 0. - * @return on success, the number of bytes actually transferred
- * LIBUSB_ERROR_TIMEOUT if the transfer timed out
- * LIBUSB_ERROR_PIPE if the control request was not supported by the - * device
- * LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
- * another LIBUSB_ERROR code on other failures - */ - public static native int libusb_control_transfer(long dev_handle, - int bmRequestType, int bRequest, int wValue, int wIndex, - byte[] data, int wLength, int timeout); - - /** - * Perform a USB bulk transfer.
- *
- * The direction of the transfer is inferred from the direction bits of the - * endpoint address.
- *
- * For bulk reads, the length field indicates the maximum length of data you - * are expecting to receive. If less data arrives than expected, this - * function will return that data, so be sure to check the returned value.
- *
- * You should also check this value for bulk writes. Not all of the data may - * have been written. - * - * @param dev_handle - * a handle for the device to communicate with - * @param endpoint - * the address of a valid endpoint to communicate with - * @param data - * a suitably-sized data buffer for either input or output - * (depending on endpoint) - * @param length - * for bulk writes, the number of bytes from data to be sent. for - * bulk reads, the maximum number of bytes to receive into the - * data buffer. - * @param timeout - * timeout (in millseconds) that this function should wait before - * giving up due to no response being received. For an unlimited - * timeout, use value 0. - * @return The number of bytes actually transferred - * @throws LibusbError - * in case an error occured
- * Possible causes are:
- * - ERROR_TIMEOUT if the transfer timed out
- * - ERROR_PIPE if the control request was not supported by the - * device
- * - ERROR_OVERFLOW if the device offered more data
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another code on other failures. - */ - public static native int libusb_bulk_transfer(long dev_handle, - byte endpoint, byte[] data, int length, int timeout) - throws LibusbError; - - /** - * Perform a USB interrupt transfer.
- *
- * The direction of the transfer is inferred from the direction bits of the - * endpoint address.
- *
- * For bulk reads, the length field indicates the maximum length of data you - * are expecting to receive. If less data arrives than expected, this - * function will return that data, so be sure to check the returned value.
- *
- * You should also check this value for bulk writes. Not all of the data may - * have been written.
- *
- * The default endpoint bInterval value is used as the polling interval. - * - * @param dev_handle - * a handle for the device to communicate with - * @param endpoint - * the address of a valid endpoint to communicate with - * @param data - * a suitably-sized data buffer for either input or output - * (depending on endpoint) - * @param length - * for bulk writes, the number of bytes from data to be sent. for - * bulk reads, the maximum number of bytes to receive into the - * data buffer. - * @param timeout - * timeout (in millseconds) that this function should wait before - * giving up due to no response being received. For an unlimited - * timeout, use value 0. - * @return The number of bytes actually transferred
- * @throws LibusbError - * in case an error occured
- * Possible causes are:
- * - ERROR_TIMEOUT if the transfer timed out
- * - ERROR_PIPE if the control request was not supported by the - * device
- * - ERROR_OVERFLOW if the device offered more data
- * - ERROR_NO_DEVICE if the device has been disconnected
- * - another ERROR code on other failures - */ - public static native int libusb_interrupt_transfer(long dev_handle, - byte endpoint, byte[] data, int length, int timeout) - throws LibusbError; - - /** - * Returns the error string after an error occured. - * - * @return the last error sring. - */ - public static native String libusb_strerror(); - - static { - Native.load("com.github.boukefalos", "jlibusb"); - - /* - * After loading the library, we register a "shutdown hook" to be called - * for cleaning up stuff in the library when exiting. - */ - Runtime.getRuntime().addShutdownHook(new Thread() { - public void run() { - try { - LibusbJava1.teardown(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - - /* - * After setting up the cleanup callback, it's now safe to call the code - * that initializes stuff in the native library - */ - int setup_result = setup(); - - if (setup_result < 0) { - throw new UnsatisfiedLinkError("Could not setup the library. (" - + setup_result + ")"); - } - } - - /** - * This method is used to setup stuff in the native library. After calling - * this function, {@link #teardown()} has to be called if the native library - * is not used anymore. - * - * @return - 0 if successful - <0 if an error occured - */ - private static native int setup(); - - /** - * This method cleans up stuff initialized using {@link #setup()}. - */ - private static native void teardown(); -} diff --git a/src/main/java/ch/ntb/usb/Libusb_event.java b/src/main/java/ch/ntb/usb/Libusb_event.java deleted file mode 100644 index 2efcbd3..0000000 --- a/src/main/java/ch/ntb/usb/Libusb_event.java +++ /dev/null @@ -1,19 +0,0 @@ -package ch.ntb.usb; - -public class Libusb_event { - - public void transferCallback(){ - - } - - public void fdAddedCallback(int fd){ - System.out.println("addedCallback"); - - } - - public void fdRemovedCallback(int fd){ - System.out.println("removedCallback"); - - } - -} diff --git a/src/main/java/ch/ntb/usb/Libusb_pollfd.java b/src/main/java/ch/ntb/usb/Libusb_pollfd.java deleted file mode 100644 index 7edaf95..0000000 --- a/src/main/java/ch/ntb/usb/Libusb_pollfd.java +++ /dev/null @@ -1,7 +0,0 @@ -package ch.ntb.usb; - -public class Libusb_pollfd { - int fd; - byte events; - -} diff --git a/src/main/java/ch/ntb/usb/USB.java b/src/main/java/ch/ntb/usb/USB.java index 6b79e0a..f372ef3 100644 --- a/src/main/java/ch/ntb/usb/USB.java +++ b/src/main/java/ch/ntb/usb/USB.java @@ -23,7 +23,7 @@ public class USB { /** * This request returns status for the specified recipient (USB spec 9.4.5). * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_GET_STATUS = 0x00; @@ -31,7 +31,7 @@ public class USB { * This request is used to clear or disable a specific feature (USB spec * 9.4.1). * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_CLEAR_FEATURE = 0x01; @@ -40,7 +40,7 @@ public class USB { * This request is used to set or enable a specific feature (USB spec * 9.4.9). * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_SET_FEATURE = 0x03; @@ -49,7 +49,7 @@ public class USB { * This request sets the device address for all future device accesses (USB * spec 9.4.6). * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_SET_ADDRESS = 0x05; @@ -57,7 +57,7 @@ public class USB { * This request returns the specified descriptor if the descriptor exists * (USB spec 9.4.3). * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_GET_DESCRIPTOR = 0x06; @@ -65,7 +65,7 @@ public class USB { * 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.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_SET_DESCRIPTOR = 0x07; @@ -73,14 +73,14 @@ public class USB { * This request returns the current device configuration value (USB spec * 9.4.2). * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @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.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_SET_CONFIGURATION = 0x09; @@ -88,7 +88,7 @@ public class USB { * This request returns the selected alternate setting for the specified * interface (USB spec 9.4.4). * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_GET_INTERFACE = 0x0A; @@ -96,7 +96,7 @@ public class USB { * This request allows the host to select an alternate setting for the * specified interface (USB spec 9.4.10). * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_SET_INTERFACE = 0x0B; @@ -104,7 +104,7 @@ public class USB { * This request is used to set and then report an endpoint’s synchronization * frame (USB spec 9.4.11). * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_SYNCH_FRAME = 0x0C; @@ -117,7 +117,7 @@ public class USB { * signifying there is no Data stage.
* Specifies bit 7 of bmRequestType. * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @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), @@ -128,7 +128,7 @@ public class USB { * Specifies the type of the request.
* Specifies bits 6..5 of bmRequestType. * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_TYPE_TYPE_STANDARD = (0x00 << 5), @@ -144,7 +144,7 @@ public class USB { * specified, the wIndex field identifies the interface or endpoint.
* Specifies bits 4..0 of bmRequestType. * - * @see ch.ntb.inf.libusbJava.Device#controlMsg(int, int, int, int, byte[], int, int, + * @see ch.ntb.usb.Device#controlMsg(int, int, int, int, byte[], int, int, * boolean) */ public static final int REQ_TYPE_RECIP_DEVICE = 0x00, @@ -163,7 +163,7 @@ public class USB { */ public static int FULLSPEED_MAX_BULK_PACKET_SIZE = 64; - private static final Logger logger = LogUtil.getLogger("ch.ntb.inf.libusbJava"); + private static final Logger logger = LogUtil.getLogger("ch.ntb.usb"); private static LinkedList devices = new LinkedList(); diff --git a/src/main/java/ch/ntb/usb/Usb_Bus.java b/src/main/java/ch/ntb/usb/Usb_Bus.java index fb0a828..a7c59fc 100644 --- a/src/main/java/ch/ntb/usb/Usb_Bus.java +++ b/src/main/java/ch/ntb/usb/Usb_Bus.java @@ -25,11 +25,6 @@ public class Usb_Bus { private Usb_Device root_dev; - public Usb_Bus(String dirname, long location) { - this.dirname = dirname; - this.location = location; - } - /** * Get the first device ojects of the devices linked list.
* @@ -39,10 +34,6 @@ public class Usb_Bus { return devices; } - protected void setDevices(Usb_Device devices) { - this.devices = devices; - } - /** * Returns the systems String representation of the bus.
* @@ -61,10 +52,6 @@ public class Usb_Bus { return next; } - protected void setNext(Usb_Bus bus) { - next = bus; - } - /** * Returns the previous bus object.
* @@ -74,10 +61,6 @@ public class Usb_Bus { return prev; } - protected void setPrev(Usb_Bus bus) { - prev = bus; - } - /** * Get the root device of this bus.
* @@ -96,10 +79,6 @@ public class Usb_Bus { return location; } - protected void setLocation(long busnumber) { - location = busnumber; - } - @Override public String toString() { return "Usb_Bus " + dirname; diff --git a/src/main/java/ch/ntb/usb/Usb_Config_Descriptor.java b/src/main/java/ch/ntb/usb/Usb_Config_Descriptor.java index 320e78b..9bf6ff5 100644 --- a/src/main/java/ch/ntb/usb/Usb_Config_Descriptor.java +++ b/src/main/java/ch/ntb/usb/Usb_Config_Descriptor.java @@ -12,8 +12,8 @@ package ch.ntb.usb; * A USB device can have several different configuration.
*
* The length of the configuration descriptor is - * {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_CONFIG_SIZE} and the type is - * {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_CONFIG}. + * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_CONFIG_SIZE} and the type is + * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_CONFIG}. * */ public class Usb_Config_Descriptor extends Usb_Descriptor { diff --git a/src/main/java/ch/ntb/usb/Usb_Descriptor.java b/src/main/java/ch/ntb/usb/Usb_Descriptor.java index d1b9ab0..6aee245 100644 --- a/src/main/java/ch/ntb/usb/Usb_Descriptor.java +++ b/src/main/java/ch/ntb/usb/Usb_Descriptor.java @@ -23,9 +23,7 @@ public class Usb_Descriptor { /** * Descriptor types ({@link #bDescriptorType}). */ - public static final int LIBUSB_DT_DEVICE = 0x01, LIBUSB_DT_CONFIG = 0x02, - LIBUSB_DT_STRING = 0x03, LIBUSB_DT_INTERFACE = 0x04, - LIBUSB_DT_ENDPOINT = 0x05, USB_DT_HID = 0x21, USB_DT_REPORT = 0x22, + public static final int USB_DT_HID = 0x21, USB_DT_REPORT = 0x22, USB_DT_PHYSICAL = 0x23, USB_DT_HUB = 0x29; /** diff --git a/src/main/java/ch/ntb/usb/Usb_Device.java b/src/main/java/ch/ntb/usb/Usb_Device.java index 95ba0ca..5cb314a 100644 --- a/src/main/java/ch/ntb/usb/Usb_Device.java +++ b/src/main/java/ch/ntb/usb/Usb_Device.java @@ -45,9 +45,6 @@ public class Usb_Device { public Usb_Bus getBus() { return bus; } - protected void setBus(Usb_Bus bus){ - this.bus = bus; - } /** * Returns a reference to the first child.
@@ -102,41 +99,7 @@ public class Usb_Device { public Usb_Device getNext() { return next; } - - protected void setNext(Usb_Device dev){ - next = dev; - } - public static void freeDeviceList(Usb_Device device) - { - Usb_Device curr = device.getPrev(); - - /* Detach the left part of the list */ - device.setPrev(null); - - /* First walk to the left of the list and free all - devices on our way */ - while (curr != null) - { - freeDevice(curr); - curr = curr.getPrev(); - } - - curr = device; - /* Then walk to the right of the list and free all */ - while (curr != null) - { - freeDevice(curr); - curr = curr.getNext(); - } - } - - public static void freeDevice(Usb_Device device) - { - freeDeviceList(device.getChildren()); - LibusbJava1.libusb_unref_device(device); - } - /** * Returns the number of children of this device.
* @@ -154,9 +117,6 @@ public class Usb_Device { public Usb_Device getPrev() { return prev; } - protected void setPrev(Usb_Device dev){ - prev = dev; - } @Override public String toString() { diff --git a/src/main/java/ch/ntb/usb/Usb_Device_Descriptor.java b/src/main/java/ch/ntb/usb/Usb_Device_Descriptor.java index 8a0a618..5cf30e9 100644 --- a/src/main/java/ch/ntb/usb/Usb_Device_Descriptor.java +++ b/src/main/java/ch/ntb/usb/Usb_Device_Descriptor.java @@ -13,8 +13,8 @@ package ch.ntb.usb; * yet important information about the device.
*
* The length of the device descriptor is - * {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_DEVICE_SIZE} and the type is - * {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_DEVICE}. + * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_DEVICE_SIZE} and the type is + * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_DEVICE}. * */ public class Usb_Device_Descriptor extends Usb_Descriptor { @@ -22,9 +22,8 @@ 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, LIBUSB_CLASS_PTP = 6, - USB_CLASS_PRINTER = 7, USB_CLASS_MASS_STORAGE = 8, - USB_CLASS_HUB = 9, USB_CLASS_DATA = 10, + 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; diff --git a/src/main/java/ch/ntb/usb/Usb_Endpoint_Descriptor.java b/src/main/java/ch/ntb/usb/Usb_Endpoint_Descriptor.java index 626d4a9..00e4bbc 100644 --- a/src/main/java/ch/ntb/usb/Usb_Endpoint_Descriptor.java +++ b/src/main/java/ch/ntb/usb/Usb_Endpoint_Descriptor.java @@ -16,8 +16,8 @@ package ch.ntb.usb; * the bus.
*
* The length of the configuration descriptor is - * {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_ENDPOINT_SIZE} and the type is - * {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_ENDPOINT}. + * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_ENDPOINT_SIZE} and the type is + * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_ENDPOINT}. * */ public class Usb_Endpoint_Descriptor extends Usb_Descriptor { @@ -36,32 +36,15 @@ public class Usb_Endpoint_Descriptor extends Usb_Descriptor { /** * Endpoint type mask (in bmAttributes). */ - public static final int USB_ENDPOINT_TRANSFER_TYPE_MASK = 0x03, - USB_ENDPOINT_ISO_SYNC_TYPE = 0x0C, - USB_ENDPOINT_ISO_USAGE_TYPE = 0x30; + public static final int USB_ENDPOINT_TYPE_MASK = 0x03; /** * Possible endpoint types (in bmAttributes). */ - public static final int USB_ENDPOINT_TRANSFER_TYPE_CONTROL = 0, - USB_ENDPOINT_TRANSFER_TYPE_ISOCHRONOUS = 1, - USB_ENDPOINT_TRANSFER_TYPE_BULK = 2, - USB_ENDPOINT_TRANSFER_TYPE_INTERRUPT = 3; - /** - * Possible synchronization types for isochronous endpoints. - */ - public static final int USB_ENDPOINT_ISO_SYNC_TYPE_NONE = 0, - USB_ENDPOINT_ISO_SYNC_TYPE_ASYNC = 1, - USB_ENDPOINT_ISO_SYNC_TYPE_ADAPTIVE = 2, - USB_ENDPOINT_ISO_SYNC_TYPE_SYNC = 3; + 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 usage types for isochronous endpoints - */ - public static final int USB_ENDPOINT_ISO_USAGE_TYPE_DATA = 0, - USB_ENDPOINT_ISO_USAGE_TYPE_FEEDBACK = 1, - USB_ENDPOINT_ISO_USAGE_TYPE_IMPLICIT = 2; - private byte bEndpointAddress; private byte bmAttributes; diff --git a/src/main/java/ch/ntb/usb/Usb_Interface_Descriptor.java b/src/main/java/ch/ntb/usb/Usb_Interface_Descriptor.java index dc136f7..a36d3ed 100644 --- a/src/main/java/ch/ntb/usb/Usb_Interface_Descriptor.java +++ b/src/main/java/ch/ntb/usb/Usb_Interface_Descriptor.java @@ -13,8 +13,8 @@ package ch.ntb.usb; * endpoints into a functional group performing a single feature of the device.
*
* The length of the interface descriptor is - * {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_INTERFACE_SIZE} and the - * type is {@link ch.ntb.inf.libusbJava.Usb_Descriptor#USB_DT_INTERFACE}. + * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_INTERFACE_SIZE} and the type is + * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_INTERFACE}. * */ public class Usb_Interface_Descriptor extends Usb_Descriptor { @@ -51,8 +51,7 @@ public class Usb_Interface_Descriptor extends Usb_Descriptor { } /** - * Returns the value used to select the alternate setting ( - * {@link LibusbJava#usb_set_altinterface(long, int)}).
+ * Returns the value used to select the alternate setting ({@link LibusbJava#usb_set_altinterface(long, int)}).
* * @return the alternate setting */ diff --git a/src/main/java/ch/ntb/usb/exceptions/LibusbError.java b/src/main/java/ch/ntb/usb/exceptions/LibusbError.java deleted file mode 100644 index e7e31f2..0000000 --- a/src/main/java/ch/ntb/usb/exceptions/LibusbError.java +++ /dev/null @@ -1,150 +0,0 @@ -package ch.ntb.usb.exceptions; - -public class LibusbError extends Exception { - private static final long serialVersionUID = 9096323614080207236L; - - /** - * libusb error codes - */ - public static final int ERROR_NONE = 0; - public static final int ERROR_IO = -1; - public static final int ERROR_INVALID_PARAM = -2; - public static final int ERROR_ACCESS = -3; - public static final int ERROR_NO_DEVICE = -4; - public static final int ERROR_NOT_FOUND = -5; - public static final int ERROR_BUSY = -6; - public static final int ERROR_TIMEOUT = -7; - public static final int ERROR_OVERFLOW = -8; - public static final int ERROR_PIPE = -9; - public static final int ERROR_INTERRUPTED = -10; - public static final int ERROR_NO_MEM = -11; - public static final int ERROR_NOT_SUPPORTED = -12; - public static final int ERROR_OTHER = -99; - public static final int ERROR_JAVA_REFERENCES_NOT_LOADED = -100; - public static final int ERROR_JAVA_WRONG_ENVIRONMENT = -101; - public static final int ERROR_JAVA_ILEGAL_DEVICE_HANDLE = -102; - - private int code = ERROR_NONE; - - public LibusbError(int code) - { - super("libusb result: " + getStringFromCode(code)); - this.code = code; - } - - public int getErrorCode() - { - return code; - } - - public static String getStringFromCode(int code) - { - String result; - - switch (code) - { - case ERROR_IO: - { - result = "ERROR_IO"; - break; - } - case ERROR_INVALID_PARAM: - { - result = "ERROR_INVALID_PARAM"; - break; - } - case ERROR_ACCESS: - { - result = "ERROR_ACCESS"; - break; - } - case ERROR_NO_DEVICE: - { - result = "ERROR_NO_DEVICE"; - break; - } - case ERROR_NOT_FOUND: - { - result = "ERROR_NOT_FOUND"; - break; - } - case ERROR_BUSY: - { - result = "ERROR_BUSY"; - break; - } - - case ERROR_TIMEOUT: - { - result = "ERROR_TIMEOUT"; - break; - } - - case ERROR_OVERFLOW: - { - result = "ERROR_OVERFLOW"; - break; - } - - case ERROR_PIPE: - { - result = "ERROR_PIPE"; - break; - } - - case ERROR_INTERRUPTED: - { - result = "ERROR_INTERRUPTED"; - break; - } - - case ERROR_NO_MEM: - { - result = "ERROR_NO_MEM"; - break; - } - - case ERROR_NOT_SUPPORTED: - { - result = "ERROR_NOT_SUPPORTED"; - break; - } - - case ERROR_OTHER: - { - result = "ERROR_OTHER"; - break; - } - - case ERROR_JAVA_REFERENCES_NOT_LOADED: - { - result = "ERROR_JAVA_REFERENCES_NOT_LOADED"; - break; - } - - case ERROR_JAVA_WRONG_ENVIRONMENT: - { - result = "ERROR_JAVA_WRONG_ENVIRONMENT"; - break; - } - - case ERROR_JAVA_ILEGAL_DEVICE_HANDLE: - { - result = "ERROR_JAVA_ILEGAL_DEVICE_HANDLE"; - break; - } - - default: - { - result = "ERROR_UNKNWON (" + code + ")"; - break; - } - } - - return result; - } - - public String getErrorString() { - return getStringFromCode(getErrorCode()); - } -} diff --git a/src/main/java/ch/ntb/usb/logger/LogUtil.java b/src/main/java/ch/ntb/usb/logger/LogUtil.java index 51fd7b4..998b602 100644 --- a/src/main/java/ch/ntb/usb/logger/LogUtil.java +++ b/src/main/java/ch/ntb/usb/logger/LogUtil.java @@ -20,7 +20,7 @@ public class LogUtil { // debug this class private static final boolean debugLogUtil = false; - private static final String PLUGIN_ID = "ch.ntb.inf.libusbJava"; + 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()