From 299d0a9b01df60e1ee7354c1c7fa05db94b3f786 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 30 Mar 2021 22:45:45 +0200 Subject: [PATCH] finish Dana pumps --- .../maintenance/MaintenanceFragment.kt | 3 ++ .../danaRKorean/DanaRKoreanPlugin.java | 2 +- .../androidaps/danaRv2/DanaRv2Plugin.java | 6 ++- .../danaRv2/comm/MsgHistoryEvents_v2.kt | 42 +++++++++---------- .../androidaps/danar/AbstractDanaRPlugin.java | 6 ++- .../androidaps/danar/DanaRPlugin.java | 23 ++++++++-- 6 files changed, 53 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt index e2473b5005..97a99468c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt @@ -11,6 +11,7 @@ import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding import info.nightscout.androidaps.events.EventNewBG +import info.nightscout.androidaps.interfaces.DataSyncSelector import info.nightscout.androidaps.interfaces.DatabaseHelperInterface import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface import info.nightscout.androidaps.logging.AAPSLogger @@ -36,6 +37,7 @@ class MaintenanceFragment : DaggerFragment() { @Inject lateinit var repository: AppRepository @Inject lateinit var databaseHelper: DatabaseHelperInterface @Inject lateinit var uel: UserEntryLogger + @Inject lateinit var dataSyncSelector: DataSyncSelector private val compositeDisposable = CompositeDisposable() @@ -65,6 +67,7 @@ class MaintenanceFragment : DaggerFragment() { fromAction { databaseHelper.resetDatabases() repository.clearDatabases() + dataSyncSelector.resetToNextFullSync() } .subscribeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.main) diff --git a/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.java b/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.java index 2dcafe1fa5..0a15328ea3 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.java +++ b/danar/src/main/java/info/nightscout/androidaps/danaRKorean/DanaRKoreanPlugin.java @@ -71,7 +71,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { PumpSync pumpSync, FabricPrivacy fabricPrivacy ) { - super(injector, danaPump, resourceHelper, constraintChecker, aapsLogger, aapsSchedulers, commandQueue, rxBus, activePlugin, sp, dateUtil); + super(injector, danaPump, resourceHelper, constraintChecker, aapsLogger, aapsSchedulers, commandQueue, rxBus, activePlugin, sp, dateUtil, pumpSync); this.aapsLogger = aapsLogger; this.context = context; this.resourceHelper = resourceHelper; diff --git a/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java b/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java index c53d025a78..9f1fb6f616 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java +++ b/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java @@ -24,6 +24,7 @@ import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.CommandQueueProvider; import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.PumpSync; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -69,9 +70,10 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { CommandQueueProvider commandQueue, DetailedBolusInfoStorage detailedBolusInfoStorage, DateUtil dateUtil, - FabricPrivacy fabricPrivacy + FabricPrivacy fabricPrivacy, + PumpSync pumpSync ) { - super(injector, danaPump, resourceHelper, constraintChecker, aapsLogger, aapsSchedulers, commandQueue, rxBus, activePlugin, sp, dateUtil); + super(injector, danaPump, resourceHelper, constraintChecker, aapsLogger, aapsSchedulers, commandQueue, rxBus, activePlugin, sp, dateUtil, pumpSync); this.aapsLogger = aapsLogger; this.context = context; this.resourceHelper = resourceHelper; diff --git a/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgHistoryEvents_v2.kt b/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgHistoryEvents_v2.kt index 83fe642c80..5c939bda8d 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgHistoryEvents_v2.kt +++ b/danar/src/main/java/info/nightscout/androidaps/danaRv2/comm/MsgHistoryEvents_v2.kt @@ -3,7 +3,6 @@ package info.nightscout.androidaps.danaRv2.comm import dagger.android.HasAndroidInjector import info.nightscout.androidaps.danar.R import info.nightscout.androidaps.danar.comm.MessageBase -import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.db.ExtendedBolus import info.nightscout.androidaps.db.Source import info.nightscout.androidaps.db.TemporaryBasal @@ -91,26 +90,26 @@ class MsgHistoryEvents_v2 constructor( info.nightscout.androidaps.dana.DanaPump.BOLUS -> { val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0) - ?: DetailedBolusInfo() - detailedBolusInfo.bolusTimestamp = datetime - detailedBolusInfo.pumpType = PumpType.DANA_RV2 - detailedBolusInfo.pumpSerial = danaPump.serialNumber - detailedBolusInfo.bolusPumpId = datetime - detailedBolusInfo.insulin = param1 / 100.0 - val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false) + val newRecord = pumpSync.syncBolusWithPumpId( + timestamp = datetime, + amount = param1 / 100.0, + type = detailedBolusInfo?.bolusType, + pumpId = datetime, + pumpType = PumpType.DANA_RV2, + pumpSerial = danaPump.serialNumber) aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT BOLUS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min") status = "BOLUS " + dateUtil.timeString(datetime) } info.nightscout.androidaps.dana.DanaPump.DUALBOLUS -> { val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0) - ?: DetailedBolusInfo() - detailedBolusInfo.bolusTimestamp = datetime - detailedBolusInfo.pumpType = PumpType.DANA_RV2 - detailedBolusInfo.pumpSerial = danaPump.serialNumber - detailedBolusInfo.bolusPumpId = datetime - detailedBolusInfo.insulin = param1 / 100.0 - val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false) + val newRecord = pumpSync.syncBolusWithPumpId( + timestamp = datetime, + amount = param1 / 100.0, + type = detailedBolusInfo?.bolusType, + pumpId = datetime, + pumpType = PumpType.DANA_RV2, + pumpSerial = danaPump.serialNumber) aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT DUALBOLUS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min") status = "DUALBOLUS " + dateUtil.timeString(datetime) } @@ -155,13 +154,12 @@ class MsgHistoryEvents_v2 constructor( } info.nightscout.androidaps.dana.DanaPump.CARBS -> { - val emptyCarbsInfo = DetailedBolusInfo() - emptyCarbsInfo.carbs = param1.toDouble() - emptyCarbsInfo.carbsTimestamp = datetime - emptyCarbsInfo.pumpType = PumpType.DANA_RV2 - emptyCarbsInfo.pumpSerial = danaPump.serialNumber - emptyCarbsInfo.carbsPumpId = datetime - val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(emptyCarbsInfo, false) + val newRecord = pumpSync.syncCarbsWithTimestamp( + timestamp = datetime, + amount = param1.toDouble(), + pumpId = datetime, + pumpType = PumpType.DANA_RV2, + pumpSerial = danaPump.serialNumber) aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g") status = "CARBS " + dateUtil.timeString(datetime) } diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java b/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java index 819b503d3b..0927406653 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java +++ b/danar/src/main/java/info/nightscout/androidaps/danar/AbstractDanaRPlugin.java @@ -29,6 +29,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpPluginBase; +import info.nightscout.androidaps.interfaces.PumpSync; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -64,6 +65,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump protected SP sp; protected DateUtil dateUtil; protected AapsSchedulers aapsSchedulers; + protected PumpSync pumpSync; protected AbstractDanaRPlugin( HasAndroidInjector injector, @@ -76,7 +78,8 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump RxBusWrapper rxBus, ActivePluginProvider activePlugin, SP sp, - DateUtil dateUtil + DateUtil dateUtil, + PumpSync pumpSync ) { super(new PluginDescription() .mainType(PluginType.PUMP) @@ -95,6 +98,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump this.sp = sp; this.dateUtil = dateUtil; this.aapsSchedulers = aapsSchedulers; + this.pumpSync = pumpSync; } @Override protected void onStart() { diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java b/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java index d2ea26c091..5d52f0cd2d 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java +++ b/danar/src/main/java/info/nightscout/androidaps/danar/DanaRPlugin.java @@ -25,6 +25,7 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.CommandQueueProvider; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.PumpSync; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -34,6 +35,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.Round; +import info.nightscout.androidaps.utils.T; import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.rx.AapsSchedulers; import info.nightscout.androidaps.utils.sharedPreferences.SP; @@ -63,9 +65,10 @@ public class DanaRPlugin extends AbstractDanaRPlugin { CommandQueueProvider commandQueue, DanaPump danaPump, DateUtil dateUtil, - FabricPrivacy fabricPrivacy + FabricPrivacy fabricPrivacy, + PumpSync pumpSync ) { - super(injector, danaPump, resourceHelper, constraintChecker, aapsLogger, aapsSchedulers, commandQueue, rxBus, activePlugin, sp, dateUtil); + super(injector, danaPump, resourceHelper, constraintChecker, aapsLogger, aapsSchedulers, commandQueue, rxBus, activePlugin, sp, dateUtil, pumpSync); this.aapsLogger = aapsLogger; this.context = context; this.resourceHelper = resourceHelper; @@ -176,7 +179,21 @@ public class DanaRPlugin extends AbstractDanaRPlugin { aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.getBolusDelivered()); detailedBolusInfo.insulin = t.insulin; detailedBolusInfo.timestamp = System.currentTimeMillis(); - activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false); + if (detailedBolusInfo.insulin > 0) + pumpSync.syncBolusWithPumpId( + detailedBolusInfo.timestamp, + detailedBolusInfo.insulin, + detailedBolusInfo.getBolusType(), + dateUtil._now(), + PumpType.DANA_R, + serialNumber()); + if (detailedBolusInfo.carbs > 0) + pumpSync.syncCarbsWithTimestamp( + detailedBolusInfo.timestamp + T.mins(detailedBolusInfo.carbTime).msecs(), + detailedBolusInfo.carbs, + null, + PumpType.DANA_R, + serialNumber()); return result; } else { PumpEnactResult result = new PumpEnactResult(getInjector());