Browse Source

Integrated xyRobot libSerial fixes.

Thomas Buck 12 years ago
parent
commit
668b6a6311

+ 2
- 2
CubeControl/libSerial/makefile View File

16
 ifeq ($(UNAME),Darwin)
16
 ifeq ($(UNAME),Darwin)
17
 HEADERPATH = /System/Library/Frameworks/JavaVM.framework/Headers
17
 HEADERPATH = /System/Library/Frameworks/JavaVM.framework/Headers
18
 else 
18
 else 
19
-HEADERPATH = /usr/lib/jvm/java-6-openjdk/include
19
+HEADERPATH = /usr/lib/jvm/java-6-openjdk/include -I/usr/lib/jvm/java-6-openjdk/include/linux
20
 endif
20
 endif
21
 endif
21
 endif
22
 endif
22
 endif
46
 
46
 
47
 libSerial.so: serialHelper.c unixSerial.c serialInterface.h
47
 libSerial.so: serialHelper.c unixSerial.c serialInterface.h
48
 	$(CC) -x c -std=$(STANDARD) -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o
48
 	$(CC) -x c -std=$(STANDARD) -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o
49
-	$(CC) -dynamiclib -o libSerial.so serialHelper.o
49
+	$(CC) -shared -o libSerial.so serialHelper.o
50
 
50
 
51
 Serial.dll: serialHelper.c winSerial.c serialInterface.h
51
 Serial.dll: serialHelper.c winSerial.c serialInterface.h
52
 	$(CC) -x c -std=$(STANDARD) -DBUILDINGDLL -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o -D winHelper
52
 	$(CC) -x c -std=$(STANDARD) -DBUILDINGDLL -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o -D winHelper

+ 8
- 2
CubeControl/libSerial/serialHelper.c View File

21
 #include <stdlib.h>
21
 #include <stdlib.h>
22
 #include <stdio.h>
22
 #include <stdio.h>
23
 #include <jni.h>
23
 #include <jni.h>
24
+#include <time.h>
24
 #include "serialInterface.h"
25
 #include "serialInterface.h"
25
 
26
 
26
 #ifdef winHelper
27
 #ifdef winHelper
80
 JNIEXPORT jshortArray JNICALL Java_HelperUtility_readDataNative(JNIEnv *env, jclass class, jint length) {
81
 JNIEXPORT jshortArray JNICALL Java_HelperUtility_readDataNative(JNIEnv *env, jclass class, jint length) {
81
 	jshortArray arr = (*env)->NewShortArray(env, length);
82
 	jshortArray arr = (*env)->NewShortArray(env, length);
82
 	int toBeRead = 0, read, i, error = 0;
83
 	int toBeRead = 0, read, i, error = 0;
83
-	char *data = (char *)malloc(length * sizeof(char));
84
+	unsigned char *data = (char *)malloc(length * sizeof(char));
84
 	jshort *data2 = (jshort *)malloc(length * sizeof(jshort));
85
 	jshort *data2 = (jshort *)malloc(length * sizeof(jshort));
86
+	time_t startTime = time(NULL);
87
+	time_t diff = (length / 3000) + 1;
85
 
88
 
86
 	while (length > 0) {
89
 	while (length > 0) {
87
-		read = serialRead(data + toBeRead, length);
90
+		read = serialRead((char *)data + toBeRead, length);
88
 		if (read == -1) {
91
 		if (read == -1) {
89
 			error++;
92
 			error++;
90
 			if (error > 10) {
93
 			if (error > 10) {
94
 			toBeRead += read;
97
 			toBeRead += read;
95
 			length -= read;
98
 			length -= read;
96
 		}
99
 		}
100
+		if (difftime(time(NULL), startTime) > diff) {
101
+			return NULL;
102
+		}
97
 	}
103
 	}
98
 
104
 
99
 	for (i = 0; i < (*env)->GetArrayLength(env, arr); i++) {
105
 	for (i = 0; i < (*env)->GetArrayLength(env, arr); i++) {

+ 17
- 2
CubeControl/libSerial/unixSerial.c View File

1
 /*
1
 /*
2
- *
3
  * unixSerial.c
2
  * unixSerial.c
4
  *
3
  *
5
  * POSIX compatible serial port library
4
  * POSIX compatible serial port library
118
 	files = (char **)malloc((size + 1) * sizeof(char *));
117
 	files = (char **)malloc((size + 1) * sizeof(char *));
119
 	files[size++] = NULL;
118
 	files[size++] = NULL;
120
 	closedir(dir);
119
 	closedir(dir);
120
+
121
+	// printf("JNI: Counted files in /dev/: %d\n", size);
122
+
121
 	dir = opendir("/dev/");
123
 	dir = opendir("/dev/");
122
 	while ((ent = readdir(dir)) != NULL) {
124
 	while ((ent = readdir(dir)) != NULL) {
125
+		if (i == (size - 1)) {
126
+			break;
127
+		}
123
 		files[i] = (char *)malloc((strlen(ent->d_name) + 1) * sizeof(char));
128
 		files[i] = (char *)malloc((strlen(ent->d_name) + 1) * sizeof(char));
124
 		files[i] = strcpy(files[i], ent->d_name);
129
 		files[i] = strcpy(files[i], ent->d_name);
125
 		i++;
130
 		i++;
126
 	}
131
 	}
127
 	closedir(dir);
132
 	closedir(dir);
128
 
133
 
134
+	// printf("JNI: Got names...\n");
135
+
129
 	char *tmp = NULL;
136
 	char *tmp = NULL;
130
-	// Fix every string, addin /dev/ in front of it...
137
+	// Fix every string, add /dev/ in front of it...
131
 	for (i = 0; i < (size - 1); i++) {
138
 	for (i = 0; i < (size - 1); i++) {
139
+		// printf("JNI: (%d)Allocating %d\n", i, strlen(files[i]) + 6);
132
 		tmp = (char *)malloc((strlen(files[i]) + 6) * sizeof(char));
140
 		tmp = (char *)malloc((strlen(files[i]) + 6) * sizeof(char));
141
+		if (tmp == NULL) {
142
+			printf("JNI: Ran out of memory!\n");
143
+			exit(1);
144
+		}
133
 		tmp[0] = '/';
145
 		tmp[0] = '/';
134
 		tmp[1] = 'd';
146
 		tmp[1] = 'd';
135
 		tmp[2] = 'e';
147
 		tmp[2] = 'e';
136
 		tmp[3] = 'v';
148
 		tmp[3] = 'v';
137
 		tmp[4] = '/';
149
 		tmp[4] = '/';
150
+		tmp[5] = '\0';
138
 		files[i] = strncat(tmp, files[i], strlen(files[i]));
151
 		files[i] = strncat(tmp, files[i], strlen(files[i]));
139
 	}
152
 	}
140
 
153
 
154
+	// printf("JNI: Paths fixed!\n");
155
+
141
 	*siz = size;
156
 	*siz = size;
142
 	return files;
157
 	return files;
143
 }
158
 }

+ 0
- 1
CubeControl/libSerial/winSerial.c View File

1
 /*
1
 /*
2
- *
3
  * winSerial.c
2
  * winSerial.c
4
  *
3
  *
5
  * Windows 16 (& 32 & 64?) compatible serial port library
4
  * Windows 16 (& 32 & 64?) compatible serial port library

+ 2
- 2
CubeFirmware/cube.c View File

146
 		for (i = 0; i < 8; i++) {
146
 		for (i = 0; i < 8; i++) {
147
 			for (j = 0; j < 8; j++) {
147
 			for (j = 0; j < 8; j++) {
148
 				// First line uses the lookUp Table to account for our wrong connection
148
 				// First line uses the lookUp Table to account for our wrong connection
149
-				// imgBuffer[j][7 - i] = ~(pgm_read_byte(&(lookUp[img[j + (i * 8)]])));
149
+				imgBuffer[j][7 - i] = ~(pgm_read_byte(&(lookUp[img[j + (i * 8)]])));
150
 
150
 
151
 				// This line is simply displaying the data, for correct connections
151
 				// This line is simply displaying the data, for correct connections
152
-				imgBuffer[j][i] = ~(img[j + (i * 8)]);
152
+				// imgBuffer[j][i] = ~(img[j + (i * 8)]);
153
 
153
 
154
 				// Uncomment the desired line, comment the other...
154
 				// Uncomment the desired line, comment the other...
155
 			}
155
 			}

+ 1093
- 1092
CubeFirmware/main.hex
File diff suppressed because it is too large
View File


Loading…
Cancel
Save