Add sendMessage retry counter, cleanup old comments
This commit is contained in:
parent
ef2cc13dd8
commit
94e6189ab3
6 changed files with 21 additions and 21 deletions
|
@ -276,16 +276,16 @@ import kotlin.math.round
|
||||||
if (connectionOK
|
if (connectionOK
|
||||||
&& medtrumPump.tempBasalInProgress
|
&& medtrumPump.tempBasalInProgress
|
||||||
&& Math.abs(medtrumPump.tempBasalAbsoluteRate - pumpRate) <= 0.05
|
&& Math.abs(medtrumPump.tempBasalAbsoluteRate - pumpRate) <= 0.05
|
||||||
/*&& Math.abs(medtrumPump.tempBasalRemainingMinutes - durationInMinutes) <= 5*/) {
|
) {
|
||||||
|
|
||||||
return PumpEnactResult(injector).success(true).enacted(true).duration(/*medtrumPump.tempBasalRemainingMinutes*/durationInMinutes).absolute(medtrumPump.tempBasalAbsoluteRate)
|
return PumpEnactResult(injector).success(true).enacted(true).duration(durationInMinutes).absolute(medtrumPump.tempBasalAbsoluteRate)
|
||||||
.isPercent(false)
|
.isPercent(false)
|
||||||
.isTempCancel(false)
|
.isTempCancel(false)
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.error(
|
aapsLogger.error(
|
||||||
LTag.PUMP,
|
LTag.PUMP,
|
||||||
"setTempBasalAbsolute failed, connectionOK: $connectionOK, tempBasalInProgress: ${medtrumPump.tempBasalInProgress}, tempBasalAbsoluteRate: ${medtrumPump.tempBasalAbsoluteRate}"
|
"setTempBasalAbsolute failed, connectionOK: $connectionOK, tempBasalInProgress: ${medtrumPump.tempBasalInProgress}, tempBasalAbsoluteRate: ${medtrumPump.tempBasalAbsoluteRate}"
|
||||||
) //, tempBasalRemainingMinutes: ${medtrumPump.tempBasalRemainingMinutes}")
|
)
|
||||||
return PumpEnactResult(injector).success(false).enacted(false).comment("Medtrum setTempBasalAbsolute failed")
|
return PumpEnactResult(injector).success(false).enacted(false).comment("Medtrum setTempBasalAbsolute failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -453,11 +453,6 @@ import kotlin.math.round
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun deactivate(): PumpEnactResult {
|
override fun deactivate(): PumpEnactResult {
|
||||||
// if (!isInitialized()) {
|
|
||||||
// val result = PumpEnactResult(injector).success(false)
|
|
||||||
// result.comment = "pump not initialized"
|
|
||||||
// return result
|
|
||||||
// }
|
|
||||||
val connectionOK = medtrumService?.deactivatePatch() ?: false
|
val connectionOK = medtrumService?.deactivatePatch() ?: false
|
||||||
return PumpEnactResult(injector).success(connectionOK)
|
return PumpEnactResult(injector).success(connectionOK)
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,9 +207,9 @@ class MedtrumPump @Inject constructor(
|
||||||
get() = _pumpSN
|
get() = _pumpSN
|
||||||
|
|
||||||
var needTimeUpdate = false
|
var needTimeUpdate = false
|
||||||
var lastTimeReceivedFromPump = 0L // Time in ms! // TODO: Consider removing as is not used?
|
var lastTimeReceivedFromPump = 0L // Time in ms!
|
||||||
var suspendTime = 0L // Time in ms!
|
var suspendTime = 0L // Time in ms!
|
||||||
var patchAge = 0L // Time in seconds?! // TODO: Not used
|
var patchAge = 0L // Time in seconds?! // As reported by pump, not used (yet)
|
||||||
|
|
||||||
// bolus status
|
// bolus status
|
||||||
var bolusingTreatment: EventOverviewBolusProgress.Treatment? = null // actually delivered treatment
|
var bolusingTreatment: EventOverviewBolusProgress.Treatment? = null // actually delivered treatment
|
||||||
|
|
|
@ -99,7 +99,7 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Normal bolus notification received")
|
aapsLogger.debug(LTag.PUMPCOMM, "Normal bolus notification received")
|
||||||
var bolusData = data.copyOfRange(offset, offset + 1).toInt()
|
var bolusData = data.copyOfRange(offset, offset + 1).toInt()
|
||||||
var bolusType = bolusData and 0x7F
|
var bolusType = bolusData and 0x7F
|
||||||
val bolusCompleted: Boolean = ((bolusData shr 7) and 0x01) != 0 // TODO: Check for other flags here :)
|
val bolusCompleted: Boolean = ((bolusData shr 7) and 0x01) != 0
|
||||||
var bolusDelivered = data.copyOfRange(offset + 1, offset + 3).toInt() * 0.05
|
var bolusDelivered = data.copyOfRange(offset + 1, offset + 3).toInt() * 0.05
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Bolus type: $bolusType, bolusData: $bolusData bolus completed: $bolusCompleted, bolus delivered: $bolusDelivered")
|
aapsLogger.debug(LTag.PUMPCOMM, "Bolus type: $bolusType, bolusData: $bolusData bolus completed: $bolusCompleted, bolus delivered: $bolusDelivered")
|
||||||
medtrumPump.handleBolusStatusUpdate(bolusType, bolusCompleted, bolusDelivered)
|
medtrumPump.handleBolusStatusUpdate(bolusType, bolusCompleted, bolusDelivered)
|
||||||
|
@ -171,8 +171,7 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
||||||
}
|
}
|
||||||
val patchId = data.copyOfRange(offset + 2, offset + 4).toLong()
|
val patchId = data.copyOfRange(offset + 2, offset + 4).toLong()
|
||||||
if (patchId != medtrumPump.patchId) {
|
if (patchId != medtrumPump.patchId) {
|
||||||
aapsLogger.error(LTag.PUMPCOMM, "handleMaskedMessage: WTF? We got wrong patch id!")
|
aapsLogger.warn(LTag.PUMPCOMM, "handleMaskedMessage: We got wrong patch id!")
|
||||||
// TODO: We should terminate session or stop patch here? or at least throw error? THis can be thrown during activation process though
|
|
||||||
}
|
}
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Last known sequence number: ${medtrumPump.currentSequenceNumber}, patch id: ${patchId}")
|
aapsLogger.debug(LTag.PUMPCOMM, "Last known sequence number: ${medtrumPump.currentSequenceNumber}, patch id: ${patchId}")
|
||||||
offset += 4
|
offset += 4
|
||||||
|
|
|
@ -599,6 +599,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
protected var responseHandled = false
|
protected var responseHandled = false
|
||||||
protected var responseSuccess = false
|
protected var responseSuccess = false
|
||||||
|
protected var sendRetryCounter = 0
|
||||||
|
|
||||||
open fun onEnter() {}
|
open fun onEnter() {}
|
||||||
open fun onIndication(data: ByteArray) {
|
open fun onIndication(data: ByteArray) {
|
||||||
|
@ -632,7 +633,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
toState(IdleState())
|
toState(IdleState())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
SystemClock.sleep(100)
|
SystemClock.sleep(25)
|
||||||
}
|
}
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Medtrum Service State responseHandled: $responseHandled responseSuccess: $responseSuccess")
|
aapsLogger.debug(LTag.PUMPCOMM, "Medtrum Service State responseHandled: $responseHandled responseSuccess: $responseSuccess")
|
||||||
return responseSuccess
|
return responseSuccess
|
||||||
|
@ -640,8 +641,16 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
fun onSendMessageError(reason: String) {
|
fun onSendMessageError(reason: String) {
|
||||||
aapsLogger.warn(LTag.PUMPCOMM, "onSendMessageError: " + this.toString() + "reason: $reason")
|
aapsLogger.warn(LTag.PUMPCOMM, "onSendMessageError: " + this.toString() + "reason: $reason")
|
||||||
responseHandled = true
|
// Retry 3 times
|
||||||
responseSuccess = false
|
if (sendRetryCounter < 3) {
|
||||||
|
sendRetryCounter++
|
||||||
|
mPacket?.getRequest()?.let { bleComm.sendMessage(it) }
|
||||||
|
} else {
|
||||||
|
responseHandled = true
|
||||||
|
responseSuccess = false
|
||||||
|
bleComm.disconnect("onSendMessageError")
|
||||||
|
toState(IdleState())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -718,10 +727,10 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
// Succes!
|
// Succes!
|
||||||
responseHandled = true
|
responseHandled = true
|
||||||
responseSuccess = true
|
responseSuccess = true
|
||||||
// TODO Get device type and SN
|
// Place holder, not really used (yet)
|
||||||
val deviceType = (mPacket as GetDeviceTypePacket).deviceType
|
val deviceType = (mPacket as GetDeviceTypePacket).deviceType
|
||||||
val deviceSN = (mPacket as GetDeviceTypePacket).deviceSN
|
val deviceSN = (mPacket as GetDeviceTypePacket).deviceSN
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "GetDeviceTypeState: deviceType: $deviceType deviceSN: $deviceSN") // TODO remove me later
|
aapsLogger.debug(LTag.PUMPCOMM, "GetDeviceTypeState: deviceType: $deviceType deviceSN: $deviceSN")
|
||||||
toState(GetTimeState())
|
toState(GetTimeState())
|
||||||
} else if (mPacket?.failed == true) {
|
} else if (mPacket?.failed == true) {
|
||||||
// Failure
|
// Failure
|
||||||
|
@ -761,7 +770,6 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
medtrumPump.lastTimeReceivedFromPump
|
medtrumPump.lastTimeReceivedFromPump
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
// TODO: Setting time cancels any TBR, so we need to handle that and cancel? or let AAPS handle time syncs?
|
|
||||||
toState(SetTimeState())
|
toState(SetTimeState())
|
||||||
}
|
}
|
||||||
} else if (mPacket?.failed == true) {
|
} else if (mPacket?.failed == true) {
|
||||||
|
|
|
@ -59,7 +59,6 @@ class NotificationPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(167, medtrumPump.currentSequenceNumber)
|
assertEquals(167, medtrumPump.currentSequenceNumber)
|
||||||
// TODO: Test error notif on wrong patch id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleNotificationGivenBolusInProgressThenDataSaved() {
|
@Test fun handleNotificationGivenBolusInProgressThenDataSaved() {
|
||||||
|
|
|
@ -57,7 +57,6 @@ class SynchronizePacketTest : MedtrumTestBase() {
|
||||||
assertEquals(true, result)
|
assertEquals(true, result)
|
||||||
assertEquals(false, packet.failed)
|
assertEquals(false, packet.failed)
|
||||||
assertEquals(state, packet.medtrumPump.pumpState.state)
|
assertEquals(state, packet.medtrumPump.pumpState.state)
|
||||||
// TODO: Maybe test cutting behavoir
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
|
Loading…
Reference in a new issue