[PATCH] Cochran: Add read retry
John Van Ostrand
john at vanostrand.com
Wed Sep 6 13:02:03 PDT 2017
Using FTDI for custom_io resulted in very unrealible reads. This
patch allows more reliable use of FTDI custom io, like what might
be needed when used on a mobile device like Android.
---
src/cochran_commander.c | 34 +++++++++++++++++++++++++++++++---
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/src/cochran_commander.c b/src/cochran_commander.c
index 921c8c0..1de6c07 100644
--- a/src/cochran_commander.c
+++ b/src/cochran_commander.c
@@ -806,11 +806,39 @@ cochran_commander_device_set_fingerprint (dc_device_t *abstract, const unsigned
static dc_status_t
+cochran_commander_read_retry(cochran_commander_device_t *device, dc_event_progress_t *progress, unsigned int address, unsigned char data[], unsigned int size)
+{
+
+ dc_status_t rc = DC_STATUS_SUCCESS;
+ unsigned int nretries = 0;
+ int last_current = 0;
+
+ if (progress)
+ last_current = progress->current;
+
+ while (nretries < 3) {
+ if (nretries)
+ WARNING(device->base.context, "Read error, attempting retry.");
+
+ rc = cochran_commander_read(device, progress, address, data, size);
+ if (rc == DC_STATUS_SUCCESS)
+ return rc;
+
+ nretries++;
+ if (progress)
+ progress->current = last_current;
+ }
+
+ return rc;
+}
+
+
+static dc_status_t
cochran_commander_device_read (dc_device_t *abstract, unsigned int address, unsigned char data[], unsigned int size)
{
cochran_commander_device_t *device = (cochran_commander_device_t *) abstract;
- return cochran_commander_read(device, NULL, address, data, size);
+ return cochran_commander_read_retry(device, NULL, address, data, size);
}
@@ -854,7 +882,7 @@ cochran_commander_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
return rc;
// Read the sample data, logbook and sample data are contiguous
- rc = cochran_commander_read (device, &progress, device->layout->rb_logbook_begin, dc_buffer_get_data(buffer), size);
+ rc = cochran_commander_read_retry (device, &progress, device->layout->rb_logbook_begin, dc_buffer_get_data(buffer), size);
if (rc != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to read the sample data.");
return rc;
@@ -934,7 +962,7 @@ cochran_commander_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
}
// Request log book
- rc = cochran_commander_read(device, &progress, layout->rb_logbook_begin, data.logbook, data.logbook_size);
+ rc = cochran_commander_read_retry(device, &progress, layout->rb_logbook_begin, data.logbook, data.logbook_size);
if (rc != DC_STATUS_SUCCESS) {
status = rc;
goto error;
--
2.4.11
More information about the devel
mailing list