Browse Source

continued implementing the download function

Max Nuding 12 years ago
parent
commit
98206a2f0f
1 changed files with 114 additions and 7 deletions
  1. 114
    7
      HardwareEmulator/main.c

+ 114
- 7
HardwareEmulator/main.c View File

@@ -8,6 +8,7 @@
8 8
 #include <strings.h>
9 9
 
10 10
 #include "serial.h"
11
+#include "mem.h"
11 12
 
12 13
 #define VERSION "LED-Cube Emu V1\n"
13 14
 
@@ -125,19 +126,125 @@ int sendFrames() {
125 126
 	return -1;*/
126 127
 	char c;
127 128
 	ssize_t size;
128
-	int a, frameCount, f, d;
129
-	char data[65];
130
-
131
-	c = OK;
132
-	if (serialWriteTry(&c, 1)) {
129
+	int a, frameCount, f, d, duration, animationCount;
130
+	char *data;
131
+	
132
+	/*while(keepRunning) {
133
+		size = serialRead(&c, 1);
134
+		if(size == 1) {
135
+			break;
136
+		} else if (size == -1) {
137
+			printf("Couldn't read from pseudo terminal");
138
+		}
139
+	}*/
140
+	//Insert check
141
+	
142
+	animationCount = 1; //dummy
143
+	c = animationCount;
144
+	if(serialWriteTry(&c, 1)) {
133 145
 		printf("Could not write to pseudo terminal\n");
134
-		return -1;
146
+		return -1;	
135 147
 	}
136 148
 
149
+	/*while(keepRunning) {
150
+		size = serialRead(&c, 1);
151
+		if(size == 1) {
152
+			break;
153
+		} else if (size == -1) {
154
+			printf("Couldn't read from pseudo terminal");
155
+		}
156
+	}*/
157
+	//Insert check
158
+
159
+
137 160
 	frameCount = framesStored();
138
-	printf("FrameCount = %d\n", frameCount);
161
+	printf("Sending frameCount = %d\n", frameCount);
139 162
 
163
+	c = frameCount;
164
+	if(serialWriteTry(&c, 1)) {
165
+		printf("Could not write to pseudo terminal\n");
166
+		return -1;	
167
+	}
168
+
169
+	/*while(keepRunning) {
170
+		size = serialRead(&c, 1);
171
+		if(size == 1) {
172
+			break;
173
+		} else if (size == -1) {
174
+			printf("Couldn't read from pseudo terminal");
175
+		}
176
+	}*/
177
+	//Insert check
140 178
 	
179
+	duration = 1; //Dummy duration time
180
+	for(f = 0; f < frameCount; f++){
181
+		data = getFrame(f);
182
+		
183
+		printf("Sending duration = %d of frame %d\n", duration, f);
184
+		c = duration;
185
+		
186
+		if(serialWriteTry(&c, 1)) {
187
+			printf("Could not write to pseudo terminal\n");
188
+			return -1;	
189
+		}
190
+
191
+		/*while(keepRunning) {
192
+			size = serialRead(&c, 1);
193
+			if(size == 1) {
194
+				break;
195
+			} else if (size == -1) {
196
+				printf("Couldn't read from pseudo terminal");
197
+			}
198
+		}*/ //insert check	
199
+		for(d = 0; d < 64; d++) {
200
+			c = data[d];
201
+			
202
+			if(serialWriteTry(&c, 1)) {
203
+				printf("Could not write to pseudo terminal\n");
204
+				return -1;	
205
+			}
206
+		}
207
+		printf("Data of frame %d successfully sent\n", f);
208
+
209
+		/*while(keepRunning) {
210
+			size = serialRead(&c, 1);
211
+			if(size == 1) {
212
+				break;
213
+			} else if (size == -1) {
214
+				printf("Couldn't read from pseudo terminal");
215
+			}
216
+		}*/
217
+	//Insert check
218
+	}
219
+
220
+	printf("Done sending frames, start sending final sequence\n");
221
+	c = OK;
222
+	if(serialWriteTry(&c, 1)) {
223
+		printf("Could not write to pseudo terminal\n");
224
+		return -1;	
225
+	}
226
+	if(serialWriteTry(&c, 1)) {
227
+		printf("Could not write to pseudo terminal\n");
228
+		return -1;	
229
+	}
230
+	if(serialWriteTry(&c, 1)) {
231
+		printf("Could not write to pseudo terminal\n");
232
+		return -1;	
233
+	}
234
+	if(serialWriteTry(&c, 1)) {
235
+		printf("Could not write to pseudo terminal\n");
236
+		return -1;	
237
+	}
238
+	
239
+	/*while(keepRunning) {
240
+		size = serialRead(&c, 1);
241
+		if(size == 1) {
242
+			break;
243
+		} else if (size == -1) {
244
+			printf("Couldn't read from pseudo terminal");
245
+		}
246
+	}*/
247
+	return 0;	
141 248
 }
142 249
 
143 250
 int recieveFrames() {

Loading…
Cancel
Save