fix discard pod

This commit is contained in:
Andrei Vereha 2022-06-19 19:00:19 +02:00
parent 1eb7cd69d9
commit 4c690eefd6

View file

@ -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
}
}