This commit is contained in:
Andrei Vereha 2021-04-21 22:37:58 +02:00
parent 3ef983b732
commit 3a2fa6d04f
4 changed files with 35 additions and 42 deletions

View file

@ -33,6 +33,7 @@ import io.reactivex.Observable
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.rxkotlin.blockingSubscribeBy import io.reactivex.rxkotlin.blockingSubscribeBy
import io.reactivex.rxkotlin.subscribeBy import io.reactivex.rxkotlin.subscribeBy
import io.reactivex.rxkotlin.toCompletable
import org.json.JSONObject import org.json.JSONObject
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
@ -81,7 +82,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
override fun isConnected(): Boolean { override fun isConnected(): Boolean {
// TODO // TODO
return true return podStateManager.activeCommand == null
} }
override fun isConnecting(): Boolean { override fun isConnecting(): Boolean {
@ -99,7 +100,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
} }
override fun connect(reason: String) { override fun connect(reason: String) {
// TODO if (podStateManager.activeCommand == null) {
return
}
getPumpStatus("unconfirmed command")
} }
override fun disconnect(reason: String) { override fun disconnect(reason: String) {
@ -414,33 +418,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
} }
private fun playTestBeep(): PumpEnactResult { private fun playTestBeep(): PumpEnactResult {
return executeProgrammingCommand(
return Single.create<PumpEnactResult> { source -> history.createRecord(OmnipodCommandType.PLAY_TEST_BEEP),
Observable.concat( omnipodManager.playBeep(BeepType.LONG_SINGLE_BEEP)
omnipodManager.playBeep(BeepType.LONG_SINGLE_BEEP), )
history.updateFromState(podStateManager).toObservable(),
podStateManager.updateActiveCommand().toObservable(),
).subscribeBy(
onNext = { podEvent ->
aapsLogger.debug(
LTag.PUMP,
"Received PodEvent in playTestBeep: $podEvent"
)
},
onError = { throwable ->
aapsLogger.error(LTag.PUMP, "Error in playTestBeep", throwable)
source.onSuccess(
PumpEnactResult(injector).success(false).enacted(false).comment(throwable.message)
)
},
onComplete = {
aapsLogger.debug("playTestBeep completed")
source.onSuccess(
PumpEnactResult(injector).success(true).enacted(true)
)
}
)
}.blockingGet()
} }
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) { override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {

View file

@ -86,8 +86,10 @@ class Connection(
val msgIO = MessageIO(aapsLogger, cmdBleIO, dataBleIO) val msgIO = MessageIO(aapsLogger, cmdBleIO, dataBleIO)
fun connect() { fun connect() {
disconnect() if (session!=null) {
disconnect()
}
aapsLogger.debug("Connecting")
if (!gattConnection.connect()) { if (!gattConnection.connect()) {
throw FailedToConnectException("connect() returned false") throw FailedToConnectException("connect() returned false")
} }
@ -167,6 +169,6 @@ class Connection(
companion object { companion object {
private const val CONNECT_TIMEOUT_MS = 7000 private const val CONNECT_TIMEOUT_MS = 12000
} }
} }

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state
import android.os.SystemClock import android.os.SystemClock
import com.google.gson.Gson import com.google.gson.Gson
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
@ -19,6 +20,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.Completable import io.reactivex.Completable
import io.reactivex.Maybe import io.reactivex.Maybe
import io.reactivex.Single
import java.io.Serializable import java.io.Serializable
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
@ -201,16 +203,24 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
} }
@Synchronized @Synchronized
override fun updateActiveCommand(): Maybe<PodEvent> { override fun updateActiveCommand() = Maybe.create<PodEvent> { source ->
return podState.activeCommand?.run { podState.activeCommand?.run {
logger.debug(
"Trying to confirm active command with parameters: $activeCommand " +
"lastResponse=$lastStatusResponseReceived " +
"$sequenceNumberOfLastProgrammingCommand $historyId"
)
if (createdRealtime >= lastStatusResponseReceived) if (createdRealtime >= lastStatusResponseReceived)
Maybe.empty() source.onComplete()
else if (sequenceNumberOfLastProgrammingCommand == sequence) else {
Maybe.just(PodEvent.CommandConfirmed(historyId)) podState.activeCommand = null
else if (sequenceNumberOfLastProgrammingCommand == sequence)
Maybe.just(PodEvent.CommandDenied(historyId)) source.onSuccess(PodEvent.CommandConfirmed(historyId))
else
source.onSuccess(PodEvent.CommandDenied(historyId))
}
} }
?: Maybe.empty() // no active programming command ?: source.onComplete() // no active programming command
} }
override fun increaseEapAkaSequenceNumber(): ByteArray { override fun increaseEapAkaSequenceNumber(): ByteArray {

View file

@ -74,8 +74,8 @@ class DashHistory @Inject constructor(
fun getRecordsAfter(time: Long): Single<List<HistoryRecordEntity>> = dao.allSince(time) fun getRecordsAfter(time: Long): Single<List<HistoryRecordEntity>> = dao.allSince(time)
fun updateFromState(podState: OmnipodDashPodStateManager): Completable { fun updateFromState(podState: OmnipodDashPodStateManager) = Completable.defer {
return podState.activeCommand?.run { podState.activeCommand?.run {
when { when {
createdRealtime <= podState.lastStatusResponseReceived && createdRealtime <= podState.lastStatusResponseReceived &&