Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Restructuring a bit.

  • Loading branch information...
commit c86ae540820694c34171d823c0e6575d6801c464 1 parent af088c4
@trygvis authored
Showing with 252 additions and 206 deletions.
  1. +14 −1 NOTES.txt
  2. +17 −12 ftdi/src/main/java/no/hackaton/ftdi/Ftdi232.java
  3. +1 −1  ftdi/src/main/java/no/hackaton/ftdi/Ftdi232Util.java
  4. +25 −0 ftdi/src/test/java/no/hackaton/ftdi/ReadSerial.java
  5. +4 −0 ftdi/src/test/java/no/hackaton/ftdi/ToggleDtr.java
  6. +5 −5 javalibusb1/Makefile
  7. +42 −43 javalibusb1/javalibusb.c
  8. +45 −0 javalibusb1/javalibusb1_Libusb1UsbDevice.h
  9. +37 −0 javalibusb1/javalibusb1_Libusb1UsbInterface.h
  10. +13 −0 javalibusb1/javalibusb1_Libusb1UsbPipe.h
  11. +0 −45 javalibusb1/javalibusb1_impl_Libusb1UsbDevice.h
  12. +0 −37 javalibusb1/javalibusb1_impl_Libusb1UsbInterface.h
  13. +0 −29 javalibusb1/javalibusb1_impl_Libusb1UsbPipe.h
  14. +9 −1 javalibusb1/javalibusb1_libusb1.h
  15. +1 −1  javalibusb1/src/main/java/javalibusb1/{impl → }/Libusb1UsbConfiguration.java
  16. +23 −4 javalibusb1/src/main/java/javalibusb1/{impl → }/Libusb1UsbDevice.java
  17. +1 −1  javalibusb1/src/main/java/javalibusb1/{impl → }/Libusb1UsbEndpoint.java
  18. +1 −1  javalibusb1/src/main/java/javalibusb1/{impl → }/Libusb1UsbInterface.java
  19. +4 −20 javalibusb1/src/main/java/javalibusb1/{impl → }/Libusb1UsbPipe.java
  20. +5 −3 javalibusb1/src/main/java/javalibusb1/libusb1.java
  21. +1 −2  javax.usb/src/main/java/javax/usb/util/DefaultUsbControlIrp.java
  22. +4 −0 javax.usb/src/main/java/javax/usb/util/DefaultUsbIrp.java
View
15 NOTES.txt
@@ -1,4 +1,17 @@
-TCK Notes
+= Implementation Notes =
+
+Right now there's a whole lot of libusb_open() and libusb_close() going on. I
+wonder if that has a big impact on anything. If it has I have to find a way to
+associate a handle with a device or something. However, as there are no
+close() operations on a device it's kinda hard to know when to release the
+handle.
+
+= TCK Notes =
* The TCK should not assert if a method is synchronized or not.
* The TCK should not assert private methods. They are PRIVATE.
+
+Stuff I know I don't do properly that the TCK should catch:
+
+ * When closing a parent object (like a UsbDevice) it should implicitly close
+ all child objects (like any UsbPipes that are open).
View
29 ftdi/src/main/java/no/hackaton/ftdi/Ftdi232.java
@@ -35,10 +35,13 @@ public void close() throws IOException {
UsbUtil.close(device);
}
- public void setBaudRate(int requestedBaudRate) {
- int value = calculateBaudRate(requestedBaudRate);
+ public void setBaudRate(int requestedBaudRate) throws UsbException {
+ short value = (short) (calculateBaudRate(requestedBaudRate) >> 16);
+ short index = 0;
+
+ byte outRequestType = ENDPOINT_DIRECTION_OUT | REQUESTTYPE_TYPE_VENDOR | REQUESTTYPE_RECIPIENT_DEVICE;
- throw new RuntimeException("Not implemented");
+ device.syncSubmit(device.createUsbControlIrp(outRequestType, SET_BAUDRATE_REQUEST, value, index));
}
public void setDtr(boolean b) throws UsbException {
@@ -47,14 +50,16 @@ public void setDtr(boolean b) throws UsbException {
byte outRequestType = ENDPOINT_DIRECTION_OUT | REQUESTTYPE_TYPE_VENDOR | REQUESTTYPE_RECIPIENT_DEVICE;
- UsbPipe pipe = controlEndpoint.getUsbPipe();
- try {
- pipe.open();
- UsbControlIrp irp = pipe.createUsbControlIrp(outRequestType, SET_MODEM_CONTROL_REQUEST, value, index);
- irp.setData(new byte[0], 0, 0);
- pipe.syncSubmit(irp);
- } finally {
- UsbUtil.close(pipe);
- }
+ device.syncSubmit(device.createUsbControlIrp(outRequestType, SET_MODEM_CONTROL_REQUEST, value, index));
+
+// UsbPipe pipe = controlEndpoint.getUsbPipe();
+// try {
+// pipe.open();
+// UsbControlIrp irp = pipe.createUsbControlIrp(outRequestType, SET_MODEM_CONTROL_REQUEST, value, index);
+// irp.setData(new byte[0], 0, 0);
+// pipe.syncSubmit(irp);
+// } finally {
+// UsbUtil.close(pipe);
+// }
}
}
View
2  ftdi/src/main/java/no/hackaton/ftdi/Ftdi232Util.java
@@ -6,7 +6,7 @@
public static int calculateBaudRate(int requestedBaudRate) {
int base = 3000000 / requestedBaudRate;
- return base;
+ return base << 16;
}
public static UsbDevice findDevice(UsbHub usbHub) {
View
25 ftdi/src/test/java/no/hackaton/ftdi/ReadSerial.java
@@ -0,0 +1,25 @@
+package no.hackaton.ftdi;
+
+import static java.lang.Thread.*;
+
+import javax.usb.*;
+
+public class ReadSerial {
+ public static void main(String[] args) throws Exception {
+ UsbServices usbServices = UsbHostManager.getUsbServices();
+
+ UsbDevice device = Ftdi232Util.findDevice(usbServices.getRootUsbHub());
+
+ if(device == null) {
+ System.err.println("Could not find appropriate FTDI device.");
+ return;
+ }
+
+ Ftdi232 ftdi232 = new Ftdi232(device);
+
+ ftdi232.setBaudRate(2400);
+ ftdi232.setDtr(true);
+ sleep(1000);
+ ftdi232.setDtr(false);
+ }
+}
View
4 ftdi/src/test/java/no/hackaton/ftdi/ToggleDtr.java
@@ -17,8 +17,12 @@ public static void main(String[] args) throws Exception {
Ftdi232 ftdi232 = new Ftdi232(device);
+ System.out.println("Setting DRT");
+ System.out.flush();
ftdi232.setDtr(true);
sleep(1000);
+ System.out.println("Clearing DRT");
+ System.out.flush();
ftdi232.setDtr(false);
}
}
View
10 javalibusb1/Makefile
@@ -20,7 +20,7 @@ javalibusb.lo: javalibusb.c
usbw.lo: usbw.c
$(LIBTOOL) --mode=compile --tag=CC cc $(CCFLAGS) -g -c -shared -o $@ $<
-javalibusb.c: javalibusb1_libusb1.h javalibusb1_impl_Libusb1UsbDevice.h javalibusb1_impl_Libusb1UsbInterface.h javalibusb1_impl_Libusb1UsbPipe.h
+javalibusb.c: javalibusb1_libusb1.h javalibusb1_Libusb1UsbDevice.h javalibusb1_Libusb1UsbInterface.h javalibusb1_Libusb1UsbPipe.h
target/classes/javalibusb1/%.class: src/main/java/javalibusb1/libusb1.java
mkdir -p target/classes target/test-classes
@@ -29,13 +29,13 @@ target/classes/javalibusb1/%.class: src/main/java/javalibusb1/libusb1.java
rsync -a --progress src/main/resources/ target/classes
%.h:
- rm $@
+ rm -f $@
$(JDK_HOME)/bin/javah -classpath $(CLASSPATH) -jni $(shell echo $< | sed "s,target.classes.\(.*\).class$$,\1," | tr "/" ".")
javalibusb1_libusb1.h: target/classes/javalibusb1/libusb1.class
-javalibusb1_impl_Libusb1UsbDevice.h: target/classes/javalibusb1/impl/Libusb1UsbDevice.class
-javalibusb1_impl_Libusb1UsbInterface.h: target/classes/javalibusb1/impl/Libusb1UsbInterface.class
-javalibusb1_impl_Libusb1UsbPipe.h: target/classes/javalibusb1/impl/Libusb1UsbPipe.class
+javalibusb1_Libusb1UsbDevice.h: target/classes/javalibusb1/Libusb1UsbDevice.class
+javalibusb1_Libusb1UsbInterface.h: target/classes/javalibusb1/Libusb1UsbInterface.class
+javalibusb1_Libusb1UsbPipe.h: target/classes/javalibusb1/Libusb1UsbPipe.class
clean: clean-java clean-native
View
85 javalibusb1/javalibusb.c
@@ -9,21 +9,21 @@
/* javalibusb1.Libusb1UsbServices */
jfieldID usb_services_context_field;
-/* javalibusb1.impl.Libusb1UsbDevice */
+/* javalibusb1.Libusb1UsbDevice */
jclass libusb1UsbDeviceClass = NULL;
jmethodID libusb1UsbDeviceConstructor = NULL;
jfieldID device_libusb_device_field;
-/* javalibusb1.impl.Libusb1UsbConfiguration */
+/* javalibusb1.Libusb1UsbConfiguration */
jclass libusb1UsbConfigurationClass = NULL;
jmethodID libusb1UsbConfigurationConstructor = NULL;
-/* javalibusb1.impl.Libusb1UsbInterface */
+/* javalibusb1.Libusb1UsbInterface */
jclass libusb1UsbInterfaceClass = NULL;
jmethodID libusb1UsbInterfaceConstructor = NULL;
jfieldID interface_libusb_device_field;
-/* javalibusb1.impl.Libusb1UsbEndpoint */
+/* javalibusb1.Libusb1UsbEndpoint */
jclass libusb1UsbEndpointClass = NULL;
jmethodID libusb1UsbEndpointConstructor = NULL;
@@ -267,7 +267,7 @@ JNIEXPORT jobject JNICALL Java_javalibusb1_libusb1_create
goto fail;
}
- if((libusb1UsbDeviceClass = findAndReferenceClass(env, "javalibusb1/impl/Libusb1UsbDevice")) == NULL) {
+ if((libusb1UsbDeviceClass = findAndReferenceClass(env, "javalibusb1/Libusb1UsbDevice")) == NULL) {
return NULL;
}
if((libusb1UsbDeviceConstructor = (*env)->GetMethodID(env, libusb1UsbDeviceClass, "<init>", "(IBBLjavax/usb/UsbDeviceDescriptor;)V")) == NULL) {
@@ -277,27 +277,27 @@ JNIEXPORT jobject JNICALL Java_javalibusb1_libusb1_create
goto fail;
}
- if((libusb1UsbConfigurationClass = findAndReferenceClass(env, "javalibusb1/impl/Libusb1UsbConfiguration")) == NULL) {
+ if((libusb1UsbConfigurationClass = findAndReferenceClass(env, "javalibusb1/Libusb1UsbConfiguration")) == NULL) {
return NULL;
}
- if((libusb1UsbConfigurationConstructor = (*env)->GetMethodID(env, libusb1UsbConfigurationClass, "<init>", "(Ljavalibusb1/impl/Libusb1UsbDevice;Ljavax/usb/UsbConfigurationDescriptor;[[Ljavax/usb/UsbInterface;Z)V")) == NULL) {
+ if((libusb1UsbConfigurationConstructor = (*env)->GetMethodID(env, libusb1UsbConfigurationClass, "<init>", "(Ljavalibusb1/Libusb1UsbDevice;Ljavax/usb/UsbConfigurationDescriptor;[[Ljavax/usb/UsbInterface;Z)V")) == NULL) {
return NULL;
}
- if((libusb1UsbInterfaceClass = findAndReferenceClass(env, "javalibusb1/impl/Libusb1UsbInterface")) == NULL) {
+ if((libusb1UsbInterfaceClass = findAndReferenceClass(env, "javalibusb1/Libusb1UsbInterface")) == NULL) {
return NULL;
}
- if((libusb1UsbInterfaceConstructor = (*env)->GetMethodID(env, libusb1UsbInterfaceClass, "<init>", "(Ljavalibusb1/impl/Libusb1UsbConfiguration;Ljavax/usb/UsbInterfaceDescriptor;[Ljavax/usb/UsbEndpoint;Z)V")) == NULL) {
+ if((libusb1UsbInterfaceConstructor = (*env)->GetMethodID(env, libusb1UsbInterfaceClass, "<init>", "(Ljavalibusb1/Libusb1UsbConfiguration;Ljavax/usb/UsbInterfaceDescriptor;[Ljavax/usb/UsbEndpoint;Z)V")) == NULL) {
return NULL;
}
if((interface_libusb_device_field = (*env)->GetFieldID(env, libusb1UsbInterfaceClass, "libusb_device", "I")) == NULL) {
goto fail;
}
- if((libusb1UsbEndpointClass = findAndReferenceClass(env, "javalibusb1/impl/Libusb1UsbEndpoint")) == NULL) {
+ if((libusb1UsbEndpointClass = findAndReferenceClass(env, "javalibusb1/Libusb1UsbEndpoint")) == NULL) {
return NULL;
}
- if((libusb1UsbEndpointConstructor = (*env)->GetMethodID(env, libusb1UsbEndpointClass, "<init>", "(Ljavalibusb1/impl/Libusb1UsbInterface;Ljavax/usb/UsbEndpointDescriptor;)V")) == NULL) {
+ if((libusb1UsbEndpointConstructor = (*env)->GetMethodID(env, libusb1UsbEndpointClass, "<init>", "(Ljavalibusb1/Libusb1UsbInterface;Ljavax/usb/UsbEndpointDescriptor;)V")) == NULL) {
return NULL;
}
@@ -485,11 +485,34 @@ JNIEXPORT jobjectArray JNICALL Java_javalibusb1_libusb1_get_1devices
return NULL;
}
+JNIEXPORT jint JNICALL Java_javalibusb1_libusb1_control_1transfer
+ (JNIEnv *env, jobject obj, jint java_device, jbyte bmRequestType, jbyte bRequest, jshort wValue, jshort wIndex, jlong timeout)
+{
+ int err;
+ struct libusb_device* device;
+ struct libusb_device_handle *handle;
+
+ device = (struct libusb_device*)java_device;
+
+ if((err = usbw_open(device, &handle))) {
+ throwPlatformExceptionMsgCode(env, "libusb_open()", err);
+ return 0;
+ }
+
+ if((err = usbw_control_transfer((struct libusb_device_handle*)handle, bmRequestType, bRequest, wValue, wIndex, NULL, 0, timeout)) < 0) {
+ throwPlatformExceptionMsgCode(env, "libusb_control_transfer()", err);
+ }
+
+ usbw_close(handle);
+
+ return err;
+}
+
/*****************************************************************************
- * javalibusb1_impl_Libusb1UsbDevice
+ * javalibusb1_Libusb1UsbDevice
*****************************************************************************/
-JNIEXPORT void JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_closeNative
+JNIEXPORT void JNICALL Java_javalibusb1_Libusb1UsbDevice_closeNative
(JNIEnv *env, jobject obj)
{
struct libusb_device *device;
@@ -505,7 +528,7 @@ JNIEXPORT void JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_closeNative
usbw_unref_device(device);
}
-JNIEXPORT jstring JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_getStringNative
+JNIEXPORT jstring JNICALL Java_javalibusb1_Libusb1UsbDevice_getStringNative
(JNIEnv *env, jobject obj, jbyte index, jint length)
{
struct libusb_device *device;
@@ -543,7 +566,7 @@ JNIEXPORT jstring JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_getStringNative
return s;
}
-JNIEXPORT jobject JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_nativeGetActiveUsbConfiguration
+JNIEXPORT jobject JNICALL Java_javalibusb1_Libusb1UsbDevice_nativeGetActiveUsbConfiguration
(JNIEnv *env, jobject usbDevice)
{
struct libusb_device *device;
@@ -575,7 +598,7 @@ JNIEXPORT jobject JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_nativeGetActive
return usbConfiguration;
}
-JNIEXPORT jobject JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_nativeGetUsbConfiguration
+JNIEXPORT jobject JNICALL Java_javalibusb1_Libusb1UsbDevice_nativeGetUsbConfiguration
(JNIEnv *env, jobject usbDevice, jbyte index)
{
struct libusb_device *device;
@@ -617,7 +640,7 @@ JNIEXPORT jobject JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_nativeGetUsbCon
//
// -----------------------------------------------------------------------
-JNIEXPORT void JNICALL Java_javalibusb1_impl_Libusb1UsbInterface_nativeSetConfiguration
+JNIEXPORT void JNICALL Java_javalibusb1_Libusb1UsbInterface_nativeSetConfiguration
(JNIEnv *env, jobject obj, jint configuration)
{
struct libusb_device *device;
@@ -640,7 +663,7 @@ JNIEXPORT void JNICALL Java_javalibusb1_impl_Libusb1UsbInterface_nativeSetConfig
usbw_close(handle);
}
-JNIEXPORT jint JNICALL Java_javalibusb1_impl_Libusb1UsbInterface_nativeClaimInterface
+JNIEXPORT jint JNICALL Java_javalibusb1_Libusb1UsbInterface_nativeClaimInterface
(JNIEnv *env, jobject obj, jint bInterfaceNumber)
{
struct libusb_device *device;
@@ -666,32 +689,8 @@ JNIEXPORT jint JNICALL Java_javalibusb1_impl_Libusb1UsbInterface_nativeClaimInte
return 0;
}
-JNIEXPORT void JNICALL Java_javalibusb1_impl_Libusb1UsbInterface_nativeRelease
+JNIEXPORT void JNICALL Java_javalibusb1_Libusb1UsbInterface_nativeRelease
(JNIEnv *env, jobject obj, jint handle)
{
usbw_close((struct libusb_device_handle*)handle);
}
-
-/*****************************************************************************
- * javalibusb1_impl_Libusb1UsbPipe
- *****************************************************************************/
-
-/*
-JNIEXPORT jint JNICALL Java_javalibusb1_impl_Libusb1UsbPipe_nativeSyncSubmit
- (JNIEnv *env, jobject obj)
-{
-}
-*/
-
-JNIEXPORT jint JNICALL Java_javalibusb1_impl_Libusb1UsbPipe_nativeSyncSubmitControl
- (JNIEnv *env, jobject obj, jint handle, jbyte bmRequestType, jbyte bRequest, jshort wValue, jshort wIndex, jlong timeout)
-{
- int err;
-
- if((err = usbw_control_transfer((struct libusb_device_handle*)handle, bmRequestType, bRequest, wValue, wIndex, NULL, 0, timeout)) < 0) {
- throwPlatformExceptionMsgCode(env, "libusb_control_transfer()", err);
- return 0;
- }
-
- return err;
-}
View
45 javalibusb1/javalibusb1_Libusb1UsbDevice.h
@@ -0,0 +1,45 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class javalibusb1_Libusb1UsbDevice */
+
+#ifndef _Included_javalibusb1_Libusb1UsbDevice
+#define _Included_javalibusb1_Libusb1UsbDevice
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: javalibusb1_Libusb1UsbDevice
+ * Method: closeNative
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_javalibusb1_Libusb1UsbDevice_closeNative
+ (JNIEnv *, jobject);
+
+/*
+ * Class: javalibusb1_Libusb1UsbDevice
+ * Method: getStringNative
+ * Signature: (BI)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_javalibusb1_Libusb1UsbDevice_getStringNative
+ (JNIEnv *, jobject, jbyte, jint);
+
+/*
+ * Class: javalibusb1_Libusb1UsbDevice
+ * Method: nativeGetActiveUsbConfiguration
+ * Signature: ()Ljavax/usb/UsbConfiguration;
+ */
+JNIEXPORT jobject JNICALL Java_javalibusb1_Libusb1UsbDevice_nativeGetActiveUsbConfiguration
+ (JNIEnv *, jobject);
+
+/*
+ * Class: javalibusb1_Libusb1UsbDevice
+ * Method: nativeGetUsbConfiguration
+ * Signature: (B)Ljavax/usb/UsbConfiguration;
+ */
+JNIEXPORT jobject JNICALL Java_javalibusb1_Libusb1UsbDevice_nativeGetUsbConfiguration
+ (JNIEnv *, jobject, jbyte);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
View
37 javalibusb1/javalibusb1_Libusb1UsbInterface.h
@@ -0,0 +1,37 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class javalibusb1_Libusb1UsbInterface */
+
+#ifndef _Included_javalibusb1_Libusb1UsbInterface
+#define _Included_javalibusb1_Libusb1UsbInterface
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: javalibusb1_Libusb1UsbInterface
+ * Method: nativeSetConfiguration
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_javalibusb1_Libusb1UsbInterface_nativeSetConfiguration
+ (JNIEnv *, jobject, jint);
+
+/*
+ * Class: javalibusb1_Libusb1UsbInterface
+ * Method: nativeClaimInterface
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_javalibusb1_Libusb1UsbInterface_nativeClaimInterface
+ (JNIEnv *, jobject, jint);
+
+/*
+ * Class: javalibusb1_Libusb1UsbInterface
+ * Method: nativeRelease
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_javalibusb1_Libusb1UsbInterface_nativeRelease
+ (JNIEnv *, jobject, jint);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
View
13 javalibusb1/javalibusb1_Libusb1UsbPipe.h
@@ -0,0 +1,13 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class javalibusb1_Libusb1UsbPipe */
+
+#ifndef _Included_javalibusb1_Libusb1UsbPipe
+#define _Included_javalibusb1_Libusb1UsbPipe
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
View
45 javalibusb1/javalibusb1_impl_Libusb1UsbDevice.h
@@ -1,45 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class javalibusb1_impl_Libusb1UsbDevice */
-
-#ifndef _Included_javalibusb1_impl_Libusb1UsbDevice
-#define _Included_javalibusb1_impl_Libusb1UsbDevice
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: javalibusb1_impl_Libusb1UsbDevice
- * Method: closeNative
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_closeNative
- (JNIEnv *, jobject);
-
-/*
- * Class: javalibusb1_impl_Libusb1UsbDevice
- * Method: getStringNative
- * Signature: (BI)Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_getStringNative
- (JNIEnv *, jobject, jbyte, jint);
-
-/*
- * Class: javalibusb1_impl_Libusb1UsbDevice
- * Method: nativeGetActiveUsbConfiguration
- * Signature: ()Ljavax/usb/UsbConfiguration;
- */
-JNIEXPORT jobject JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_nativeGetActiveUsbConfiguration
- (JNIEnv *, jobject);
-
-/*
- * Class: javalibusb1_impl_Libusb1UsbDevice
- * Method: nativeGetUsbConfiguration
- * Signature: (B)Ljavax/usb/UsbConfiguration;
- */
-JNIEXPORT jobject JNICALL Java_javalibusb1_impl_Libusb1UsbDevice_nativeGetUsbConfiguration
- (JNIEnv *, jobject, jbyte);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
View
37 javalibusb1/javalibusb1_impl_Libusb1UsbInterface.h
@@ -1,37 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class javalibusb1_impl_Libusb1UsbInterface */
-
-#ifndef _Included_javalibusb1_impl_Libusb1UsbInterface
-#define _Included_javalibusb1_impl_Libusb1UsbInterface
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: javalibusb1_impl_Libusb1UsbInterface
- * Method: nativeSetConfiguration
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL Java_javalibusb1_impl_Libusb1UsbInterface_nativeSetConfiguration
- (JNIEnv *, jobject, jint);
-
-/*
- * Class: javalibusb1_impl_Libusb1UsbInterface
- * Method: nativeClaimInterface
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL Java_javalibusb1_impl_Libusb1UsbInterface_nativeClaimInterface
- (JNIEnv *, jobject, jint);
-
-/*
- * Class: javalibusb1_impl_Libusb1UsbInterface
- * Method: nativeRelease
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL Java_javalibusb1_impl_Libusb1UsbInterface_nativeRelease
- (JNIEnv *, jobject, jint);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
View
29 javalibusb1/javalibusb1_impl_Libusb1UsbPipe.h
@@ -1,29 +0,0 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class javalibusb1_impl_Libusb1UsbPipe */
-
-#ifndef _Included_javalibusb1_impl_Libusb1UsbPipe
-#define _Included_javalibusb1_impl_Libusb1UsbPipe
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: javalibusb1_impl_Libusb1UsbPipe
- * Method: nativeSyncSubmit
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_javalibusb1_impl_Libusb1UsbPipe_nativeSyncSubmit
- (JNIEnv *, jobject);
-
-/*
- * Class: javalibusb1_impl_Libusb1UsbPipe
- * Method: nativeSyncSubmitControl
- * Signature: (IBBSSJ)I
- */
-JNIEXPORT jint JNICALL Java_javalibusb1_impl_Libusb1UsbPipe_nativeSyncSubmitControl
- (JNIEnv *, jobject, jint, jbyte, jbyte, jshort, jshort, jlong);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
View
10 javalibusb1/javalibusb1_libusb1.h
@@ -42,11 +42,19 @@ JNIEXPORT void JNICALL Java_javalibusb1_libusb1_set_1debug
/*
* Class: javalibusb1_libusb1
* Method: get_devices
- * Signature: ()[Ljavalibusb1/impl/Libusb1UsbDevice;
+ * Signature: ()[Ljavalibusb1/Libusb1UsbDevice;
*/
JNIEXPORT jobjectArray JNICALL Java_javalibusb1_libusb1_get_1devices
(JNIEnv *, jobject);
+/*
+ * Class: javalibusb1_libusb1
+ * Method: control_transfer
+ * Signature: (IBBSSJ)I
+ */
+JNIEXPORT jint JNICALL Java_javalibusb1_libusb1_control_1transfer
+ (JNIEnv *, jclass, jint, jbyte, jbyte, jshort, jshort, jlong);
+
#ifdef __cplusplus
}
#endif
View
2  ...libusb1/impl/Libusb1UsbConfiguration.java → .../javalibusb1/Libusb1UsbConfiguration.java
@@ -1,4 +1,4 @@
-package javalibusb1.impl;
+package javalibusb1;
import javax.usb.*;
import java.util.Arrays;
View
27 ...va/javalibusb1/impl/Libusb1UsbDevice.java → ...in/java/javalibusb1/Libusb1UsbDevice.java
@@ -1,7 +1,8 @@
-package javalibusb1.impl;
+package javalibusb1;
import javax.usb.*;
import javax.usb.event.*;
+import javax.usb.util.*;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
@@ -75,7 +76,7 @@ public void removeUsbDeviceListener(UsbDeviceListener listener) {
}
public UsbControlIrp createUsbControlIrp(byte bmRequestType, byte bRequest, short wValue, short wIndex) {
- throw new RuntimeException("Not implemented");
+ return new DefaultUsbControlIrp(bmRequestType, bRequest, wValue, wIndex);
}
public void asyncSubmit(List<UsbControlIrp> list) {
@@ -90,8 +91,8 @@ public void syncSubmit(List<UsbControlIrp> list) {
throw new RuntimeException("Not implemented");
}
- public void syncSubmit(UsbControlIrp irp) {
- throw new RuntimeException("Not implemented");
+ public void syncSubmit(UsbControlIrp irp) throws UsbException {
+ internalSyncSubmit(irp);
}
public UsbPort getParentUsbPort() throws UsbDisconnectedException {
@@ -132,6 +133,24 @@ protected void finalize() throws Throwable {
close();
}
+ private void internalSyncSubmit(UsbControlIrp irp) throws UsbException {
+ if (irp == null) {
+ throw new IllegalArgumentException("irp");
+ }
+
+ // TODO: check if this is active
+
+ if (irp.getUsbException() != null) {
+ throw new IllegalArgumentException("usbException is not null");
+ }
+
+ if (irp.isComplete()) {
+ throw new IllegalArgumentException("complete == true");
+ }
+
+ libusb1.control_transfer(libusb_device, irp.bmRequestType(), irp.bRequest(), irp.wValue(), irp.wIndex(), 0);
+ }
+
// -----------------------------------------------------------------------
// Native Interface
// -----------------------------------------------------------------------
View
2  .../javalibusb1/impl/Libusb1UsbEndpoint.java → .../java/javalibusb1/Libusb1UsbEndpoint.java
@@ -1,4 +1,4 @@
-package javalibusb1.impl;
+package javalibusb1;
import javax.usb.*;
View
2  ...javalibusb1/impl/Libusb1UsbInterface.java → ...java/javalibusb1/Libusb1UsbInterface.java
@@ -1,4 +1,4 @@
-package javalibusb1.impl;
+package javalibusb1;
import javax.usb.*;
import javax.usb.impl.*;
View
24 ...java/javalibusb1/impl/Libusb1UsbPipe.java → ...main/java/javalibusb1/Libusb1UsbPipe.java
@@ -1,4 +1,4 @@
-package javalibusb1.impl;
+package javalibusb1;
import static javax.usb.UsbConst.*;
@@ -112,10 +112,11 @@ private int internalSyncSubmit(UsbIrp irp) throws UsbException {
if(irp instanceof UsbControlIrp) {
UsbControlIrp controlIrp = (UsbControlIrp) irp;
- return nativeSyncSubmitControl(endpoint.usbInterface.libusb_handle,
+ return libusb1.control_transfer(endpoint.usbInterface.libusb_handle,
controlIrp.bmRequestType(), controlIrp.bRequest(), controlIrp.wValue(), controlIrp.wIndex(), timeout);
}
- return nativeSyncSubmit();
+
+ throw new RuntimeException("Not implemented");
}
private void checkIrp(UsbIrp irp) {
@@ -149,21 +150,4 @@ private void checkIrp(UsbIrp irp) {
throw new IllegalArgumentException("complete == true");
}
}
-
- // -----------------------------------------------------------------------
- // Native
- // -----------------------------------------------------------------------
-
- native
- private int nativeSyncSubmit()
- throws UsbException;
-
- native
- private int nativeSyncSubmitControl(int handle,
- byte bmRequestType,
- byte bRequest,
- short wValue,
- short wIndex,
- long timeout)
- throws UsbException;
}
View
8 javalibusb1/src/main/java/javalibusb1/libusb1.java
@@ -1,8 +1,7 @@
package javalibusb1;
-import javalibusb1.impl.Libusb1UsbDevice;
-
-import java.io.Closeable;
+import javax.usb.*;
+import java.io.*;
class libusb1 implements Closeable {
@@ -32,6 +31,9 @@
native
public Libusb1UsbDevice[] get_devices();
+ native
+ public static int control_transfer(int device, byte bmRequestType, byte bRequest, short wValue, short wIndex, long timeout) throws UsbException;
+
static {
System.loadLibrary("javalibusb1");
}
View
3  javax.usb/src/main/java/javax/usb/util/DefaultUsbControlIrp.java
@@ -44,7 +44,6 @@ public short wValue() {
}
public short wLength() {
- return 0; // TODO: This is not right.
- // Probably have to find the constant given the request type + data length
+ return (short)length;
}
}
View
4 javax.usb/src/main/java/javax/usb/util/DefaultUsbIrp.java
@@ -39,6 +39,8 @@ public int getActualLength() {
}
public void setActualLength(int actualLength) throws IllegalArgumentException{
+ // TODO: shouldn't this check to see if the length is bigger than 2^16-1?
+ // There's not mention of the requirement in the docs - trygve
if (length < 0) {
throw new IllegalArgumentException("length < 0");
}
@@ -73,6 +75,8 @@ public int getLength() {
}
public void setLength(int length) throws IllegalArgumentException {
+ // TODO: shouldn't this check to see if the length is bigger than 2^16-1?
+ // There's not mention of the requirement in the docs - trygve
if (length < 0) {
throw new IllegalArgumentException("length < 0");
}
Please sign in to comment.
Something went wrong with that request. Please try again.