diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt index 293babfc2b..d7833a4fe4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.common.bolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.logging.L +import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData import info.nightscout.androidaps.utils.T import org.slf4j.LoggerFactory import java.util.* @@ -19,6 +20,10 @@ object DetailedBolusInfoStorage { @Synchronized fun findDetailedBolusInfo(bolusTime: Long, bolus: Double): DetailedBolusInfo? { + + if (MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: findDetailedBolusInfo::bolusTime={}, bolus={}", bolusTime, bolus) + // Look for info with bolus for (i in store.indices) { val d = store[i] @@ -28,6 +33,9 @@ object DetailedBolusInfoStorage { if (L.isEnabled(L.PUMP)) log.debug("Using & removing bolus info: " + store[i]) store.removeAt(i) + if (MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: findDetailedBolusInfo::selectedBolus[DetailedBolusInfo={}]", d) + return d } } @@ -38,6 +46,8 @@ object DetailedBolusInfoStorage { if (L.isEnabled(L.PUMP)) log.debug("Using & removing bolus info: " + store[i]) store.removeAt(i) + if (MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: findDetailedBolusInfo::selectedBolus[DetailedBolusInfo={}]", d) return d } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java index b886861b00..021d1ee068 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneral.java @@ -122,10 +122,10 @@ public class RileyLinkStatusGeneral extends Fragment implements RefreshableInter this.medtronicPumpStatus = MedtronicUtil.getPumpStatus(); if (medtronicPumpStatus != null) { - this.deviceType.setText(MainApp.gs(RileyLinkUtil.getTargetDevice().getResourceId())); + this.deviceType.setText(MainApp.gs(RileyLinkTargetDevice.MedtronicPump.getResourceId())); this.deviceModel.setText(medtronicPumpStatus.pumpType.getDescription()); this.serialNumber.setText(medtronicPumpStatus.serialNumber); - this.pumpFrequency.setText(medtronicPumpStatus.pumpFrequency); + this.pumpFrequency.setText(MainApp.gs(medtronicPumpStatus.pumpFrequency.equals("medtronic_pump_frequency_us_ca") ? R.string.medtronic_pump_frequency_us_ca : R.string.medtronic_pump_frequency_worldwide)); // TODO extend when Omnipod used diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java index e255779fac..35c45893e5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.java @@ -88,7 +88,7 @@ public class MedtronicHistoryData { * from history. This flag turns on debugging for that (default is off=false)... Debuging is pretty detailed, * so log files will get bigger. */ - public static boolean doubleBolusDebug = true; + public static boolean doubleBolusDebug = false; public MedtronicHistoryData() { @@ -600,6 +600,8 @@ public class MedtronicHistoryData { filterOutAlreadyAddedEntries(entryList, entriesFromHistory); if (entryList.isEmpty()) { + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: EntryList was filtered out."); return; } @@ -611,6 +613,8 @@ public class MedtronicHistoryData { for (PumpHistoryEntry treatment : entryList) { if (isLogEnabled()) LOG.debug("Add Bolus (no db entry): " + treatment); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: Add Bolus: FromDb=null, Treatment={}", treatment); addBolus(treatment, null); } @@ -619,6 +623,8 @@ public class MedtronicHistoryData { DbObjectBase treatmentDb = findDbEntry(treatment, entriesFromHistory); if (isLogEnabled()) LOG.debug("Add Bolus {} - (entryFromDb={}) ", treatment, treatmentDb); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: Add Bolus: FromDb={}, Treatment={}", treatmentDb, treatment); addBolus(treatment, (Treatment) treatmentDb); } @@ -771,9 +777,30 @@ public class MedtronicHistoryData { //proposedTime += (this.pumpTime.timeDifference * 1000); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}", treatment, gson.toJson(entriesFromHistory)); + if (entriesFromHistory.size() == 0) { + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: findDbEntry Treatment={}, FromDb=null", treatment); return null; } else if (entriesFromHistory.size() == 1) { + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}. Type=SingleEntry", treatment, entriesFromHistory.get(0)); + + // TODO: Fix db code + // if difference is bigger than 2 minutes we discard entry + long maxMillisAllowed = DateTimeUtil.getMillisFromATDWithAddedMinutes(treatment.atechDateTime, 2); + + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: findDbEntry maxMillisAllowed={}, AtechDateTime={} (add 2 minutes). ", maxMillisAllowed, treatment.atechDateTime); + + if (entriesFromHistory.get(0).getDate() > maxMillisAllowed) { + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: findDbEntry entry filtered out, returning null. "); + return null; + } + return entriesFromHistory.get(0); } @@ -796,10 +823,10 @@ public class MedtronicHistoryData { } } -// LOG.debug("Entries: (timeDiff=[min={},sec={}],count={},list={})", min, sec, outList.size(), -// gsonPretty.toJson(outList)); - if (outList.size() == 1) { + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}. Type=EntrySelected, AtTimeMin={}, AtTimeSec={}", treatment, entriesFromHistory.get(0), min, sec); + return outList.get(0); } @@ -807,6 +834,9 @@ public class MedtronicHistoryData { if (isLogEnabled()) LOG.error("Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})", min, sec, outList.size(), gson.toJson(outList)); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: findDbEntry Error - Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})", + min, sec, outList.size(), gson.toJson(outList)); } } } @@ -860,7 +890,6 @@ public class MedtronicHistoryData { BolusDTO bolusDTO = (BolusDTO) bolus.getDecodedData().get("Object"); - if (treatment == null) { if (doubleBolusDebug) LOG.debug("DoubleBolusDebug: addBolus(tretament==null): Bolus={}", bolusDTO); @@ -901,6 +930,9 @@ public class MedtronicHistoryData { bolus.setLinkedObject(extendedBolus); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: addBolus(tretament==null): ExtendedBolus={}", extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); if (isLogEnabled()) @@ -914,8 +946,15 @@ public class MedtronicHistoryData { } else { DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.INSTANCE.findDetailedBolusInfo(treatment.date, bolusDTO.getDeliveredAmount()); + + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: addBolus(tretament={}): Bolus={}, DetailedBolusInfo={}", treatment, bolusDTO, detailedBolusInfo); + if (detailedBolusInfo == null) { detailedBolusInfo = new DetailedBolusInfo(); + + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: detailedBolusInfoCouldNotBeRetrived !"); } detailedBolusInfo.date = treatment.date; @@ -926,6 +965,9 @@ public class MedtronicHistoryData { addCarbsFromEstimate(detailedBolusInfo, bolus); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: addBolus(tretament!=null): DetailedBolusInfo(New)={}", detailedBolusInfo); + boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); bolus.setLinkedObject(detailedBolusInfo); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java index c8bd2347d0..93b5eb10cb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java @@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.pump.medtronic.data.dto; import com.google.gson.annotations.Expose; +import java.util.Locale; + import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType; /** @@ -38,10 +40,11 @@ public class BatteryStatusDTO { public String toString() { - return String.format("BatteryStatusDTO [voltage=%.2f, alkaline=%d, lithium=%d]", + return String.format(Locale.ENGLISH, "BatteryStatusDTO [voltage=%.2f, alkaline=%d, lithium=%d, niZn={}]", voltage == null ? 0.0f : voltage, getCalculatedPercent(BatteryType.Alkaline), - getCalculatedPercent(BatteryType.Lithium)); + getCalculatedPercent(BatteryType.Lithium), + getCalculatedPercent(BatteryType.NiZn)); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/BatteryType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/BatteryType.java index 0d228d43ec..5c7bf245a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/BatteryType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/BatteryType.java @@ -14,7 +14,9 @@ public enum BatteryType { None(R.string.key_medtronic_pump_battery_no, 0, 0), Alkaline(R.string.key_medtronic_pump_battery_alkaline, 1.20d, 1.47d), // - Lithium(R.string.key_medtronic_pump_battery_lithium, 1.22d, 1.64d); + Lithium(R.string.key_medtronic_pump_battery_lithium, 1.22d, 1.64d), // + NiZn(R.string.key_medtronic_pump_battery_nizn, 1.40d, 1.70d) // + ; private final String description; public double lowVoltage; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java index 29387b0724..fc1208a340 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.Rile import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkTargetFrequency; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; +import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData; import info.nightscout.androidaps.plugins.pump.medtronic.defs.BasalProfileStatus; import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType; @@ -281,6 +282,12 @@ public class MedtronicPumpStatus extends PumpStatus { MedtronicUtil.setBatteryType(this.batteryType); } + String bolusDebugEnabled = SP.getString(MedtronicConst.Prefs.BolusDebugEnabled, null); + + boolean bolusDebug = bolusDebugEnabled != null && bolusDebugEnabled.equals(MainApp.gs(R.string.common_on)); + + MedtronicHistoryData.doubleBolusDebug = bolusDebug; + reconfigureService(); return true; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java index cd39ba53bf..fef95087de 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicConst.java @@ -11,17 +11,6 @@ public class MedtronicConst { static final String Prefix = "AAPS.Medtronic."; public class Prefs { - -// public static final String PrefPrefix = "pref_medtronic_"; -// public static final String PumpSerial = PrefPrefix + "serial"; -// public static final String PumpType = PrefPrefix + "pump_type"; -// public static final String PumpFrequency = PrefPrefix + "frequency"; -// public static final String MaxBolus = PrefPrefix + "max_bolus"; -// public static final String MaxBasal = PrefPrefix + "max_basal"; -// public static final String BolusDelay = PrefPrefix + "bolus_delay"; -// public static final String Encoding = PrefPrefix + "encoding"; -// public static final String BatteryType = PrefPrefix + "battery_type"; - public static final int PumpSerial = R.string.key_medtronic_serial; public static final int PumpType = R.string.key_medtronic_pump_type; public static final int PumpFrequency = R.string.key_medtronic_frequency; @@ -30,6 +19,7 @@ public class MedtronicConst { public static final int BolusDelay = R.string.key_medtronic_bolus_delay; public static final int Encoding = R.string.key_medtronic_encoding; public static final int BatteryType = R.string.key_medtronic_battery_type; + public static final int BolusDebugEnabled = R.string.key_medtronic_bolus_debug; } public class Statistics { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index 1c92ca6eb7..28181da190 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -357,7 +357,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface } if (MedtronicHistoryData.doubleBolusDebug) - log.debug("DoubleBolusDebug: FilteredTreatments: After={}, Items={}", fromTimestamp, MedtronicUtil.getGsonInstance().toJson(in5minback)); + log.debug("DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={}", fromTimestamp, MedtronicUtil.getGsonInstance().toJson(in5minback)); return in5minback; } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index acaa1019de..6b98e1c0dd 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -181,12 +181,17 @@ @string/medtronic_pump_battery_no @string/medtronic_pump_battery_alkaline @string/medtronic_pump_battery_lithium + @string/medtronic_pump_battery_nizn @string/key_medtronic_pump_battery_no @string/key_medtronic_pump_battery_alkaline @string/key_medtronic_pump_battery_lithium + @string/key_medtronic_pump_battery_nizn + + key_medtronic_bolus_debug + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3a4e43e6e1..70e05db6c4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1424,6 +1424,7 @@ pref_medtronic_bolus_delay pref_medtronic_encoding pref_medtronic_battery_type + pref_medtronic_bolus_debug pref_rileylink_mac_address medtronic_pump_frequency_us_ca medtronic_pump_frequency_worldwide @@ -1432,6 +1433,7 @@ medtronic_pump_battery_no medtronic_pump_battery_alkaline medtronic_pump_battery_lithium + medtronic_pump_battery_nizn Pump Serial Number Pump Type @@ -1451,6 +1453,7 @@ Not selected (Simple view) Alkaline (Extended view) Lithium (Extended view) + NiZn (Extended view) Bolus/Treatments Debugging diff --git a/app/src/main/res/xml/pref_medtronic.xml b/app/src/main/res/xml/pref_medtronic.xml index a38cc22923..10730f4fcb 100644 --- a/app/src/main/res/xml/pref_medtronic.xml +++ b/app/src/main/res/xml/pref_medtronic.xml @@ -60,14 +60,6 @@ android:selectable="true" android:title="@string/medtronic_pump_encoding" /> - - + +