aboutsummaryrefslogtreecommitdiffstats
path: root/core/serial_usb_android.cpp
diff options
context:
space:
mode:
authorGravatar Christof Arnosti <charno@charno.ch>2020-03-08 15:25:55 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-08 11:22:55 -0700
commitb15b9c6cd0e8d83ec12a868c10cf184217f51309 (patch)
tree78ea1cf9a3772745222830053545af080e667c8d /core/serial_usb_android.cpp
parentfe932059fe0e989089bd259c541db41d358cfa47 (diff)
downloadsubsurface-b15b9c6cd0e8d83ec12a868c10cf184217f51309.tar.gz
usb-serial-for-android: Implement timeout-handling
Since the Android USB stack and subsequently the usb-serial-for-android driver have problems with read-timeouts, the read-timeout is now implemented in AndroidSerial.java. Also, DC_STATUS_TIMEOUT is returned if there are less bytes returned than expected. Different chipsets seem to behave differently with usb-serial-for-android. On CP210x the read blocks until there is some data here, but on FTDI the chip seems to return whatever is currently in the buffer (so 0 bytes if the buffer is empty). This different behaviour should be mitigated by the changes by this commit. Signed-off-by: Christof Arnosti <charno@charno.ch>
Diffstat (limited to 'core/serial_usb_android.cpp')
-rw-r--r--core/serial_usb_android.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/core/serial_usb_android.cpp b/core/serial_usb_android.cpp
index a5db132ae..8f53c56bb 100644
--- a/core/serial_usb_android.cpp
+++ b/core/serial_usb_android.cpp
@@ -141,7 +141,11 @@ static dc_status_t serial_usb_android_read(void *io, void *data, size_t size, si
env->GetByteArrayRegion(array, 0, retval, (jbyte *) data);
env->DeleteLocalRef(array);
TRACE (device->context, "%s: actual read size: %i", __FUNCTION__, retval);
- return DC_STATUS_SUCCESS;
+
+ if (retval < size)
+ return DC_STATUS_TIMEOUT;
+ else
+ return DC_STATUS_SUCCESS;
}