Browse Source

Added Protocol description as pdf.

Take a look at this to understand the protocol between hard- and
software.
Thomas Buck 12 years ago
parent
commit
3192302288
5 changed files with 121 additions and 4 deletions
  1. 40
    4
      HardwareEmulator/main.c
  2. 1
    0
      HardwareEmulator/makefile
  3. 64
    0
      HardwareEmulator/mem.c
  4. 16
    0
      HardwareEmulator/mem.h
  5. BIN
      Protokoll.pdf

+ 40
- 4
HardwareEmulator/main.c View File

14
 #define OK 0x42
14
 #define OK 0x42
15
 #define ERROR 0x23
15
 #define ERROR 0x23
16
 
16
 
17
+int sendFrames(void);
18
+int recieveFrames(void);
19
+int deleteFrames(void);
17
 int serialWriteString(char *s);
20
 int serialWriteString(char *s);
18
 int serialWriteTry(char *data, size_t length);
21
 int serialWriteTry(char *data, size_t length);
19
 void intHandler(int dummy);
22
 void intHandler(int dummy);
47
 			switch(c) {
50
 			switch(c) {
48
 				case OK:
51
 				case OK:
49
 					if (serialWriteTry(&c, 1)) {
52
 					if (serialWriteTry(&c, 1)) {
50
-						printf("Could not write to pseudo terminal");
53
+						printf("Could not write to pseudo terminal\n");
51
 						return -1;
54
 						return -1;
52
 					}
55
 					}
53
 					break;
56
 					break;
54
 
57
 
55
 				case 'h': case 'H':
58
 				case 'h': case 'H':
56
 					if (serialWriteString("(d)elete, (g)et anims, (s)et anims, (v)ersion\n")) {
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
 						return -1;
61
 						return -1;
59
 					}
62
 					}
60
 					break;
63
 					break;
61
 
64
 
62
 				case 'v': case 'V':
65
 				case 'v': case 'V':
63
 					if (serialWriteString(VERSION)) {
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
 						return -1;
89
 						return -1;
66
 					}
90
 					}
67
 					break;
91
 					break;
69
 				default:
93
 				default:
70
 					c = ERROR;
94
 					c = ERROR;
71
 					if (serialWriteTry(&c, 1)) {
95
 					if (serialWriteTry(&c, 1)) {
72
-						printf("Could not write to pseudo terminal");
96
+						printf("Could not write to pseudo terminal\n");
73
 						return -1;
97
 						return -1;
74
 					}
98
 					}
75
 					break;
99
 					break;
82
 	return 0;
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
 int serialWriteString(char *s) {
121
 int serialWriteString(char *s) {
86
 	return serialWriteTry(s, strlen(s));
122
 	return serialWriteTry(s, strlen(s));
87
 }
123
 }

+ 1
- 0
HardwareEmulator/makefile View File

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

+ 64
- 0
HardwareEmulator/mem.c View File

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 View File

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 View File


Loading…
Cancel
Save