Poll the serial line to avoid the use of an infinite timeout.

Because the user needs to initiate the transfer on the device itself, we
have to wait for an unknown amount of time. The infinite timeout works,
but causes problems if the data never arrives. By polling the serial
line, an application can at least cancel the operation.
This commit is contained in:
Jef Driesen 2010-11-14 22:19:58 +01:00
parent 685660e42a
commit 642996bfe6

View File

@ -122,7 +122,7 @@ mares_nemo_device_open (device_t **out, const char* name)
}
// Set the timeout for receiving data (1000 ms).
if (serial_set_timeout (device->port, -1) == -1) {
if (serial_set_timeout (device->port, 1000) == -1) {
WARNING ("Failed to set the timeout.");
serial_close (device->port);
free (device);
@ -138,6 +138,9 @@ mares_nemo_device_open (device_t **out, const char* name)
return DEVICE_STATUS_IO;
}
// Make sure everything is in a sane state.
serial_flush (device->port, SERIAL_QUEUE_BOTH);
*out = (device_t*) device;
return DEVICE_STATUS_SUCCESS;
@ -185,6 +188,15 @@ mares_nemo_device_dump (device_t *abstract, dc_buffer_t *buffer)
progress.maximum = MEMORYSIZE + 20;
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
// Wait until some data arrives.
while (serial_get_received (device->port) == 0) {
if (device_is_cancelled (abstract))
return DEVICE_STATUS_CANCELLED;
device_event_emit (abstract, DEVICE_EVENT_WAITING, NULL);
serial_sleep (100);
}
// Receive the header of the package.
unsigned char header = 0x00;
for (unsigned int i = 0; i < 20;) {