Fixing a bug, when it had to download more than 0x40 frames.
--- a/pce.c Sun Oct 24 13:06:54 2010 +0200
+++ b/pce.c Sun Oct 24 19:24:00 2010 +0200
@@ -204,37 +204,43 @@
parse_data(data);
- char frame[3];
- frame[0] = 0;
- frame[1] = 0;
- frame[2] = num_frames;
+ int sec = 0;
+ do
+ {
+ char frame[3];
+ int step_frames = num_frames >= 0x40 ? 0x40 : num_frames;
+ frame[0] = 0;
+ frame[1] = 0;
+ frame[2] = step_frames;
- res = usb_bulk_write(handle, ep_out, frame, 3, 1000);
- assert(res == 3);
+ res = usb_bulk_write(handle, ep_out, frame, 3, 1000);
+ assert(res == 3);
- res = usb_bulk_read(handle, ep_in, data, 3, 1000);
- assert(res == 3);
- fprintf(stderr, "Debug: %02hhx%02hhx%02hhx\n", data[0], data[1], data[2]);
- assert(data[0] == 2);
+ res = usb_bulk_read(handle, ep_in, data, 3, 1000);
+ assert(res == 3);
+ fprintf(stderr, "Debug: %02hhx%02hhx%02hhx\n", data[0], data[1], data[2]);
+ assert(data[0] == 2);
- int i;
- int sec = 0;
- for(i=0; i < num_frames; ++i)
- {
- res = usb_bulk_read(handle, ep_in, data, 64, 1000);
- assert(res == 64);
- int take = (num >= 64) ? 64 : num;
+ int i;
+ for(i=0; i < step_frames; ++i)
+ {
+ res = usb_bulk_read(handle, ep_in, data, 64, 5000);
+ assert(res == 64);
+ int take = (num >= 64) ? 64 : num;
- int j;
- for(j=0; j<take; j+=4)
- {
- float temp = *((short int *) (data + j)) / 10.;
- float hum = *((short int *) (data + j + 2)) / 10.;
- fprintf(outfile, "%i %g %g\n", sec, temp, hum);
- sec++;
+ int j;
+ for(j=0; j<take; j+=4)
+ {
+ float temp = *((short int *) (data + j)) / 10.;
+ float hum = *((short int *) (data + j + 2)) / 10.;
+ fprintf(outfile, "%i %g %g\n", sec, temp, hum);
+ sec++;
+ }
+ num -= 64;
+ num_frames -= 1;
}
- num -= 64;
}
+ while(num_frames > 0);
}
}