Medtrum: Fallback for case when activation response is not received
This commit is contained in:
parent
8caa6db2f0
commit
a8897df753
|
@ -2,6 +2,7 @@ package info.nightscout.pump.medtrum
|
|||
|
||||
import android.util.Base64
|
||||
import info.nightscout.interfaces.profile.Profile
|
||||
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
||||
import info.nightscout.interfaces.pump.PumpSync
|
||||
import info.nightscout.interfaces.pump.TemporaryBasalStorage
|
||||
import info.nightscout.interfaces.pump.defs.PumpType
|
||||
|
@ -537,6 +538,26 @@ class MedtrumPump @Inject constructor(
|
|||
return rh.gs(stringId)
|
||||
}
|
||||
|
||||
fun handleNewPatch(newPatchId: Long, sequenceNumber: Int, newStartTime: Long) {
|
||||
patchId = newPatchId
|
||||
patchStartTime = newStartTime
|
||||
currentSequenceNumber = sequenceNumber // We are activated, set the new seq nr
|
||||
syncedSequenceNumber = 1 // Always start with 1
|
||||
// Sync cannula change
|
||||
pumpSync.insertTherapyEventIfNewWithTimestamp(
|
||||
timestamp = newStartTime,
|
||||
type = DetailedBolusInfo.EventType.CANNULA_CHANGE,
|
||||
pumpType = pumpType(),
|
||||
pumpSerial = pumpSN.toString(radix = 16)
|
||||
)
|
||||
pumpSync.insertTherapyEventIfNewWithTimestamp(
|
||||
timestamp = newStartTime,
|
||||
type = DetailedBolusInfo.EventType.INSULIN_CHANGE,
|
||||
pumpType = pumpType(),
|
||||
pumpSerial = pumpSN.toString(radix = 16)
|
||||
)
|
||||
}
|
||||
|
||||
private fun saveActiveAlarms() {
|
||||
val alarmsStr = activeAlarms.joinToString(separator = ",") { it.name }
|
||||
sp.putString(R.string.key_active_alarms, alarmsStr)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package info.nightscout.pump.medtrum.comm.packets
|
||||
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
||||
import info.nightscout.interfaces.pump.PumpSync
|
||||
import info.nightscout.pump.medtrum.MedtrumPump
|
||||
import info.nightscout.pump.medtrum.comm.enums.CommandType.ACTIVATE
|
||||
|
@ -93,24 +92,8 @@ class ActivatePacket(injector: HasAndroidInjector, private val basalProfile: Byt
|
|||
val basalPatchId = data.copyOfRange(RESP_BASAL_PATCH_ID_START, RESP_BASAL_PATCH_ID_END).toLong()
|
||||
val basalStartTime = medtrumTimeUtil.convertPumpTimeToSystemTimeMillis(data.copyOfRange(RESP_BASAL_START_TIME_START, RESP_BASAL_START_TIME_END).toLong())
|
||||
|
||||
medtrumPump.patchId = patchId
|
||||
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 ()
|
||||
|
||||
// Sync cannula change
|
||||
pumpSync.insertTherapyEventIfNewWithTimestamp(
|
||||
timestamp = System.currentTimeMillis(),
|
||||
type = DetailedBolusInfo.EventType.CANNULA_CHANGE,
|
||||
pumpType = medtrumPump.pumpType(),
|
||||
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
|
||||
)
|
||||
pumpSync.insertTherapyEventIfNewWithTimestamp(
|
||||
timestamp = System.currentTimeMillis(),
|
||||
type = DetailedBolusInfo.EventType.INSULIN_CHANGE,
|
||||
pumpType = medtrumPump.pumpType(),
|
||||
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
|
||||
)
|
||||
medtrumPump.handleNewPatch(patchId, basalSequence, System.currentTimeMillis())
|
||||
|
||||
// Update the actual basal profile
|
||||
medtrumPump.actualBasalProfile = basalProfile
|
||||
|
|
|
@ -85,6 +85,7 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
|||
fun handleMaskedMessage(data: ByteArray) {
|
||||
val fieldMask = data.copyOfRange(0, 2).toInt()
|
||||
var offset = 2
|
||||
var newPatchStartTime: Long? = null
|
||||
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Message field mask: $fieldMask")
|
||||
|
||||
|
@ -148,12 +149,12 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
|||
|
||||
if (fieldMask and MASK_START_TIME != 0) {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Start time notification received")
|
||||
val patchStartTime = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(offset, offset + 4).toLong())
|
||||
if (medtrumPump.patchStartTime != patchStartTime) {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Patch start time changed from ${medtrumPump.patchStartTime} to $patchStartTime")
|
||||
medtrumPump.patchStartTime = patchStartTime
|
||||
newPatchStartTime = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(offset, offset + 4).toLong())
|
||||
if (medtrumPump.patchStartTime != newPatchStartTime) {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Patch start time changed from ${medtrumPump.patchStartTime} to $newPatchStartTime")
|
||||
medtrumPump.patchStartTime = newPatchStartTime
|
||||
}
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Patch start time: ${patchStartTime}")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Patch start time: $newPatchStartTime")
|
||||
offset += 4
|
||||
}
|
||||
|
||||
|
@ -176,6 +177,11 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
|||
val patchId = data.copyOfRange(offset + 2, offset + 4).toLong()
|
||||
if (patchId != medtrumPump.patchId) {
|
||||
aapsLogger.warn(LTag.PUMPCOMM, "handleMaskedMessage: We got wrong patch id!")
|
||||
if (newPatchStartTime != null) {
|
||||
// This is a fallback for when the activate packet did not receive the ack but the patch activated anyway
|
||||
aapsLogger.error(LTag.PUMPCOMM, "handleMaskedMessage: Also Received start time in this packet, registering new patch id: $patchId")
|
||||
medtrumPump.handleNewPatch(patchId, sequence, newPatchStartTime)
|
||||
}
|
||||
}
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Last known sequence number: ${medtrumPump.currentSequenceNumber}, patch id: ${patchId}")
|
||||
offset += 4
|
||||
|
|
Loading…
Reference in a new issue