From b4777a1312135799695170662ea3512e190c9be9 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Mon, 28 Jun 2021 20:54:47 +0200 Subject: [PATCH] wip: stop connecting --- .../omnipod/dash/OmnipodDashPumpPlugin.kt | 23 +++++++++++++++---- .../omnipod/dash/driver/OmnipodDashManager.kt | 4 ++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt index 9585f79885..7c9059c558 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/OmnipodDashPumpPlugin.kt @@ -48,8 +48,10 @@ import io.reactivex.Completable import io.reactivex.Single import org.json.JSONObject import java.util.* +import java.util.concurrent.CountDownLatch import javax.inject.Inject import javax.inject.Singleton +import kotlin.concurrent.thread import kotlin.math.ceil import kotlin.random.Random @@ -73,6 +75,7 @@ class OmnipodDashPumpPlugin @Inject constructor( private val handler: Handler = Handler(Looper.getMainLooper()) private lateinit var statusChecker: Runnable var nextPodWarningCheck : Long = 0 + @Volatile var stopConnecting: CountDownLatch? = null companion object { private const val BOLUS_RETRY_INTERVAL_MS = 2000.toLong() @@ -171,19 +174,29 @@ class OmnipodDashPumpPlugin @Inject constructor( } override fun connect(reason: String) { - // empty on purpose + thread( + start = true, + name = "ConnectionThread", + ) { + // TODO quadruple check that we are not creating a party of Threads here + try { + val stop = CountDownLatch(1) + stopConnecting = stop + omnipodManager.connect(stop) + } finally { + stopConnecting = null + } + } } override fun disconnect(reason: String) { - // TODO + omnipodManager.disconnect() } override fun stopConnecting() { - // TODO + stopConnecting?.let { it.countDown() } } - - override fun getPumpStatus(reason: String) { aapsLogger.debug(LTag.PUMP, "getPumpStatus reason=$reason") if (reason != "REQUESTED BY USER" && !podStateManager.isActivationCompleted) { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManager.kt index 0a5b743f94..a905016f99 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManager.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManager.kt @@ -9,6 +9,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definitio import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.ResponseType import io.reactivex.Observable import java.util.* +import java.util.concurrent.CountDownLatch interface OmnipodDashManager { @@ -39,4 +40,7 @@ interface OmnipodDashManager { fun silenceAlerts(alertTypes: EnumSet): Observable fun deactivatePod(): Observable + + fun disconnect() + fun connect(stop: CountDownLatch) }