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 e43de9ed52..5c60486659 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 @@ -17,6 +17,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event.PodEven import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.ActivationProgress import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepType import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.ResponseType +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.CommandConfirmed import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.DashHistory import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.BolusRecord @@ -25,9 +26,11 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data.TempBas import info.nightscout.androidaps.plugins.pump.omnipod.dash.ui.OmnipodDashOverviewFragment import info.nightscout.androidaps.plugins.pump.omnipod.dash.util.mapProfileToBasalProgram import info.nightscout.androidaps.queue.commands.CustomCommand +import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.TimeChangeType import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP +import io.reactivex.Completable import io.reactivex.Observable import io.reactivex.Single import io.reactivex.rxkotlin.blockingSubscribeBy @@ -44,6 +47,7 @@ class OmnipodDashPumpPlugin @Inject constructor( private val sp: SP, private val profileFunction: ProfileFunction, private val history: DashHistory, + private val pumpSync: PumpSync, injector: HasAndroidInjector, aapsLogger: AAPSLogger, resourceHelper: ResourceHelper, @@ -151,12 +155,12 @@ class OmnipodDashPumpPlugin @Inject constructor( } override fun setNewBasalProfile(profile: Profile): PumpEnactResult { - return executeProgrammingCommand( + return executeSimpleProgrammingCommand( history.createRecord( commandType = OmnipodCommandType.SET_BASAL_PROFILE ), - omnipodManager.setBasalProgram(mapProfileToBasalProgram(profile)) - ) + omnipodManager.setBasalProgram(mapProfileToBasalProgram(profile)).ignoreElements() + ).toPumpEnactResult() } override fun isThisProfileSet(profile: Profile): Boolean = podStateManager.basalProgram?.let { @@ -240,10 +244,10 @@ class OmnipodDashPumpPlugin @Inject constructor( override fun stopBolusDelivering() { // TODO update Treatments (?) - executeProgrammingCommand( + executeSimpleProgrammingCommand( history.createRecord(OmnipodCommandType.CANCEL_BOLUS), - omnipodManager.stopBolus(), - ) + omnipodManager.stopBolus().ignoreElements() + ).toPumpEnactResult() } override fun setTempBasalAbsolute( @@ -253,24 +257,84 @@ class OmnipodDashPumpPlugin @Inject constructor( enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType ): PumpEnactResult { - // TODO update Treatments - // TODO check for existing basal - // check existing basal(locally and maybe? get status) - // if enforceNew -> cancel it() - // else -> return error that existing basal is running - // set new temp basal - // update treatments - // profit - return executeProgrammingCommand( - history.createRecord( + val tempBasalBeeps = sp.getBoolean(R.string.key_omnipod_common_tbr_beeps_enabled, false) + + return executeSimpleProgrammingCommand( + historyEntry = history.createRecord( commandType = OmnipodCommandType.SET_TEMPORARY_BASAL, tempBasalRecord = TempBasalRecord(duration = durationInMinutes, rate = absoluteRate) ), - omnipodManager.setTempBasal( + command = omnipodManager.setTempBasal( absoluteRate, - durationInMinutes.toShort() + durationInMinutes.toShort(), + tempBasalBeeps ) + .filter { podEvent -> podEvent is PodEvent.CommandSent } + .map { pumpSyncTempBasal(it, tbrType) } + .ignoreElements(), + pre = observeNoActiveTempBasal() + ).toPumpEnactResult() + } + + private fun pumpSyncTempBasal( + podEvent: PodEvent, + tbrType: PumpSync.TemporaryBasalType + ): Boolean { + val activeCommand = podStateManager.activeCommand + if (activeCommand == null || podEvent !is PodEvent.CommandSent) { + throw IllegalArgumentException( + "No active command or illegal podEvent: " + + "activeCommand=$activeCommand" + + "podEvent=$podEvent" + ) + } + val historyEntry = history.getById(activeCommand.historyId) + val record = historyEntry.record + if (record == null || !(record is TempBasalRecord)) { + throw IllegalArgumentException("Illegal recording in history: $record. Expected a temp basal") + } + val ret = pumpSync.syncTemporaryBasalWithPumpId( + timestamp = historyEntry.createdAt, + rate = record.rate, + duration = T.mins(record.duration.toLong()).msecs(), + isAbsolute = true, + type = tbrType, + pumpId = historyEntry.pumpId(), + pumpType = PumpType.OMNIPOD_DASH, + pumpSerial = serialNumber() ) + aapsLogger.debug(LTag.PUMP, "Pump sync temp basal: $ret") + return ret + } + + private fun observeNoActiveTempBasal(): Completable { + return Completable.defer { + val expectedState = pumpSync.expectedPumpState() + if (expectedState.temporaryBasal == null) { + aapsLogger.info(LTag.PUMP, "No temporary basal to cancel") + Completable.complete() + } else { + // enforceNew == true + aapsLogger.info(LTag.PUMP, "Canceling existing temp basal") + executeSimpleProgrammingCommand( + history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL), + omnipodManager.stopTempBasal().ignoreElements() + ) + } + } + } + + private fun observeActiveTempBasal(): Completable { + return Completable.defer { + if (podStateManager.tempBasalActive) + Completable.complete() + else + Completable.error( + java.lang.IllegalStateException( + "There is no active basal to cancel" + ) + ) + } } override fun setTempBasalPercent( @@ -292,11 +356,47 @@ class OmnipodDashPumpPlugin @Inject constructor( } override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult { - // TODO update Treatments - return executeProgrammingCommand( - history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL), - omnipodManager.stopTempBasal() - ) + return executeSimpleProgrammingCommand( + historyEntry = history.createRecord(OmnipodCommandType.CANCEL_TEMPORARY_BASAL), + command = omnipodManager.stopTempBasal().ignoreElements(), + pre = observeActiveTempBasal(), + ).toPumpEnactResult() + } + + fun Completable.toPumpEnactResult(): PumpEnactResult { + return this.toSingleDefault(PumpEnactResult(injector).success(true).enacted(true)) + .onErrorReturnItem(PumpEnactResult(injector).success(false).enacted(false)) + .blockingGet() + } + + private fun handleCommandConfirmation(confirmation: CommandConfirmed) { + val historyEntry = history.getById(confirmation.historyId) + when (historyEntry.commandType) { + OmnipodCommandType.CANCEL_TEMPORARY_BASAL -> + // We can't invalidate this command, + // and this is why it is pumpSync-ed at this point + if (confirmation.success) { + pumpSync.syncStopTemporaryBasalWithPumpId( + historyEntry.createdAt, + historyEntry.pumpId(), + PumpType.OMNIPOD_DASH, + serialNumber() + ) + } + OmnipodCommandType.SET_TEMPORARY_BASAL -> + // This treatment was synced before sending the command + if (!confirmation.success) { + // TODO: the ID here is the temp basal id, not the pumpId!! + pumpSync.invalidateTemporaryBasal(historyEntry.pumpId()) + } + + else -> + aapsLogger.warn( + LTag.PUMP, + "Will not sync confirmed command of type: $historyEntry and " + + "succes: ${confirmation.success}" + ) + } } override fun cancelExtendedBolus(): PumpEnactResult { @@ -414,26 +514,26 @@ class OmnipodDashPumpPlugin @Inject constructor( } private fun suspendDelivery(): PumpEnactResult { - return executeProgrammingCommand( + return executeSimpleProgrammingCommand( history.createRecord(OmnipodCommandType.RESUME_DELIVERY), - omnipodManager.suspendDelivery() - ) + omnipodManager.suspendDelivery().ignoreElements() + ).toPumpEnactResult() } private fun resumeDelivery(): PumpEnactResult { return profileFunction.getProfile()?.let { - executeProgrammingCommand( + executeSimpleProgrammingCommand( history.createRecord(OmnipodCommandType.RESUME_DELIVERY), - omnipodManager.setBasalProgram(mapProfileToBasalProgram(it)) - ) + omnipodManager.setBasalProgram(mapProfileToBasalProgram(it)).ignoreElements() + ).toPumpEnactResult() } ?: PumpEnactResult(injector).success(false).enacted(false).comment("No profile active") // TODO i18n } private fun deactivatePod(): PumpEnactResult { - return executeProgrammingCommand( + return executeSimpleProgrammingCommand( history.createRecord(OmnipodCommandType.DEACTIVATE_POD), - omnipodManager.deactivatePod() - ) + omnipodManager.deactivatePod().ignoreElements() + ).toPumpEnactResult() } private fun handleTimeChange(): PumpEnactResult { @@ -447,10 +547,10 @@ class OmnipodDashPumpPlugin @Inject constructor( } private fun playTestBeep(): PumpEnactResult { - return executeProgrammingCommand( + return executeSimpleProgrammingCommand( history.createRecord(OmnipodCommandType.PLAY_TEST_BEEP), - omnipodManager.playBeep(BeepType.LONG_SINGLE_BEEP) - ) + omnipodManager.playBeep(BeepType.LONG_SINGLE_BEEP).ignoreElements() + ).toPumpEnactResult() } override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) { @@ -474,50 +574,27 @@ class OmnipodDashPumpPlugin @Inject constructor( commandQueue.customCommand(CommandHandleTimeChange(false), null) } - private fun observeAddNewActiveCommandToHistory(observeCreateHistoryEntry: Single): Observable { - return observeCreateHistoryEntry.flatMapObservable { - podStateManager.createActiveCommand(it).toObservable() - } - } - - private fun executeProgrammingCommand( - observeCreateHistoryEntry: Single, - command: Observable - ): PumpEnactResult { - return Single.create { source -> - Observable.concat( - listOf( - podStateManager.observeNoActiveCommand(), - observeAddNewActiveCommandToHistory(observeCreateHistoryEntry), - command, - history.updateFromState(podStateManager).toObservable(), - podStateManager.updateActiveCommand().toObservable(), - ) - ).subscribeBy( - onNext = { podEvent -> - aapsLogger.debug( - LTag.PUMP, - "Received PodEvent: $podEvent" - ) - }, - onError = { throwable -> - aapsLogger.error(LTag.PUMP, "Error executing command", throwable) - // Here we assume that onError will be called only BEFORE we manage to send a command - // If it gets called later, we will have the command as "not sent" in history and will not try to - // get it's final status, even if it was send - - podStateManager.maybeMarkActiveCommandFailed() - source.onSuccess( - PumpEnactResult(injector).success(false).enacted(false).comment(throwable.toString()) - ) - }, - onComplete = { - aapsLogger.debug("Command completed") - source.onSuccess( - PumpEnactResult(injector).success(true).enacted(true) - ) - } + private fun executeSimpleProgrammingCommand( + historyEntry: Single, + command: Completable, + pre: Completable = Completable.complete(), + ): Completable { + return Completable.concat( + listOf( + pre, + podStateManager.observeNoActiveCommand().ignoreElements(), + historyEntry + .flatMap { podStateManager.createActiveCommand(it) } + .ignoreElement(), + command.doOnError { + podStateManager.activeCommand?.sendError = it + aapsLogger.error(LTag.PUMP, "Error executing command", it) + }.onErrorComplete(), + history.updateFromState(podStateManager), + podStateManager.updateActiveCommand() + .map { handleCommandConfirmation(it) } + .ignoreElement() ) - }.blockingGet() + ) } } 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 2b9333bdab..b6dccbf118 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 @@ -24,7 +24,7 @@ interface OmnipodDashManager { fun setTime(): Observable - fun setTempBasal(rate: Double, durationInMinutes: Short): Observable + fun setTempBasal(rate: Double, durationInMinutes: Short, tempBasalBeeps: Boolean): Observable fun stopTempBasal(): Observable diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt index 5de1c4fd1f..0d44fd4b3f 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/OmnipodDashManagerImpl.kt @@ -460,14 +460,14 @@ class OmnipodDashManagerImpl @Inject constructor( return Observable.empty() } - private fun observeSendProgramTempBasalCommand(rate: Double, durationInMinutes: Short): Observable { + private fun observeSendProgramTempBasalCommand(rate: Double, durationInMinutes: Short, tempBasalBeeps: Boolean): Observable { return Observable.defer { - // TODO cancel current temp basal (if active) bleManager.sendCommand( ProgramTempBasalCommand.Builder() .setSequenceNumber(podStateManager.messageSequenceNumber) .setUniqueId(podStateManager.uniqueId!!.toInt()) .setNonce(NONCE) + .setProgramReminder(ProgramReminder(tempBasalBeeps, tempBasalBeeps, 0)) .setRateInUnitsPerHour(rate) .setDurationInMinutes(durationInMinutes) .build(), @@ -476,11 +476,11 @@ class OmnipodDashManagerImpl @Inject constructor( } } - override fun setTempBasal(rate: Double, durationInMinutes: Short): Observable { + override fun setTempBasal(rate: Double, durationInMinutes: Short, tempBasalBeeps: Boolean): Observable { return Observable.concat( observePodRunning, observeConnectToPod, - observeSendProgramTempBasalCommand(rate, durationInMinutes) + observeSendProgramTempBasalCommand(rate, durationInMinutes, tempBasalBeeps) ) // TODO these would be common for any observable returned in a public function in this class .doOnNext(PodEventInterceptor()) @@ -700,7 +700,7 @@ class OmnipodDashManagerImpl @Inject constructor( inner class ErrorInterceptor : Consumer { override fun accept(throwable: Throwable) { - logger.debug(LTag.PUMP, "Intercepted error in OmnipodDashManagerImpl: ${throwable.javaClass.simpleName}") + logger.debug(LTag.PUMP, "Intercepted error in OmnipodDashManagerImpl: $throwable") } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManager.kt index f3708c8031..b2400713c7 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManager.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManager.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm -import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.status.ConnectionStatus +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session.ConnectionState import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event.PodEvent import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.Response @@ -11,7 +11,7 @@ interface OmnipodDashBleManager { fun sendCommand(cmd: Command, responseType: KClass): Observable - fun getStatus(): ConnectionStatus + fun getStatus(): ConnectionState fun connect(): Observable diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt index 0b9eee3a52..622b3663a3 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt @@ -11,7 +11,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptio import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.pair.LTKExchanger import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.scan.PodScanner import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session.* -import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.status.ConnectionStatus import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event.PodEvent import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.Response @@ -34,7 +33,6 @@ class OmnipodDashBleManagerImpl @Inject constructor( context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager private val bluetoothAdapter: BluetoothAdapter = bluetoothManager.adapter private var connection: Connection? = null - private var status: ConnectionStatus = ConnectionStatus.IDLE private val ids = Ids(podState) override fun sendCommand(cmd: Command, responseType: KClass): Observable = @@ -85,13 +83,9 @@ class OmnipodDashBleManagerImpl @Inject constructor( ?: throw NotConnectedException("Missing session") } - override fun getStatus(): ConnectionStatus { - // TODO is this used? - var s: ConnectionStatus - synchronized(status) { - s = status - } - return s + override fun getStatus(): ConnectionState { + return connection?.let { getStatus() } + ?: NotConnected } override fun connect(): Observable = Observable.create { emitter -> @@ -106,9 +100,10 @@ class OmnipodDashBleManagerImpl @Inject constructor( ?: throw FailedToConnectException("Missing bluetoothAddress, activate the pod first") val podDevice = bluetoothAdapter.getRemoteDevice(podAddress) val conn = connection - ?: Connection(podDevice, aapsLogger, context) + ?: Connection(podDevice, aapsLogger, context, podState) connection = conn if (conn.connectionState() is Connected) { + podState.lastConnection = System.currentTimeMillis() if (conn.session == null) { emitter.onNext(PodEvent.EstablishingSession) establishSession(1.toByte()) @@ -121,7 +116,7 @@ class OmnipodDashBleManagerImpl @Inject constructor( } conn.connect() emitter.onNext(PodEvent.BluetoothConnected(podAddress)) - + podState.lastConnection = System.currentTimeMillis() emitter.onNext(PodEvent.EstablishingSession) establishSession(1.toByte()) emitter.onNext(PodEvent.Connected) @@ -190,7 +185,7 @@ class OmnipodDashBleManagerImpl @Inject constructor( emitter.onNext(PodEvent.BluetoothConnecting) val podDevice = bluetoothAdapter.getRemoteDevice(podAddress) - val conn = Connection(podDevice, aapsLogger, context) + val conn = Connection(podDevice, aapsLogger, context, podState) connection = conn emitter.onNext(PodEvent.BluetoothConnected(podAddress)) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/IOState.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/IOState.kt deleted file mode 100644 index b426f8420f..0000000000 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/IOState.kt +++ /dev/null @@ -1,5 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io - -enum class IOState { - IDLE, WRITING, READING -} 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 104b7fc3a2..fb3ddc1cb5 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 @@ -20,6 +20,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.CmdBl import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.DataBleIO import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.IncomingPackets import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message.MessageIO +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager sealed class ConnectionState @@ -29,7 +30,8 @@ object NotConnected : ConnectionState() class Connection( private val podDevice: BluetoothDevice, private val aapsLogger: AAPSLogger, - context: Context + context: Context, + private val podState: OmnipodDashPodStateManager ) : DisconnectHandler { private val incomingPackets = IncomingPackets() @@ -50,13 +52,15 @@ class Connection( aapsLogger.debug(LTag.PUMPBTCOMM, "Connecting to ${podDevice.address}") val autoConnect = false - + podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING gattConnection = podDevice.connectGatt(context, autoConnect, bleCommCallbacks, BluetoothDevice.TRANSPORT_LE) // OnDisconnect can be called after this point!!! val state = waitForConnection() if (state !is Connected) { + podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED throw FailedToConnectException(podDevice.address) } + podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTED val discoverer = ServiceDiscoverer(aapsLogger, gattConnection, bleCommCallbacks) val discoveredCharacteristics = discoverer.discoverServices() cmdBleIO = CmdBleIO( @@ -90,13 +94,17 @@ class Connection( disconnect() } aapsLogger.debug("Connecting") + podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING + if (!gattConnection.connect()) { throw FailedToConnectException("connect() returned false") } - if (waitForConnection() is NotConnected) { + if (waitForConnection() !is Connected) { + podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED throw FailedToConnectException(podDevice.address) } + podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTED val discoverer = ServiceDiscoverer(aapsLogger, gattConnection, bleCommCallbacks) val discovered = discoverer.discoverServices() @@ -110,6 +118,8 @@ class Connection( fun disconnect() { aapsLogger.debug(LTag.PUMPBTCOMM, "Disconnecting") + podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED + gattConnection.disconnect() bleCommCallbacks.resetConnection() session = null diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/status/ConnectionStatus.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/status/ConnectionStatus.kt deleted file mode 100644 index 6977f342f3..0000000000 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/status/ConnectionStatus.kt +++ /dev/null @@ -1,10 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.status - -enum class ConnectionStatus { - IDLE, - BUSY, - CONNECTING, - ESTABLISHING_SESSION, - PAIRING, - RUNNING_COMMAND; -} diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/event/PodEvent.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/event/PodEvent.kt index c2a721c208..08d33a43fe 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/event/PodEvent.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/event/PodEvent.kt @@ -65,6 +65,4 @@ sealed class PodEvent { return "ResponseReceived(command=$command, response=$response)" } } - - data class CommandConfirmed(val historyId: String, val success: Boolean) : PodEvent() } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/CommandConfirmed.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/CommandConfirmed.kt new file mode 100644 index 0000000000..d5f57243d8 --- /dev/null +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/CommandConfirmed.kt @@ -0,0 +1,3 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state + +class CommandConfirmed(val historyId: String, val success: Boolean) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt index 9fff97203d..bc5fdf060a 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt @@ -8,9 +8,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response. import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.DefaultStatusResponse import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.SetUniqueIdResponse import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.VersionResponse -import io.reactivex.Completable import io.reactivex.Maybe import io.reactivex.Observable +import io.reactivex.Single import java.io.Serializable import java.util.* @@ -22,6 +22,7 @@ interface OmnipodDashPodStateManager { val isSuspended: Boolean val isPodRunning: Boolean var lastConnection: Long + var bluetoothConnectionState: BluetoothConnectionState val lastUpdatedSystem: Long // System.currentTimeMillis() val lastStatusResponseReceived: Long @@ -66,17 +67,21 @@ interface OmnipodDashPodStateManager { fun updateFromPairing(uniqueId: Id, pairResult: PairResult) fun reset() - fun createActiveCommand(historyId: String): Completable - fun updateActiveCommand(): Maybe + fun createActiveCommand(historyId: String): Single + fun updateActiveCommand(): Maybe fun observeNoActiveCommand(): Observable - fun maybeMarkActiveCommandFailed() data class ActiveCommand( val sequence: Short, val createdRealtime: Long, var sentRealtime: Long = 0, - val historyId: String + val historyId: String, + var sendError: Throwable?, ) // TODO: set created to "now" on boot data class TempBasal(val startTime: Long, val rate: Double, val durationInMinutes: Short) : Serializable + + enum class BluetoothConnectionState { + CONNECTING, CONNECTED, DISCONNECTED + } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index a8e31905bc..9724f7f819 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -17,9 +17,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response. import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.SetUniqueIdResponse import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.VersionResponse import info.nightscout.androidaps.utils.sharedPreferences.SP -import io.reactivex.Completable import io.reactivex.Maybe import io.reactivex.Observable +import io.reactivex.Single import java.io.Serializable import java.util.* import javax.inject.Inject @@ -148,7 +148,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( get() = podState.tempBasal override val tempBasalActive: Boolean - get() = tempBasal != null && tempBasal!!.startTime + tempBasal!!.durationInMinutes * 60 * 1000 > System.currentTimeMillis() + get() = podState.deliveryStatus in arrayOf(DeliveryStatus.TEMP_BASAL_ACTIVE, DeliveryStatus.BOLUS_AND_TEMP_BASAL_ACTIVE) override var basalProgram: BasalProgram? get() = podState.basalProgram @@ -160,6 +160,14 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( override val lastStatusResponseReceived: Long get() = podState.lastStatusResponseReceived + override var bluetoothConnectionState: OmnipodDashPodStateManager.BluetoothConnectionState + get() = podState.bluetoothConnectionState + set(bluetoothConnectionState) { + podState.bluetoothConnectionState = bluetoothConnectionState + rxBus.send(EventOmnipodDashPumpValuesChanged()) + // do not store + } + override fun increaseMessageSequenceNumber() { podState.messageSequenceNumber = ((podState.messageSequenceNumber.toInt() + 1) and 0x0f).toShort() store() @@ -183,21 +191,25 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( get() = podState.activeCommand @Synchronized - override fun createActiveCommand(historyId: String) = Completable.create { source -> - if (activeCommand == null) { - podState.activeCommand = OmnipodDashPodStateManager.ActiveCommand( - podState.messageSequenceNumber, - createdRealtime = SystemClock.elapsedRealtime(), - historyId = historyId - ) - source.onComplete() - } else { - source.onError( - java.lang.IllegalStateException( - "Trying to send a command " + - "and the last command was not confirmed" + override fun createActiveCommand(historyId: String): Single { + return Single.create { source -> + if (activeCommand == null) { + val command = OmnipodDashPodStateManager.ActiveCommand( + podState.messageSequenceNumber, + createdRealtime = SystemClock.elapsedRealtime(), + historyId = historyId, + sendError = null, ) - ) + podState.activeCommand = command + source.onSuccess(command) + } else { + source.onError( + java.lang.IllegalStateException( + "Trying to send a command " + + "and the last command was not confirmed" + ) + ) + } } } @@ -218,35 +230,35 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( } @Synchronized - override fun maybeMarkActiveCommandFailed() { - podState.activeCommand?.run { - if (sentRealtime < createdRealtime) { - // command was not sent - podState.activeCommand = null - } - } - } - - @Synchronized - override fun updateActiveCommand() = Maybe.create { source -> + override fun updateActiveCommand() = Maybe.create { source -> podState.activeCommand?.run { logger.debug( "Trying to confirm active command with parameters: $activeCommand " + "lastResponse=$lastStatusResponseReceived " + "$sequenceNumberOfLastProgrammingCommand $historyId" ) - if (createdRealtime >= lastStatusResponseReceived) + + if (sentRealtime < createdRealtime) { // command was not sent, clear it up + podState.activeCommand = null + source.onError( + this.sendError + ?: java.lang.IllegalStateException( + "Could not send command and sendError is " + + "missing" + ) + ) + } else if (createdRealtime >= lastStatusResponseReceived) // we did not receive a valid response yet source.onComplete() else { podState.activeCommand = null if (sequenceNumberOfLastProgrammingCommand == sequence) - source.onSuccess(PodEvent.CommandConfirmed(historyId, true)) + source.onSuccess(CommandConfirmed(historyId, true)) else - source.onSuccess(PodEvent.CommandConfirmed(historyId, false)) + source.onSuccess(CommandConfirmed(historyId, false)) } - } - ?: source.onComplete() // no active programming command + } ?: source.onComplete() + // no active programming command } override fun increaseEapAkaSequenceNumber(): ByteArray { @@ -377,7 +389,8 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( var lastConnection: Long = 0 var lastUpdatedSystem: Long = 0 var lastStatusResponseReceived: Long = 0 - + var bluetoothConnectionState: OmnipodDashPodStateManager.BluetoothConnectionState = + OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED var messageSequenceNumber: Short = 0 var sequenceNumberOfLastProgrammingCommand: Short? = null var activationTime: Long? = null diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt index 66fc8f614b..dea243e814 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/DashHistory.kt @@ -35,6 +35,14 @@ class DashHistory @Inject constructor( currentTimeMillis() ) + fun getById(id: String): HistoryRecord { + val entry = dao.byIdBlocking(id) + if (entry == null) { + throw java.lang.IllegalArgumentException("history entry [$id] not found") + } + return historyMapper.entityToDomain(entry) + } + @Suppress("ReturnCount") fun createRecord( commandType: OmnipodCommandType, @@ -77,7 +85,6 @@ class DashHistory @Inject constructor( fun updateFromState(podState: OmnipodDashPodStateManager) = Completable.defer { podState.activeCommand?.run { when { - createdRealtime <= podState.lastStatusResponseReceived && sequence == podState.sequenceNumberOfLastProgrammingCommand -> dao.setInitialResult(historyId, InitialResult.SENT) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt index 56aa2dc6b2..65a2d5294c 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/HistoryRecord.kt @@ -1,6 +1,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.history.data +import com.github.guepardoapps.kulid.ULID import info.nightscout.androidaps.plugins.pump.omnipod.common.definition.OmnipodCommandType +import java.nio.ByteBuffer data class HistoryRecord( val id: String, // ULID @@ -11,4 +13,9 @@ data class HistoryRecord( val record: Record?, val resolvedResult: ResolvedResult?, val resolvedAt: Long? -) +) { + fun pumpId(): Long { + val entropy = ULID.getEntropy(id) + return ByteBuffer.wrap(entropy).getLong() + } +} diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt index bedeb1e4f5..188adfc848 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/data/Record.kt @@ -14,7 +14,7 @@ enum class BolusType { companion object { fun fromBolusInfoBolusType(type: DetailedBolusInfo.BolusType): BolusType { return when (type) { - DetailedBolusInfo.BolusType.SMB -> SMB; + DetailedBolusInfo.BolusType.SMB -> SMB else -> DEFAULT } } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt index 21ff7dbced..84ca7f9f4d 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/history/database/HistoryRecordDao.kt @@ -22,6 +22,9 @@ abstract class HistoryRecordDao { @Query("SELECT * from historyrecords WHERE createdAt <= :since") abstract fun allSince(since: Long): Single> + @Query("SELECT * FROM historyrecords WHERE id = :id LIMIT 1") + abstract fun byIdBlocking(id: String): HistoryRecordEntity? + @Insert(onConflict = OnConflictStrategy.REPLACE) abstract fun saveBlocking(historyRecordEntity: HistoryRecordEntity) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt index 95fdf5b155..f79180f061 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt @@ -13,6 +13,7 @@ import info.nightscout.androidaps.Constants import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.events.EventPreferenceChange import info.nightscout.androidaps.interfaces.CommandQueueProvider +import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification @@ -58,6 +59,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { @Inject lateinit var sp: SP @Inject lateinit var dateUtil: DateUtil @Inject lateinit var aapsSchedulers: AapsSchedulers + @Inject lateinit var pumpSync: PumpSync companion object { @@ -211,11 +213,26 @@ class OmnipodDashOverviewFragment : DaggerFragment() { private fun updateUi() { // TODO update bluetooth status + updateBluetoothStatus() updateOmnipodStatus() updatePodActionButtons() updateQueueStatus() } + private fun updateBluetoothStatus() { + bluetoothStatusBinding.omnipodDashBluetoothAddress.text = podStateManager.bluetoothAddress + ?: PLACEHOLDER + bluetoothStatusBinding.omnipodDashBluetoothStatus.text = + when (podStateManager.bluetoothConnectionState) { + OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTED -> + "{fa-bluetooth}" + OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED -> + "{fa-bluetooth-b}" + OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING -> + "{fa-bluetooth-b spin}" + } + } + private fun updateOmnipodStatus() { updateLastConnection() updateLastBolus() @@ -246,10 +263,9 @@ class OmnipodDashOverviewFragment : DaggerFragment() { podStateManager.firmwareVersion.toString(), podStateManager.bluetoothVersion.toString() ) - + podInfoBinding.timeOnPod.text = podStateManager.minutesSinceActivation.toString() + " minutes" // TODO /* - podInfoBinding.timeOnPod.text = readableZonedTime(podStateManager.time) podInfoBinding.timeOnPod.setTextColor(if (podStateManager.timeDeviatesMoreThan(OmnipodConstants.TIME_DEVIATION_THRESHOLD)) { Color.RED } else { @@ -373,7 +389,9 @@ class OmnipodDashOverviewFragment : DaggerFragment() { if (podStateManager.isSuspended) { resourceHelper.gs(R.string.omnipod_common_pod_status_suspended) } else { - resourceHelper.gs(R.string.omnipod_common_pod_status_running) + resourceHelper.gs(R.string.omnipod_common_pod_status_running) + + podStateManager.deliveryStatus?.let { " " + podStateManager.deliveryStatus.toString() } + // TODO Display deliveryStatus in a nice way } // TODO /* @@ -421,10 +439,11 @@ class OmnipodDashOverviewFragment : DaggerFragment() { } private fun updateTempBasal() { - if (podStateManager.isActivationCompleted && podStateManager.tempBasalActive) { - val startTime = podStateManager.tempBasal!!.startTime - val rate = podStateManager.tempBasal!!.rate - val duration = podStateManager.tempBasal!!.durationInMinutes + val tempBasal = podStateManager.tempBasal + if (podStateManager.isActivationCompleted && podStateManager.tempBasalActive && tempBasal != null) { + val startTime = tempBasal.startTime + val rate = tempBasal.rate + val duration = tempBasal.durationInMinutes val minutesRunning = 0 // TODO @@ -560,46 +579,45 @@ class OmnipodDashOverviewFragment : DaggerFragment() { } */ - private fun readableDuration(time: Long): String { - // TODO - return "TODO" - - /* - val duration = Duration(dateTime, DateTime.now()) + private fun readableDuration(dateTime: Long): String { + val duration = Duration(dateTime, System.currentTimeMillis()) val hours = duration.standardHours.toInt() val minutes = duration.standardMinutes.toInt() val seconds = duration.standardSeconds.toInt() when { - seconds < 10 -> { + seconds < 10 -> { return resourceHelper.gs(R.string.omnipod_common_moments_ago) } - seconds < 60 -> { + seconds < 60 -> { return resourceHelper.gs(R.string.omnipod_common_less_than_a_minute_ago) } - seconds < 60 * 60 -> { // < 1 hour + seconds < 60 * 60 -> { // < 1 hour return resourceHelper.gs(R.string.omnipod_common_time_ago, resourceHelper.gq(R.plurals.omnipod_common_minutes, minutes, minutes)) } seconds < 24 * 60 * 60 -> { // < 1 day val minutesLeft = minutes % 60 if (minutesLeft > 0) - return resourceHelper.gs(R.string.omnipod_common_time_ago, - resourceHelper.gs(R.string.omnipod_common_composite_time, resourceHelper.gq(R.plurals.omnipod_common_hours, hours, hours), resourceHelper.gq(R.plurals.omnipod_common_minutes, minutesLeft, minutesLeft))) + return resourceHelper.gs( + R.string.omnipod_common_time_ago, + resourceHelper.gs(R.string.omnipod_common_composite_time, resourceHelper.gq(R.plurals.omnipod_common_hours, hours, hours), resourceHelper.gq(R.plurals.omnipod_common_minutes, minutesLeft, minutesLeft)) + ) return resourceHelper.gs(R.string.omnipod_common_time_ago, resourceHelper.gq(R.plurals.omnipod_common_hours, hours, hours)) } - else -> { + else -> { val days = hours / 24 val hoursLeft = hours % 24 if (hoursLeft > 0) - return resourceHelper.gs(R.string.omnipod_common_time_ago, - resourceHelper.gs(R.string.omnipod_common_composite_time, resourceHelper.gq(R.plurals.omnipod_common_days, days, days), resourceHelper.gq(R.plurals.omnipod_common_hours, hoursLeft, hoursLeft))) + return resourceHelper.gs( + R.string.omnipod_common_time_ago, + resourceHelper.gs(R.string.omnipod_common_composite_time, resourceHelper.gq(R.plurals.omnipod_common_days, days, days), resourceHelper.gq(R.plurals.omnipod_common_hours, hoursLeft, hoursLeft)) + ) return resourceHelper.gs(R.string.omnipod_common_time_ago, resourceHelper.gq(R.plurals.omnipod_common_days, days, days)) } } - */ } private fun isQueueEmpty(): Boolean { diff --git a/omnipod-dash/src/main/res/layout/omnipod_dash_overview_bluetooth_status.xml b/omnipod-dash/src/main/res/layout/omnipod_dash_overview_bluetooth_status.xml index d9d95b3a60..8d7ac5e903 100644 --- a/omnipod-dash/src/main/res/layout/omnipod_dash_overview_bluetooth_status.xml +++ b/omnipod-dash/src/main/res/layout/omnipod_dash_overview_bluetooth_status.xml @@ -1,44 +1,6 @@ - - - - - - - - - - - + + + + + + + + + diff --git a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/endecrypt/EnDecryptTest.kt b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/endecrypt/EnDecryptTest.kt index 36a07eface..e6ad2844dc 100644 --- a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/endecrypt/EnDecryptTest.kt +++ b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/endecrypt/EnDecryptTest.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.endecrypt +import info.nightscout.androidaps.extensions.toHex import info.nightscout.androidaps.logging.AAPSLoggerTest import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message.MessagePacket -import info.nightscout.androidaps.extensions.toHex import org.junit.Assert import org.junit.Test import org.spongycastle.util.encoders.Hex diff --git a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessagePacketTest.kt b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessagePacketTest.kt index e6a25e3eb6..6ca71c6b94 100644 --- a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessagePacketTest.kt +++ b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessagePacketTest.kt @@ -1,9 +1,9 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message import com.google.crypto.tink.subtle.Hex +import info.nightscout.androidaps.extensions.toHex import info.nightscout.androidaps.logging.AAPSLoggerTest import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id -import info.nightscout.androidaps.extensions.toHex import org.junit.Assert.assertEquals import org.junit.Test diff --git a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadJoinerTest.kt b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadJoinerTest.kt index b1a1d51519..0ff9673c1d 100644 --- a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadJoinerTest.kt +++ b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadJoinerTest.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message import com.google.crypto.tink.subtle.Hex -import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.packet.PayloadJoiner import info.nightscout.androidaps.extensions.toHex +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.packet.PayloadJoiner import org.junit.Assert.assertEquals import org.junit.Test diff --git a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadSplitJoinTest.kt b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadSplitJoinTest.kt index 6a12e87bd5..ffc3510d57 100644 --- a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadSplitJoinTest.kt +++ b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadSplitJoinTest.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message +import info.nightscout.androidaps.extensions.toHex import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.packet.PayloadJoiner import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.packet.PayloadSplitter -import info.nightscout.androidaps.extensions.toHex import org.junit.Assert.assertEquals import org.junit.Test import java.util.* diff --git a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadSplitterTest.kt b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadSplitterTest.kt index bd08be97f6..a8f148acb4 100644 --- a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadSplitterTest.kt +++ b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/PayloadSplitterTest.kt @@ -1,8 +1,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message import com.google.crypto.tink.subtle.Hex -import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.packet.PayloadSplitter import info.nightscout.androidaps.extensions.toHex +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.packet.PayloadSplitter import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test diff --git a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/KeyExchangeTest.kt b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/KeyExchangeTest.kt index 6041748403..237d1041ad 100644 --- a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/KeyExchangeTest.kt +++ b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/KeyExchangeTest.kt @@ -1,9 +1,9 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.pair +import info.nightscout.androidaps.extensions.toHex import info.nightscout.androidaps.logging.AAPSLoggerTest import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.util.RandomByteGenerator import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.util.X25519KeyGenerator -import info.nightscout.androidaps.extensions.toHex import org.junit.Assert.assertEquals import org.junit.Test import org.mockito.ArgumentMatchers.anyInt diff --git a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/EapMessageTest.kt b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/EapMessageTest.kt index fff01c494b..1289b9c93a 100644 --- a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/EapMessageTest.kt +++ b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/EapMessageTest.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session -import info.nightscout.androidaps.logging.AAPSLoggerTest import info.nightscout.androidaps.extensions.toHex +import info.nightscout.androidaps.logging.AAPSLoggerTest import org.junit.Assert import org.junit.Test import org.spongycastle.util.encoders.Hex diff --git a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/MilenageTest.kt b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/MilenageTest.kt index 4fecfc01f9..107bfd7a03 100644 --- a/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/MilenageTest.kt +++ b/omnipod-dash/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/MilenageTest.kt @@ -1,7 +1,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session -import info.nightscout.androidaps.logging.AAPSLoggerTest import info.nightscout.androidaps.extensions.toHex +import info.nightscout.androidaps.logging.AAPSLoggerTest import org.junit.Assert import org.junit.Test import org.spongycastle.util.encoders.Hex