From 25182315770a42f61a0c4bfa23e013e2aee8f60f Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 1 Oct 2018 16:21:42 -0700 Subject: [PATCH] Aqualung i770R: add packet send retry on reply failure It seems to make things more robust. Without this, the first packet in particular seems to easily get lost, and the retry gets things going again. Signed-off-by: Linus Torvalds --- src/oceanic_atom2.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index 0ca6f53..94bbbf4 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -777,6 +777,7 @@ oceanic_atom2_ble_transfer (oceanic_atom2_device_t *device, const unsigned char unsigned char cmd_seq = device->sequence; unsigned char pkt_seq; dc_status_t ret = DC_STATUS_SUCCESS; + int retry = 3; /* * The serial commands have a NUL byte at the end. It's bogus. @@ -786,6 +787,10 @@ oceanic_atom2_ble_transfer (oceanic_atom2_device_t *device, const unsigned char if (csize > 1 && csize < 8 && !command[csize-1]) csize--; +retry: + if (--retry < 0) + return ret; + ret = oceanic_atom2_ble_write(device, command, csize); if (ret != DC_STATUS_SUCCESS) return ret; @@ -796,12 +801,13 @@ oceanic_atom2_ble_transfer (oceanic_atom2_device_t *device, const unsigned char unsigned int size; ret = oceanic_atom2_ble_read(device, &buf, &size); if (ret != DC_STATUS_SUCCESS) - return ret; + goto retry; if (size > asize && buf[0] == ACK) { memcpy(answer, buf+1, asize); } else { ERROR(device->base.base.context, "Result too small: got %d bytes, expected at least %d bytes", size, asize+1); ret = DC_STATUS_IO; + goto retry; } free(buf); }