mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
immediately fail bluetooth links if we get a read or write error
This commit is contained in:
parent
6baae70125
commit
d282c7911e
1 changed files with 23 additions and 19 deletions
|
|
@ -210,28 +210,34 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
|
|||
|
||||
/// Send a packet/command out the radio link
|
||||
override fun handleSendToRadio(a: ByteArray) {
|
||||
safe?.let { s ->
|
||||
val uuid = BTM_TORADIO_CHARACTER
|
||||
debug("queuing ${a.size} bytes to $uuid")
|
||||
try {
|
||||
safe?.let { s ->
|
||||
val uuid = BTM_TORADIO_CHARACTER
|
||||
debug("queuing ${a.size} bytes to $uuid")
|
||||
|
||||
// Note: we generate a new characteristic each time, because we are about to
|
||||
// change the data and we want the data stored in the closure
|
||||
val toRadio = getCharacteristic(uuid)
|
||||
toRadio.value = a
|
||||
// Note: we generate a new characteristic each time, because we are about to
|
||||
// change the data and we want the data stored in the closure
|
||||
val toRadio = getCharacteristic(uuid)
|
||||
toRadio.value = a
|
||||
|
||||
s.asyncWriteCharacteristic(toRadio) { r ->
|
||||
try {
|
||||
r.getOrThrow()
|
||||
debug("write of ${a.size} bytes completed")
|
||||
s.asyncWriteCharacteristic(toRadio) { r ->
|
||||
try {
|
||||
r.getOrThrow()
|
||||
debug("write of ${a.size} bytes completed")
|
||||
|
||||
if (isFirstSend) {
|
||||
isFirstSend = false
|
||||
doReadFromRadio(false)
|
||||
if (isFirstSend) {
|
||||
isFirstSend = false
|
||||
doReadFromRadio(false)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
warn("error during asyncWriteCharacteristic - disconnecting, ${ex.message}")
|
||||
service.serviceScope.handledLaunch { retryDueToException() }
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
errormsg("Ignoring sendToRadio exception: $ex")
|
||||
}
|
||||
}
|
||||
} catch (ex: BLEException) {
|
||||
warn("error during handleSendToRadio - disconnecting, ${ex.message}")
|
||||
service.serviceScope.handledLaunch { retryDueToException() }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -257,9 +263,7 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
|
|||
startWatchingFromNum()
|
||||
}
|
||||
} catch (ex: BLEException) {
|
||||
warn(
|
||||
"error during doReadFromRadio - disconnecting, ${ex.message}"
|
||||
)
|
||||
warn("error during doReadFromRadio - disconnecting, ${ex.message}")
|
||||
service.serviceScope.handledLaunch { retryDueToException() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue