Mercurial > ~darius > hgwebdir.cgi > wh1080
comparison wh1080.c @ 7:9a14029b3782
- Wait longer (100msec) for a read, and reduce the number of retries to match.
- Print out if we read OK after more than 1 attempt for diagnostic purposes.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Thu, 11 Feb 2010 12:47:59 +1030 |
parents | b22a888eb975 |
children | e3d2b5500b53 |
comparison
equal
deleted
inserted
replaced
6:e0b32014ed14 | 7:9a14029b3782 |
---|---|
228 /* | 228 /* |
229 * Read 8 bytes from the device. | 229 * Read 8 bytes from the device. |
230 */ | 230 */ |
231 int read_station (char *buf) | 231 int read_station (char *buf) |
232 { | 232 { |
233 #define MAXTRIES 100 | 233 #define MAXTRIES 10 |
234 int bytes_read, i = 0; | 234 int bytes_read, i = 0; |
235 | 235 |
236 /* XXX Find out what all this means, and be cleverer about retries */ | 236 /* XXX Find out what all this means, and be cleverer about retries */ |
237 do | 237 do |
238 { | 238 { |
239 if ((bytes_read = usb_interrupt_read (station, | 239 if ((bytes_read = usb_interrupt_read (station, |
240 USB_ENDPOINT_IN | USB_RECIP_INTERFACE, | 240 USB_ENDPOINT_IN | USB_RECIP_INTERFACE, |
241 buf, | 241 buf, |
242 8, | 242 8, |
243 10 )) == 8 ){ | 243 100 )) == 8 ){ |
244 if (i > 5) | 244 if (i > 0) |
245 fprintf(stderr, "Read OK after %d tries\n", i + 1); | 245 fprintf(stderr, "Read OK after %d tries\n", i + 1); |
246 return bytes_read; | 246 return bytes_read; |
247 } | 247 } |
248 | 248 fprintf(stderr, "Retrying..\n"); |
249 if (errno == EAGAIN) | 249 |
250 usleep (10000); | 250 usleep (10000); |
251 i++; | 251 i++; |
252 } | 252 } |
253 while (errno != EINTR && i < MAXTRIES); | 253 while (errno != EINTR && i < MAXTRIES); |
254 if (i == MAXTRIES) { | 254 if (i == MAXTRIES) { |
255 #if 0 | |
256 fprintf(stderr, | 255 fprintf(stderr, |
257 "Can't read from device after %d attempts\n", MAXTRIES); | 256 "Can't read from device after %d attempts\n", MAXTRIES); |
258 #endif | |
259 } else | 257 } else |
260 fprintf (stderr, | 258 fprintf (stderr, |
261 "Can't read device: %s (%d)\n", | 259 "Can't read device: %s (%d)\n", |
262 usb_strerror (), | 260 usb_strerror (), |
263 errno ); | 261 errno ); |
291 if (write_station_control ((char *) request) == 0) | 289 if (write_station_control ((char *) request) == 0) |
292 exit (1); /* XXX we've already complained */ | 290 exit (1); /* XXX we've already complained */ |
293 | 291 |
294 while (bytes_read < 32) { | 292 while (bytes_read < 32) { |
295 if ((i = read_station ((char *) &buf [bytes_read])) == 0) { | 293 if ((i = read_station ((char *) &buf [bytes_read])) == 0) { |
296 #if 0 | |
297 fprintf(stderr, "Couldn't read from the device, rerequesting\n"); | 294 fprintf(stderr, "Couldn't read from the device, rerequesting\n"); |
298 #endif | |
299 goto rerequest; | 295 goto rerequest; |
300 } | 296 } |
301 | 297 |
302 bytes_read += i; | 298 bytes_read += i; |
303 } | 299 } |