kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
Merge 0f954cc2f1
into 25fe0a1e05
commit
b78a405ce3
|
@ -111,6 +111,8 @@ class BluetoothInterface @AssistedInject constructor(
|
||||||
UUID.fromString("f75c76d2-129e-4dad-a1dd-7866124401e7")
|
UUID.fromString("f75c76d2-129e-4dad-a1dd-7866124401e7")
|
||||||
val BTM_FROMNUM_CHARACTER: UUID =
|
val BTM_FROMNUM_CHARACTER: UUID =
|
||||||
UUID.fromString("ed9da18c-a800-4f66-a670-aa7547e34453")
|
UUID.fromString("ed9da18c-a800-4f66-a670-aa7547e34453")
|
||||||
|
val BTM_LOGRADIO_CHARACTER: UUID =
|
||||||
|
UUID.fromString("6c6fd238-78fa-436b-aacf-15c5be1ef2e2")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this is created in onCreate()
|
* this is created in onCreate()
|
||||||
|
@ -132,6 +134,7 @@ class BluetoothInterface @AssistedInject constructor(
|
||||||
?: throw RadioNotConnectedException("BLE service not found")
|
?: throw RadioNotConnectedException("BLE service not found")
|
||||||
|
|
||||||
private lateinit var fromNum: BluetoothGattCharacteristic
|
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,
|
* 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
|
* 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.
|
* disconnect and try again when the device reenumerates.
|
||||||
|
@ -338,6 +372,7 @@ class BluetoothInterface @AssistedInject constructor(
|
||||||
} */
|
} */
|
||||||
|
|
||||||
fromNum = getCharacteristic(BTM_FROMNUM_CHARACTER)
|
fromNum = getCharacteristic(BTM_FROMNUM_CHARACTER)
|
||||||
|
logRadio = getCharacteristic(BTM_LOGRADIO_CHARACTER)
|
||||||
|
|
||||||
// We treat the first send by a client as special
|
// We treat the first send by a client as special
|
||||||
isFirstSend = true
|
isFirstSend = true
|
||||||
|
@ -347,6 +382,7 @@ class BluetoothInterface @AssistedInject constructor(
|
||||||
|
|
||||||
// Immediately broadcast any queued packets sitting on the device
|
// Immediately broadcast any queued packets sitting on the device
|
||||||
doReadFromRadio(true)
|
doReadFromRadio(true)
|
||||||
|
startWatchingLogRadio()
|
||||||
} catch (ex: BLEException) {
|
} catch (ex: BLEException) {
|
||||||
scheduleReconnect(
|
scheduleReconnect(
|
||||||
"Unexpected error in initial device enumeration, forcing disconnect $ex"
|
"Unexpected error in initial device enumeration, forcing disconnect $ex"
|
||||||
|
|
Ładowanie…
Reference in New Issue