Thomas Buck пре 13 година
родитељ
комит
b4d12ed27f
3 измењених фајлова са 34 додато и 14 уклоњено
  1. 15
    1
      CubeControl/HelperUtility.java
  2. 16
    11
      CubeControl/helper/unixSerial.c
  3. 3
    2
      CubeControl/serialHelper.c

+ 15
- 1
CubeControl/HelperUtility.java Прегледај датотеку

@@ -39,7 +39,21 @@ public class HelperUtility {
39 39
 	 * Get all the existing serial port names
40 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 59
 	 * Open Connection to a port

+ 16
- 11
CubeControl/helper/unixSerial.c Прегледај датотеку

@@ -32,8 +32,6 @@
32 32
 #include <termios.h>
33 33
 #include <dirent.h>
34 34
 
35
-#define SEARCH "tty."
36
-
37 35
 #define BAUD B19200
38 36
 
39 37
 int fd = -1;
@@ -140,7 +138,7 @@ char** namesInDev(int *siz) {
140 138
 	return files;
141 139
 }
142 140
 
143
-char** getSerialPorts(void) {
141
+char** getSerialPorts(const char *search) {
144 142
 	int size;
145 143
 	char** files = namesInDev(&size);
146 144
 	char **fin = NULL, **finish = NULL;
@@ -153,18 +151,25 @@ char** getSerialPorts(void) {
153 151
 
154 152
 	while (files[i] != NULL) {
155 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 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 164
 				// printf(" and is a serial port\n");
162 165
 				fin[j++] = files[i];
163
-				serialClose();
164
-			} else {
166
+			// 	serialClose();
167
+			// } else {
165 168
 				// printf(" and is not a serial port\n");
166
-				free(files[i]);
167
-			}
169
+			// 	free(files[i]);
170
+			// }
171
+
172
+
168 173
 		} else {
169 174
 			free(files[i]);
170 175
 		}

+ 3
- 2
CubeControl/serialHelper.c Прегледај датотеку

@@ -31,8 +31,9 @@
31 31
 #include "helper/unixSerial.c"
32 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 37
 	char *string = NULL;
37 38
 	int length = 0, leng2 = 0, lengthabs = 0;
38 39
 

Loading…
Откажи
Сачувај