Implement progress events for the device_dump() function.
A helper function is added to simplify implementing the devic_dump() function on top of the device_read() function, and enable progress events automatically.
This commit is contained in:
parent
e2c6bdf880
commit
a87398b7c6
@ -69,6 +69,9 @@ device_init (device_t *device, const device_backend_t *backend);
|
|||||||
void
|
void
|
||||||
device_event_emit (device_t *device, device_event_t event, const void *data);
|
device_event_emit (device_t *device, device_event_t event, const void *data);
|
||||||
|
|
||||||
|
device_status_t
|
||||||
|
device_dump_read (device_t *device, unsigned char data[], unsigned int size, unsigned int blocksize);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|||||||
37
src/device.c
37
src/device.c
@ -125,6 +125,43 @@ device_dump (device_t *device, dc_buffer_t *buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
device_status_t
|
||||||
|
device_dump_read (device_t *device, unsigned char data[], unsigned int size, unsigned int blocksize)
|
||||||
|
{
|
||||||
|
if (device == NULL)
|
||||||
|
return DEVICE_STATUS_UNSUPPORTED;
|
||||||
|
|
||||||
|
if (device->backend->read == NULL)
|
||||||
|
return DEVICE_STATUS_UNSUPPORTED;
|
||||||
|
|
||||||
|
// Enable progress notifications.
|
||||||
|
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
|
||||||
|
progress.maximum = size;
|
||||||
|
device_event_emit (device, DEVICE_EVENT_PROGRESS, &progress);
|
||||||
|
|
||||||
|
unsigned int nbytes = 0;
|
||||||
|
while (nbytes < size) {
|
||||||
|
// Calculate the packet size.
|
||||||
|
unsigned int len = size - nbytes;
|
||||||
|
if (len > blocksize)
|
||||||
|
len = blocksize;
|
||||||
|
|
||||||
|
// Read the packet.
|
||||||
|
device_status_t rc = device->backend->read (device, nbytes, data + nbytes, len);
|
||||||
|
if (rc != DEVICE_STATUS_SUCCESS)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
// Update and emit a progress event.
|
||||||
|
progress.current += len;
|
||||||
|
device_event_emit (device, DEVICE_EVENT_PROGRESS, &progress);
|
||||||
|
|
||||||
|
nbytes += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DEVICE_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
device_status_t
|
device_status_t
|
||||||
device_foreach (device_t *device, dive_callback_t callback, void *userdata)
|
device_foreach (device_t *device, dive_callback_t callback, void *userdata)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -351,12 +351,8 @@ mares_puck_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
|||||||
return DEVICE_STATUS_MEMORY;
|
return DEVICE_STATUS_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
device_status_t rc = mares_puck_device_read (abstract, 0x00,
|
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
|
dc_buffer_get_size (buffer), MARES_PUCK_PACKET_SIZE);
|
||||||
if (rc != DEVICE_STATUS_SUCCESS)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
return DEVICE_STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -481,12 +481,8 @@ oceanic_atom2_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
|||||||
return DEVICE_STATUS_MEMORY;
|
return DEVICE_STATUS_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
device_status_t rc = oceanic_atom2_device_read (abstract, 0x00,
|
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
|
dc_buffer_get_size (buffer), OCEANIC_ATOM2_PACKET_SIZE);
|
||||||
if (rc != DEVICE_STATUS_SUCCESS)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
return DEVICE_STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -457,12 +457,8 @@ oceanic_veo250_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
|||||||
return DEVICE_STATUS_MEMORY;
|
return DEVICE_STATUS_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
device_status_t rc = oceanic_veo250_device_read (abstract, 0x00,
|
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
|
dc_buffer_get_size (buffer), OCEANIC_VEO250_PACKET_SIZE);
|
||||||
if (rc != DEVICE_STATUS_SUCCESS)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
return DEVICE_STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -533,12 +533,8 @@ oceanic_vtpro_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
|||||||
return DEVICE_STATUS_MEMORY;
|
return DEVICE_STATUS_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
device_status_t rc = oceanic_vtpro_device_read (abstract, 0x00,
|
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
|
dc_buffer_get_size (buffer), OCEANIC_VTPRO_PACKET_SIZE);
|
||||||
if (rc != DEVICE_STATUS_SUCCESS)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
return DEVICE_STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -230,17 +230,8 @@ suunto_common2_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
|||||||
return DEVICE_STATUS_MEMORY;
|
return DEVICE_STATUS_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable progress notifications.
|
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||||
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
|
dc_buffer_get_size (buffer), SZ_PACKET);
|
||||||
progress.maximum = SZ_MEMORY;
|
|
||||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
|
||||||
|
|
||||||
device_status_t rc = suunto_common2_read (abstract, 0x00,
|
|
||||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), &progress);
|
|
||||||
if (rc != DEVICE_STATUS_SUCCESS)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
return DEVICE_STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -542,17 +542,8 @@ suunto_vyper_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
|||||||
return DEVICE_STATUS_MEMORY;
|
return DEVICE_STATUS_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable progress notifications.
|
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||||
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
|
dc_buffer_get_size (buffer), SUUNTO_VYPER_PACKET_SIZE);
|
||||||
progress.maximum = SUUNTO_VYPER_MEMORY_SIZE;
|
|
||||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
|
||||||
|
|
||||||
device_status_t rc = suunto_vyper_read (abstract, 0x00,
|
|
||||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), &progress);
|
|
||||||
if (rc != DEVICE_STATUS_SUCCESS)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
return DEVICE_STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user