Integrate the new poll function
Replace the manual polling, implemented using a combination of the dc_iostream_get_available and dc_iostream_sleep functions, with the new and more efficient poll function.
This commit is contained in:
parent
f6fa2b84bc
commit
af5716d685
@ -326,15 +326,7 @@ hw_ostc3_transfer (hw_ostc3_device_t *device,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (delay && device->available == 0) {
|
if (delay && device->available == 0) {
|
||||||
unsigned int count = delay / 100;
|
dc_iostream_poll (device->iostream, delay);
|
||||||
for (unsigned int i = 0; i < count; ++i) {
|
|
||||||
size_t available = 0;
|
|
||||||
status = dc_iostream_get_available (device->iostream, &available);
|
|
||||||
if (status == DC_STATUS_SUCCESS && available > 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
dc_iostream_sleep (device->iostream, 100);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd != EXIT) {
|
if (cmd != EXIT) {
|
||||||
|
|||||||
@ -177,13 +177,11 @@ mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
|
|||||||
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
|
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
|
||||||
|
|
||||||
// Wait until some data arrives.
|
// Wait until some data arrives.
|
||||||
size_t available = 0;
|
while (dc_iostream_poll (device->iostream, 100) == DC_STATUS_TIMEOUT) {
|
||||||
while (dc_iostream_get_available (device->iostream, &available) == DC_STATUS_SUCCESS && available == 0) {
|
|
||||||
if (device_is_cancelled (abstract))
|
if (device_is_cancelled (abstract))
|
||||||
return DC_STATUS_CANCELLED;
|
return DC_STATUS_CANCELLED;
|
||||||
|
|
||||||
device_event_emit (abstract, DC_EVENT_WAITING, NULL);
|
device_event_emit (abstract, DC_EVENT_WAITING, NULL);
|
||||||
dc_iostream_sleep (device->iostream, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receive the header of the package.
|
// Receive the header of the package.
|
||||||
|
|||||||
@ -309,14 +309,13 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t *
|
|||||||
{
|
{
|
||||||
dc_status_t status = DC_STATUS_SUCCESS;
|
dc_status_t status = DC_STATUS_SUCCESS;
|
||||||
dc_device_t *abstract = (dc_device_t *) device;
|
dc_device_t *abstract = (dc_device_t *) device;
|
||||||
size_t available = 0;
|
|
||||||
|
|
||||||
// Enable progress notifications.
|
// Enable progress notifications.
|
||||||
dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
|
dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
|
||||||
device_event_emit (&device->base, DC_EVENT_PROGRESS, &progress);
|
device_event_emit (&device->base, DC_EVENT_PROGRESS, &progress);
|
||||||
|
|
||||||
// Waiting for greeting message.
|
// Waiting for greeting message.
|
||||||
while (dc_iostream_get_available (device->iostream, &available) == DC_STATUS_SUCCESS && available == 0) {
|
while (dc_iostream_poll (device->iostream, 300) == DC_STATUS_TIMEOUT) {
|
||||||
if (device_is_cancelled (abstract))
|
if (device_is_cancelled (abstract))
|
||||||
return DC_STATUS_CANCELLED;
|
return DC_STATUS_CANCELLED;
|
||||||
|
|
||||||
@ -330,8 +329,6 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t *
|
|||||||
ERROR (abstract->context, "Failed to reject the packet.");
|
ERROR (abstract->context, "Failed to reject the packet.");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_iostream_sleep (device->iostream, 300);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the ID string.
|
// Read the ID string.
|
||||||
@ -385,12 +382,11 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t *
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait for the data packet.
|
// Wait for the data packet.
|
||||||
while (dc_iostream_get_available (device->iostream, &available) == DC_STATUS_SUCCESS && available == 0) {
|
while (dc_iostream_poll (device->iostream, 100) == DC_STATUS_TIMEOUT) {
|
||||||
if (device_is_cancelled (abstract))
|
if (device_is_cancelled (abstract))
|
||||||
return DC_STATUS_CANCELLED;
|
return DC_STATUS_CANCELLED;
|
||||||
|
|
||||||
device_event_emit (&device->base, DC_EVENT_WAITING, NULL);
|
device_event_emit (&device->base, DC_EVENT_WAITING, NULL);
|
||||||
dc_iostream_sleep (device->iostream, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the current system time.
|
// Fetch the current system time.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user