Browse Source

Fixed download in emulator.

Thomas Buck 12 years ago
parent
commit
7cc8543a48
1 changed files with 62 additions and 45 deletions
  1. 62
    45
      HardwareEmulator/main.c

+ 62
- 45
HardwareEmulator/main.c View File

118
 }
118
 }
119
 
119
 
120
 int sendFrames() {
120
 int sendFrames() {
121
-	/*char c = ERROR;
122
-	printf("Not implemented!\n");
123
-	if (serialWriteTry(&c, 1)) {
124
-		printf("Could not write to pseudo terminal\n");
125
-	}
126
-	return -1;*/
127
 	char c;
121
 	char c;
128
 	ssize_t size;
122
 	ssize_t size;
129
-	int a, frameCount, f, d, duration, animationCount;
123
+	int frameCount, f, d;
130
 	char *data;
124
 	char *data;
131
 	
125
 	
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
126
+	// Acknowledge sending this
127
+	c = OK;
128
+	if(serialWriteTry(&c, 1)) {
129
+		printf("Could not write to pseudo terminal\n");
130
+		return -1;	
131
+	}
141
 	
132
 	
142
-	animationCount = 1; //dummy
143
-	c = animationCount;
133
+	// Send animation count. We dont store animations --> send 1
134
+	printf("Sending animation count.\n");
135
+	c = 1;
144
 	if(serialWriteTry(&c, 1)) {
136
 	if(serialWriteTry(&c, 1)) {
145
 		printf("Could not write to pseudo terminal\n");
137
 		printf("Could not write to pseudo terminal\n");
146
 		return -1;	
138
 		return -1;	
147
 	}
139
 	}
148
 
140
 
149
-	/*while(keepRunning) {
141
+	// Await OK from Host software
142
+	while(keepRunning) {
150
 		size = serialRead(&c, 1);
143
 		size = serialRead(&c, 1);
151
-		if(size == 1) {
144
+		if (size == 1) {
152
 			break;
145
 			break;
153
 		} else if (size == -1) {
146
 		} else if (size == -1) {
154
 			printf("Couldn't read from pseudo terminal");
147
 			printf("Couldn't read from pseudo terminal");
148
+			return -1;
155
 		}
149
 		}
156
-	}*/
157
-	//Insert check
158
-
150
+	}
151
+	if (c != OK) {
152
+		printf("Invalid acknowledge from Host (%d)!", c);
153
+		return -1;
154
+	}
159
 
155
 
156
+	// Send framecount
160
 	frameCount = framesStored();
157
 	frameCount = framesStored();
161
 	printf("Sending frameCount = %d\n", frameCount);
158
 	printf("Sending frameCount = %d\n", frameCount);
162
-
163
 	c = frameCount;
159
 	c = frameCount;
164
 	if(serialWriteTry(&c, 1)) {
160
 	if(serialWriteTry(&c, 1)) {
165
 		printf("Could not write to pseudo terminal\n");
161
 		printf("Could not write to pseudo terminal\n");
166
 		return -1;	
162
 		return -1;	
167
 	}
163
 	}
168
 
164
 
169
-	/*while(keepRunning) {
165
+	// Await OK from Host software
166
+	while(keepRunning) {
170
 		size = serialRead(&c, 1);
167
 		size = serialRead(&c, 1);
171
-		if(size == 1) {
168
+		if (size == 1) {
172
 			break;
169
 			break;
173
 		} else if (size == -1) {
170
 		} else if (size == -1) {
174
 			printf("Couldn't read from pseudo terminal");
171
 			printf("Couldn't read from pseudo terminal");
172
+			return -1;
175
 		}
173
 		}
176
-	}*/
177
-	//Insert check
174
+	}
175
+	if (c != OK) {
176
+		printf("Invalid acknowledge from Host (%d)!", c);
177
+		return -1;
178
+	}
178
 	
179
 	
179
-	duration = 1; //Dummy duration time
180
 	for(f = 0; f < frameCount; f++){
180
 	for(f = 0; f < frameCount; f++){
181
 		data = getFrame(f);
181
 		data = getFrame(f);
182
-		
183
-		printf("Sending duration = %d of frame %d\n", duration, f);
184
-		c = duration;
185
-		
182
+
183
+		printf("Sending duration = %d of frame %d\n", data[64], f);
184
+		c = data[64]; // duration at end of frame data
186
 		if(serialWriteTry(&c, 1)) {
185
 		if(serialWriteTry(&c, 1)) {
187
 			printf("Could not write to pseudo terminal\n");
186
 			printf("Could not write to pseudo terminal\n");
188
 			return -1;	
187
 			return -1;	
189
 		}
188
 		}
190
 
189
 
191
-		/*while(keepRunning) {
190
+		// Await OK from Host software
191
+		while(keepRunning) {
192
 			size = serialRead(&c, 1);
192
 			size = serialRead(&c, 1);
193
-			if(size == 1) {
193
+			if (size == 1) {
194
 				break;
194
 				break;
195
 			} else if (size == -1) {
195
 			} else if (size == -1) {
196
 				printf("Couldn't read from pseudo terminal");
196
 				printf("Couldn't read from pseudo terminal");
197
+				return -1;
197
 			}
198
 			}
198
-		}*/ //insert check	
199
+		}
200
+		if (c != OK) {
201
+			printf("Invalid acknowledge from Host (%d)!", c);
202
+			return -1;
203
+		}
204
+
205
+		printf("Sending frame data...");
199
 		for(d = 0; d < 64; d++) {
206
 		for(d = 0; d < 64; d++) {
200
 			c = data[d];
207
 			c = data[d];
201
-			
202
 			if(serialWriteTry(&c, 1)) {
208
 			if(serialWriteTry(&c, 1)) {
203
 				printf("Could not write to pseudo terminal\n");
209
 				printf("Could not write to pseudo terminal\n");
204
 				return -1;	
210
 				return -1;	
205
 			}
211
 			}
206
 		}
212
 		}
207
-		printf("Data of frame %d successfully sent\n", f);
213
+		printf(" %d successfully sent\n", f);
208
 
214
 
209
-		/*while(keepRunning) {
215
+		// Await OK from Host software
216
+		while(keepRunning) {
210
 			size = serialRead(&c, 1);
217
 			size = serialRead(&c, 1);
211
-			if(size == 1) {
218
+			if (size == 1) {
212
 				break;
219
 				break;
213
 			} else if (size == -1) {
220
 			} else if (size == -1) {
214
 				printf("Couldn't read from pseudo terminal");
221
 				printf("Couldn't read from pseudo terminal");
222
+				return -1;
215
 			}
223
 			}
216
-		}*/
217
-	//Insert check
224
+		}
225
+		if (c != OK) {
226
+			printf("Invalid acknowledge from Host (%d)!", c);
227
+			return -1;
228
+		}
218
 	}
229
 	}
219
 
230
 
220
 	printf("Done sending frames, start sending final sequence\n");
231
 	printf("Done sending frames, start sending final sequence\n");
236
 		return -1;	
247
 		return -1;	
237
 	}
248
 	}
238
 	
249
 	
239
-	/*while(keepRunning) {
250
+	// Await OK from Host software
251
+	while(keepRunning) {
240
 		size = serialRead(&c, 1);
252
 		size = serialRead(&c, 1);
241
-		if(size == 1) {
253
+		if (size == 1) {
242
 			break;
254
 			break;
243
 		} else if (size == -1) {
255
 		} else if (size == -1) {
244
 			printf("Couldn't read from pseudo terminal");
256
 			printf("Couldn't read from pseudo terminal");
257
+			return -1;
245
 		}
258
 		}
246
-	}*/
259
+	}
260
+	if (c != OK) {
261
+		printf("Invalid acknowledge from Host (%d)!", c);
262
+	}
263
+
247
 	return 0;	
264
 	return 0;	
248
 }
265
 }
249
 
266
 

Loading…
Cancel
Save