diff --git a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt index c7e43749f..26be612c7 100644 --- a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt @@ -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() } } } } diff --git a/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt b/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt index b00774a0e..8dd81830e 100644 --- a/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt +++ b/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt @@ -418,7 +418,9 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD cb: (Result) -> 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