소스 검색

Merge branch 'master' of github.com:xythobuz/LED-Cube

Max Nuding 12 년 전
부모
커밋
189dfefa20
2개의 변경된 파일23개의 추가작업 그리고 15개의 파일을 삭제
  1. 7
    11
      CubeControl/helper/unixSerial.c
  2. 16
    4
      CubeControl/serialHelper.c

+ 7
- 11
CubeControl/helper/unixSerial.c 파일 보기

114
 		size++;
114
 		size++;
115
 	}
115
 	}
116
 	files = (char **)malloc((size + 1) * sizeof(char *));
116
 	files = (char **)malloc((size + 1) * sizeof(char *));
117
-	files[size] = NULL;
117
+	files[size++] = NULL;
118
 	closedir(dir);
118
 	closedir(dir);
119
 	dir = opendir("/dev/");
119
 	dir = opendir("/dev/");
120
 	while ((ent = readdir(dir)) != NULL) {
120
 	while ((ent = readdir(dir)) != NULL) {
126
 
126
 
127
 	char *tmp = NULL;
127
 	char *tmp = NULL;
128
 	// Fix every string, addin /dev/ in front of it...
128
 	// Fix every string, addin /dev/ in front of it...
129
-	for (i = 0; i < size; i++) {
129
+	for (i = 0; i < (size - 1); i++) {
130
 		tmp = (char *)malloc((strlen(files[i]) + 6) * sizeof(char));
130
 		tmp = (char *)malloc((strlen(files[i]) + 6) * sizeof(char));
131
 		tmp[0] = '/';
131
 		tmp[0] = '/';
132
 		tmp[1] = 'd';
132
 		tmp[1] = 'd';
146
 	char** fin = NULL;
146
 	char** fin = NULL;
147
 	int i = 0, j = 0, f, g;
147
 	int i = 0, j = 0, f, g;
148
 
148
 
149
-	fin = (char **)malloc((size + 1) * sizeof(char *));
150
-	fin[size] = NULL;
149
+	printf("JNI: Got files in /dev/\n");
150
+
151
+	fin = (char **)malloc(size * sizeof(char *));
152
+	fin[size - 1] = NULL;
151
 	while (files[i] != NULL) {
153
 	while (files[i] != NULL) {
152
 		if (strstr(files[i], SEARCH) != NULL) {
154
 		if (strstr(files[i], SEARCH) != NULL) {
153
 			f = serialOpen(files[i]);
155
 			f = serialOpen(files[i]);
160
 	}
162
 	}
161
 	free(files);
163
 	free(files);
162
 
164
 
163
-	char** finish = (char **)malloc((j + 1) * sizeof(char *));
164
-	for (i = 0; i < (j + 1); i++) {
165
-		finish[i] = fin[i];
166
-	}
167
-	free(fin);
168
-
169
-	return finish;
165
+	return fin;
170
 }
166
 }

+ 16
- 4
CubeControl/serialHelper.c 파일 보기

34
 JNIEXPORT jstring JNICALL Java_HelperUtility_getPorts(JNIEnv *env, jclass class) {
34
 JNIEXPORT jstring JNICALL Java_HelperUtility_getPorts(JNIEnv *env, jclass class) {
35
 	char **ports = getSerialPorts();
35
 	char **ports = getSerialPorts();
36
 	char *string = NULL;
36
 	char *string = NULL;
37
-	int length = 0, leng2 = 0, lengthabs = 0;;
37
+	int length = 0, leng2 = 0, lengthabs = 0;
38
+
39
+	printf("JNI: Got serial ports...\n");
40
+
41
+	// Count how much memory we need for string of all ports, with \n in between
38
 	while (ports[length] != NULL) {
42
 	while (ports[length] != NULL) {
43
+		printf("JNI: Startin count...\n");
39
 		while (ports[length][leng2] != '\0') {
44
 		while (ports[length][leng2] != '\0') {
40
 			leng2++;
45
 			leng2++;
41
 		}
46
 		}
47
+		printf("JNI: Counted %s\n", ports[length]);
42
 		lengthabs += leng2;
48
 		lengthabs += leng2;
43
 		leng2 = 0;
49
 		leng2 = 0;
44
 		length++;
50
 		length++;
45
 	}
51
 	}
46
-	
47
 	length += lengthabs;
52
 	length += lengthabs;
48
-	string = (char *)malloc((length * sizeof(char)) + 1);
49
-	
53
+
54
+	printf("JNI: Counted serial ports...\n");
55
+
56
+	string = (char *)malloc((length + 1) * sizeof(char));
57
+	if (string == NULL) {
58
+		printf("JNI: Not enough memory!\n");
59
+		return (*env)->NewStringUTF(env, NULL);
60
+	}
61
+
50
 	length = 0;
62
 	length = 0;
51
 	lengthabs = 0;
63
 	lengthabs = 0;
52
 	while (ports[length] != NULL) {
64
 	while (ports[length] != NULL) {

Loading…
취소
저장