From 7e6da9323bc033793c5403a1189debe3fce43371 Mon Sep 17 00:00:00 2001 From: miyeongkim Date: Wed, 5 Jul 2023 10:02:33 +0900 Subject: [PATCH 1/2] tempbasal will be applied without confirm(otp) on pump version 3.52 above --- .../nightscout/pump/diaconn/DiaconnG8Pump.kt | 8 +- .../BigAPSMainInfoInquireResponsePacket.kt | 1 + .../BigMainInfoInquireResponsePacket.kt | 1 + .../pump/diaconn/service/DiaconnG8Service.kt | 80 ++++++++++++------- 4 files changed, 60 insertions(+), 30 deletions(-) diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/DiaconnG8Pump.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/DiaconnG8Pump.kt index 9ee19f4c8c..4eceb897f2 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/DiaconnG8Pump.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/DiaconnG8Pump.kt @@ -21,13 +21,14 @@ class DiaconnG8Pump @Inject constructor( ) { var isPumpLogUploadFailed: Boolean = false - //var bleResultInfo: Pair = Pair(null, false) var bolusConfirmMessage: Byte = 0 + var isReadyToBolus: Boolean = false var maxBolusePerDay: Double = 0.0 var pumpIncarnationNum: Int = 65536 var isPumpVersionGe2_63: Boolean = false // is pumpVersion higher then 2.63 + var isPumpVersionGe3_53: Boolean = false // is pumpVersion higher then 3.42 var insulinWarningGrade: Int =0 var insulinWarningProcess: Int =0 var insulinWarningRemain: Int =0 @@ -363,6 +364,11 @@ class DiaconnG8Pump @Inject constructor( var otpNumber = 0 + var bolusingSetAmount = 0.0 + var bolusingInjAmount = 0.0 + var bolusingSpeed = 0 + var bolusingInjProgress = 0 + companion object { // User settings const val ALARM = 0 diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigAPSMainInfoInquireResponsePacket.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigAPSMainInfoInquireResponsePacket.kt index 975e8edade..7e63db4267 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigAPSMainInfoInquireResponsePacket.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigAPSMainInfoInquireResponsePacket.kt @@ -215,6 +215,7 @@ class BigAPSMainInfoInquireResponsePacket( //incarnation no 처리 diaconnG8Pump.isPumpVersionGe2_63 = PumpLogUtil.isPumpVersionGe(sp.getString(rh.gs(R.string.pumpversion), ""), 2, 63) + diaconnG8Pump.isPumpVersionGe3_53 = PumpLogUtil.isPumpVersionGe(sp.getString(rh.gs(R.string.pumpversion), ""), 3, 53) aapsLogger.debug(LTag.PUMPCOMM, "result > " + diaconnG8Pump.result) aapsLogger.debug(LTag.PUMPCOMM, "systemRemainInsulin > " + diaconnG8Pump.systemRemainInsulin) diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigMainInfoInquireResponsePacket.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigMainInfoInquireResponsePacket.kt index ce67dc789d..1354b1915b 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigMainInfoInquireResponsePacket.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigMainInfoInquireResponsePacket.kt @@ -214,6 +214,7 @@ class BigMainInfoInquireResponsePacket( //incarnation no 처리 diaconnG8Pump.isPumpVersionGe2_63 = PumpLogUtil.isPumpVersionGe(sp.getString(rh.gs(R.string.pumpversion), ""), 2, 63) + diaconnG8Pump.isPumpVersionGe3_53 = PumpLogUtil.isPumpVersionGe(sp.getString(rh.gs(R.string.pumpversion), ""), 3, 53) aapsLogger.debug(LTag.PUMPCOMM, "result > " + diaconnG8Pump.result) aapsLogger.debug(LTag.PUMPCOMM, "systemRemainInsulin > " + diaconnG8Pump.systemRemainInsulin) diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt index 907b4c90c4..8f4699a196 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt @@ -549,29 +549,39 @@ class DiaconnG8Service : DaggerService() { // temp state check sendMessage(TempBasalInquirePacket(injector)) + val result : DiaconnG8Packet + if(diaconnG8Pump.isPumpVersionGe3_53) { + val tbrPacket = TempBasalSettingPacket(injector, 3, ((durationInHours * 60) / 15).toInt(), ((absoluteRate * 100) + 1000).toInt()) + sendMessage(tbrPacket, 100) + result = tbrPacket + if (!processConfirm(tbrPacket.msgType)) return false + } else { - if (diaconnG8Pump.tbStatus == 1) { - rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal))) - val msgPacket = TempBasalSettingPacket(injector, 2, diaconnG8Pump.tbTime, diaconnG8Pump.tbInjectRateRatio) - // tempbasal stop - sendMessage(msgPacket, 100) + if (diaconnG8Pump.tbStatus == 1) { + rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal))) + val tbrPacket = TempBasalSettingPacket(injector, 2, diaconnG8Pump.tbTime, diaconnG8Pump.tbInjectRateRatio) + // tempbasal stop + sendMessage(tbrPacket, 100) + // otp process + if (!processConfirm(tbrPacket.msgType)) return false + diaconnG8Pump.tempBasalStart = dateUtil.now() + } + rxBus.send(EventPumpStatusChanged(rh.gs(R.string.settingtempbasal))) + val tbInjectRate = ((absoluteRate * 100) + 1000).toInt() + val tbrPacket = TempBasalSettingPacket(injector, 1, ((durationInHours * 60) / 15).toInt(), tbInjectRate) + sendMessage(tbrPacket, 100) + result = tbrPacket // otp process - if (!processConfirm(msgPacket.msgType)) return false - diaconnG8Pump.tempBasalStart = dateUtil.now() + if (!processConfirm(tbrPacket.msgType)) return false + // pump tempbasal status inquire } - rxBus.send(EventPumpStatusChanged(rh.gs(R.string.settingtempbasal))) - val tbInjectRate = ((absoluteRate * 100) + 1000).toInt() - val msgTBR = TempBasalSettingPacket(injector, 1, ((durationInHours * 60) / 15).toInt(), tbInjectRate) - sendMessage(msgTBR, 100) - // otp process - if (!processConfirm(msgTBR.msgType)) return false - // pump tempbasal status inquire + sendMessage(TempBasalInquirePacket(injector)) loadHistory() val tbr = pumpSync.expectedPumpState().temporaryBasal diaconnG8Pump.fromTemporaryBasal(tbr) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) - return msgTBR.success() + return result.success() } fun tempBasalShortDuration(absoluteRate: Double, durationInMinutes: Int): Boolean { @@ -581,28 +591,40 @@ class DiaconnG8Service : DaggerService() { } // temp state check + val result:DiaconnG8Packet sendMessage(TempBasalInquirePacket(injector)) - if (diaconnG8Pump.tbStatus == 1) { - rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal))) - val msgPacket = TempBasalSettingPacket(injector, 2, diaconnG8Pump.tbTime, diaconnG8Pump.tbInjectRateRatio) - // tempbasal stop - sendMessage(msgPacket, 100) + if(diaconnG8Pump.isPumpVersionGe3_53) { + rxBus.send(EventPumpStatusChanged(rh.gs(R.string.settingtempbasal))) + val tbrSettingPacket = TempBasalSettingPacket(injector, 3, 2, ((absoluteRate * 100) + 1000).toInt()) + sendMessage(tbrSettingPacket, 100) + result=tbrSettingPacket // otp process - if (!processConfirm(msgPacket.msgType)) return false - SystemClock.sleep(500) + if (!processConfirm(tbrSettingPacket.msgType)) return false + sendMessage(TempBasalInquirePacket(injector)) + } else { + if (diaconnG8Pump.tbStatus == 1) { + rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal))) + val tbrPacket = TempBasalSettingPacket(injector, 2, diaconnG8Pump.tbTime, diaconnG8Pump.tbInjectRateRatio) + // tempbasal stop + sendMessage(tbrPacket, 100) + // otp process + if (!processConfirm(tbrPacket.msgType)) return false + SystemClock.sleep(500) + } + rxBus.send(EventPumpStatusChanged(rh.gs(R.string.settingtempbasal))) + val tbInjectRate = absoluteRate * 100 + 1000 + val msgTBR = TempBasalSettingPacket(injector, 1, 2, tbInjectRate.toInt()) + sendMessage(msgTBR, 100) + result=msgTBR + // otp process + if (!processConfirm(msgTBR.msgType)) return false } - rxBus.send(EventPumpStatusChanged(rh.gs(R.string.settingtempbasal))) - val tbInjectRate = absoluteRate * 100 + 1000 - val msgTBR = TempBasalSettingPacket(injector, 1, 2, tbInjectRate.toInt()) - sendMessage(msgTBR, 100) - // otp process - if (!processConfirm(msgTBR.msgType)) return false sendMessage(TempBasalInquirePacket(injector)) loadHistory() val tbr = pumpSync.expectedPumpState().temporaryBasal diaconnG8Pump.fromTemporaryBasal(tbr) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) - return msgTBR.success() + return result.success() } fun tempBasalStop(): Boolean { From 44e878d33b0b89de423417c4cb70ba35a4833408 Mon Sep 17 00:00:00 2001 From: miyeongkim Date: Thu, 6 Jul 2023 17:43:56 +0900 Subject: [PATCH 2/2] bolus progress changes on pump version 3.52 above. pump notify progress during bolus --- .../pump/diaconn/di/DiaconnG8PacketModule.kt | 2 + .../DiaconnG8ResponseMessageHashTable.kt | 1 + .../packet/InjectionProgressReportPacket.kt | 53 +++++++++++++++++++ .../pump/diaconn/service/DiaconnG8Service.kt | 29 +++++++--- 4 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/InjectionProgressReportPacket.kt diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/di/DiaconnG8PacketModule.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/di/DiaconnG8PacketModule.kt index 0c80964704..0aa758cf58 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/di/DiaconnG8PacketModule.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/di/DiaconnG8PacketModule.kt @@ -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 } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/DiaconnG8ResponseMessageHashTable.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/DiaconnG8ResponseMessageHashTable.kt index f72fbeb8d2..35ce96fc24 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/DiaconnG8ResponseMessageHashTable.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/DiaconnG8ResponseMessageHashTable.kt @@ -48,5 +48,6 @@ class DiaconnG8ResponseMessageHashTable @Inject constructor(val injector: HasAnd put(BatteryWarningReportPacket(injector)) put(InjectionBlockReportPacket(injector)) put(BolusSpeedSettingReportPacket(injector)) + put(InjectionProgressReportPacket(injector)) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/InjectionProgressReportPacket.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/InjectionProgressReportPacket.kt new file mode 100644 index 0000000000..9e0de742e4 --- /dev/null +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/InjectionProgressReportPacket.kt @@ -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" + + } +} \ No newline at end of file diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt index 8f4699a196..88859f33d6 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt @@ -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))) } })