restart service discovery

This commit is contained in:
Andrei Vereha 2021-06-25 22:14:05 +02:00
parent a62b5f7f70
commit 8f5ecfd0d6
2 changed files with 5 additions and 0 deletions

View file

@ -21,6 +21,7 @@ class ServiceDiscoverer(
*/
fun discoverServices(): Map<CharacteristicType, BluetoothGattCharacteristic> {
logger.debug(LTag.PUMPBTCOMM, "Discovering services")
bleCallbacks.startServiceDiscovery()
val discover = gatt.discoverServices()
if (!discover) {
throw ConnectException("Could not start discovering services`")

View file

@ -61,6 +61,10 @@ class BleCommCallbacks(
}
}
fun startServiceDiscovery() {
serviceDiscoveryComplete = CountDownLatch(1)
}
fun waitForServiceDiscovery(timeoutMs: Int) {
try {
serviceDiscoveryComplete.await(timeoutMs.toLong(), TimeUnit.MILLISECONDS)