Browse files

Integrated xyRobot libSerial fixes.

  • Loading branch information...
1 parent 0bfe145 commit 668b6a631140122dd092c495d2ccf924b8d73c44 @xythobuz committed Aug 1, 2012
View
4 CubeControl/libSerial/makefile
@@ -16,7 +16,7 @@ UNAME := $(shell uname -s)
ifeq ($(UNAME),Darwin)
HEADERPATH = /System/Library/Frameworks/JavaVM.framework/Headers
else
-HEADERPATH = /usr/lib/jvm/java-6-openjdk/include
+HEADERPATH = /usr/lib/jvm/java-6-openjdk/include -I/usr/lib/jvm/java-6-openjdk/include/linux
endif
endif
endif
@@ -46,7 +46,7 @@ libSerial.jnilib: serialHelper.c unixSerial.c serialInterface.h
libSerial.so: serialHelper.c unixSerial.c serialInterface.h
$(CC) -x c -std=$(STANDARD) -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o
- $(CC) -dynamiclib -o libSerial.so serialHelper.o
+ $(CC) -shared -o libSerial.so serialHelper.o
Serial.dll: serialHelper.c winSerial.c serialInterface.h
$(CC) -x c -std=$(STANDARD) -DBUILDINGDLL -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o -D winHelper
View
10 CubeControl/libSerial/serialHelper.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <jni.h>
+#include <time.h>
#include "serialInterface.h"
#ifdef winHelper
@@ -80,11 +81,13 @@ JNIEXPORT jstring JNICALL Java_HelperUtility_getThePorts(JNIEnv *env, jclass cla
JNIEXPORT jshortArray JNICALL Java_HelperUtility_readDataNative(JNIEnv *env, jclass class, jint length) {
jshortArray arr = (*env)->NewShortArray(env, length);
int toBeRead = 0, read, i, error = 0;
- char *data = (char *)malloc(length * sizeof(char));
+ unsigned char *data = (char *)malloc(length * sizeof(char));
jshort *data2 = (jshort *)malloc(length * sizeof(jshort));
+ time_t startTime = time(NULL);
+ time_t diff = (length / 3000) + 1;
while (length > 0) {
- read = serialRead(data + toBeRead, length);
+ read = serialRead((char *)data + toBeRead, length);
if (read == -1) {
error++;
if (error > 10) {
@@ -94,6 +97,9 @@ JNIEXPORT jshortArray JNICALL Java_HelperUtility_readDataNative(JNIEnv *env, jcl
toBeRead += read;
length -= read;
}
+ if (difftime(time(NULL), startTime) > diff) {
+ return NULL;
+ }
}
for (i = 0; i < (*env)->GetArrayLength(env, arr); i++) {
View
19 CubeControl/libSerial/unixSerial.c
@@ -1,5 +1,4 @@
/*
- *
* unixSerial.c
*
* POSIX compatible serial port library
@@ -118,26 +117,42 @@ char** namesInDev(int *siz) {
files = (char **)malloc((size + 1) * sizeof(char *));
files[size++] = NULL;
closedir(dir);
+
+ // printf("JNI: Counted files in /dev/: %d\n", size);
+
dir = opendir("/dev/");
while ((ent = readdir(dir)) != NULL) {
+ if (i == (size - 1)) {
+ break;
+ }
files[i] = (char *)malloc((strlen(ent->d_name) + 1) * sizeof(char));
files[i] = strcpy(files[i], ent->d_name);
i++;
}
closedir(dir);
+ // printf("JNI: Got names...\n");
+
char *tmp = NULL;
- // Fix every string, addin /dev/ in front of it...
+ // Fix every string, add /dev/ in front of it...
for (i = 0; i < (size - 1); i++) {
+ // printf("JNI: (%d)Allocating %d\n", i, strlen(files[i]) + 6);
tmp = (char *)malloc((strlen(files[i]) + 6) * sizeof(char));
+ if (tmp == NULL) {
+ printf("JNI: Ran out of memory!\n");
+ exit(1);
+ }
tmp[0] = '/';
tmp[1] = 'd';
tmp[2] = 'e';
tmp[3] = 'v';
tmp[4] = '/';
+ tmp[5] = '\0';
files[i] = strncat(tmp, files[i], strlen(files[i]));
}
+ // printf("JNI: Paths fixed!\n");
+
*siz = size;
return files;
}
View
1 CubeControl/libSerial/winSerial.c
@@ -1,5 +1,4 @@
/*
- *
* winSerial.c
*
* Windows 16 (& 32 & 64?) compatible serial port library
View
4 CubeFirmware/cube.c
@@ -146,10 +146,10 @@ void setImage(uint8_t *img) {
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
// First line uses the lookUp Table to account for our wrong connection
- // imgBuffer[j][7 - i] = ~(pgm_read_byte(&(lookUp[img[j + (i * 8)]])));
+ imgBuffer[j][7 - i] = ~(pgm_read_byte(&(lookUp[img[j + (i * 8)]])));
// This line is simply displaying the data, for correct connections
- imgBuffer[j][i] = ~(img[j + (i * 8)]);
+ // imgBuffer[j][i] = ~(img[j + (i * 8)]);
// Uncomment the desired line, comment the other...
}
View
2,185 CubeFirmware/main.hex
1,093 additions, 1,092 deletions not shown because the diff is too large. Please use a local Git client to view these changes.

0 comments on commit 668b6a6

Please sign in to comment.