Fix calling syncStopTemporaryBasalWithPumpId() twice
This commit is contained in:
parent
c941926a7e
commit
592a45612c
|
@ -414,16 +414,15 @@ class MedtrumPump @Inject constructor(
|
||||||
// Pump suspended, set fake TBR
|
// Pump suspended, set fake TBR
|
||||||
setFakeTBR()
|
setFakeTBR()
|
||||||
} else if (basalType == BasalType.STANDARD) {
|
} else if (basalType == BasalType.STANDARD) {
|
||||||
if (expectedTemporaryBasal != null && System.currentTimeMillis() - basalStartTime > 1000) {
|
if (expectedTemporaryBasal != null) {
|
||||||
// Pump resumed, but end was not synced before, sync it now
|
// Pump resumed, sync end
|
||||||
aapsLogger.warn(LTag.PUMPCOMM, "handleBasalStatusUpdate: Pump resumed, but end was not synced before, sync it now")
|
|
||||||
val success = pumpSync.syncStopTemporaryBasalWithPumpId(
|
val success = pumpSync.syncStopTemporaryBasalWithPumpId(
|
||||||
timestamp = basalStartTime + 500, // Time of normal basal start = time of tbr end
|
timestamp = basalStartTime + 250, // Time of normal basal start = time of tbr end
|
||||||
endPumpId = basalStartTime + 500, // +500ms Make sure there is time between start and stop of TBR
|
endPumpId = basalStartTime + 250, // +250ms Make sure there is time between start and stop of TBR
|
||||||
pumpType = pumpType(),
|
pumpType = pumpType(),
|
||||||
pumpSerial = pumpSN.toString(radix = 16)
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,9 +97,6 @@ class ActivatePacket(injector: HasAndroidInjector, private val basalProfile: Byt
|
||||||
medtrumPump.lastTimeReceivedFromPump = time
|
medtrumPump.lastTimeReceivedFromPump = time
|
||||||
medtrumPump.currentSequenceNumber = basalSequence // We are activated, set the new seq nr
|
medtrumPump.currentSequenceNumber = basalSequence // We are activated, set the new seq nr
|
||||||
medtrumPump.syncedSequenceNumber = basalSequence // We are activated, reset the synced 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
|
// 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()
|
pumpSync.connectNewPump()
|
||||||
|
@ -116,6 +113,10 @@ class ActivatePacket(injector: HasAndroidInjector, private val basalProfile: Byt
|
||||||
pumpType = medtrumPump.pumpType(),
|
pumpType = medtrumPump.pumpType(),
|
||||||
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
|
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Update the actual basal profile
|
||||||
|
medtrumPump.actualBasalProfile = basalProfile
|
||||||
|
medtrumPump.handleBasalStatusUpdate(basalType, basalValue, basalSequence, basalPatchId, basalStartTime, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
return success
|
return success
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package info.nightscout.pump.medtrum.comm.packets
|
package info.nightscout.pump.medtrum.comm.packets
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.interfaces.pump.PumpSync
|
|
||||||
import info.nightscout.pump.medtrum.MedtrumPump
|
import info.nightscout.pump.medtrum.MedtrumPump
|
||||||
import info.nightscout.pump.medtrum.comm.enums.CommandType.CANCEL_TEMP_BASAL
|
import info.nightscout.pump.medtrum.comm.enums.CommandType.CANCEL_TEMP_BASAL
|
||||||
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
||||||
|
@ -15,7 +14,6 @@ import javax.inject.Inject
|
||||||
class CancelTempBasalPacket(injector: HasAndroidInjector) : MedtrumPacket(injector) {
|
class CancelTempBasalPacket(injector: HasAndroidInjector) : MedtrumPacket(injector) {
|
||||||
|
|
||||||
@Inject lateinit var medtrumPump: MedtrumPump
|
@Inject lateinit var medtrumPump: MedtrumPump
|
||||||
@Inject lateinit var pumpSync: PumpSync
|
|
||||||
@Inject lateinit var dateUtil: DateUtil
|
@Inject lateinit var dateUtil: DateUtil
|
||||||
|
|
||||||
companion object {
|
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())
|
val basalStartTime = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(RESP_BASAL_START_TIME_START, RESP_BASAL_START_TIME_END).toLong())
|
||||||
|
|
||||||
medtrumPump.handleBasalStatusUpdate(basalType, basalRate, basalSequence, basalPatchId, basalStartTime)
|
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
|
return success
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ class CancelTempBasalPacketTest : MedtrumTestBase() {
|
||||||
if (it is CancelTempBasalPacket) {
|
if (it is CancelTempBasalPacket) {
|
||||||
it.aapsLogger = aapsLogger
|
it.aapsLogger = aapsLogger
|
||||||
it.medtrumPump = medtrumPump
|
it.medtrumPump = medtrumPump
|
||||||
it.pumpSync = pumpSync
|
|
||||||
it.dateUtil = dateUtil
|
it.dateUtil = dateUtil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue