This commit is contained in:
Andrei Vereha 2021-07-11 18:05:06 +02:00
parent c4fc95768e
commit 4fc0a34785
4 changed files with 5 additions and 7 deletions

View file

@ -99,7 +99,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
statusChecker = Runnable { statusChecker = Runnable {
refreshStatusOnUnacknowledgedCommands() refreshStatusOnUnacknowledgedCommands()
updatePodWarnings() updatePodWarnings()
createFakeTBRWhenNoActivePod() // createFakeTBRWhenNoActivePod()
// TODO: this is called from the main thread
handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS) handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS)
} }
} }

View file

@ -186,7 +186,6 @@ class OmnipodDashBleManagerImpl @Inject constructor(
throw BusyException() throw BusyException()
} }
try { try {
if (podState.ltk != null) { if (podState.ltk != null) {
emitter.onNext(PodEvent.AlreadyPaired) emitter.onNext(PodEvent.AlreadyPaired)
emitter.onComplete() emitter.onComplete()
@ -222,7 +221,6 @@ class OmnipodDashBleManagerImpl @Inject constructor(
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
aapsLogger.info(LTag.PUMPCOMM, "Got LTK: ${pairResult.ltk.toHex()}") aapsLogger.info(LTag.PUMPCOMM, "Got LTK: ${pairResult.ltk.toHex()}")
} }
emitter.onNext(PodEvent.EstablishingSession) emitter.onNext(PodEvent.EstablishingSession)
establishSession(pairResult.msgSeq) establishSession(pairResult.msgSeq)
emitter.onNext(PodEvent.Connected) emitter.onNext(PodEvent.Connected)
@ -241,8 +239,6 @@ class OmnipodDashBleManagerImpl @Inject constructor(
} }
companion object { companion object {
const val MAX_NUMBER_OF_CONNECTION_ATTEMPTS = 2
const val CONTROLLER_ID = 4242 // TODO read from preferences or somewhere else. const val CONTROLLER_ID = 4242 // TODO read from preferences or somewhere else.
private const val CONNECT_TIMEOUT_MULTIPLIER = 4
} }
} }

View file

@ -32,7 +32,7 @@ class ServiceDiscoverer(
bleCallbacks.waitForServiceDiscovery(it) bleCallbacks.waitForServiceDiscovery(it)
} }
connectionWaitCond.stopConnection?.let { connectionWaitCond.stopConnection?.let {
while (!bleCallbacks.waitForConnection(STOP_CONNECTING_CHECK_INTERVAL_MS)) { while (!bleCallbacks.waitForServiceDiscovery(STOP_CONNECTING_CHECK_INTERVAL_MS)) {
if (it.count == 0L) { if (it.count == 0L) {
throw ConnectException("stopConnecting called") throw ConnectException("stopConnecting called")
} }

View file

@ -66,12 +66,13 @@ class BleCommCallbacks(
serviceDiscoveryComplete = CountDownLatch(1) serviceDiscoveryComplete = CountDownLatch(1)
} }
fun waitForServiceDiscovery(timeoutMs: Long) { fun waitForServiceDiscovery(timeoutMs: Long): Boolean {
try { try {
serviceDiscoveryComplete.await(timeoutMs, TimeUnit.MILLISECONDS) serviceDiscoveryComplete.await(timeoutMs, TimeUnit.MILLISECONDS)
} catch (e: InterruptedException) { } catch (e: InterruptedException) {
aapsLogger.warn(LTag.PUMPBTCOMM, "Interrupted while waiting for ServiceDiscovery") aapsLogger.warn(LTag.PUMPBTCOMM, "Interrupted while waiting for ServiceDiscovery")
} }
return serviceDiscoveryComplete.count == 0L
} }
fun confirmWrite(expectedPayload: ByteArray, expectedUUID: String, timeoutMs: Long): WriteConfirmation { fun confirmWrite(expectedPayload: ByteArray, expectedUUID: String, timeoutMs: Long): WriteConfirmation {