- starting pumpSync changes

This commit is contained in:
Andy Rozman 2021-04-14 16:06:33 +01:00
parent 93b1b37021
commit bcc7672116
3 changed files with 80 additions and 7 deletions

View file

@ -10,6 +10,8 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.core.R;
@ -27,11 +29,13 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
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;
import info.nightscout.androidaps.plugins.common.ManufacturerType;
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.pump.common.data.PumpDbEntry;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
@ -69,6 +73,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
protected boolean displayConnectionMessages = false;
protected PumpType pumpType;
protected AapsSchedulers aapsSchedulers;
protected PumpSync pumpSync;
protected PumpPluginAbstract(
@ -84,7 +89,8 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
Context context,
FabricPrivacy fabricPrivacy,
DateUtil dateUtil,
AapsSchedulers aapsSchedulers
AapsSchedulers aapsSchedulers,
PumpSync pumpSync
) {
super(pluginDescription, injector, aapsLogger, resourceHelper, commandQueue);
@ -101,6 +107,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
this.pumpType = pumpType;
this.dateUtil = dateUtil;
this.aapsSchedulers = aapsSchedulers;
this.pumpSync = pumpSync;
}
@ -335,6 +342,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
} catch (Exception ignored) {
}
// TODO fix
TemporaryBasal tb = activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis());
if (tb != null) {
extended.put("TempBasalAbsoluteRate",
@ -343,6 +351,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
}
// TODO fix
ExtendedBolus eb = activePlugin.getActiveTreatments().getExtendedBolusFromHistory(System.currentTimeMillis());
if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
@ -377,10 +386,12 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
ret += "LastBolus: " + DecimalFormatter.INSTANCE.to2Decimal(getPumpStatusData().lastBolusAmount) + "U @" + //
android.text.format.DateFormat.format("HH:mm", getPumpStatusData().lastBolusTime) + "\n";
}
// TODO fix
TemporaryBasal activeTemp = activePlugin.getActiveTreatments().getRealTempBasalFromHistory(System.currentTimeMillis());
if (activeTemp != null) {
ret += "Temp: " + activeTemp.toStringFull() + "\n";
}
// TODO fix
ExtendedBolus activeExtendedBolus = activePlugin.getActiveTreatments().getExtendedBolusFromHistory(
System.currentTimeMillis());
if (activeExtendedBolus != null) {
@ -413,6 +424,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
//if (MedtronicHistoryData.doubleBolusDebug)
// aapsLogger.debug("DoubleBolusDebug: deliverTreatment::(carb only entry)");
// TODO fix
// no bolus required, carb only treatment
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
@ -471,4 +483,29 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(resourceId);
}
// PumpSync
Map<Long, PumpDbEntry> driverHistory = new HashMap<>();
public abstract long generateTempId(long timeMillis);
public boolean addBolusWithTempId(DetailedBolusInfo detailedBolusInfo, boolean writeToInternalHistory) {
long temporaryId = generateTempId(detailedBolusInfo.timestamp);
boolean response = pumpSync.addBolusWithTempId(detailedBolusInfo.timestamp, detailedBolusInfo.insulin,
generateTempId(detailedBolusInfo.timestamp), detailedBolusInfo.getBolusType(),
getPumpType(), serialNumber());
if (response && writeToInternalHistory) {
driverHistory.put(temporaryId, new PumpDbEntry(temporaryId, model(), serialNumber(), detailedBolusInfo));
}
return response;
}
public void removeTemporaryId(long temporaryId) {
driverHistory.remove(temporaryId);
}
}

View file

@ -0,0 +1,21 @@
package info.nightscout.androidaps.plugins.pump.common.data;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
public class PumpDbEntry {
long temporaryId;
PumpType pumpType;
String serialNumber;
DetailedBolusInfo detailedBolusInfo;
public PumpDbEntry(long temporaryId, PumpType pumpType, String serialNumber, DetailedBolusInfo detailedBolusInfo) {
this.temporaryId = temporaryId;
this.pumpType = pumpType;
this.serialNumber = serialNumber;
this.detailedBolusInfo = detailedBolusInfo;
}
}

View file

@ -40,6 +40,7 @@ import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
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;
@ -98,7 +99,6 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
@Singleton
public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface, RileyLinkPumpDevice {
private final SP sp;
private final MedtronicUtil medtronicUtil;
private final MedtronicPumpStatus medtronicPumpStatus;
private final MedtronicHistoryData medtronicHistoryData;
@ -117,7 +117,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
public static boolean isBusy = false;
private final List<Long> busyTimestamps = new ArrayList<>();
private boolean hasTimeDateOrTimeZoneChanged = false;
private boolean usePumpSync = false;
@Inject
public MedtronicPumpPlugin(
@ -136,7 +136,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
RileyLinkServiceData rileyLinkServiceData,
ServiceTaskExecutor serviceTaskExecutor,
DateUtil dateUtil,
AapsSchedulers aapsSchedulers
AapsSchedulers aapsSchedulers,
PumpSync pumpSync
) {
super(new PluginDescription() //
@ -148,11 +149,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
.preferencesId(R.xml.pref_medtronic)
.description(R.string.description_pump_medtronic), //
PumpType.MEDTRONIC_522_722, // we default to most basic model, correct model from config is loaded later
injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil, aapsSchedulers
injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy, dateUtil, aapsSchedulers, pumpSync
);
this.medtronicUtil = medtronicUtil;
this.sp = sp;
this.medtronicPumpStatus = medtronicPumpStatus;
this.medtronicHistoryData = medtronicHistoryData;
this.rileyLinkServiceData = rileyLinkServiceData;
@ -733,6 +733,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
rxBus.send(new EventMedtronicPumpValuesChanged());
}
@Override public long generateTempId(long timeMillis) {
return 0;
}
@Override public String getSerial() {
return null;
}
private BolusDeliveryType bolusDeliveryType = BolusDeliveryType.Idle;
private enum BolusDeliveryType {
@ -878,7 +886,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
detailedBolusInfo.timestamp = now;
detailedBolusInfo.deliverAtTheLatest = now; // not sure about that one
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
// TODO fix
if (usePumpSync) {
addBolusWithTempId(detailedBolusInfo, true);
} else {
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
}
// we subtract insulin, exact amount will be visible with next remainingInsulin update.
medtronicPumpStatus.reservoirRemainingUnits -= detailedBolusInfo.insulin;
@ -1044,6 +1057,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
.absolute(absoluteRate) //
.source(Source.USER);
// TODO fix
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempStart);
incrementStatistics(MedtronicConst.Statistics.TBRsSet);
@ -1391,6 +1405,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
.duration(0) //
.source(Source.USER);
// TODO fix
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempBasal);
return new PumpEnactResult(getInjector()).success(true).enacted(true) //