Przeglądaj źródła

Added Protocol description as pdf.

Take a look at this to understand the protocol between hard- and
software.
Thomas Buck 12 lat temu
rodzic
commit
3192302288

+ 40
- 4
HardwareEmulator/main.c Wyświetl plik

@@ -14,6 +14,9 @@
14 14
 #define OK 0x42
15 15
 #define ERROR 0x23
16 16
 
17
+int sendFrames(void);
18
+int recieveFrames(void);
19
+int deleteFrames(void);
17 20
 int serialWriteString(char *s);
18 21
 int serialWriteTry(char *data, size_t length);
19 22
 void intHandler(int dummy);
@@ -47,21 +50,42 @@ int main(int argc, char *argv[]) {
47 50
 			switch(c) {
48 51
 				case OK:
49 52
 					if (serialWriteTry(&c, 1)) {
50
-						printf("Could not write to pseudo terminal");
53
+						printf("Could not write to pseudo terminal\n");
51 54
 						return -1;
52 55
 					}
53 56
 					break;
54 57
 
55 58
 				case 'h': case 'H':
56 59
 					if (serialWriteString("(d)elete, (g)et anims, (s)et anims, (v)ersion\n")) {
57
-						printf("Could not write to pseudo terminal");
60
+						printf("Could not write to pseudo terminal\n");
58 61
 						return -1;
59 62
 					}
60 63
 					break;
61 64
 
62 65
 				case 'v': case 'V':
63 66
 					if (serialWriteString(VERSION)) {
64
-						printf("Could not write to pseudo terminal");
67
+						printf("Could not write to pseudo terminal\n");
68
+						return -1;
69
+					}
70
+					break;
71
+
72
+				case 's': case 'S':
73
+					if (recieveFrames()) {
74
+						printf("Error while recieving frames!\n");
75
+						return -1;
76
+					}
77
+					break;
78
+
79
+				case 'g': case 'G':
80
+					if (sendFrames()) {
81
+						printf("Error while sending frames!\n");
82
+						return -1;
83
+					}
84
+					break;
85
+
86
+				case 'd': case 'D':
87
+					if (deleteFrames()) {
88
+						printf("Error while deleting frames!\n");
65 89
 						return -1;
66 90
 					}
67 91
 					break;
@@ -69,7 +93,7 @@ int main(int argc, char *argv[]) {
69 93
 				default:
70 94
 					c = ERROR;
71 95
 					if (serialWriteTry(&c, 1)) {
72
-						printf("Could not write to pseudo terminal");
96
+						printf("Could not write to pseudo terminal\n");
73 97
 						return -1;
74 98
 					}
75 99
 					break;
@@ -82,6 +106,18 @@ int main(int argc, char *argv[]) {
82 106
 	return 0;
83 107
 }
84 108
 
109
+int sendFrames() {
110
+
111
+}
112
+
113
+int recieveFrames() {
114
+
115
+}
116
+
117
+int deleteFrames() {
118
+
119
+}
120
+
85 121
 int serialWriteString(char *s) {
86 122
 	return serialWriteTry(s, strlen(s));
87 123
 }

+ 1
- 0
HardwareEmulator/makefile Wyświetl plik

@@ -1,6 +1,7 @@
1 1
 CC = gcc
2 2
 SRC = main.c
3 3
 SRC += serial.c
4
+SRC += mem.c
4 5
 
5 6
 TARGET = cubeEmu
6 7
 

+ 64
- 0
HardwareEmulator/mem.c Wyświetl plik

@@ -0,0 +1,64 @@
1
+/*
2
+ * mem.c - HardwareEmulator
3
+ * frame is represented as 65 bytes.
4
+ * 0 - 63: frame data
5
+ * 64: duration, 0 => 1/24th second
6
+ */
7
+
8
+#include <stdio.h>
9
+#include <stdlib.h>
10
+#include <string.h>
11
+
12
+#include "mem.h"
13
+
14
+char *mem = NULL;
15
+int frameCount = 0;
16
+
17
+// return != 0 if error
18
+int addFrame(char *frame) {
19
+	char *newMem, *oldMem = mem;
20
+	int i;
21
+
22
+	if (oldMem != NULL) {
23
+		newMem = (char *)malloc(65 * frameCount);
24
+		if (newMem == NULL) {
25
+			return 1;
26
+		}
27
+		memcpy(newMem, oldMem, 65 * frameCount); // Copy old frames
28
+		free(oldMem);
29
+	} else {
30
+		// oldMem == NULL
31
+		frameCount = 0;
32
+		newMem = (char *)malloc(65);
33
+		if (newMem == NULL) {
34
+			return 1;
35
+		}
36
+	}
37
+
38
+	memcpy((newMem + (65 * frameCount)), frame, 65); // Add new frame
39
+
40
+	frameCount++;
41
+	mem = newMem;
42
+	return 0;
43
+}
44
+
45
+// returns NULL if error
46
+char *getFrame(int index) {
47
+	if (index >= frameCount) {
48
+		return NULL;
49
+	} else if (mem == NULL) {
50
+		return NULL;
51
+	} else {
52
+		return (mem + (65 * index));
53
+	}
54
+}
55
+
56
+int framesStored() {
57
+	return frameCount;
58
+}
59
+
60
+void clearMemory() {
61
+	free(mem);
62
+	mem = NULL;
63
+	frameCount = 0;
64
+}

+ 16
- 0
HardwareEmulator/mem.h Wyświetl plik

@@ -0,0 +1,16 @@
1
+/*
2
+ * mem.c - HardwareEmulator
3
+ * frame is represented as 65 bytes.
4
+ * 0 - 63: frame data
5
+ * 64: duration, 0 => 1/24th second
6
+ */
7
+
8
+// return != 0 if error
9
+int addFrame(char *frame);
10
+
11
+// returns NULL if error
12
+char *getFrame(int index);
13
+
14
+int framesStored();
15
+
16
+void clearMemory();

BIN
Protokoll.pdf Wyświetl plik


Ładowanie…
Anuluj
Zapisz