From 9dcb8d5137e694b940a94ba3329ca971696ebe8a Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sun, 19 Jan 2020 18:52:33 +0100 Subject: [PATCH 01/10] Log OmnipodMessages exchanged in OmnipodCommunicationService --- .../comm/OmnipodCommunicationService.java | 5 +++++ .../omnipod/comm/message/OmnipodMessage.java | 20 ++++++++++--------- .../command/AcknowledgeAlertsCommand.java | 8 ++++++++ .../message/command/AssignAddressCommand.java | 6 ++++++ .../command/BasalScheduleExtraCommand.java | 13 ++++++++++++ .../message/command/BeepConfigCommand.java | 13 ++++++++++++ .../message/command/BolusExtraCommand.java | 13 ++++++++++++ .../command/CancelDeliveryCommand.java | 9 +++++++++ .../command/ConfigureAlertsCommand.java | 8 ++++++++ .../message/command/ConfigurePodCommand.java | 10 ++++++++++ .../message/command/DeactivatePodCommand.java | 7 +++++++ .../message/command/FaultConfigCommand.java | 9 +++++++++ .../message/command/GetStatusCommand.java | 7 +++++++ .../command/SetInsulinScheduleCommand.java | 8 ++++++++ .../command/TempBasalExtraCommand.java | 12 +++++++++++ .../defs/schedule/BasalDeliverySchedule.java | 10 ++++++++++ .../defs/schedule/BasalDeliveryTable.java | 7 +++++++ .../defs/schedule/BasalTableEntry.java | 9 +++++++++ .../defs/schedule/BolusDeliverySchedule.java | 8 ++++++++ .../pump/omnipod/defs/schedule/RateEntry.java | 8 ++++++++ .../schedule/TempBasalDeliverySchedule.java | 9 +++++++++ 21 files changed, 190 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationService.java index 21c5459a91..7222376e7e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodCommunicationService.java @@ -102,6 +102,11 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager { } public synchronized T exchangeMessages(Class responseClass, PodState podState, OmnipodMessage message, Integer addressOverride, Integer ackAddressOverride, boolean automaticallyResyncNonce) { + if (isLoggingEnabled()) { + LOG.debug("Exchanging OmnipodMessage [responseClass={}, podState={}, message={}, addressOverride={}, ackAddressOverride={}, automaticallyResyncNonce={}]: {}", // + responseClass.getSimpleName(), podState, message, addressOverride, ackAddressOverride, automaticallyResyncNonce, message); + } + for (int i = 0; 2 > i; i++) { if (podState.hasNonceState() && message.isNonceResyncable()) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/OmnipodMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/OmnipodMessage.java index 68b43d96d4..f3dc4a1856 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/OmnipodMessage.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/OmnipodMessage.java @@ -105,15 +105,6 @@ public class OmnipodMessage { return sequenceNumber; } - @Override - public String toString() { - return "OmnipodMessage{" + - "address=" + address + - ", encoded=" + ByteUtil.shortHexString(getEncoded()) + - ", sequenceNumber=" + sequenceNumber + - '}'; - } - public boolean isNonceResyncable() { return containsBlock(NonceResyncableMessageBlock.class); } @@ -143,4 +134,15 @@ public class OmnipodMessage { } return false; } + + + @Override + public String toString() { + return "OmnipodMessage{" + + "address=" + address + + ", messageBlocks=" + messageBlocks + + ", encoded=" + ByteUtil.shortHexStringWithoutSpaces(getEncoded()) + + ", sequenceNumber=" + sequenceNumber + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AcknowledgeAlertsCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AcknowledgeAlertsCommand.java index 546bd4c5df..f429ed8b6f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AcknowledgeAlertsCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AcknowledgeAlertsCommand.java @@ -43,4 +43,12 @@ public class AcknowledgeAlertsCommand extends NonceResyncableMessageBlock { this.nonce = nonce; encode(); } + + @Override + public String toString() { + return "AcknowledgeAlertsCommand{" + + "alerts=" + alerts + + ", nonce=" + nonce + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AssignAddressCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AssignAddressCommand.java index b69c418ef0..e7a942885c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AssignAddressCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/AssignAddressCommand.java @@ -22,4 +22,10 @@ public class AssignAddressCommand extends MessageBlock { return MessageBlockType.ASSIGN_ADDRESS; } + @Override + public String toString() { + return "AssignAddressCommand{" + + "address=" + address + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BasalScheduleExtraCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BasalScheduleExtraCommand.java index 175b17e809..5d628537f9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BasalScheduleExtraCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BasalScheduleExtraCommand.java @@ -111,4 +111,17 @@ public class BasalScheduleExtraCommand extends MessageBlock { public List getRateEntries() { return new ArrayList<>(rateEntries); } + + @Override + public String toString() { + return "BasalScheduleExtraCommand{" + + "acknowledgementBeep=" + acknowledgementBeep + + ", completionBeep=" + completionBeep + + ", programReminderInterval=" + programReminderInterval + + ", currentEntryIndex=" + currentEntryIndex + + ", remainingPulses=" + remainingPulses + + ", delayUntilNextTenthOfPulseInSeconds=" + delayUntilNextTenthOfPulseInSeconds + + ", rateEntries=" + rateEntries + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommand.java index 09c1290d1f..9695548f85 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BeepConfigCommand.java @@ -45,4 +45,17 @@ public class BeepConfigCommand extends MessageBlock { public MessageBlockType getType() { return MessageBlockType.BEEP_CONFIG; } + + @Override + public String toString() { + return "BeepConfigCommand{" + + "beepType=" + beepType + + ", basalCompletionBeep=" + basalCompletionBeep + + ", basalIntervalBeep=" + basalIntervalBeep + + ", tempBasalCompletionBeep=" + tempBasalCompletionBeep + + ", tempBasalIntervalBeep=" + tempBasalIntervalBeep + + ", bolusCompletionBeep=" + bolusCompletionBeep + + ", bolusIntervalBeep=" + bolusIntervalBeep + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BolusExtraCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BolusExtraCommand.java index c623a8c296..e12aece3fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BolusExtraCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/BolusExtraCommand.java @@ -60,4 +60,17 @@ public class BolusExtraCommand extends MessageBlock { public MessageBlockType getType() { return MessageBlockType.BOLUS_EXTRA; } + + @Override + public String toString() { + return "BolusExtraCommand{" + + "acknowledgementBeep=" + acknowledgementBeep + + ", completionBeep=" + completionBeep + + ", programReminderInterval=" + programReminderInterval + + ", units=" + units + + ", timeBetweenPulses=" + timeBetweenPulses + + ", squareWaveUnits=" + squareWaveUnits + + ", squareWaveDuration=" + squareWaveDuration + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/CancelDeliveryCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/CancelDeliveryCommand.java index bd950c200f..451f9205f6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/CancelDeliveryCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/CancelDeliveryCommand.java @@ -59,4 +59,13 @@ public class CancelDeliveryCommand extends NonceResyncableMessageBlock { this.nonce = nonce; encode(); } + + @Override + public String toString() { + return "CancelDeliveryCommand{" + + "beepType=" + beepType + + ", deliveryTypes=" + deliveryTypes + + ", nonce=" + nonce + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommand.java index 82c27d28cd..ac0a6a9f67 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigureAlertsCommand.java @@ -39,4 +39,12 @@ public class ConfigureAlertsCommand extends NonceResyncableMessageBlock { this.nonce = nonce; encode(); } + + @Override + public String toString() { + return "ConfigureAlertsCommand{" + + "configurations=" + configurations + + ", nonce=" + nonce + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigurePodCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigurePodCommand.java index 7962bd710f..0f35a1fa24 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigurePodCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/ConfigurePodCommand.java @@ -43,4 +43,14 @@ public class ConfigurePodCommand extends MessageBlock { encodedData = ByteUtil.concat(encodedData, ByteUtil.getBytesFromInt(lot)); encodedData = ByteUtil.concat(encodedData, ByteUtil.getBytesFromInt(tid)); } + + @Override + public String toString() { + return "ConfigurePodCommand{" + + "lot=" + lot + + ", tid=" + tid + + ", date=" + date + + ", address=" + address + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/DeactivatePodCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/DeactivatePodCommand.java index 4c0cf4ad2b..554d778d14 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/DeactivatePodCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/DeactivatePodCommand.java @@ -31,4 +31,11 @@ public class DeactivatePodCommand extends NonceResyncableMessageBlock { this.nonce = nonce; encode(); } + + @Override + public String toString() { + return "DeactivatePodCommand{" + + "nonce=" + nonce + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/FaultConfigCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/FaultConfigCommand.java index d342210119..9d165583e3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/FaultConfigCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/FaultConfigCommand.java @@ -38,4 +38,13 @@ public class FaultConfigCommand extends NonceResyncableMessageBlock { this.nonce = nonce; encode(); } + + @Override + public String toString() { + return "FaultConfigCommand{" + + "tab5sub16=" + tab5sub16 + + ", tab5sub17=" + tab5sub17 + + ", nonce=" + nonce + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/GetStatusCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/GetStatusCommand.java index e49ac08e9d..68af71e277 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/GetStatusCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/GetStatusCommand.java @@ -20,4 +20,11 @@ public class GetStatusCommand extends MessageBlock { public MessageBlockType getType() { return MessageBlockType.GET_STATUS; } + + @Override + public String toString() { + return "GetStatusCommand{" + + "podInfoType=" + podInfoType + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetInsulinScheduleCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetInsulinScheduleCommand.java index c1e4005074..8f1dae6edb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetInsulinScheduleCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/SetInsulinScheduleCommand.java @@ -87,4 +87,12 @@ public class SetInsulinScheduleCommand extends NonceResyncableMessageBlock { this.nonce = nonce; encode(); } + + @Override + public String toString() { + return "SetInsulinScheduleCommand{" + + "schedule=" + schedule + + ", nonce=" + nonce + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/TempBasalExtraCommand.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/TempBasalExtraCommand.java index 3c3a42344a..8f21c69a5e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/TempBasalExtraCommand.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/command/TempBasalExtraCommand.java @@ -93,4 +93,16 @@ public class TempBasalExtraCommand extends MessageBlock { public List getRateEntries() { return new ArrayList<>(rateEntries); } + + @Override + public String toString() { + return "TempBasalExtraCommand{" + + "acknowledgementBeep=" + acknowledgementBeep + + ", completionBeep=" + completionBeep + + ", programReminderInterval=" + programReminderInterval + + ", remainingPulses=" + remainingPulses + + ", delayUntilNextPulse=" + delayUntilNextPulse + + ", rateEntries=" + rateEntries + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalDeliverySchedule.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalDeliverySchedule.java index e6076fa189..ab46dacd76 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalDeliverySchedule.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalDeliverySchedule.java @@ -48,4 +48,14 @@ public class BasalDeliverySchedule extends DeliverySchedule implements IRawRepre return checksum; } + + @Override + public String toString() { + return "BasalDeliverySchedule{" + + "currentSegment=" + currentSegment + + ", secondsRemaining=" + secondsRemaining + + ", pulsesRemaining=" + pulsesRemaining + + ", basalTable=" + basalTable + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalDeliveryTable.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalDeliveryTable.java index 83b997ef60..3e18d6b5d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalDeliveryTable.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalDeliveryTable.java @@ -90,6 +90,13 @@ public class BasalDeliveryTable { return numSegments; } + @Override + public String toString() { + return "BasalDeliveryTable{" + + "entries=" + entries + + '}'; + } + private class TempSegment { private int pulses; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalTableEntry.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalTableEntry.java index e652ebec44..55339865a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalTableEntry.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BasalTableEntry.java @@ -41,4 +41,13 @@ public class BasalTableEntry implements IRawRepresentable { public boolean isAlternateSegmentPulse() { return alternateSegmentPulse; } + + @Override + public String toString() { + return "BasalTableEntry{" + + "segments=" + segments + + ", pulses=" + pulses + + ", alternateSegmentPulse=" + alternateSegmentPulse + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BolusDeliverySchedule.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BolusDeliverySchedule.java index 54d92ab70a..167f1bcce5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BolusDeliverySchedule.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/BolusDeliverySchedule.java @@ -49,4 +49,12 @@ public class BolusDeliverySchedule extends DeliverySchedule implements IRawRepre } return checksum; } + + @Override + public String toString() { + return "BolusDeliverySchedule{" + + "units=" + units + + ", timeBetweenPulses=" + timeBetweenPulses + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/RateEntry.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/RateEntry.java index 3021652479..c9bda11562 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/RateEntry.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/RateEntry.java @@ -66,4 +66,12 @@ public class RateEntry implements IRawRepresentable { } return rawData; } + + @Override + public String toString() { + return "RateEntry{" + + "totalPulses=" + totalPulses + + ", delayBetweenPulsesInSeconds=" + delayBetweenPulsesInSeconds + + '}'; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/TempBasalDeliverySchedule.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/TempBasalDeliverySchedule.java index 6f078651a1..a4c320b1d3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/TempBasalDeliverySchedule.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/schedule/TempBasalDeliverySchedule.java @@ -57,4 +57,13 @@ public class TempBasalDeliverySchedule extends DeliverySchedule implements IRawR public BasalDeliveryTable getBasalTable() { return basalTable; } + + @Override + public String toString() { + return "TempBasalDeliverySchedule{" + + "secondsRemaining=" + secondsRemaining + + ", firstSegmentPulses=" + firstSegmentPulses + + ", basalTable=" + basalTable + + '}'; + } } From 6f2e39dca7eee3d8bac47f23d7f42e68a3d62fd4 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sun, 19 Jan 2020 21:40:37 +0100 Subject: [PATCH 02/10] Remove pump unreachable preferences for pumps that have a fixed unreachable warning --- .../activities/PreferencesActivity.java | 17 +++++++++++++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_others.xml | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java index 0e93a47151..54e9bfe39a 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java @@ -9,6 +9,7 @@ import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; +import android.preference.PreferenceScreen; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; @@ -17,11 +18,13 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRebuildTabs; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin; import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin; import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin; import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin; @@ -199,6 +202,20 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre for (PluginBase plugin : MainApp.getPluginsList()) { plugin.preprocessPreferences(this); } + + PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump(); + PreferenceScreen localAlertsPreferenceScreen = (PreferenceScreen) findPreference(MainApp.gs(R.string.key_preferences_screen_local_alerts)); + if (activePump != null && localAlertsPreferenceScreen != null && activePump.getPumpDescription().hasFixedUnreachableAlert) { + Preference pumpUnreachableEnabledPreference = findPreference(MainApp.gs(R.string.key_enable_pump_unreachable_alert)); + if (pumpUnreachableEnabledPreference != null) { + localAlertsPreferenceScreen.removePreference(pumpUnreachableEnabledPreference); + } + + Preference pumpUnreachableThresholdPreference = findPreference(MainApp.gs(R.string.key_pump_unreachable_threshold)); + if (pumpUnreachableThresholdPreference != null) { + localAlertsPreferenceScreen.removePreference(pumpUnreachableThresholdPreference); + } + } } @Override diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f083f9a09d..267e9195a5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -812,6 +812,7 @@ Use system notifications for alerts and notifications enable_pump_unreachable_alert enable_missed_bg_readings + preferences_screen_local_alerts Local alerts Alert if no BG data is received Alert if pump is unreachable diff --git a/app/src/main/res/xml/pref_others.xml b/app/src/main/res/xml/pref_others.xml index cbe2b9c705..10302348b3 100644 --- a/app/src/main/res/xml/pref_others.xml +++ b/app/src/main/res/xml/pref_others.xml @@ -72,7 +72,7 @@ android:key="@string/key_short_tabtitles" android:title="@string/short_tabtitles" /> - + Date: Sun, 19 Jan 2020 21:48:11 +0100 Subject: [PATCH 03/10] make preference key non-translatable --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 267e9195a5..1c72b45296 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -812,7 +812,7 @@ Use system notifications for alerts and notifications enable_pump_unreachable_alert enable_missed_bg_readings - preferences_screen_local_alerts + preferences_screen_local_alerts Local alerts Alert if no BG data is received Alert if pump is unreachable From bc06b6b24a9d03d18e1c76ac6bad0c53ad138687 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sun, 19 Jan 2020 22:27:00 +0100 Subject: [PATCH 04/10] Disable instead of remove 'Enable pump unreachable' preference for pumps that have a fixed unreachable warning; make pump unreachable threshold configurable for pumps that have a fixed unreachable warning --- .../activities/PreferencesActivity.java | 7 +++++-- .../androidaps/interfaces/PumpInterface.java | 2 +- .../pump/omnipod/OmnipodPumpPlugin.java | 8 ++------ .../androidaps/utils/LocalAlertUtils.java | 18 ++++++++++-------- app/src/main/res/xml/pref_others.xml | 2 +- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java index 54e9bfe39a..acffae8839 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java @@ -10,6 +10,7 @@ import android.preference.PreferenceFragment; import android.preference.PreferenceGroup; import android.preference.PreferenceManager; import android.preference.PreferenceScreen; +import android.preference.SwitchPreference; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; @@ -208,12 +209,14 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre if (activePump != null && localAlertsPreferenceScreen != null && activePump.getPumpDescription().hasFixedUnreachableAlert) { Preference pumpUnreachableEnabledPreference = findPreference(MainApp.gs(R.string.key_enable_pump_unreachable_alert)); if (pumpUnreachableEnabledPreference != null) { - localAlertsPreferenceScreen.removePreference(pumpUnreachableEnabledPreference); + ((SwitchPreference) pumpUnreachableEnabledPreference).setChecked(true); + pumpUnreachableEnabledPreference.setEnabled(false); + pumpUnreachableEnabledPreference.setShouldDisableView(true); } Preference pumpUnreachableThresholdPreference = findPreference(MainApp.gs(R.string.key_pump_unreachable_threshold)); if (pumpUnreachableThresholdPreference != null) { - localAlertsPreferenceScreen.removePreference(pumpUnreachableThresholdPreference); + pumpUnreachableThresholdPreference.setDependency(null); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java index 0a0bc2da13..0d98c9bfdd 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -100,7 +100,7 @@ public interface PumpInterface { void timeDateOrTimeZoneChanged(); /* Only used for pump types where hasFixedUnreachableAlert=true */ - default boolean isFixedUnreachableAlertTimeoutExceeded() { + default boolean isFixedUnreachableAlertTimeoutExceeded(long alertTimeoutMilliseconds) { return false; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java index 00d112ac61..56808be5c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodPumpPlugin.java @@ -70,7 +70,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.SP; -import info.nightscout.androidaps.utils.T; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.schedulers.Schedulers; @@ -108,7 +107,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump boolean omnipodServiceRunning = false; private long nextPodCheck = 0L; - private static long UNREACHABLE_ALERT_THRESHOLD_MILLIS = T.mins(30).msecs(); private OmnipodPumpPlugin() { @@ -942,11 +940,11 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump @Override - public boolean isFixedUnreachableAlertTimeoutExceeded() { + public boolean isFixedUnreachableAlertTimeoutExceeded(long unreachableTimeoutMilliseconds) { getPodPumpStatusObject(); if (pumpStatusLocal.lastConnection != 0 || pumpStatusLocal.lastErrorConnection != 0) { - if (pumpStatusLocal.lastConnection + UNREACHABLE_ALERT_THRESHOLD_MILLIS < System.currentTimeMillis()) { + if (pumpStatusLocal.lastConnection + unreachableTimeoutMilliseconds < System.currentTimeMillis()) { if (pumpStatusLocal.lastErrorConnection > pumpStatusLocal.lastConnection) { // We exceeded the alert threshold, and our last connection failed // We should show an alert @@ -960,8 +958,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump } - // If we have no last connection and error data, don't show any alert - // FIXME is this appropriate? return false; } } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.java b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.java index 0cb3f386fb..257c21839e 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.java @@ -36,7 +36,7 @@ public class LocalAlertUtils { public static void checkPumpUnreachableAlarm(long lastConnection, boolean isStatusOutdated) { PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump(); - if(activePump != null && activePump.getPumpDescription().hasFixedUnreachableAlert) { + if (activePump != null && activePump.getPumpDescription().hasFixedUnreachableAlert) { checkPumpUnreachableAlarmStatic(activePump); } else { checkPumpUnreachableAlarmConfigured(lastConnection, isStatusOutdated); @@ -44,14 +44,16 @@ public class LocalAlertUtils { } private static void checkPumpUnreachableAlarmStatic(PumpInterface pump) { - if(pump == null) { + if (pump == null) { return; } - if(pump.isFixedUnreachableAlertTimeoutExceeded()) { + long pumpUnreachableThresholdMilliseconds = pumpUnreachableThreshold(); + + if (pump.isFixedUnreachableAlertTimeoutExceeded(pumpUnreachableThresholdMilliseconds)) { log.debug("Generating static pump unreachable alarm."); - showUnreachableNotification(T.mins(30).msecs()); + showUnreachableNotification(pumpUnreachableThresholdMilliseconds); } else { RxBus.INSTANCE.send(new EventDismissNotification(Notification.PUMP_UNREACHABLE)); } @@ -85,10 +87,10 @@ public class LocalAlertUtils { * Call only at startup! */ public static void presnoozeAlarms() { - if (SP.getLong("nextMissedReadingsAlarm", 0l) < System.currentTimeMillis()) { + if (SP.getLong("nextMissedReadingsAlarm", 0L) < System.currentTimeMillis()) { SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + 5 * 60 * 1000); } - if (SP.getLong("nextPumpDisconnectedAlarm", 0l) < System.currentTimeMillis()) { + if (SP.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis()) { SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + 5 * 60 * 1000); } } @@ -112,7 +114,7 @@ public class LocalAlertUtils { if (pump != null && profile != null) { long lastConnection = pump.lastDataTime(); long earliestAlarmTime = lastConnection + pumpUnreachableThreshold(); - if (SP.getLong("nextPumpDisconnectedAlarm", 0l) < earliestAlarmTime) { + if (SP.getLong("nextPumpDisconnectedAlarm", 0L) < earliestAlarmTime) { SP.putLong("nextPumpDisconnectedAlarm", earliestAlarmTime); } } @@ -122,7 +124,7 @@ public class LocalAlertUtils { BgReading bgReading = DatabaseHelper.lastBg(); if (SP.getBoolean(MainApp.gs(R.string.key_enable_missed_bg_readings_alert), false) && bgReading != null && bgReading.date + missedReadingsThreshold() < System.currentTimeMillis() - && SP.getLong("nextMissedReadingsAlarm", 0l) < System.currentTimeMillis()) { + && SP.getLong("nextMissedReadingsAlarm", 0L) < System.currentTimeMillis()) { Notification n = new Notification(Notification.BG_READINGS_MISSED, MainApp.gs(R.string.missed_bg_readings), Notification.URGENT); n.soundId = R.raw.alarm; SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold()); diff --git a/app/src/main/res/xml/pref_others.xml b/app/src/main/res/xml/pref_others.xml index 10302348b3..dc12ad792d 100644 --- a/app/src/main/res/xml/pref_others.xml +++ b/app/src/main/res/xml/pref_others.xml @@ -89,7 +89,7 @@ android:title="@string/enable_pump_unreachable_alert" /> Date: Mon, 20 Jan 2020 20:43:40 +0100 Subject: [PATCH 05/10] Add test for safety of future fix for reporting correct insulin delivered amount after cancel bolus --- .../podinfo/PodInfoFaultEventTest.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java index 4acd7f9ac4..80e5093c18 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java @@ -77,7 +77,7 @@ public class PodInfoFaultEventTest { } @Test - public void testPodInfoFaultEventIsulinNotDelivered() { + public void testPodInfoFaultEventInsulinNotDelivered() { PodInfoFaultEvent podInfoFaultEvent = new PodInfoFaultEvent(ByteUtil.fromHexString("020f0000010200ec6a026803ff026b000028a7082023")); assertEquals(PodProgressStatus.INACTIVE, podInfoFaultEvent.getPodProgressStatus()); @@ -95,4 +95,24 @@ public class PodInfoFaultEventTest { assertEquals(2, podInfoFaultEvent.getReceiverLowGain()); assertEquals(39, podInfoFaultEvent.getRadioRSSI()); } + + @Test + public void testPodInfoFaultEventMaxInsulinNotDelivered() { + PodInfoFaultEvent podInfoFaultEvent = new PodInfoFaultEvent(ByteUtil.fromHexString("020f00ffff0200ec6a026803ff026b000028a7082023")); + + assertEquals(PodProgressStatus.INACTIVE, podInfoFaultEvent.getPodProgressStatus()); + assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus()); + assertEquals(11.8, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001); + assertEquals(3276.75, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001); // Insane and will not happen, but this verifies that we convert it to an unsigned int + assertEquals(0x02, podInfoFaultEvent.getPodMessageCounter()); + assertEquals(FaultEventType.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoFaultEvent.getFaultEventType()); + assertTrue(Duration.standardMinutes(616).isEqual(podInfoFaultEvent.getFaultEventTime())); + assertNull(podInfoFaultEvent.getReservoirLevel()); + assertEquals(0, podInfoFaultEvent.getUnacknowledgedAlerts().getRawValue()); + assertFalse(podInfoFaultEvent.isFaultAccessingTables()); + assertEquals(LogEventErrorCode.INTERNAL_2_BIT_VARIABLE_SET_AND_MANIPULATED_IN_MAIN_LOOP_ROUTINES_2, podInfoFaultEvent.getLogEventErrorType()); + assertEquals(PodProgressStatus.RUNNING_ABOVE_FIFTY_UNITS, podInfoFaultEvent.getPodProgressStatusAtTimeOfFirstLoggedFaultEvent()); + assertEquals(2, podInfoFaultEvent.getReceiverLowGain()); + assertEquals(39, podInfoFaultEvent.getRadioRSSI()); + } } From 24fc4594b3f0b1ccf150135d055a15b7f3a4e995 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Tue, 21 Jan 2020 18:45:55 +0100 Subject: [PATCH 06/10] Use two CancelDelivery commands instead of CancelDelivery command and BeepConfig command as a workaround for strange cancel delivery beep behavior --- .../comm/action/CancelDeliveryAction.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/CancelDeliveryAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/CancelDeliveryAction.java index 91590272a5..9dc84d18ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/CancelDeliveryAction.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/CancelDeliveryAction.java @@ -7,10 +7,8 @@ import java.util.List; import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationService; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.MessageBlock; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.OmnipodMessage; -import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.BeepConfigCommand; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.command.CancelDeliveryCommand; import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse; -import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepConfigType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; @@ -38,18 +36,18 @@ public class CancelDeliveryAction implements OmnipodAction { public StatusResponse execute(OmnipodCommunicationService communicationService) { List messageBlocks = new ArrayList<>(); - messageBlocks.add(new CancelDeliveryCommand(podState.getCurrentNonce(), - acknowledgementBeep && deliveryTypes.size() == 1 ? BeepType.BEEP : BeepType.NO_BEEP, deliveryTypes)); - if (acknowledgementBeep && deliveryTypes.size() > 1) { - // Workaround for strange beep behaviour when cancelling multiple delivery types at the same time + // Workaround for strange beep behaviour when cancelling multiple delivery types + List deliveryTypeList = new ArrayList<>(deliveryTypes); - // FIXME we should use other constructor with all beep configs. - // Theoretically, if we would cancel multiple delivery types but not all, - // we should keep the beep config for delivery types that we're not cancelling. - // We currently have no use case that though, - // as we either cancel 1 type or all types, - messageBlocks.add(new BeepConfigCommand(BeepConfigType.BEEP)); + EnumSet deliveryTypeWithBeep = EnumSet.of(deliveryTypeList.remove(deliveryTypeList.size() - 1)); + EnumSet deliveryTypesWithoutBeep = EnumSet.copyOf(deliveryTypeList); + + messageBlocks.add(new CancelDeliveryCommand(podState.getCurrentNonce(), BeepType.NO_BEEP, deliveryTypesWithoutBeep)); + messageBlocks.add(new CancelDeliveryCommand(podState.getCurrentNonce(), BeepType.BEEP, deliveryTypeWithBeep)); + } else { + messageBlocks.add(new CancelDeliveryCommand(podState.getCurrentNonce(), + acknowledgementBeep && deliveryTypes.size() == 1 ? BeepType.BEEP : BeepType.NO_BEEP, deliveryTypes)); } return communicationService.exchangeMessages(StatusResponse.class, podState, From 6f7a07185a62dae1f83b05c07451e788308d3f7f Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Tue, 21 Jan 2020 18:54:20 +0100 Subject: [PATCH 07/10] Change expiration alerts to more sensible values --- .../omnipod/comm/action/service/InsertCannulaService.java | 2 +- .../androidaps/plugins/pump/omnipod/util/OmnipodConst.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/InsertCannulaService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/InsertCannulaService.java index 4a6c6a4093..43248af7d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/InsertCannulaService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/action/service/InsertCannulaService.java @@ -31,7 +31,7 @@ public class InsertCannulaService { DateTime endOfServiceTime = podState.getActivatedAt().plus(OmnipodConst.SERVICE_DURATION); Duration timeUntilExpirationAdvisoryAlarm = new Duration(DateTime.now(), - endOfServiceTime.minus(OmnipodConst.END_OF_SERVICE_IMMINENT_WINDOW).minus(OmnipodConst.EXPIRATION_ADVISORY_WINDOW)); + endOfServiceTime.minus(OmnipodConst.EXPIRATION_ADVISORY_WINDOW)); Duration timeUntilShutdownImminentAlarm = new Duration(DateTime.now(), endOfServiceTime.minus(OmnipodConst.END_OF_SERVICE_IMMINENT_WINDOW)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java index 367008b5e7..dba478b0f6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java @@ -45,9 +45,9 @@ public class OmnipodConst { public static final Duration AVERAGE_BOLUS_COMMAND_COMMUNICATION_DURATION = Duration.millis(1500); public static final Duration SERVICE_DURATION = Duration.standardHours(80); - public static final Duration EXPIRATION_ADVISORY_WINDOW = Duration.standardHours(2); + public static final Duration EXPIRATION_ADVISORY_WINDOW = Duration.standardHours(9); public static final Duration END_OF_SERVICE_IMMINENT_WINDOW = Duration.standardHours(1); - public static final Duration NOMINAL_POD_LIFE = SERVICE_DURATION.minus(END_OF_SERVICE_IMMINENT_WINDOW).minus(EXPIRATION_ADVISORY_WINDOW); + public static final Duration NOMINAL_POD_LIFE = Duration.standardHours(72); public static final double LOW_RESERVOIR_ALERT = 20.0; public static final double POD_PRIME_BOLUS_UNITS = 2.6; From afc07c5117021fac9c5a93bbdb4dc7c3a1e70625 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Tue, 21 Jan 2020 20:02:24 +0000 Subject: [PATCH 08/10] - changed version information - added logging for time switches --- app/build.gradle | 2 +- .../androidaps/receivers/TimeDateOrTZChangeReceiver.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 610582e791..36f360da41 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -109,7 +109,7 @@ android { targetSdkVersion 28 multiDexEnabled true versionCode 1500 - version "omnipod-0.2-SNAPSHOT" + version "2.6-omnipod-0.2-SNAPSHOT" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "DEV_VERSION", '"2.6-dev"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.java index e74dfec20d..3ee5ff24a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/TimeDateOrTZChangeReceiver.java @@ -13,6 +13,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil; public class TimeDateOrTZChangeReceiver extends BroadcastReceiver { @@ -26,6 +27,8 @@ public class TimeDateOrTZChangeReceiver extends BroadcastReceiver { LOG.debug("Date, Time and/or TimeZone changed."); + LOG.debug("TimeDateOrTZChangeReceiver::Intent::{}", OmnipodUtil.getGsonInstance().toJson(intent)); + if (action != null && activePump != null) { LOG.debug("Date, Time and/or TimeZone changed. Notifying pump driver."); activePump.timeDateOrTimeZoneChanged(); From 93e7eb518f18793a29d9af3dcfe2bac67d44142a Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Wed, 22 Jan 2020 21:14:41 +0100 Subject: [PATCH 09/10] Use insulinNotDelivered field from StatusResponse to determine units delivered after cancelled bolus or pod fault --- .../pump/omnipod/comm/OmnipodManager.java | 147 ++++++++---------- .../pump/omnipod/defs/PodProgressStatus.java | 4 +- .../podinfo/PodInfoFaultEventTest.java | 2 +- 3 files changed, 70 insertions(+), 83 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java index d03f6762ed..7eb8656ca4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java @@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.BeepType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryStatus; import info.nightscout.androidaps.plugins.pump.omnipod.defs.DeliveryType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress; import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; @@ -158,13 +159,13 @@ public class OmnipodManager { } } - public synchronized void acknowledgeAlerts() { + public synchronized StatusResponse acknowledgeAlerts() { assertReadyForDelivery(); logStartingCommandExecution("acknowledgeAlerts"); try { - executeAndVerify(() -> communicationService.executeAction(new AcknowledgeAlertsAction(podState, podState.getActiveAlerts()))); + return executeAndVerify(() -> communicationService.executeAction(new AcknowledgeAlertsAction(podState, podState.getActiveAlerts()))); } finally { logCommandExecutionFinished("acknowledgeAlerts"); } @@ -172,7 +173,7 @@ public class OmnipodManager { // CAUTION: cancels all delivery // CAUTION: suspends and then resumes delivery. An OmnipodException[certainFailure=false] indicates that the pod is or might be suspended - public synchronized void setBasalSchedule(BasalSchedule schedule, boolean acknowledgementBeep) { + public synchronized StatusResponse setBasalSchedule(BasalSchedule schedule, boolean acknowledgementBeep) { assertReadyForDelivery(); logStartingCommandExecution("setBasalSchedule [basalSchedule=" + schedule + ", acknowledgementBeep=" + acknowledgementBeep + "]"); @@ -186,7 +187,7 @@ public class OmnipodManager { try { try { - executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podState, schedule, + return executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podState, schedule, false, podState.getScheduleOffset(), acknowledgementBeep))); } catch (OmnipodException ex) { // Treat all exceptions as uncertain failures, because all delivery has been suspended here. @@ -200,7 +201,7 @@ public class OmnipodManager { } // CAUTION: cancels temp basal and then sets new temp basal. An OmnipodException[certainFailure=false] indicates that the pod might have cancelled the previous temp basal, but did not set a new temp basal - public synchronized void setTemporaryBasal(double rate, Duration duration, boolean acknowledgementBeep, boolean completionBeep) { + public synchronized StatusResponse setTemporaryBasal(double rate, Duration duration, boolean acknowledgementBeep, boolean completionBeep) { assertReadyForDelivery(); logStartingCommandExecution("setTemporaryBasal [rate=" + rate + ", duration=" + duration + ", acknowledgementBeep=" + acknowledgementBeep + ", completionBeep=" + completionBeep + "]"); @@ -213,7 +214,7 @@ public class OmnipodManager { } try { - executeAndVerify(() -> communicationService.executeAction(new SetTempBasalAction( + return executeAndVerify(() -> communicationService.executeAction(new SetTempBasalAction( podState, rate, duration, acknowledgementBeep, completionBeep))); } catch (OmnipodException ex) { @@ -230,17 +231,18 @@ public class OmnipodManager { cancelDelivery(EnumSet.of(DeliveryType.TEMP_BASAL), acknowledgementBeep); } - private synchronized void cancelDelivery(EnumSet deliveryTypes, boolean acknowledgementBeep) { + private synchronized StatusResponse cancelDelivery(EnumSet deliveryTypes, boolean acknowledgementBeep) { assertReadyForDelivery(); logStartingCommandExecution("cancelDelivery [deliveryTypes=" + deliveryTypes + ", acknowledgementBeep=" + acknowledgementBeep + "]"); try { - executeAndVerify(() -> { + return executeAndVerify(() -> { StatusResponse statusResponse = communicationService.executeAction(new CancelDeliveryAction(podState, deliveryTypes, acknowledgementBeep)); if (isLoggingEnabled()) { LOG.info("Status response after cancel delivery[types={}]: {}", deliveryTypes.toString(), statusResponse.toString()); } + return statusResponse; }); } finally { logCommandExecutionFinished("cancelDelivery"); @@ -303,10 +305,11 @@ public class OmnipodManager { .observeOn(Schedulers.io()) // .doOnComplete(() -> { synchronized (bolusDataMutex) { + StatusResponse statusResponse = null; for (int i = 0; i < ACTION_VERIFICATION_TRIES; i++) { try { // Retrieve a status response in order to update the pod state - StatusResponse statusResponse = getPodStatus(); + statusResponse = getPodStatus(); if (statusResponse.getDeliveryStatus().isBolusing()) { throw new IllegalDeliveryStatusException(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus()); } else { @@ -319,8 +322,11 @@ public class OmnipodManager { } } + // Substract units not delivered in case of a Pod failure + double unitsNotDelivered = statusResponse != null && PodProgressStatus.FAULT_EVENT_OCCURRED.equals(statusResponse.getPodProgressStatus()) ? statusResponse.getInsulinNotDelivered() : 0.0D; + if (hasActiveBolus()) { - activeBolusData.bolusCompletionSubject.onSuccess(new BolusDeliveryResult(units)); + activeBolusData.bolusCompletionSubject.onSuccess(new BolusDeliveryResult(units - unitsNotDelivered)); activeBolusData = null; } } @@ -341,22 +347,23 @@ public class OmnipodManager { logStartingCommandExecution("cancelBolus [acknowledgementBeep=" + acknowledgementBeep + "]"); try { - cancelDelivery(EnumSet.of(DeliveryType.BOLUS), acknowledgementBeep); + StatusResponse statusResponse = cancelDelivery(EnumSet.of(DeliveryType.BOLUS), acknowledgementBeep); + discardActiveBolusData(statusResponse.getInsulinNotDelivered()); } catch (PodFaultException ex) { - discardActiveBolusData(); + discardActiveBolusData(ex.getFaultEvent().getInsulinNotDelivered()); throw ex; } finally { logCommandExecutionFinished("cancelBolus"); } - - discardActiveBolusData(); } } - private void discardActiveBolusData() { - activeBolusData.getDisposables().dispose(); - activeBolusData.getBolusCompletionSubject().onSuccess(new BolusDeliveryResult(activeBolusData.estimateUnitsDelivered())); - activeBolusData = null; + private void discardActiveBolusData(double unitsNotDelivered) { + synchronized (bolusDataMutex) { + activeBolusData.getDisposables().dispose(); + activeBolusData.getBolusCompletionSubject().onSuccess(new BolusDeliveryResult(activeBolusData.getUnits() - unitsNotDelivered)); + activeBolusData = null; + } } public synchronized void suspendDelivery(boolean acknowledgementBeep) { @@ -364,12 +371,12 @@ public class OmnipodManager { } // Same as setting basal schedule, but without suspending delivery first - public synchronized void resumeDelivery(boolean acknowledgementBeep) { + public synchronized StatusResponse resumeDelivery(boolean acknowledgementBeep) { assertReadyForDelivery(); logStartingCommandExecution("resumeDelivery"); try { - executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(), + return executeAndVerify(() -> communicationService.executeAction(new SetBasalScheduleAction(podState, podState.getBasalSchedule(), false, podState.getScheduleOffset(), acknowledgementBeep))); } finally { logCommandExecutionFinished("resumeDelivery"); @@ -475,34 +482,46 @@ public class OmnipodManager { } // Only works for commands with nonce resyncable message blocks - private void executeAndVerify(Runnable runnable) { + // FIXME method is too big, needs refactoring + private StatusResponse executeAndVerify(VerifiableAction runnable) { try { - runnable.run(); - } catch (Exception ex) { - if (isCertainFailure(ex)) { - throw ex; + return runnable.run(); + } catch (Exception originalException) { + if (isCertainFailure(originalException)) { + throw originalException; } else { if (isLoggingEnabled()) { - LOG.debug("Caught exception in executeAndVerify: ", ex); + LOG.warn("Caught exception in executeAndVerify. Verifying command by using cancel none command to verify nonce", originalException); } - CommandDeliveryStatus verificationResult = verifyCommand(); + try { + logStartingCommandExecution("verifyCommand"); + StatusResponse statusResponse = communicationService.sendCommand(StatusResponse.class, podState, + new CancelDeliveryCommand(podState.getCurrentNonce(), BeepType.NO_BEEP, DeliveryType.NONE), false); + if (isLoggingEnabled()) { + LOG.info("Command status resolved to SUCCESS. Status response after cancelDelivery[types=DeliveryType.NONE]: {}", statusResponse); + } - switch (verificationResult) { - case CERTAIN_FAILURE: - if (ex instanceof OmnipodException) { - ((OmnipodException) ex).setCertainFailure(true); - throw ex; - } else { - OmnipodException newException = new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex); - newException.setCertainFailure(true); - throw newException; - } - case UNCERTAIN_FAILURE: - throw ex; - case SUCCESS: - // Ignore original exception - break; + return statusResponse; + } catch (NonceOutOfSyncException verificationException) { + if (isLoggingEnabled()) { + LOG.error("Command resolved to FAILURE (CERTAIN_FAILURE)", verificationException); + } + if (originalException instanceof OmnipodException) { + ((OmnipodException) originalException).setCertainFailure(true); + throw originalException; + } else { + OmnipodException newException = new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, originalException); + newException.setCertainFailure(true); + throw newException; + } + } catch (Exception verificationException) { + if (isLoggingEnabled()) { + LOG.error("Command unresolved (UNCERTAIN_FAILURE)", verificationException); + } + throw originalException; + } finally { + logCommandExecutionFinished("verifyCommand"); } } } @@ -537,40 +556,6 @@ public class OmnipodManager { return result; } - // Only works for commands which contain nonce resyncable message blocks - private CommandDeliveryStatus verifyCommand() { - if (isLoggingEnabled()) { - LOG.warn("Verifying command by using cancel none command to verify nonce"); - } - try { - logStartingCommandExecution("verifyCommand"); - StatusResponse statusResponse = communicationService.sendCommand(StatusResponse.class, podState, - new CancelDeliveryCommand(podState.getCurrentNonce(), BeepType.NO_BEEP, DeliveryType.NONE), false); - if (isLoggingEnabled()) { - LOG.info("Status response after verifyCommand (cancelDelivery[types=DeliveryType.NONE]): {}", statusResponse.toString()); - } - } catch (NonceOutOfSyncException ex) { - if (isLoggingEnabled()) { - LOG.info("Command resolved to FAILURE (CERTAIN_FAILURE)", ex); - } - return CommandDeliveryStatus.CERTAIN_FAILURE; - } catch (Exception ex) { - if (isLoggingEnabled()) { - LOG.error("Command unresolved (UNCERTAIN_FAILURE)", ex); - } - return CommandDeliveryStatus.UNCERTAIN_FAILURE; - } finally { - logCommandExecutionFinished("verifyCommand"); - } - - if (isLoggingEnabled()) { - if (isLoggingEnabled()) { - LOG.info("Command status resolved to SUCCESS"); - } - } - return CommandDeliveryStatus.SUCCESS; - } - private void logStartingCommandExecution(String action) { if (isLoggingEnabled()) { LOG.debug("Starting command execution for action: " + action); @@ -670,10 +655,6 @@ public class OmnipodManager { return bolusCompletionSubject; } - public void setBolusCompletionSubject(SingleSubject bolusCompletionSubject) { - this.bolusCompletionSubject = bolusCompletionSubject; - } - public double estimateUnitsDelivered() { long elapsedMillis = new Duration(startDate, DateTime.now()).getMillis(); long totalDurationMillis = (long) (units / OmnipodConst.POD_BOLUS_DELIVERY_RATE * 1000); @@ -684,4 +665,10 @@ public class OmnipodManager { return (double) Math.round(estimatedUnits * roundingDivisor) / roundingDivisor; } } + + // Could be replaced with Supplier when min API level >= 24 + @FunctionalInterface + private interface VerifiableAction { + StatusResponse run(); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/PodProgressStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/PodProgressStatus.java index 300e0c287c..4bd9780118 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/PodProgressStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/PodProgressStatus.java @@ -14,8 +14,8 @@ public enum PodProgressStatus { ONE_NOT_USED_BUT_IN_33((byte) 0x0a), TWO_NOT_USED_BUT_IN_33((byte) 0x0b), THREE_NOT_USED_BUT_IN_33((byte) 0x0c), - ERROR_EVENT_LOGGED_SHUTTING_DOWN((byte) 0x0d), - DELAYED_PRIME((byte) 0x0e), + FAULT_EVENT_OCCURRED((byte) 0x0d), + FAILED_TO_INITIALIZE_IN_TIME((byte) 0x0e), INACTIVE((byte) 0x0f); private byte value; diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java index 80e5093c18..a15c681ab3 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/message/response/podinfo/PodInfoFaultEventTest.java @@ -60,7 +60,7 @@ public class PodInfoFaultEventTest { public void testPodInfoFaultEventErrorShuttingDown() { PodInfoFaultEvent podInfoFaultEvent = new PodInfoFaultEvent(ByteUtil.fromHexString("020d0000000407f28609ff03ff0a0200000823080000")); - assertEquals(PodProgressStatus.ERROR_EVENT_LOGGED_SHUTTING_DOWN, podInfoFaultEvent.getPodProgressStatus()); + assertEquals(PodProgressStatus.FAULT_EVENT_OCCURRED, podInfoFaultEvent.getPodProgressStatus()); assertEquals(DeliveryStatus.SUSPENDED, podInfoFaultEvent.getDeliveryStatus()); assertEquals(101.7, podInfoFaultEvent.getTotalInsulinDelivered(), 0.000001); assertEquals(0, podInfoFaultEvent.getInsulinNotDelivered(), 0.000001); From f5af60712520eedfe7fc382a9b06a64f439fc46e Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Wed, 22 Jan 2020 23:45:42 +0100 Subject: [PATCH 10/10] Add logging in OmnipodManager.resetPodState and fix NonceState.toString --- .../plugins/pump/omnipod/comm/OmnipodManager.java | 7 +++++-- .../androidaps/plugins/pump/omnipod/defs/NonceState.java | 4 +++- .../pump/omnipod/driver/comm/AapsOmnipodManager.java | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java index 7eb8656ca4..51f858c283 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/comm/OmnipodManager.java @@ -446,10 +446,13 @@ public class OmnipodManager { logCommandExecutionFinished("deactivatePod"); } - resetPodState(); + resetPodState(false); } - public void resetPodState() { + public void resetPodState(boolean forcedByUser) { + if(isLoggingEnabled()) { + LOG.warn("resetPodState has been called. forcedByUser={}", forcedByUser); + } podState = null; SP.remove(OmnipodConst.Prefs.PodState); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/NonceState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/NonceState.java index eca7dbf791..4698f88266 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/NonceState.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/NonceState.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.defs; +import java.util.Arrays; + public class NonceState { private final long[] table = new long[21]; private int index; @@ -44,7 +46,7 @@ public class NonceState { @Override public String toString() { return "NonceState{" + - "currentNonce=" + getCurrentNonce() + + "table=" + Arrays.toString(table) + ", index=" + index + '}'; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java index baaaa8d4e4..6e44dfac8e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java @@ -266,7 +266,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface @Override public PumpEnactResult resetPodStatus() { - delegate.resetPodState(); + delegate.resetPodState(true); reportImplicitlyCanceledTbr();