finish Dana pumps

This commit is contained in:
Milos Kozak 2021-03-30 22:45:45 +02:00
parent 07d060c2b5
commit 299d0a9b01
6 changed files with 53 additions and 29 deletions

View file

@ -11,6 +11,7 @@ import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding
import info.nightscout.androidaps.events.EventNewBG import info.nightscout.androidaps.events.EventNewBG
import info.nightscout.androidaps.interfaces.DataSyncSelector
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
@ -36,6 +37,7 @@ class MaintenanceFragment : DaggerFragment() {
@Inject lateinit var repository: AppRepository @Inject lateinit var repository: AppRepository
@Inject lateinit var databaseHelper: DatabaseHelperInterface @Inject lateinit var databaseHelper: DatabaseHelperInterface
@Inject lateinit var uel: UserEntryLogger @Inject lateinit var uel: UserEntryLogger
@Inject lateinit var dataSyncSelector: DataSyncSelector
private val compositeDisposable = CompositeDisposable() private val compositeDisposable = CompositeDisposable()
@ -65,6 +67,7 @@ class MaintenanceFragment : DaggerFragment() {
fromAction { fromAction {
databaseHelper.resetDatabases() databaseHelper.resetDatabases()
repository.clearDatabases() repository.clearDatabases()
dataSyncSelector.resetToNextFullSync()
} }
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)

View file

@ -71,7 +71,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
PumpSync pumpSync, PumpSync pumpSync,
FabricPrivacy fabricPrivacy 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.aapsLogger = aapsLogger;
this.context = context; this.context = context;
this.resourceHelper = resourceHelper; this.resourceHelper = resourceHelper;

View file

@ -24,6 +24,7 @@ import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.CommandQueueProvider; import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PumpSync;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
@ -69,9 +70,10 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
CommandQueueProvider commandQueue, CommandQueueProvider commandQueue,
DetailedBolusInfoStorage detailedBolusInfoStorage, DetailedBolusInfoStorage detailedBolusInfoStorage,
DateUtil dateUtil, 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.aapsLogger = aapsLogger;
this.context = context; this.context = context;
this.resourceHelper = resourceHelper; this.resourceHelper = resourceHelper;

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.danaRv2.comm
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.danar.R import info.nightscout.androidaps.danar.R
import info.nightscout.androidaps.danar.comm.MessageBase import info.nightscout.androidaps.danar.comm.MessageBase
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.db.ExtendedBolus import info.nightscout.androidaps.db.ExtendedBolus
import info.nightscout.androidaps.db.Source import info.nightscout.androidaps.db.Source
import info.nightscout.androidaps.db.TemporaryBasal import info.nightscout.androidaps.db.TemporaryBasal
@ -91,26 +90,26 @@ class MsgHistoryEvents_v2 constructor(
info.nightscout.androidaps.dana.DanaPump.BOLUS -> { info.nightscout.androidaps.dana.DanaPump.BOLUS -> {
val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0) val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
?: DetailedBolusInfo() val newRecord = pumpSync.syncBolusWithPumpId(
detailedBolusInfo.bolusTimestamp = datetime timestamp = datetime,
detailedBolusInfo.pumpType = PumpType.DANA_RV2 amount = param1 / 100.0,
detailedBolusInfo.pumpSerial = danaPump.serialNumber type = detailedBolusInfo?.bolusType,
detailedBolusInfo.bolusPumpId = datetime pumpId = datetime,
detailedBolusInfo.insulin = param1 / 100.0 pumpType = PumpType.DANA_RV2,
val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false) 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") 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) status = "BOLUS " + dateUtil.timeString(datetime)
} }
info.nightscout.androidaps.dana.DanaPump.DUALBOLUS -> { info.nightscout.androidaps.dana.DanaPump.DUALBOLUS -> {
val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0) val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
?: DetailedBolusInfo() val newRecord = pumpSync.syncBolusWithPumpId(
detailedBolusInfo.bolusTimestamp = datetime timestamp = datetime,
detailedBolusInfo.pumpType = PumpType.DANA_RV2 amount = param1 / 100.0,
detailedBolusInfo.pumpSerial = danaPump.serialNumber type = detailedBolusInfo?.bolusType,
detailedBolusInfo.bolusPumpId = datetime pumpId = datetime,
detailedBolusInfo.insulin = param1 / 100.0 pumpType = PumpType.DANA_RV2,
val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false) 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") 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) status = "DUALBOLUS " + dateUtil.timeString(datetime)
} }
@ -155,13 +154,12 @@ class MsgHistoryEvents_v2 constructor(
} }
info.nightscout.androidaps.dana.DanaPump.CARBS -> { info.nightscout.androidaps.dana.DanaPump.CARBS -> {
val emptyCarbsInfo = DetailedBolusInfo() val newRecord = pumpSync.syncCarbsWithTimestamp(
emptyCarbsInfo.carbs = param1.toDouble() timestamp = datetime,
emptyCarbsInfo.carbsTimestamp = datetime amount = param1.toDouble(),
emptyCarbsInfo.pumpType = PumpType.DANA_RV2 pumpId = datetime,
emptyCarbsInfo.pumpSerial = danaPump.serialNumber pumpType = PumpType.DANA_RV2,
emptyCarbsInfo.carbsPumpId = datetime pumpSerial = danaPump.serialNumber)
val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(emptyCarbsInfo, false)
aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g") aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g")
status = "CARBS " + dateUtil.timeString(datetime) status = "CARBS " + dateUtil.timeString(datetime)
} }

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.PumpPluginBase; import info.nightscout.androidaps.interfaces.PumpPluginBase;
import info.nightscout.androidaps.interfaces.PumpSync;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
@ -64,6 +65,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
protected SP sp; protected SP sp;
protected DateUtil dateUtil; protected DateUtil dateUtil;
protected AapsSchedulers aapsSchedulers; protected AapsSchedulers aapsSchedulers;
protected PumpSync pumpSync;
protected AbstractDanaRPlugin( protected AbstractDanaRPlugin(
HasAndroidInjector injector, HasAndroidInjector injector,
@ -76,7 +78,8 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
RxBusWrapper rxBus, RxBusWrapper rxBus,
ActivePluginProvider activePlugin, ActivePluginProvider activePlugin,
SP sp, SP sp,
DateUtil dateUtil DateUtil dateUtil,
PumpSync pumpSync
) { ) {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.PUMP) .mainType(PluginType.PUMP)
@ -95,6 +98,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
this.sp = sp; this.sp = sp;
this.dateUtil = dateUtil; this.dateUtil = dateUtil;
this.aapsSchedulers = aapsSchedulers; this.aapsSchedulers = aapsSchedulers;
this.pumpSync = pumpSync;
} }
@Override protected void onStart() { @Override protected void onStart() {

View file

@ -25,6 +25,7 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.CommandQueueProvider; import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpSync;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; 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.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.Round; import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers; import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -63,9 +65,10 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
CommandQueueProvider commandQueue, CommandQueueProvider commandQueue,
DanaPump danaPump, DanaPump danaPump,
DateUtil dateUtil, 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.aapsLogger = aapsLogger;
this.context = context; this.context = context;
this.resourceHelper = resourceHelper; this.resourceHelper = resourceHelper;
@ -176,7 +179,21 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.getBolusDelivered()); aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.getBolusDelivered());
detailedBolusInfo.insulin = t.insulin; detailedBolusInfo.insulin = t.insulin;
detailedBolusInfo.timestamp = System.currentTimeMillis(); 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; return result;
} else { } else {
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());