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,103 +118,114 @@ int main(int argc, char *argv[]) {
118 118
 }
119 119
 
120 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 121
 	char c;
128 122
 	ssize_t size;
129
-	int a, frameCount, f, d, duration, animationCount;
123
+	int frameCount, f, d;
130 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 136
 	if(serialWriteTry(&c, 1)) {
145 137
 		printf("Could not write to pseudo terminal\n");
146 138
 		return -1;	
147 139
 	}
148 140
 
149
-	/*while(keepRunning) {
141
+	// Await OK from Host software
142
+	while(keepRunning) {
150 143
 		size = serialRead(&c, 1);
151
-		if(size == 1) {
144
+		if (size == 1) {
152 145
 			break;
153 146
 		} else if (size == -1) {
154 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 157
 	frameCount = framesStored();
161 158
 	printf("Sending frameCount = %d\n", frameCount);
162
-
163 159
 	c = frameCount;
164 160
 	if(serialWriteTry(&c, 1)) {
165 161
 		printf("Could not write to pseudo terminal\n");
166 162
 		return -1;	
167 163
 	}
168 164
 
169
-	/*while(keepRunning) {
165
+	// Await OK from Host software
166
+	while(keepRunning) {
170 167
 		size = serialRead(&c, 1);
171
-		if(size == 1) {
168
+		if (size == 1) {
172 169
 			break;
173 170
 		} else if (size == -1) {
174 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 180
 	for(f = 0; f < frameCount; f++){
181 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 185
 		if(serialWriteTry(&c, 1)) {
187 186
 			printf("Could not write to pseudo terminal\n");
188 187
 			return -1;	
189 188
 		}
190 189
 
191
-		/*while(keepRunning) {
190
+		// Await OK from Host software
191
+		while(keepRunning) {
192 192
 			size = serialRead(&c, 1);
193
-			if(size == 1) {
193
+			if (size == 1) {
194 194
 				break;
195 195
 			} else if (size == -1) {
196 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 206
 		for(d = 0; d < 64; d++) {
200 207
 			c = data[d];
201
-			
202 208
 			if(serialWriteTry(&c, 1)) {
203 209
 				printf("Could not write to pseudo terminal\n");
204 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 217
 			size = serialRead(&c, 1);
211
-			if(size == 1) {
218
+			if (size == 1) {
212 219
 				break;
213 220
 			} else if (size == -1) {
214 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 231
 	printf("Done sending frames, start sending final sequence\n");
@@ -236,14 +247,20 @@ int sendFrames() {
236 247
 		return -1;	
237 248
 	}
238 249
 	
239
-	/*while(keepRunning) {
250
+	// Await OK from Host software
251
+	while(keepRunning) {
240 252
 		size = serialRead(&c, 1);
241
-		if(size == 1) {
253
+		if (size == 1) {
242 254
 			break;
243 255
 		} else if (size == -1) {
244 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 264
 	return 0;	
248 265
 }
249 266
 

Loading…
Cancel
Save