Ben Meadors 2025-04-06 18:06:23 -05:00 zatwierdzone przez GitHub
commit b78a405ce3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 36 dodań i 0 usunięć

Wyświetl plik

@ -111,6 +111,8 @@ class BluetoothInterface @AssistedInject constructor(
UUID.fromString("f75c76d2-129e-4dad-a1dd-7866124401e7")
val BTM_FROMNUM_CHARACTER: UUID =
UUID.fromString("ed9da18c-a800-4f66-a670-aa7547e34453")
val BTM_LOGRADIO_CHARACTER: UUID =
UUID.fromString("6c6fd238-78fa-436b-aacf-15c5be1ef2e2")
/**
* this is created in onCreate()
@ -132,6 +134,7 @@ class BluetoothInterface @AssistedInject constructor(
?: throw RadioNotConnectedException("BLE service not found")
private lateinit var fromNum: BluetoothGattCharacteristic
private lateinit var logRadio: BluetoothGattCharacteristic
/**
* With the new rev2 api, our first send is to start the configure readbacks. In that case,
@ -275,6 +278,37 @@ class BluetoothInterface @AssistedInject constructor(
}
}
private fun startWatchingLogRadio() {
safe?.setNotify(logRadio, true) {
service.serviceScope.handledLaunch {
safe?.asyncReadCharacteristic(logRadio) {
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()) {
val logMessage = b.toString(Charsets.UTF_8)
if (logMessage.startsWith("INFO"))
info(logMessage.replace("INFO | ", ""))
else if (logMessage.startsWith("DEBUG"))
debug(logMessage.replace("DEBUG | ", ""))
else if (logMessage.startsWith("WARN"))
warn(logMessage.replace("WARN | ", ""))
else if (logMessage.startsWith("ERROR"))
error(logMessage.replace("ERROR | ", ""))
else
debug(logMessage)
}
} catch (ex: BLEException) {
scheduleReconnect("error during doReadFromRadio - disconnecting, ${ex.message}")
}
}
}
}
}
/**
* Some buggy BLE stacks can fail on initial connect, with either missing services or missing characteristics. If that happens we
* disconnect and try again when the device reenumerates.
@ -338,6 +372,7 @@ class BluetoothInterface @AssistedInject constructor(
} */
fromNum = getCharacteristic(BTM_FROMNUM_CHARACTER)
logRadio = getCharacteristic(BTM_LOGRADIO_CHARACTER)
// We treat the first send by a client as special
isFirstSend = true
@ -347,6 +382,7 @@ class BluetoothInterface @AssistedInject constructor(
// Immediately broadcast any queued packets sitting on the device
doReadFromRadio(true)
startWatchingLogRadio()
} catch (ex: BLEException) {
scheduleReconnect(
"Unexpected error in initial device enumeration, forcing disconnect $ex"