Merge branch 'double_bolus_debug_master' of https://github.com/andyrozman/AndroidAPS into double_bolus_debug_master

This commit is contained in:
Andy Rozman 2019-11-11 23:02:49 +00:00
commit 1d1549105b
5 changed files with 36 additions and 16 deletions

View file

@ -109,7 +109,7 @@ android {
targetSdkVersion 28 targetSdkVersion 28
multiDexEnabled true multiDexEnabled true
versionCode 1500 versionCode 1500
version "2.5.1" version "medtronic-2.5.1.1"
buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"'

View file

@ -48,6 +48,7 @@ import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperAc
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract; import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
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;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
@ -386,7 +387,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
RileyLinkServiceState rileyLinkServiceState = MedtronicUtil.getServiceState(); RileyLinkServiceState rileyLinkServiceState = MedtronicUtil.getServiceState();
if (rileyLinkServiceState==null) { if (rileyLinkServiceState == null) {
LOG.error("RileyLink unreachable. RileyLinkServiceState is null."); LOG.error("RileyLink unreachable. RileyLinkServiceState is null.");
return false; return false;
} }
@ -744,13 +745,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
ClockDTO clock = MedtronicUtil.getPumpTime(); ClockDTO clock = MedtronicUtil.getPumpTime();
if (clock==null) { // retry if (clock == null) { // retry
medtronicUIComm.executeCommand(MedtronicCommandType.GetRealTimeClock); medtronicUIComm.executeCommand(MedtronicCommandType.GetRealTimeClock);
clock = MedtronicUtil.getPumpTime(); clock = MedtronicUtil.getPumpTime();
} }
if (clock==null) if (clock == null)
return; return;
int timeDiff = Math.abs(clock.timeDifference); int timeDiff = Math.abs(clock.timeDifference);
@ -866,7 +867,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}).start(); }).start();
} }
long now = System.currentTimeMillis();
detailedBolusInfo.date = now;
detailedBolusInfo.deliverAt = now; // not sure about that one
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
DetailedBolusInfoStorage.INSTANCE.add(detailedBolusInfo);
// we subtract insulin, exact amount will be visible with next remainingInsulin update. // we subtract insulin, exact amount will be visible with next remainingInsulin update.
getMDTPumpStatus().reservoirRemainingUnits -= detailedBolusInfo.insulin; getMDTPumpStatus().reservoirRemainingUnits -= detailedBolusInfo.insulin;
@ -877,7 +884,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// calculate time for bolus and set driver to busy for that time // calculate time for bolus and set driver to busy for that time
int bolusTime = (int) (detailedBolusInfo.insulin * 42.0d); int bolusTime = (int) (detailedBolusInfo.insulin * 42.0d);
long time = System.currentTimeMillis() + (bolusTime * 1000); long time = now + (bolusTime * 1000);
this.busyTimestamps.add(time); this.busyTimestamps.add(time);
setEnableCustomAction(MedtronicCustomActionType.ClearBolusBlock, true); setEnableCustomAction(MedtronicCustomActionType.ClearBolusBlock, true);
@ -1065,10 +1072,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Override @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile,
boolean enforceNew) { boolean enforceNew) {
if (percent==0) { if (percent == 0) {
return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew); return setTempBasalAbsolute(0.0d, durationInMinutes, profile, enforceNew);
} else { } else {
double absoluteValue = profile.getBasal() * (percent /100.0d); double absoluteValue = profile.getBasal() * (percent / 100.0d);
getMDTPumpStatus(); getMDTPumpStatus();
absoluteValue = pumpStatusLocal.pumpType.determineCorrectBasalSize(absoluteValue); absoluteValue = pumpStatusLocal.pumpType.determineCorrectBasalSize(absoluteValue);
LOG.warn("setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (%d). This will start setTempBasalAbsolute, with calculated value (%.3f). Result might not be 100% correct.", percent, absoluteValue); LOG.warn("setTempBasalPercent [MedtronicPumpPlugin] - You are trying to use setTempBasalPercent with percent other then 0% (%d). This will start setTempBasalAbsolute, with calculated value (%.3f). Result might not be 100% correct.", percent, absoluteValue);

View file

@ -78,6 +78,7 @@ public class MedtronicHistoryData {
private boolean isInit = false; private boolean isInit = false;
private Gson gson; private Gson gson;
private Gson gsonCore;
private DatabaseHelper databaseHelper = MainApp.getDbHelper(); private DatabaseHelper databaseHelper = MainApp.getDbHelper();
private ClockDTO pumpTime; private ClockDTO pumpTime;
@ -95,10 +96,15 @@ public class MedtronicHistoryData {
public MedtronicHistoryData() { public MedtronicHistoryData() {
this.allHistory = new ArrayList<>(); this.allHistory = new ArrayList<>();
this.gson = MedtronicUtil.gsonInstance; this.gson = MedtronicUtil.gsonInstance;
this.gsonCore = MedtronicUtil.getGsonInstanceCore();
if (this.gson == null) { if (this.gson == null) {
this.gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); this.gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
} }
if (this.gsonCore == null) {
this.gsonCore = new GsonBuilder().create();
}
} }
@ -598,7 +604,7 @@ public class MedtronicHistoryData {
if (doubleBolusDebug) if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList), LOG.debug("DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList),
gson.toJson(entriesFromHistory)); gsonCore.toJson(entriesFromHistory));
filterOutAlreadyAddedEntries(entryList, entriesFromHistory); filterOutAlreadyAddedEntries(entryList, entriesFromHistory);
@ -610,7 +616,7 @@ public class MedtronicHistoryData {
if (doubleBolusDebug) if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList), LOG.debug("DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList),
gson.toJson(entriesFromHistory)); gsonCore.toJson(entriesFromHistory));
if (isCollectionEmpty(entriesFromHistory)) { if (isCollectionEmpty(entriesFromHistory)) {
for (PumpHistoryEntry treatment : entryList) { for (PumpHistoryEntry treatment : entryList) {
@ -863,6 +869,7 @@ public class MedtronicHistoryData {
return; return;
List<DbObjectBase> removeTreatmentsFromHistory = new ArrayList<>(); List<DbObjectBase> removeTreatmentsFromHistory = new ArrayList<>();
List<PumpHistoryEntry> removeTreatmentsFromPH = new ArrayList<>();
for (DbObjectBase treatment : treatmentsFromHistory) { for (DbObjectBase treatment : treatmentsFromHistory) {
@ -880,11 +887,17 @@ public class MedtronicHistoryData {
if (selectedBolus != null) { if (selectedBolus != null) {
entryList.remove(selectedBolus); entryList.remove(selectedBolus);
removeTreatmentsFromPH.add(selectedBolus);
removeTreatmentsFromHistory.add(treatment); removeTreatmentsFromHistory.add(treatment);
} }
} }
} }
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: filterOutAlreadyAddedEntries: PumpHistory={}, Treatments={}",
gson.toJson(removeTreatmentsFromPH),
gsonCore.toJson(removeTreatmentsFromHistory));
treatmentsFromHistory.removeAll(removeTreatmentsFromHistory); treatmentsFromHistory.removeAll(removeTreatmentsFromHistory);
} }

View file

@ -61,8 +61,7 @@ public class MedtronicUtil extends RileyLinkUtil {
private static int doneBit = 1 << 7; private static int doneBit = 1 << 7;
private static ClockDTO pumpTime; private static ClockDTO pumpTime;
public static Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); public static Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
public static Gson gsonInstancePretty = new GsonBuilder().excludeFieldsWithoutExposeAnnotation() public static Gson gsonInstanceCore = new GsonBuilder().create();
.setPrettyPrinting().create();
private static BatteryType batteryType = BatteryType.None; private static BatteryType batteryType = BatteryType.None;
@ -70,8 +69,9 @@ public class MedtronicUtil extends RileyLinkUtil {
return gsonInstance; return gsonInstance;
} }
public static Gson getGsonInstancePretty() {
return gsonInstancePretty; public static Gson getGsonInstanceCore() {
return gsonInstanceCore;
} }

View file

@ -349,7 +349,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
synchronized (treatments) { synchronized (treatments) {
if (MedtronicHistoryData.doubleBolusDebug) if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: AllTreatmentsInDb: {}", MedtronicUtil.getGsonInstance().toJson(treatments)); log.debug("DoubleBolusDebug: AllTreatmentsInDb: {}", MedtronicUtil.getGsonInstanceCore().toJson(treatments));
for (Treatment t : treatments) { for (Treatment t : treatments) {
if (t.date <= time && t.date >= fromTimestamp) if (t.date <= time && t.date >= fromTimestamp)
@ -357,7 +357,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
} }
if (MedtronicHistoryData.doubleBolusDebug) if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={}", fromTimestamp, MedtronicUtil.getGsonInstance().toJson(in5minback)); log.debug("DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={}", fromTimestamp, MedtronicUtil.getGsonInstanceCore().toJson(in5minback));
return in5minback; return in5minback;
} }