From 592a45612cb3857b127c2727c0cac583979aff3d Mon Sep 17 00:00:00 2001 From: jbr7rr <> Date: Sun, 9 Jul 2023 09:47:58 +0200 Subject: [PATCH] Fix calling syncStopTemporaryBasalWithPumpId() twice --- .../info/nightscout/pump/medtrum/MedtrumPump.kt | 11 +++++------ .../pump/medtrum/comm/packets/ActivatePacket.kt | 7 ++++--- .../comm/packets/CancelTempBasalPacket.kt | 16 ---------------- .../comm/packets/CancelTempBasalPacketTest.kt | 1 - 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt index bdba661b39..f9d053f717 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPump.kt @@ -414,16 +414,15 @@ class MedtrumPump @Inject constructor( // Pump suspended, set fake TBR setFakeTBR() } else if (basalType == BasalType.STANDARD) { - if (expectedTemporaryBasal != null && System.currentTimeMillis() - basalStartTime > 1000) { - // Pump resumed, but end was not synced before, sync it now - aapsLogger.warn(LTag.PUMPCOMM, "handleBasalStatusUpdate: Pump resumed, but end was not synced before, sync it now") + if (expectedTemporaryBasal != null) { + // Pump resumed, sync end val success = pumpSync.syncStopTemporaryBasalWithPumpId( - timestamp = basalStartTime + 500, // Time of normal basal start = time of tbr end - endPumpId = basalStartTime + 500, // +500ms Make sure there is time between start and stop of TBR + timestamp = basalStartTime + 250, // Time of normal basal start = time of tbr end + endPumpId = basalStartTime + 250, // +250ms Make sure there is time between start and stop of TBR pumpType = pumpType(), pumpSerial = pumpSN.toString(radix = 16) ) - aapsLogger.warn(LTag.PUMPCOMM, "handleBasalStatusUpdate: EVENT TEMP_END ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) success: $success") + aapsLogger.debug(LTag.PUMPCOMM, "handleBasalStatusUpdate: EVENT TEMP_END ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) success: $success") } } diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/ActivatePacket.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/ActivatePacket.kt index cfe94aee60..972d36b6a9 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/ActivatePacket.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/ActivatePacket.kt @@ -97,9 +97,6 @@ class ActivatePacket(injector: HasAndroidInjector, private val basalProfile: Byt medtrumPump.lastTimeReceivedFromPump = time medtrumPump.currentSequenceNumber = basalSequence // We are activated, set the new seq nr medtrumPump.syncedSequenceNumber = basalSequence // We are activated, reset the synced seq nr () - // Update the actual basal profile - medtrumPump.actualBasalProfile = basalProfile - medtrumPump.handleBasalStatusUpdate(basalType, basalValue, basalSequence, basalPatchId, basalStartTime, time) // Update the pump in the database, technically this is not a new pump only new patch, but still TBR's etc need to be cannceled pumpSync.connectNewPump() @@ -116,6 +113,10 @@ class ActivatePacket(injector: HasAndroidInjector, private val basalProfile: Byt pumpType = medtrumPump.pumpType(), pumpSerial = medtrumPump.pumpSN.toString(radix = 16) ) + + // Update the actual basal profile + medtrumPump.actualBasalProfile = basalProfile + medtrumPump.handleBasalStatusUpdate(basalType, basalValue, basalSequence, basalPatchId, basalStartTime, time) } return success diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/CancelTempBasalPacket.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/CancelTempBasalPacket.kt index 8d16dacebd..f6b54aaa18 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/CancelTempBasalPacket.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/comm/packets/CancelTempBasalPacket.kt @@ -1,7 +1,6 @@ package info.nightscout.pump.medtrum.comm.packets import dagger.android.HasAndroidInjector -import info.nightscout.interfaces.pump.PumpSync import info.nightscout.pump.medtrum.MedtrumPump import info.nightscout.pump.medtrum.comm.enums.CommandType.CANCEL_TEMP_BASAL import info.nightscout.pump.medtrum.comm.enums.BasalType @@ -15,7 +14,6 @@ import javax.inject.Inject class CancelTempBasalPacket(injector: HasAndroidInjector) : MedtrumPacket(injector) { @Inject lateinit var medtrumPump: MedtrumPump - @Inject lateinit var pumpSync: PumpSync @Inject lateinit var dateUtil: DateUtil companion object { @@ -47,20 +45,6 @@ class CancelTempBasalPacket(injector: HasAndroidInjector) : MedtrumPacket(inject val basalStartTime = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(RESP_BASAL_START_TIME_START, RESP_BASAL_START_TIME_END).toLong()) medtrumPump.handleBasalStatusUpdate(basalType, basalRate, basalSequence, basalPatchId, basalStartTime) - - if (basalType == BasalType.STANDARD) { - // If we have standard here, means TBR is cancelled successfully - val success = pumpSync.syncStopTemporaryBasalWithPumpId( - timestamp = basalStartTime + 250, // Time of normal basal start = time of tbr end - endPumpId = basalStartTime + 250, // +250ms Make sure there is time between start and stop of TBR - pumpType = medtrumPump.pumpType(), - pumpSerial = medtrumPump.pumpSN.toString(radix = 16) - ) - aapsLogger.debug( - LTag.PUMPCOMM, - "CancelTempBasalPacket: EVENT TEMP_END ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) success: $success" - ) - } } return success } diff --git a/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/CancelTempBasalPacketTest.kt b/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/CancelTempBasalPacketTest.kt index 208b1b9921..ca99d4278b 100644 --- a/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/CancelTempBasalPacketTest.kt +++ b/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/CancelTempBasalPacketTest.kt @@ -16,7 +16,6 @@ class CancelTempBasalPacketTest : MedtrumTestBase() { if (it is CancelTempBasalPacket) { it.aapsLogger = aapsLogger it.medtrumPump = medtrumPump - it.pumpSync = pumpSync it.dateUtil = dateUtil } }