Fix calling syncStopTemporaryBasalWithPumpId() twice

This commit is contained in:
jbr7rr 2023-07-09 09:47:58 +02:00
parent c941926a7e
commit 592a45612c
4 changed files with 9 additions and 26 deletions

View file

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

View file

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

View file

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

View file

@ -16,7 +16,6 @@ class CancelTempBasalPacketTest : MedtrumTestBase() {
if (it is CancelTempBasalPacket) {
it.aapsLogger = aapsLogger
it.medtrumPump = medtrumPump
it.pumpSync = pumpSync
it.dateUtil = dateUtil
}
}