Browse Source

Helpers in one file

Thomas Buck 12 years ago
parent
commit
44b65dc730

+ 22
- 2
Cube Control/helper/unixSerial.c View File

@@ -1,8 +1,28 @@
1 1
 /*
2
+ *
3
+ * unixSerial.c
4
+ *
2 5
  * POSIX compatible serial port library
3 6
  * Uses 8 databits, no parity, 1 stop bit, no handshaking
4
- * By: Thomas Buck <taucher.bodensee@gmail.com>
5
- * Visit: www.xythobuz.org
7
+ *
8
+ * Copyright 2011 Thomas Buck <xythobuz@me.com>
9
+ * Copyright 2011 Max Nuding <max.nuding@gmail.com>
10
+ * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
11
+ *
12
+ * This file is part of LED-Cube.
13
+ *
14
+ * LED-Cube is free software: you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License as published by
16
+ * the Free Software Foundation, either version 3 of the License, or
17
+ * (at your option) any later version.
18
+ *
19
+ * LED-Cube is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
+ * GNU General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU General Public License
25
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
6 26
  */
7 27
 
8 28
 #include <stdio.h>

+ 22
- 2
Cube Control/helper/winSerial.c View File

@@ -1,8 +1,28 @@
1 1
 /*
2
+ *
3
+ * winSerial.c
4
+ *
2 5
  * Windows 16 (& 32 & 64?) compatible serial port library
3 6
  * Uses 8 databits, no parity, 1 stop bit, no handshaking
4
- * By: Thomas Buck <taucher.bodensee@gmail.com>
5
- * Visit: www.xythobuz.org
7
+ *
8
+ * Copyright 2011 Thomas Buck <xythobuz@me.com>
9
+ * Copyright 2011 Max Nuding <max.nuding@gmail.com>
10
+ * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
11
+ *
12
+ * This file is part of LED-Cube.
13
+ *
14
+ * LED-Cube is free software: you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License as published by
16
+ * the Free Software Foundation, either version 3 of the License, or
17
+ * (at your option) any later version.
18
+ *
19
+ * LED-Cube is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
+ * GNU General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU General Public License
25
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
6 26
  */
7 27
 
8 28
 #include <stdio.h>

+ 7
- 3
Cube Control/makefile View File

@@ -6,11 +6,15 @@ TARGET = unix
6 6
 
7 7
 all: java
8 8
 
9
-java: helper
9
+java: serialHelper
10 10
 	$(JAVAC) *.java
11 11
 
12
-helper:
13
-	$(CC) -o serialHelper $(TARGET)Helper.c
12
+serialHelper:
13
+ifeq ($(TARGET),win)
14
+	$(CC) -o serialHelper -D winHelper serialHelper.c
15
+else
16
+	$(CC) -o serialHelper serialHelper.c
17
+endif
14 18
 
15 19
 clean:
16 20
 	rm -f *.class

Cube Control/unixHelper.c → Cube Control/serialHelper.c View File

@@ -1,10 +1,33 @@
1 1
 /*
2
- * By: Thomas Buck <taucher.bodensee@gmail.com>
3
- * Visit: www.xythobuz.org
2
+ * unixHelper.c
3
+ *
4
+ * Copyright 2011 Thomas Buck <xythobuz@me.com>
5
+ * Copyright 2011 Max Nuding <max.nuding@gmail.com>
6
+ * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
7
+ *
8
+ * This file is part of LED-Cube.
9
+ *
10
+ * LED-Cube is free software: you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation, either version 3 of the License, or
13
+ * (at your option) any later version.
14
+ *
15
+ * LED-Cube is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
4 22
  */
5 23
 #include <stdlib.h>
6 24
 #include <stdio.h>
25
+
26
+#ifdef winHelper
27
+#include "helper/winSerial.c"
28
+#else
7 29
 #include "helper/unixSerial.c"
30
+#endif
8 31
 
9 32
 char *fileData = NULL;
10 33
 
@@ -23,7 +46,11 @@ int main(int argc, char *argv[]) {
23 46
 	size_t length, written;
24 47
 	
25 48
 	if (argc < 3) {
49
+#ifdef winHelper
50
+		printf("Usage:\n%s COM1 C:\\file\\to\\send.txt\n", argv[0]);
51
+#else
26 52
 		printf("Usage:\n%s /dev/SerialPort /file/to/send\n", argv[0]);
53
+#endif
27 54
 		return 1;
28 55
 	} else {
29 56
 		if (serialOpen(argv[1]) != 0) {

+ 0
- 98
Cube Control/winHelper.c View File

@@ -1,98 +0,0 @@
1
-/*
2
- * By: Thomas Buck <taucher.bodensee@gmail.com>
3
- * Visit: www.xythobuz.org
4
- */
5
-#include <stdlib.h>
6
-#include <stdio.h>
7
-#include "helper/winSerial.c"
8
-
9
-char *fileData = NULL;
10
-
11
-void removeFromBeginning(size_t size, size_t remove);
12
-size_t readFile(char *path);
13
-size_t getFileSize(FILE *fp);
14
-
15
-/*
16
-Return values:
17
-0: Success
18
-1: Usage error
19
-2: Serial Port Error
20
-3: Data File Error
21
-*/
22
-int main(int argc, char *argv[]) {
23
-	size_t length, written;
24
-	
25
-	if (argc < 3) {
26
-		printf("Usage:\n%s COM1 C:\\file\\to\\send.txt\n", argv[0]);
27
-		return 1;
28
-	} else {
29
-		if (serialOpen(argv[1]) != 0) {
30
-			printf("Error: Could not open %s\n", argv[1]);
31
-			return 2;
32
-		}
33
-
34
-		length = readFile(argv[2]);
35
-		if (length == 0) {
36
-			printf("Error while reading %s\n", argv[2]);
37
-			return 3;
38
-		}
39
-
40
-		written = serialWrite(fileData, length);
41
-		while (written < length) {
42
-			removeFromBeginning(length, written);
43
-			length -= written;
44
-			written = serialWrite(fileData, length);
45
-		}
46
-
47
-		free(fileData);
48
-		fileData = NULL;
49
-		serialClose();
50
-		return 0;
51
-	}
52
-}
53
-
54
-void removeFromBeginning(size_t size, size_t remove) {
55
-	size_t i;
56
-	char *tmp = (char *)malloc((size - remove) * sizeof(char));
57
-
58
-	for (i = 0; i < (size - remove); i++) {
59
-		tmp[i] = fileData[i + remove];
60
-	}
61
-	free(fileData);
62
-	fileData = tmp;
63
-}
64
-
65
-size_t readFile(char *path) {
66
-	size_t size, i;
67
-	FILE *fp;
68
-
69
-	fp = fopen(path, "r");
70
-	if (!fp) {
71
-		return 0;
72
-	}
73
-
74
-	size = getFileSize(fp);
75
-	fileData = (char *)malloc(size * sizeof(char));
76
-	for (i = 0; i < size; i++) {
77
-		fileData[i] = fgetc(fp);
78
-	}
79
-
80
-	fclose(fp);
81
-	return size;
82
-}
83
-
84
-size_t getFileSize(FILE *fp) {
85
-	size_t size = 0;
86
-	int c;
87
-
88
-	fseek(fp, 0, 0); // Set file pointer to beginning
89
-	
90
-	do { // Calculate size
91
-		c = fgetc(fp);
92
-		size++;
93
-	} while (c != EOF);
94
-	
95
-	fseek(fp, 0, 0);
96
-
97
-	return size;
98
-}

Loading…
Cancel
Save