Bläddra i källkod

Integrated xyRobot libSerial fixes.

Thomas Buck 12 år sedan
förälder
incheckning
668b6a6311

+ 2
- 2
CubeControl/libSerial/makefile Visa fil

@@ -16,7 +16,7 @@ UNAME := $(shell uname -s)
16 16
 ifeq ($(UNAME),Darwin)
17 17
 HEADERPATH = /System/Library/Frameworks/JavaVM.framework/Headers
18 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 20
 endif
21 21
 endif
22 22
 endif
@@ -46,7 +46,7 @@ libSerial.jnilib: serialHelper.c unixSerial.c serialInterface.h
46 46
 
47 47
 libSerial.so: serialHelper.c unixSerial.c serialInterface.h
48 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 51
 Serial.dll: serialHelper.c winSerial.c serialInterface.h
52 52
 	$(CC) -x c -std=$(STANDARD) -DBUILDINGDLL -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o -D winHelper

+ 8
- 2
CubeControl/libSerial/serialHelper.c Visa fil

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

+ 17
- 2
CubeControl/libSerial/unixSerial.c Visa fil

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

+ 0
- 1
CubeControl/libSerial/winSerial.c Visa fil

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

+ 2
- 2
CubeFirmware/cube.c Visa fil

@@ -146,10 +146,10 @@ void setImage(uint8_t *img) {
146 146
 		for (i = 0; i < 8; i++) {
147 147
 			for (j = 0; j < 8; j++) {
148 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 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 154
 				// Uncomment the desired line, comment the other...
155 155
 			}

+ 1093
- 1092
CubeFirmware/main.hex
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


Laddar…
Avbryt
Spara