diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java index 6544b1b0b4..b1d5db0e2a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/PumpPluginAbstract.java @@ -34,6 +34,7 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewB 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; +import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData; import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; @@ -415,6 +416,9 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter // bolus needed, ask pump to deliver it return deliverBolus(detailedBolusInfo); } else { + if (MedtronicHistoryData.doubleBolusDebug) + LOG.debug("DoubleBolusDebug: deliverTreatment::(carb only entry)"); + // no bolus required, carb only treatment TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); 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 2fb897fcbc..1eed440cdc 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 @@ -83,6 +83,13 @@ public class MedtronicHistoryData { private long lastIdUsed = 0; + /** + * Double bolus debug. We seem to have small problem with double Boluses (or sometimes also missing boluses + * 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 = false; + public MedtronicHistoryData() { this.allHistory = new ArrayList<>(); @@ -584,23 +591,32 @@ public class MedtronicHistoryData { long oldestTimestamp = getOldestTimestamp(entryList); + Gson gson = MedtronicUtil.getGsonInstance(); + List entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.Bolus); -// LOG.debug(processHistoryRecord.getDescription() + " List (before filter): {}, FromDb={}", gsonPretty.toJson(entryList), -// gsonPretty.toJson(entriesFromHistory)); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList), + gson.toJson(entriesFromHistory)); filterOutAlreadyAddedEntries(entryList, entriesFromHistory); - if (entryList.isEmpty()) + if (entryList.isEmpty()) { + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: EntryList was filtered out."); return; + } -// LOG.debug(processHistoryRecord.getDescription() + " List (after filter): {}, FromDb={}", gsonPretty.toJson(entryList), -// gsonPretty.toJson(entriesFromHistory)); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList), + gson.toJson(entriesFromHistory)); if (isCollectionEmpty(entriesFromHistory)) { 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); } @@ -609,6 +625,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); } @@ -761,9 +779,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); } @@ -786,10 +825,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); } @@ -797,6 +836,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)); } } } @@ -851,6 +893,8 @@ public class MedtronicHistoryData { BolusDTO bolusDTO = (BolusDTO) bolus.getDecodedData().get("Object"); if (treatment == null) { + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: addBolus(tretament==null): Bolus={}", bolusDTO); switch (bolusDTO.getBolusType()) { case Normal: { @@ -863,6 +907,9 @@ public class MedtronicHistoryData { addCarbsFromEstimate(detailedBolusInfo, bolus); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: addBolus(tretament==null): DetailedBolusInfo={}", detailedBolusInfo); + boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); bolus.setLinkedObject(detailedBolusInfo); @@ -885,6 +932,9 @@ public class MedtronicHistoryData { bolus.setLinkedObject(extendedBolus); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: addBolus(tretament==null): ExtendedBolus={}", extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); if (isLogEnabled()) @@ -898,8 +948,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; @@ -910,6 +967,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); @@ -928,6 +988,9 @@ public class MedtronicHistoryData { BolusWizardDTO bolusWizard = (BolusWizardDTO) bolus.getDecodedData().get("Estimate"); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: addCarbsFromEstimate: Bolus={}, BolusWizardDTO={}", bolus, bolusWizard); + detailedBolusInfo.carbs = bolusWizard.carbs; } } @@ -1276,24 +1339,26 @@ public class MedtronicHistoryData { } } - //LocalDateTime oldestEntryTime = null; + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: getOldestTimestamp. Oldest entry found: time={}, object={}", dt, currentTreatment); try { GregorianCalendar oldestEntryTime = DateTimeUtil.toGregorianCalendar(dt); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: getOldestTimestamp. oldestEntryTime: {}", DateTimeUtil.toString(oldestEntryTime)); oldestEntryTime.add(Calendar.MINUTE, -2); + if (doubleBolusDebug) + LOG.debug("DoubleBolusDebug: getOldestTimestamp. oldestEntryTime (-2m): {}, timeInMillis={}", DateTimeUtil.toString(oldestEntryTime), oldestEntryTime.getTimeInMillis()); + return oldestEntryTime.getTimeInMillis(); -// if (this.pumpTime.timeDifference < 0) { -// oldestEntryTime = oldestEntryTime.plusSeconds(this.pumpTime.timeDifference); -// } } catch (Exception ex) { - LOG.error("Problem decoding date from last record: {}" + currentTreatment); + LOG.error("Problem decoding date from last record: {}", currentTreatment); return 8; // default return of 6 minutes } - } 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/TreatmentService.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java index 0af516678a..7123b6c96b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java @@ -39,6 +39,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData; +import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.JsonHelper; @@ -249,10 +250,14 @@ public class TreatmentService extends OrmLiteBaseService { try { Treatment treatment = Treatment.createFromJson(json); if (treatment != null) { + + if (MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: createTreatmentFromJsonIfNotExists:: medtronicPump={}", MedtronicUtil.isMedtronicPump()); + if (!MedtronicUtil.isMedtronicPump()) createOrUpdate(treatment); else - createOrUpdateMedtronic(treatment, false); + createOrUpdateMedtronic(treatment, true); } else log.error("Date is null: " + treatment.toString()); } catch (JSONException e) { @@ -392,11 +397,18 @@ public class TreatmentService extends OrmLiteBaseService { public UpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout) { + + if (MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: createOrUpdateMedtronic:: originalTreatment={}, fromNightScout={}", treatment, fromNightScout); + try { treatment.date = DatabaseHelper.roundDateToSec(treatment.date); Treatment existingTreatment = getRecord(treatment.pumpId, treatment.date); + if (MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: createOrUpdateMedtronic:: existingTreatment={}", treatment); + if (existingTreatment == null) { getDao().create(treatment); if (L.isEnabled(L.DATATREATMENTS)) @@ -407,6 +419,9 @@ public class TreatmentService extends OrmLiteBaseService { } else { if (existingTreatment.date == treatment.date) { + if (MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: createOrUpdateMedtronic::(existingTreatment.date==treatment.date)"); + // we will do update only, if entry changed if (!optionalTreatmentCopy(existingTreatment, treatment, fromNightScout)) { return new UpdateReturn(true, false); @@ -416,6 +431,9 @@ public class TreatmentService extends OrmLiteBaseService { scheduleTreatmentChange(treatment); return new UpdateReturn(true, false); } else { + if (MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: createOrUpdateMedtronic::(existingTreatment.date != treatment.date)"); + // date is different, we need to remove entry getDao().delete(existingTreatment); optionalTreatmentCopy(existingTreatment, treatment, fromNightScout); 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 881d14b9cd..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 @@ -51,6 +51,7 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData; import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin; @@ -344,12 +345,20 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface @Override public List getTreatmentsFromHistoryAfterTimestamp(long fromTimestamp) { List in5minback = new ArrayList<>(); + long time = System.currentTimeMillis(); synchronized (treatments) { + if (MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: AllTreatmentsInDb: {}", MedtronicUtil.getGsonInstance().toJson(treatments)); + for (Treatment t : treatments) { if (t.date <= time && t.date >= fromTimestamp) in5minback.add(t); } + + if (MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={}", fromTimestamp, MedtronicUtil.getGsonInstance().toJson(in5minback)); + return in5minback; } } @@ -623,6 +632,9 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface public boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo, boolean allowUpdate) { boolean medtronicPump = MedtronicUtil.isMedtronicPump(); + if (MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: addToHistoryTreatment::isMedtronicPump={}", medtronicPump); + Treatment treatment = new Treatment(); treatment.date = detailedBolusInfo.date; treatment.source = detailedBolusInfo.source; @@ -637,6 +649,9 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface treatment.boluscalc = detailedBolusInfo.boluscalc != null ? detailedBolusInfo.boluscalc.toString() : null; TreatmentService.UpdateReturn creatOrUpdateResult; + if (medtronicPump && MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: addToHistoryTreatment::treatment={}", treatment); + if (!medtronicPump) creatOrUpdateResult = getService().createOrUpdate(treatment); else @@ -645,12 +660,17 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface boolean newRecordCreated = creatOrUpdateResult.newRecord; //log.debug("Adding new Treatment record" + treatment.toString()); if (detailedBolusInfo.carbTime != 0) { + Treatment carbsTreatment = new Treatment(); carbsTreatment.source = detailedBolusInfo.source; carbsTreatment.pumpId = detailedBolusInfo.pumpId; // but this should never happen carbsTreatment.date = detailedBolusInfo.date + detailedBolusInfo.carbTime * 60 * 1000L + 1000L; // add 1 sec to make them different records carbsTreatment.carbs = detailedBolusInfo.carbs; carbsTreatment.source = detailedBolusInfo.source; + + if (medtronicPump && MedtronicHistoryData.doubleBolusDebug) + log.debug("DoubleBolusDebug: carbTime!=0, creating second treatment. CarbsTreatment={}", carbsTreatment); + if (!medtronicPump) getService().createOrUpdate(carbsTreatment); else diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 0ad824ddea..6b98e1c0dd 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -99,7 +99,7 @@ @string/use_gps_location - + PASSIVE NETWORK GPS @@ -151,7 +151,7 @@ @string/medtronic_pump_frequency_worldwide - + @string/key_medtronic_pump_frequency_us_ca @string/key_medtronic_pump_frequency_worldwide @@ -167,6 +167,11 @@ @string/medtronic_pump_encoding_4b6b_rileylink + + @string/common_on + @string/common_off + + @string/key_medtronic_pump_encoding_4b6b_local @string/key_medtronic_pump_encoding_4b6b_rileylink @@ -176,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 520b560c9d..70e05db6c4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,15 +4,15 @@ Afrikaans Bulgarian Dutch - + French German Greek - + Chinese - + Italian - + Korean Lithuanian Polish @@ -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,8 @@ Not selected (Simple view) Alkaline (Extended view) Lithium (Extended view) + NiZn (Extended view) + Bolus/Treatments Debugging SCAN @@ -1608,5 +1612,7 @@ min wizard_calculation_visible %1$dg + On + Off diff --git a/app/src/main/res/xml/pref_medtronic.xml b/app/src/main/res/xml/pref_medtronic.xml index 603d3873f8..10730f4fcb 100644 --- a/app/src/main/res/xml/pref_medtronic.xml +++ b/app/src/main/res/xml/pref_medtronic.xml @@ -68,6 +68,14 @@ android:selectable="true" android:title="@string/medtronic_pump_battery_select" /> + +