From 4c690eefd6d0bd3259b89544f8ab0f7862976f07 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 19 Jun 2022 19:00:19 +0200 Subject: [PATCH] fix discard pod --- .../pump/omnipod/dash/driver/comm/session/Connection.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt index b403cb7af2..bfb565830c 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt @@ -6,6 +6,7 @@ import android.bluetooth.BluetoothManager import android.bluetooth.BluetoothProfile import android.content.Context import android.os.SystemClock +import info.nightscout.androidaps.Constants import info.nightscout.androidaps.extensions.toHex import info.nightscout.androidaps.plugins.pump.omnipod.dash.BuildConfig import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Ids @@ -137,11 +138,16 @@ class Connection( connectionWaitCond.timeoutMs?.let { bleCommCallbacks.waitForConnection(it) } + val startWaiting = System.currentTimeMillis() connectionWaitCond.stopConnection?.let { while (!bleCommCallbacks.waitForConnection(STOP_CONNECTING_CHECK_INTERVAL_MS)) { if (it.count == 0L) { throw ConnectException("stopConnecting called") } + val secondsElapsed = (System.currentTimeMillis() - startWaiting) / 1000 + if (secondsElapsed > MAX_WAIT_FOR_CONNECTION_SECONDS) { + throw ConnectException("connection timeout") + } } } } catch (e: InterruptedException) { @@ -199,6 +205,7 @@ class Connection( const val BASE_CONNECT_TIMEOUT_MS = 10000L const val MIN_DISCOVERY_TIMEOUT_MS = 10000L const val STOP_CONNECTING_CHECK_INTERVAL_MS = 500L + const val MAX_WAIT_FOR_CONNECTION_SECONDS = Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS + 10 const val SLEEP_WHEN_FAILING_TO_CONNECT_GATT = 10000L } }