- starting pumpSync changes
This commit is contained in:
parent
93b1b37021
commit
bcc7672116
3 changed files with 80 additions and 7 deletions
|
@ -10,6 +10,8 @@ import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.core.R;
|
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.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;
|
||||||
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
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.data.PumpStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
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 boolean displayConnectionMessages = false;
|
||||||
protected PumpType pumpType;
|
protected PumpType pumpType;
|
||||||
protected AapsSchedulers aapsSchedulers;
|
protected AapsSchedulers aapsSchedulers;
|
||||||
|
protected PumpSync pumpSync;
|
||||||
|
|
||||||
|
|
||||||
protected PumpPluginAbstract(
|
protected PumpPluginAbstract(
|
||||||
|
@ -84,7 +89,8 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
Context context,
|
Context context,
|
||||||
FabricPrivacy fabricPrivacy,
|
FabricPrivacy fabricPrivacy,
|
||||||
DateUtil dateUtil,
|
DateUtil dateUtil,
|
||||||
AapsSchedulers aapsSchedulers
|
AapsSchedulers aapsSchedulers,
|
||||||
|
PumpSync pumpSync
|
||||||
) {
|
) {
|
||||||
|
|
||||||
super(pluginDescription, injector, aapsLogger, resourceHelper, commandQueue);
|
super(pluginDescription, injector, aapsLogger, resourceHelper, commandQueue);
|
||||||
|
@ -101,6 +107,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
this.pumpType = pumpType;
|
this.pumpType = pumpType;
|
||||||
this.dateUtil = dateUtil;
|
this.dateUtil = dateUtil;
|
||||||
this.aapsSchedulers = aapsSchedulers;
|
this.aapsSchedulers = aapsSchedulers;
|
||||||
|
this.pumpSync = pumpSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -335,6 +342,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO fix
|
||||||
TemporaryBasal tb = activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal tb = activePlugin.getActiveTreatments().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (tb != null) {
|
if (tb != null) {
|
||||||
extended.put("TempBasalAbsoluteRate",
|
extended.put("TempBasalAbsoluteRate",
|
||||||
|
@ -343,6 +351,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
|
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO fix
|
||||||
ExtendedBolus eb = activePlugin.getActiveTreatments().getExtendedBolusFromHistory(System.currentTimeMillis());
|
ExtendedBolus eb = activePlugin.getActiveTreatments().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||||
if (eb != null) {
|
if (eb != null) {
|
||||||
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
|
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 @" + //
|
ret += "LastBolus: " + DecimalFormatter.INSTANCE.to2Decimal(getPumpStatusData().lastBolusAmount) + "U @" + //
|
||||||
android.text.format.DateFormat.format("HH:mm", getPumpStatusData().lastBolusTime) + "\n";
|
android.text.format.DateFormat.format("HH:mm", getPumpStatusData().lastBolusTime) + "\n";
|
||||||
}
|
}
|
||||||
|
// TODO fix
|
||||||
TemporaryBasal activeTemp = activePlugin.getActiveTreatments().getRealTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal activeTemp = activePlugin.getActiveTreatments().getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (activeTemp != null) {
|
if (activeTemp != null) {
|
||||||
ret += "Temp: " + activeTemp.toStringFull() + "\n";
|
ret += "Temp: " + activeTemp.toStringFull() + "\n";
|
||||||
}
|
}
|
||||||
|
// TODO fix
|
||||||
ExtendedBolus activeExtendedBolus = activePlugin.getActiveTreatments().getExtendedBolusFromHistory(
|
ExtendedBolus activeExtendedBolus = activePlugin.getActiveTreatments().getExtendedBolusFromHistory(
|
||||||
System.currentTimeMillis());
|
System.currentTimeMillis());
|
||||||
if (activeExtendedBolus != null) {
|
if (activeExtendedBolus != null) {
|
||||||
|
@ -413,6 +424,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
//if (MedtronicHistoryData.doubleBolusDebug)
|
//if (MedtronicHistoryData.doubleBolusDebug)
|
||||||
// aapsLogger.debug("DoubleBolusDebug: deliverTreatment::(carb only entry)");
|
// aapsLogger.debug("DoubleBolusDebug: deliverTreatment::(carb only entry)");
|
||||||
|
|
||||||
|
// TODO fix
|
||||||
// no bolus required, carb only treatment
|
// no bolus required, carb only treatment
|
||||||
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
||||||
|
|
||||||
|
@ -471,4 +483,29 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
|
||||||
private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
|
private PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
|
||||||
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -40,6 +40,7 @@ import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
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;
|
||||||
|
@ -98,7 +99,6 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface, RileyLinkPumpDevice {
|
public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface, RileyLinkPumpDevice {
|
||||||
|
|
||||||
private final SP sp;
|
|
||||||
private final MedtronicUtil medtronicUtil;
|
private final MedtronicUtil medtronicUtil;
|
||||||
private final MedtronicPumpStatus medtronicPumpStatus;
|
private final MedtronicPumpStatus medtronicPumpStatus;
|
||||||
private final MedtronicHistoryData medtronicHistoryData;
|
private final MedtronicHistoryData medtronicHistoryData;
|
||||||
|
@ -117,7 +117,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
public static boolean isBusy = false;
|
public static boolean isBusy = false;
|
||||||
private final List<Long> busyTimestamps = new ArrayList<>();
|
private final List<Long> busyTimestamps = new ArrayList<>();
|
||||||
private boolean hasTimeDateOrTimeZoneChanged = false;
|
private boolean hasTimeDateOrTimeZoneChanged = false;
|
||||||
|
private boolean usePumpSync = false;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MedtronicPumpPlugin(
|
public MedtronicPumpPlugin(
|
||||||
|
@ -136,7 +136,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
RileyLinkServiceData rileyLinkServiceData,
|
RileyLinkServiceData rileyLinkServiceData,
|
||||||
ServiceTaskExecutor serviceTaskExecutor,
|
ServiceTaskExecutor serviceTaskExecutor,
|
||||||
DateUtil dateUtil,
|
DateUtil dateUtil,
|
||||||
AapsSchedulers aapsSchedulers
|
AapsSchedulers aapsSchedulers,
|
||||||
|
PumpSync pumpSync
|
||||||
) {
|
) {
|
||||||
|
|
||||||
super(new PluginDescription() //
|
super(new PluginDescription() //
|
||||||
|
@ -148,11 +149,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
.preferencesId(R.xml.pref_medtronic)
|
.preferencesId(R.xml.pref_medtronic)
|
||||||
.description(R.string.description_pump_medtronic), //
|
.description(R.string.description_pump_medtronic), //
|
||||||
PumpType.MEDTRONIC_522_722, // we default to most basic model, correct model from config is loaded later
|
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.medtronicUtil = medtronicUtil;
|
||||||
this.sp = sp;
|
|
||||||
this.medtronicPumpStatus = medtronicPumpStatus;
|
this.medtronicPumpStatus = medtronicPumpStatus;
|
||||||
this.medtronicHistoryData = medtronicHistoryData;
|
this.medtronicHistoryData = medtronicHistoryData;
|
||||||
this.rileyLinkServiceData = rileyLinkServiceData;
|
this.rileyLinkServiceData = rileyLinkServiceData;
|
||||||
|
@ -733,6 +733,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
rxBus.send(new EventMedtronicPumpValuesChanged());
|
rxBus.send(new EventMedtronicPumpValuesChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public long generateTempId(long timeMillis) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getSerial() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private BolusDeliveryType bolusDeliveryType = BolusDeliveryType.Idle;
|
private BolusDeliveryType bolusDeliveryType = BolusDeliveryType.Idle;
|
||||||
|
|
||||||
private enum BolusDeliveryType {
|
private enum BolusDeliveryType {
|
||||||
|
@ -878,7 +886,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
detailedBolusInfo.timestamp = now;
|
detailedBolusInfo.timestamp = now;
|
||||||
detailedBolusInfo.deliverAtTheLatest = now; // not sure about that one
|
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.
|
// we subtract insulin, exact amount will be visible with next remainingInsulin update.
|
||||||
medtronicPumpStatus.reservoirRemainingUnits -= detailedBolusInfo.insulin;
|
medtronicPumpStatus.reservoirRemainingUnits -= detailedBolusInfo.insulin;
|
||||||
|
@ -1044,6 +1057,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
.absolute(absoluteRate) //
|
.absolute(absoluteRate) //
|
||||||
.source(Source.USER);
|
.source(Source.USER);
|
||||||
|
|
||||||
|
// TODO fix
|
||||||
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempStart);
|
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempStart);
|
||||||
|
|
||||||
incrementStatistics(MedtronicConst.Statistics.TBRsSet);
|
incrementStatistics(MedtronicConst.Statistics.TBRsSet);
|
||||||
|
@ -1391,6 +1405,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
.duration(0) //
|
.duration(0) //
|
||||||
.source(Source.USER);
|
.source(Source.USER);
|
||||||
|
|
||||||
|
// TODO fix
|
||||||
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempBasal);
|
activePlugin.getActiveTreatments().addToHistoryTempBasal(tempBasal);
|
||||||
|
|
||||||
return new PumpEnactResult(getInjector()).success(true).enacted(true) //
|
return new PumpEnactResult(getInjector()).success(true).enacted(true) //
|
||||||
|
|
Loading…
Reference in a new issue