Browse Source

Removed scanning delay

Thomas Buck 13 years ago
parent
commit
b4d12ed27f
3 changed files with 34 additions and 14 deletions
  1. 15
    1
      CubeControl/HelperUtility.java
  2. 16
    11
      CubeControl/helper/unixSerial.c
  3. 3
    2
      CubeControl/serialHelper.c

+ 15
- 1
CubeControl/HelperUtility.java View File

39
 	 * Get all the existing serial port names
39
 	 * Get all the existing serial port names
40
 	 * @return List of port names. \n between entries
40
 	 * @return List of port names. \n between entries
41
 	 */
41
 	 */
42
-	public static native String getPorts();
42
+	public static String getPorts() {
43
+		String os = System.getProperty("os.name").toLowerCase();
44
+		if (os.indexOf("windows") > -1) {
45
+			return getThePorts("COM");
46
+		} else if (os.indexOf("linux") > -1) {
47
+			return getThePorts("tty");
48
+		} else if (os.indexOf("mac") > -1) {
49
+			return getThePorts("tty.");
50
+		}
51
+
52
+		// Not linux, windows or mac?
53
+		return getThePorts("wtf?");
54
+	}
55
+
56
+	private static native String getThePorts(String search);
43
 
57
 
44
 	/**
58
 	/**
45
 	 * Open Connection to a port
59
 	 * Open Connection to a port

+ 16
- 11
CubeControl/helper/unixSerial.c View File

32
 #include <termios.h>
32
 #include <termios.h>
33
 #include <dirent.h>
33
 #include <dirent.h>
34
 
34
 
35
-#define SEARCH "tty."
36
-
37
 #define BAUD B19200
35
 #define BAUD B19200
38
 
36
 
39
 int fd = -1;
37
 int fd = -1;
140
 	return files;
138
 	return files;
141
 }
139
 }
142
 
140
 
143
-char** getSerialPorts(void) {
141
+char** getSerialPorts(const char *search) {
144
 	int size;
142
 	int size;
145
 	char** files = namesInDev(&size);
143
 	char** files = namesInDev(&size);
146
 	char **fin = NULL, **finish = NULL;
144
 	char **fin = NULL, **finish = NULL;
153
 
151
 
154
 	while (files[i] != NULL) {
152
 	while (files[i] != NULL) {
155
 		// Filter for SEARCH and if it is a serial port
153
 		// Filter for SEARCH and if it is a serial port
156
-		if (strstr(files[i], SEARCH) != NULL) {
154
+		if (strstr(files[i], search) != NULL) {
157
 			// We have a match
155
 			// We have a match
158
-			// printf("JNI: %s matched %s", files[i], SEARCH);
159
-			f = serialOpen(files[i]);
160
-			if (f != -1) {
156
+			// printf("JNI: %s matched %s", files[i], search);
157
+			
158
+			// Don't actually check if it is a serial port
159
+			// It causes long delays while trying to connect
160
+			// to Bluetooth devices...
161
+			
162
+			// f = serialOpen(files[i]);
163
+			// if (f != -1) {
161
 				// printf(" and is a serial port\n");
164
 				// printf(" and is a serial port\n");
162
 				fin[j++] = files[i];
165
 				fin[j++] = files[i];
163
-				serialClose();
164
-			} else {
166
+			// 	serialClose();
167
+			// } else {
165
 				// printf(" and is not a serial port\n");
168
 				// printf(" and is not a serial port\n");
166
-				free(files[i]);
167
-			}
169
+			// 	free(files[i]);
170
+			// }
171
+
172
+
168
 		} else {
173
 		} else {
169
 			free(files[i]);
174
 			free(files[i]);
170
 		}
175
 		}

+ 3
- 2
CubeControl/serialHelper.c View File

31
 #include "helper/unixSerial.c"
31
 #include "helper/unixSerial.c"
32
 #endif
32
 #endif
33
 
33
 
34
-JNIEXPORT jstring JNICALL Java_HelperUtility_getPorts(JNIEnv *env, jclass class) {
35
-	char **ports = getSerialPorts();
34
+JNIEXPORT jstring JNICALL Java_HelperUtility_getThePorts(JNIEnv *env, jclass class, jstring s) {
35
+	jboolean tmp;
36
+	char **ports = getSerialPorts((*env)->GetStringUTFChars(env, s, &tmp));
36
 	char *string = NULL;
37
 	char *string = NULL;
37
 	int length = 0, leng2 = 0, lengthabs = 0;
38
 	int length = 0, leng2 = 0, lengthabs = 0;
38
 
39
 

Loading…
Cancel
Save