Merge pull request #2141 from andyrozman/double_bolus_debug

Double bolus debug
This commit is contained in:
Milos Kozak 2019-10-26 18:21:07 +02:00 committed by GitHub
commit c82fd6a56b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 180 additions and 37 deletions

View file

@ -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.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;
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil; 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 // bolus needed, ask pump to deliver it
return deliverBolus(detailedBolusInfo); return deliverBolus(detailedBolusInfo);
} else { } else {
if (MedtronicHistoryData.doubleBolusDebug)
LOG.debug("DoubleBolusDebug: deliverTreatment::(carb only entry)");
// no bolus required, carb only treatment // no bolus required, carb only treatment
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.common.bolusInfo
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.util.* import java.util.*
@ -19,6 +20,10 @@ object DetailedBolusInfoStorage {
@Synchronized @Synchronized
fun findDetailedBolusInfo(bolusTime: Long, bolus: Double): DetailedBolusInfo? { fun findDetailedBolusInfo(bolusTime: Long, bolus: Double): DetailedBolusInfo? {
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: findDetailedBolusInfo::bolusTime={}, bolus={}", bolusTime, bolus)
// Look for info with bolus // Look for info with bolus
for (i in store.indices) { for (i in store.indices) {
val d = store[i] val d = store[i]
@ -28,6 +33,9 @@ object DetailedBolusInfoStorage {
if (L.isEnabled(L.PUMP)) if (L.isEnabled(L.PUMP))
log.debug("Using & removing bolus info: " + store[i]) log.debug("Using & removing bolus info: " + store[i])
store.removeAt(i) store.removeAt(i)
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: findDetailedBolusInfo::selectedBolus[DetailedBolusInfo={}]", d)
return d return d
} }
} }
@ -38,6 +46,8 @@ object DetailedBolusInfoStorage {
if (L.isEnabled(L.PUMP)) if (L.isEnabled(L.PUMP))
log.debug("Using & removing bolus info: " + store[i]) log.debug("Using & removing bolus info: " + store[i])
store.removeAt(i) store.removeAt(i)
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: findDetailedBolusInfo::selectedBolus[DetailedBolusInfo={}]", d)
return d return d
} }
} }

View file

@ -122,10 +122,10 @@ public class RileyLinkStatusGeneral extends Fragment implements RefreshableInter
this.medtronicPumpStatus = MedtronicUtil.getPumpStatus(); this.medtronicPumpStatus = MedtronicUtil.getPumpStatus();
if (medtronicPumpStatus != null) { 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.deviceModel.setText(medtronicPumpStatus.pumpType.getDescription());
this.serialNumber.setText(medtronicPumpStatus.serialNumber); 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 // TODO extend when Omnipod used

View file

@ -83,6 +83,13 @@ public class MedtronicHistoryData {
private long lastIdUsed = 0; 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() { public MedtronicHistoryData() {
this.allHistory = new ArrayList<>(); this.allHistory = new ArrayList<>();
@ -584,23 +591,32 @@ public class MedtronicHistoryData {
long oldestTimestamp = getOldestTimestamp(entryList); long oldestTimestamp = getOldestTimestamp(entryList);
Gson gson = MedtronicUtil.getGsonInstance();
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.Bolus); List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntriesByLastTimestamp(oldestTimestamp, ProcessHistoryRecord.Bolus);
// LOG.debug(processHistoryRecord.getDescription() + " List (before filter): {}, FromDb={}", gsonPretty.toJson(entryList), if (doubleBolusDebug)
// gsonPretty.toJson(entriesFromHistory)); LOG.debug("DoubleBolusDebug: List (before filter): {}, FromDb={}", gson.toJson(entryList),
gson.toJson(entriesFromHistory));
filterOutAlreadyAddedEntries(entryList, entriesFromHistory); filterOutAlreadyAddedEntries(entryList, entriesFromHistory);
if (entryList.isEmpty()) if (entryList.isEmpty()) {
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: EntryList was filtered out.");
return; return;
}
// LOG.debug(processHistoryRecord.getDescription() + " List (after filter): {}, FromDb={}", gsonPretty.toJson(entryList), if (doubleBolusDebug)
// gsonPretty.toJson(entriesFromHistory)); LOG.debug("DoubleBolusDebug: List (after filter): {}, FromDb={}", gson.toJson(entryList),
gson.toJson(entriesFromHistory));
if (isCollectionEmpty(entriesFromHistory)) { if (isCollectionEmpty(entriesFromHistory)) {
for (PumpHistoryEntry treatment : entryList) { for (PumpHistoryEntry treatment : entryList) {
if (isLogEnabled()) if (isLogEnabled())
LOG.debug("Add Bolus (no db entry): " + treatment); LOG.debug("Add Bolus (no db entry): " + treatment);
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: Add Bolus: FromDb=null, Treatment={}", treatment);
addBolus(treatment, null); addBolus(treatment, null);
} }
@ -609,6 +625,8 @@ public class MedtronicHistoryData {
DbObjectBase treatmentDb = findDbEntry(treatment, entriesFromHistory); DbObjectBase treatmentDb = findDbEntry(treatment, entriesFromHistory);
if (isLogEnabled()) if (isLogEnabled())
LOG.debug("Add Bolus {} - (entryFromDb={}) ", treatment, treatmentDb); LOG.debug("Add Bolus {} - (entryFromDb={}) ", treatment, treatmentDb);
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: Add Bolus: FromDb={}, Treatment={}", treatmentDb, treatment);
addBolus(treatment, (Treatment) treatmentDb); addBolus(treatment, (Treatment) treatmentDb);
} }
@ -761,9 +779,30 @@ public class MedtronicHistoryData {
//proposedTime += (this.pumpTime.timeDifference * 1000); //proposedTime += (this.pumpTime.timeDifference * 1000);
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}", treatment, gson.toJson(entriesFromHistory));
if (entriesFromHistory.size() == 0) { if (entriesFromHistory.size() == 0) {
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: findDbEntry Treatment={}, FromDb=null", treatment);
return null; return null;
} else if (entriesFromHistory.size() == 1) { } 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); 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 (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); return outList.get(0);
} }
@ -797,6 +836,9 @@ public class MedtronicHistoryData {
if (isLogEnabled()) if (isLogEnabled())
LOG.error("Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})", LOG.error("Too many entries (with too small diff): (timeDiff=[min={},sec={}],count={},list={})",
min, sec, outList.size(), gson.toJson(outList)); 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"); BolusDTO bolusDTO = (BolusDTO) bolus.getDecodedData().get("Object");
if (treatment == null) { if (treatment == null) {
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: addBolus(tretament==null): Bolus={}", bolusDTO);
switch (bolusDTO.getBolusType()) { switch (bolusDTO.getBolusType()) {
case Normal: { case Normal: {
@ -863,6 +907,9 @@ public class MedtronicHistoryData {
addCarbsFromEstimate(detailedBolusInfo, bolus); addCarbsFromEstimate(detailedBolusInfo, bolus);
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: addBolus(tretament==null): DetailedBolusInfo={}", detailedBolusInfo);
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
bolus.setLinkedObject(detailedBolusInfo); bolus.setLinkedObject(detailedBolusInfo);
@ -885,6 +932,9 @@ public class MedtronicHistoryData {
bolus.setLinkedObject(extendedBolus); bolus.setLinkedObject(extendedBolus);
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: addBolus(tretament==null): ExtendedBolus={}", extendedBolus);
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
if (isLogEnabled()) if (isLogEnabled())
@ -898,8 +948,15 @@ public class MedtronicHistoryData {
} else { } else {
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.INSTANCE.findDetailedBolusInfo(treatment.date, bolusDTO.getDeliveredAmount()); DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.INSTANCE.findDetailedBolusInfo(treatment.date, bolusDTO.getDeliveredAmount());
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: addBolus(tretament={}): Bolus={}, DetailedBolusInfo={}", treatment, bolusDTO, detailedBolusInfo);
if (detailedBolusInfo == null) { if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo = new DetailedBolusInfo();
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: detailedBolusInfoCouldNotBeRetrived !");
} }
detailedBolusInfo.date = treatment.date; detailedBolusInfo.date = treatment.date;
@ -910,6 +967,9 @@ public class MedtronicHistoryData {
addCarbsFromEstimate(detailedBolusInfo, bolus); addCarbsFromEstimate(detailedBolusInfo, bolus);
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: addBolus(tretament!=null): DetailedBolusInfo(New)={}", detailedBolusInfo);
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
bolus.setLinkedObject(detailedBolusInfo); bolus.setLinkedObject(detailedBolusInfo);
@ -928,6 +988,9 @@ public class MedtronicHistoryData {
BolusWizardDTO bolusWizard = (BolusWizardDTO) bolus.getDecodedData().get("Estimate"); BolusWizardDTO bolusWizard = (BolusWizardDTO) bolus.getDecodedData().get("Estimate");
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: addCarbsFromEstimate: Bolus={}, BolusWizardDTO={}", bolus, bolusWizard);
detailedBolusInfo.carbs = bolusWizard.carbs; 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 { try {
GregorianCalendar oldestEntryTime = DateTimeUtil.toGregorianCalendar(dt); GregorianCalendar oldestEntryTime = DateTimeUtil.toGregorianCalendar(dt);
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: getOldestTimestamp. oldestEntryTime: {}", DateTimeUtil.toString(oldestEntryTime));
oldestEntryTime.add(Calendar.MINUTE, -2); oldestEntryTime.add(Calendar.MINUTE, -2);
if (doubleBolusDebug)
LOG.debug("DoubleBolusDebug: getOldestTimestamp. oldestEntryTime (-2m): {}, timeInMillis={}", DateTimeUtil.toString(oldestEntryTime), oldestEntryTime.getTimeInMillis());
return oldestEntryTime.getTimeInMillis(); return oldestEntryTime.getTimeInMillis();
// if (this.pumpTime.timeDifference < 0) {
// oldestEntryTime = oldestEntryTime.plusSeconds(this.pumpTime.timeDifference);
// }
} catch (Exception ex) { } 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 return 8; // default return of 6 minutes
} }
} }

View file

@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.pump.medtronic.data.dto;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import java.util.Locale;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType;
/** /**
@ -38,10 +40,11 @@ public class BatteryStatusDTO {
public String toString() { 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, voltage == null ? 0.0f : voltage,
getCalculatedPercent(BatteryType.Alkaline), getCalculatedPercent(BatteryType.Alkaline),
getCalculatedPercent(BatteryType.Lithium)); getCalculatedPercent(BatteryType.Lithium),
getCalculatedPercent(BatteryType.NiZn));
} }

View file

@ -14,7 +14,9 @@ public enum BatteryType {
None(R.string.key_medtronic_pump_battery_no, 0, 0), None(R.string.key_medtronic_pump_battery_no, 0, 0),
Alkaline(R.string.key_medtronic_pump_battery_alkaline, 1.20d, 1.47d), // 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; private final String description;
public double lowVoltage; public double lowVoltage;

View file

@ -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.ble.defs.RileyLinkTargetFrequency;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; 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.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.BasalProfileStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
@ -281,6 +282,12 @@ public class MedtronicPumpStatus extends PumpStatus {
MedtronicUtil.setBatteryType(this.batteryType); 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(); reconfigureService();
return true; return true;

View file

@ -11,17 +11,6 @@ public class MedtronicConst {
static final String Prefix = "AAPS.Medtronic."; static final String Prefix = "AAPS.Medtronic.";
public class Prefs { 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 PumpSerial = R.string.key_medtronic_serial;
public static final int PumpType = R.string.key_medtronic_pump_type; public static final int PumpType = R.string.key_medtronic_pump_type;
public static final int PumpFrequency = R.string.key_medtronic_frequency; 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 BolusDelay = R.string.key_medtronic_bolus_delay;
public static final int Encoding = R.string.key_medtronic_encoding; 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 BatteryType = R.string.key_medtronic_battery_type;
public static final int BolusDebugEnabled = R.string.key_medtronic_bolus_debug;
} }
public class Statistics { public class Statistics {

View file

@ -39,6 +39,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData; 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.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.JsonHelper; import info.nightscout.androidaps.utils.JsonHelper;
@ -249,10 +250,14 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
try { try {
Treatment treatment = Treatment.createFromJson(json); Treatment treatment = Treatment.createFromJson(json);
if (treatment != null) { if (treatment != null) {
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: createTreatmentFromJsonIfNotExists:: medtronicPump={}", MedtronicUtil.isMedtronicPump());
if (!MedtronicUtil.isMedtronicPump()) if (!MedtronicUtil.isMedtronicPump())
createOrUpdate(treatment); createOrUpdate(treatment);
else else
createOrUpdateMedtronic(treatment, false); createOrUpdateMedtronic(treatment, true);
} else } else
log.error("Date is null: " + treatment.toString()); log.error("Date is null: " + treatment.toString());
} catch (JSONException e) { } catch (JSONException e) {
@ -392,11 +397,18 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
public UpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout) { public UpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout) {
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: createOrUpdateMedtronic:: originalTreatment={}, fromNightScout={}", treatment, fromNightScout);
try { try {
treatment.date = DatabaseHelper.roundDateToSec(treatment.date); treatment.date = DatabaseHelper.roundDateToSec(treatment.date);
Treatment existingTreatment = getRecord(treatment.pumpId, treatment.date); Treatment existingTreatment = getRecord(treatment.pumpId, treatment.date);
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: createOrUpdateMedtronic:: existingTreatment={}", treatment);
if (existingTreatment == null) { if (existingTreatment == null) {
getDao().create(treatment); getDao().create(treatment);
if (L.isEnabled(L.DATATREATMENTS)) if (L.isEnabled(L.DATATREATMENTS))
@ -407,6 +419,9 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
} else { } else {
if (existingTreatment.date == treatment.date) { if (existingTreatment.date == treatment.date) {
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: createOrUpdateMedtronic::(existingTreatment.date==treatment.date)");
// we will do update only, if entry changed // we will do update only, if entry changed
if (!optionalTreatmentCopy(existingTreatment, treatment, fromNightScout)) { if (!optionalTreatmentCopy(existingTreatment, treatment, fromNightScout)) {
return new UpdateReturn(true, false); return new UpdateReturn(true, false);
@ -416,6 +431,9 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
scheduleTreatmentChange(treatment); scheduleTreatmentChange(treatment);
return new UpdateReturn(true, false); return new UpdateReturn(true, false);
} else { } else {
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: createOrUpdateMedtronic::(existingTreatment.date != treatment.date)");
// date is different, we need to remove entry // date is different, we need to remove entry
getDao().delete(existingTreatment); getDao().delete(existingTreatment);
optionalTreatmentCopy(existingTreatment, treatment, fromNightScout); optionalTreatmentCopy(existingTreatment, treatment, fromNightScout);

View file

@ -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.AutosensData;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; 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.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
@ -344,12 +345,20 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
@Override @Override
public List<Treatment> getTreatmentsFromHistoryAfterTimestamp(long fromTimestamp) { public List<Treatment> getTreatmentsFromHistoryAfterTimestamp(long fromTimestamp) {
List<Treatment> in5minback = new ArrayList<>(); List<Treatment> in5minback = new ArrayList<>();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
synchronized (treatments) { synchronized (treatments) {
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: AllTreatmentsInDb: {}", MedtronicUtil.getGsonInstance().toJson(treatments));
for (Treatment t : treatments) { for (Treatment t : treatments) {
if (t.date <= time && t.date >= fromTimestamp) if (t.date <= time && t.date >= fromTimestamp)
in5minback.add(t); in5minback.add(t);
} }
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={}", fromTimestamp, MedtronicUtil.getGsonInstance().toJson(in5minback));
return in5minback; return in5minback;
} }
} }
@ -623,6 +632,9 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
public boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo, boolean allowUpdate) { public boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo, boolean allowUpdate) {
boolean medtronicPump = MedtronicUtil.isMedtronicPump(); boolean medtronicPump = MedtronicUtil.isMedtronicPump();
if (MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: addToHistoryTreatment::isMedtronicPump={}", medtronicPump);
Treatment treatment = new Treatment(); Treatment treatment = new Treatment();
treatment.date = detailedBolusInfo.date; treatment.date = detailedBolusInfo.date;
treatment.source = detailedBolusInfo.source; treatment.source = detailedBolusInfo.source;
@ -637,6 +649,9 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
treatment.boluscalc = detailedBolusInfo.boluscalc != null ? detailedBolusInfo.boluscalc.toString() : null; treatment.boluscalc = detailedBolusInfo.boluscalc != null ? detailedBolusInfo.boluscalc.toString() : null;
TreatmentService.UpdateReturn creatOrUpdateResult; TreatmentService.UpdateReturn creatOrUpdateResult;
if (medtronicPump && MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: addToHistoryTreatment::treatment={}", treatment);
if (!medtronicPump) if (!medtronicPump)
creatOrUpdateResult = getService().createOrUpdate(treatment); creatOrUpdateResult = getService().createOrUpdate(treatment);
else else
@ -645,12 +660,17 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
boolean newRecordCreated = creatOrUpdateResult.newRecord; boolean newRecordCreated = creatOrUpdateResult.newRecord;
//log.debug("Adding new Treatment record" + treatment.toString()); //log.debug("Adding new Treatment record" + treatment.toString());
if (detailedBolusInfo.carbTime != 0) { if (detailedBolusInfo.carbTime != 0) {
Treatment carbsTreatment = new Treatment(); Treatment carbsTreatment = new Treatment();
carbsTreatment.source = detailedBolusInfo.source; carbsTreatment.source = detailedBolusInfo.source;
carbsTreatment.pumpId = detailedBolusInfo.pumpId; // but this should never happen 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.date = detailedBolusInfo.date + detailedBolusInfo.carbTime * 60 * 1000L + 1000L; // add 1 sec to make them different records
carbsTreatment.carbs = detailedBolusInfo.carbs; carbsTreatment.carbs = detailedBolusInfo.carbs;
carbsTreatment.source = detailedBolusInfo.source; carbsTreatment.source = detailedBolusInfo.source;
if (medtronicPump && MedtronicHistoryData.doubleBolusDebug)
log.debug("DoubleBolusDebug: carbTime!=0, creating second treatment. CarbsTreatment={}", carbsTreatment);
if (!medtronicPump) if (!medtronicPump)
getService().createOrUpdate(carbsTreatment); getService().createOrUpdate(carbsTreatment);
else else

View file

@ -167,6 +167,11 @@
<item>@string/medtronic_pump_encoding_4b6b_rileylink</item> <item>@string/medtronic_pump_encoding_4b6b_rileylink</item>
</string-array> </string-array>
<string-array name="onOff">
<item>@string/common_on</item>
<item>@string/common_off</item>
</string-array>
<string-array name="medtronicEncodingValues"> <string-array name="medtronicEncodingValues">
<item>@string/key_medtronic_pump_encoding_4b6b_local</item> <item>@string/key_medtronic_pump_encoding_4b6b_local</item>
<item>@string/key_medtronic_pump_encoding_4b6b_rileylink</item> <item>@string/key_medtronic_pump_encoding_4b6b_rileylink</item>
@ -176,12 +181,17 @@
<item>@string/medtronic_pump_battery_no</item> <item>@string/medtronic_pump_battery_no</item>
<item>@string/medtronic_pump_battery_alkaline</item> <item>@string/medtronic_pump_battery_alkaline</item>
<item>@string/medtronic_pump_battery_lithium</item> <item>@string/medtronic_pump_battery_lithium</item>
<item>@string/medtronic_pump_battery_nizn</item>
</string-array> </string-array>
<string-array name="medtronicBatteryTypeValues"> <string-array name="medtronicBatteryTypeValues">
<item>@string/key_medtronic_pump_battery_no</item> <item>@string/key_medtronic_pump_battery_no</item>
<item>@string/key_medtronic_pump_battery_alkaline</item> <item>@string/key_medtronic_pump_battery_alkaline</item>
<item>@string/key_medtronic_pump_battery_lithium</item> <item>@string/key_medtronic_pump_battery_lithium</item>
<item>@string/key_medtronic_pump_battery_nizn</item>
</string-array> </string-array>
key_medtronic_bolus_debug
</resources> </resources>

View file

@ -1424,6 +1424,7 @@
<string name="key_medtronic_bolus_delay" translatable="false">pref_medtronic_bolus_delay</string> <string name="key_medtronic_bolus_delay" translatable="false">pref_medtronic_bolus_delay</string>
<string name="key_medtronic_encoding" translatable="false">pref_medtronic_encoding</string> <string name="key_medtronic_encoding" translatable="false">pref_medtronic_encoding</string>
<string name="key_medtronic_battery_type" translatable="false">pref_medtronic_battery_type</string> <string name="key_medtronic_battery_type" translatable="false">pref_medtronic_battery_type</string>
<string name="key_medtronic_bolus_debug" translatable="false">pref_medtronic_bolus_debug</string>
<string name="key_rileylink_mac_address" translatable="false">pref_rileylink_mac_address</string> <string name="key_rileylink_mac_address" translatable="false">pref_rileylink_mac_address</string>
<string name="key_medtronic_pump_frequency_us_ca" translatable="false">medtronic_pump_frequency_us_ca</string> <string name="key_medtronic_pump_frequency_us_ca" translatable="false">medtronic_pump_frequency_us_ca</string>
<string name="key_medtronic_pump_frequency_worldwide" translatable="false">medtronic_pump_frequency_worldwide</string> <string name="key_medtronic_pump_frequency_worldwide" translatable="false">medtronic_pump_frequency_worldwide</string>
@ -1432,6 +1433,7 @@
<string name="key_medtronic_pump_battery_no" translatable="false">medtronic_pump_battery_no</string> <string name="key_medtronic_pump_battery_no" translatable="false">medtronic_pump_battery_no</string>
<string name="key_medtronic_pump_battery_alkaline" translatable="false">medtronic_pump_battery_alkaline</string> <string name="key_medtronic_pump_battery_alkaline" translatable="false">medtronic_pump_battery_alkaline</string>
<string name="key_medtronic_pump_battery_lithium" translatable="false">medtronic_pump_battery_lithium</string> <string name="key_medtronic_pump_battery_lithium" translatable="false">medtronic_pump_battery_lithium</string>
<string name="key_medtronic_pump_battery_nizn" translatable="false">medtronic_pump_battery_nizn</string>
<string name="medtronic_serial_number">Pump Serial Number</string> <string name="medtronic_serial_number">Pump Serial Number</string>
<string name="medtronic_pump_type">Pump Type</string> <string name="medtronic_pump_type">Pump Type</string>
@ -1451,6 +1453,8 @@
<string name="medtronic_pump_battery_no">Not selected (Simple view)</string> <string name="medtronic_pump_battery_no">Not selected (Simple view)</string>
<string name="medtronic_pump_battery_alkaline">Alkaline (Extended view)</string> <string name="medtronic_pump_battery_alkaline">Alkaline (Extended view)</string>
<string name="medtronic_pump_battery_lithium">Lithium (Extended view)</string> <string name="medtronic_pump_battery_lithium">Lithium (Extended view)</string>
<string name="medtronic_pump_battery_nizn">NiZn (Extended view)</string>
<string name="medtronic_bolus_debugging">Bolus/Treatments Debugging</string>
<!-- RL BLE Scanning --> <!-- RL BLE Scanning -->
<string name="rileylink_scanner_scan_scan">SCAN</string> <string name="rileylink_scanner_scan_scan">SCAN</string>
@ -1608,5 +1612,7 @@
<string name="unit_minute_short">min</string> <string name="unit_minute_short">min</string>
<string name="key_wizard_calculation_visible" translatable="false">wizard_calculation_visible</string> <string name="key_wizard_calculation_visible" translatable="false">wizard_calculation_visible</string>
<string name="format_carbs">%1$dg</string> <string name="format_carbs">%1$dg</string>
<string name="common_on">On</string>
<string name="common_off">Off</string>
</resources> </resources>

View file

@ -68,6 +68,14 @@
android:selectable="true" android:selectable="true"
android:title="@string/medtronic_pump_battery_select" /> android:title="@string/medtronic_pump_battery_select" />
<ListPreference
android:defaultValue="@string/common_off"
android:entries="@array/onOff"
android:entryValues="@array/onOff"
android:key="@string/key_medtronic_bolus_debug"
android:selectable="true"
android:title="@string/medtronic_bolus_debugging" />
<info.nightscout.androidaps.plugins.pump.common.ui.RileyLinkSelectPreference <info.nightscout.androidaps.plugins.pump.common.ui.RileyLinkSelectPreference
android:enabled="true" android:enabled="true"
android:summary="" android:summary=""