From 018198dc17a9462ae045185db472d05fd1745a31 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 26 Dec 2019 10:18:36 +0100 Subject: [PATCH] Increase the timeout to 3 seconds The BLE communication is significant slower than usb-serial. The first BLE data packet of each response often takes longer than one second to arrive. This causes the first attempt to fail with a timeout. The second attempt will appear to succeed, because it actually receives the response of the first attempt. But now the next command will fail, because it will receive the response of the second attempt of the previous command. Increasing the timeout and adding an extra delay before retrying, avoids this problem. Reported-by: Linus Torvalds --- src/mares_iconhd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mares_iconhd.c b/src/mares_iconhd.c index 2a714a4..6388bb5 100644 --- a/src/mares_iconhd.c +++ b/src/mares_iconhd.c @@ -326,6 +326,7 @@ mares_iconhd_transfer (mares_iconhd_device_t *device, const unsigned char comman return rc; // Discard any garbage bytes. + dc_iostream_sleep (device->iostream, 100); dc_iostream_purge (device->iostream, DC_DIRECTION_INPUT); device->available = 0; device->offset = 0; @@ -482,8 +483,8 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_ goto error_free; } - // Set the timeout for receiving data (1000 ms). - status = dc_iostream_set_timeout (device->iostream, 1000); + // Set the timeout for receiving data (3000 ms). + status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); goto error_free;