Fix #23: autobug, if we get mystery BLE error 133 while reading messages

drop the BLE link and reconnect and try again.
pull/28/head
geeksville 2020-04-26 13:03:35 -07:00
rodzic d28eb97497
commit 5822dddc6c
2 zmienionych plików z 22 dodań i 12 usunięć

Wyświetl plik

@ -295,19 +295,27 @@ class RadioInterfaceService : Service(), Logging {
else {
val fromRadio = getCharacteristic(BTM_FROMRADIO_CHARACTER)
safe!!.asyncReadCharacteristic(fromRadio) {
val b = it.getOrThrow()
.value.clone() // We clone the array just in case, I'm not sure if they keep reusing the array
try {
val b = it.getOrThrow()
.value.clone() // We clone the array just in case, I'm not sure if they keep reusing the array
if (b.isNotEmpty()) {
debug("Received ${b.size} bytes from radio")
handleFromRadio(b)
if (b.isNotEmpty()) {
debug("Received ${b.size} bytes from radio")
handleFromRadio(b)
// Queue up another read, until we run out of packets
doReadFromRadio(firstRead)
} else {
debug("Done reading from radio, fromradio is empty")
if (firstRead) // If we just finished our initial download, now we want to start listening for notifies
startWatchingFromNum()
// Queue up another read, until we run out of packets
doReadFromRadio(firstRead)
} else {
debug("Done reading from radio, fromradio is empty")
if (firstRead) // If we just finished our initial download, now we want to start listening for notifies
startWatchingFromNum()
}
} catch (ex: BLEException) {
errormsg(
"error during doReadFromRadio",
ex
)
serviceScope.handledLaunch { retryDueToException() }
}
}
}

Wyświetl plik

@ -418,7 +418,9 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
cb: (Result<Unit>) -> Unit,
lostConnectCb: () -> Unit
) {
logAssert(workQueue.isEmpty() && currentWork == null) // I don't think anything should be able to sneak in front
logAssert(workQueue.isEmpty())
logAssert(currentWork == null) // I don't think anything should be able to sneak in front
lostConnectCallback = lostConnectCb
connectionCallback = if (autoConnect)
cb