bolus progress changes on pump version 3.52 above.

pump notify progress during bolus
This commit is contained in:
miyeongkim 2023-07-06 17:43:56 +09:00
parent 7e6da9323b
commit 44e878d33b
4 changed files with 78 additions and 7 deletions

View file

@ -43,6 +43,7 @@ import info.nightscout.pump.diaconn.packet.InjectionCancelSettingResponsePacket
import info.nightscout.pump.diaconn.packet.InjectionExtendedBolusResultReportPacket
import info.nightscout.pump.diaconn.packet.InjectionExtendedBolusSettingPacket
import info.nightscout.pump.diaconn.packet.InjectionExtendedBolusSettingResponsePacket
import info.nightscout.pump.diaconn.packet.InjectionProgressReportPacket
import info.nightscout.pump.diaconn.packet.InjectionSnackInquirePacket
import info.nightscout.pump.diaconn.packet.InjectionSnackInquireResponsePacket
import info.nightscout.pump.diaconn.packet.InjectionSnackResultReportPacket
@ -150,6 +151,7 @@ abstract class DiaconnG8PacketModule {
@ContributesAndroidInjector abstract fun contributesBigAPSMainInfoInquireResponsePacket(): BigAPSMainInfoInquireResponsePacket
@ContributesAndroidInjector abstract fun contributesSerialNumInquirePacket(): SerialNumInquirePacket
@ContributesAndroidInjector abstract fun contributesSerialNumInquireResponsePacket(): SerialNumInquireResponsePacket
@ContributesAndroidInjector abstract fun contributesInjectionProgressReportPacket(): InjectionProgressReportPacket
}

View file

@ -48,5 +48,6 @@ class DiaconnG8ResponseMessageHashTable @Inject constructor(val injector: HasAnd
put(BatteryWarningReportPacket(injector))
put(InjectionBlockReportPacket(injector))
put(BolusSpeedSettingReportPacket(injector))
put(InjectionProgressReportPacket(injector))
}
}

View file

@ -0,0 +1,53 @@
package info.nightscout.pump.diaconn.packet
import dagger.android.HasAndroidInjector
import info.nightscout.pump.diaconn.DiaconnG8Pump
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper
import javax.inject.Inject
/**
* InjectionProgressReportPacket
*/
class InjectionProgressReportPacket(injector: HasAndroidInjector) : DiaconnG8Packet(injector ) {
@Inject lateinit var diaconnG8Pump: DiaconnG8Pump
@Inject lateinit var rxBus: RxBus
@Inject lateinit var rh: ResourceHelper
init {
msgType = 0xEA.toByte()
aapsLogger.debug(LTag.PUMPCOMM, "InjectionProgressReportPacket init ")
}
override fun handleMessage(data: ByteArray?) {
val defectCheck = defect(data)
if (defectCheck != 0) {
aapsLogger.debug(LTag.PUMPCOMM, "InjectionProgressReportPacket Got some Error")
failed = true
return
} else failed = false
val bufferData = prefixDecode(data)
val setAmount = getShortToInt(bufferData) /100.0
val injAmount = getShortToInt(bufferData)/100.0
val speed = getByteToInt(bufferData);
val injProgress = getByteToInt(bufferData)
diaconnG8Pump.bolusingSetAmount = setAmount
diaconnG8Pump.bolusingInjAmount = injAmount
diaconnG8Pump.bolusingSpeed = speed
diaconnG8Pump.bolusingInjProgress = injProgress
aapsLogger.debug(LTag.PUMPCOMM, "bolusingSetAmount --> ${diaconnG8Pump.bolusingSetAmount}")
aapsLogger.debug(LTag.PUMPCOMM, "bolusingInjAmount --> ${diaconnG8Pump.bolusingInjAmount}")
aapsLogger.debug(LTag.PUMPCOMM, "bolusingSpeed --> ${diaconnG8Pump.bolusingSpeed}")
aapsLogger.debug(LTag.PUMPCOMM, "bolusingInjProgress --> ${diaconnG8Pump.bolusingInjProgress}")
}
override fun getFriendlyName(): String {
return "PUMP_INJECTION_PROGRESS_REPORT"
}
}

View file

@ -322,6 +322,7 @@ class DiaconnG8Service : DaggerService() {
for (i in 0 until loopSize) {
val startLogNo: Int = start + i * pumpLogPageSize
val endLogNo: Int = startLogNo + min(end - startLogNo, pumpLogPageSize)
aapsLogger.debug(LTag.PUMPCOMM, "pumplog request : $startLogNo ~ $endLogNo")
val msg = BigLogInquirePacket(injector, startLogNo, endLogNo, 100)
sendMessage(msg, 500)
}
@ -500,15 +501,27 @@ class DiaconnG8Service : DaggerService() {
val bolusDurationInMSec = (insulin * speed * 1000).toLong()
val expectedEnd = bolusStart + bolusDurationInMSec + 3500L
val totalwaitTime = (expectedEnd - System.currentTimeMillis()) / 1000
// reset bolus progress history
diaconnG8Pump.bolusingInjProgress = 0
diaconnG8Pump.bolusingSetAmount = 0.0
diaconnG8Pump.bolusingInjAmount = 0.0
if (diaconnG8Pump.isReadyToBolus) {
var progressPecent = 0
while (!diaconnG8Pump.bolusDone) {
val waitTime = (expectedEnd - System.currentTimeMillis()) / 1000
bolusingEvent.status = String.format(rh.gs(R.string.waitingforestimatedbolusend), if (waitTime < 0) 0 else waitTime)
var progressPecent = 0
if (totalwaitTime > waitTime && totalwaitTime > 0) {
progressPecent = ((totalwaitTime - waitTime) * 100 / totalwaitTime).toInt()
if(diaconnG8Pump.isPumpVersionGe3_53) {
progressPecent = diaconnG8Pump.bolusingInjProgress
//bolusingEvent.status = String.format(rh.gs(R.string.waitingforestimatedbolusend), progressPecent)
bolusingEvent.status = "볼러스 주입중 ${diaconnG8Pump.bolusingInjAmount}U / ${diaconnG8Pump.bolusingSetAmount}U (${progressPecent}%)"
bolusingEvent.percent = min(progressPecent, 100)
} else {
val waitTime = (expectedEnd - System.currentTimeMillis()) / 1000
bolusingEvent.status = String.format(rh.gs(R.string.waitingforestimatedbolusend), if (waitTime < 0) 0 else waitTime)
if (totalwaitTime > waitTime && totalwaitTime > 0) {
progressPecent = ((totalwaitTime - waitTime) * 100 / totalwaitTime).toInt()
}
bolusingEvent.percent = min(progressPecent, 100)
}
bolusingEvent.percent = min(progressPecent, 100)
rxBus.send(bolusingEvent)
SystemClock.sleep(200)
}
@ -522,7 +535,9 @@ class DiaconnG8Service : DaggerService() {
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.gettingbolusstatus)))
sendMessage(InjectionSnackInquirePacket(injector), 2000) // last bolus
// 볼러스 결과 보고패킷에서 처리함.
bolusingEvent.percent = 100
if(!diaconnG8Pump.isPumpVersionGe3_53) {
bolusingEvent.percent = 100
}
rxBus.send(EventPumpStatusChanged(rh.gs(info.nightscout.shared.R.string.disconnecting)))
}
})