- finalized added BolusDebug (added debug messages, added activation by configuraton)
- added battery type NiZn - fixed problem with RileyLinkStatusGeneral - added check if only one entry found, then we check if entry is in range (previously we returned the entry), and return only if value in range +- 2min
This commit is contained in:
parent
e5e291c4da
commit
a87eceb950
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -181,12 +181,17 @@
|
|||
<item>@string/medtronic_pump_battery_no</item>
|
||||
<item>@string/medtronic_pump_battery_alkaline</item>
|
||||
<item>@string/medtronic_pump_battery_lithium</item>
|
||||
<item>@string/medtronic_pump_battery_nizn</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="medtronicBatteryTypeValues">
|
||||
<item>@string/key_medtronic_pump_battery_no</item>
|
||||
<item>@string/key_medtronic_pump_battery_alkaline</item>
|
||||
<item>@string/key_medtronic_pump_battery_lithium</item>
|
||||
<item>@string/key_medtronic_pump_battery_nizn</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
key_medtronic_bolus_debug
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -1424,6 +1424,7 @@
|
|||
<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_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_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>
|
||||
|
@ -1432,6 +1433,7 @@
|
|||
<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_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_pump_type">Pump Type</string>
|
||||
|
@ -1451,6 +1453,7 @@
|
|||
<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_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 -->
|
||||
|
|
|
@ -60,14 +60,6 @@
|
|||
android:selectable="true"
|
||||
android:title="@string/medtronic_pump_encoding" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="@string/key_medtronic_pump_encoding_4b6b_rileylinkddddd"
|
||||
android:entries="@array/medtronicEncoding"
|
||||
android:entryValues="@array/medtronicEncodingValues"
|
||||
android:key="@string/key_medtronic_encoding"
|
||||
android:selectable="true"
|
||||
android:title="@string/medtronic_bolus_debugging" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="@string/key_medtronic_pump_battery_no"
|
||||
android:entries="@array/medtronicBatteryType"
|
||||
|
@ -76,6 +68,14 @@
|
|||
android:selectable="true"
|
||||
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
|
||||
android:enabled="true"
|
||||
android:summary=""
|
||||
|
|
Loading…
Reference in a new issue