From bc6e4be3ad96d9ba23d7fc087a49afa6216549a3 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Tue, 28 Jan 2020 19:00:16 +0000 Subject: [PATCH] - reworking pump suspended / initialization of driver problem --- .../plugins/pump/omnipod/OmnipodFragment.kt | 21 ++++++++---- .../pump/omnipod/OmnipodPumpPlugin.java | 32 +++++++++++++++---- .../defs/OmnipodPumpPluginInterface.java | 3 ++ .../omnipod/driver/OmnipodDriverState.java | 9 ++++++ .../omnipod/driver/OmnipodPumpStatus.java | 3 +- .../pump/omnipod/util/OmnipodUtil.java | 22 +++++++++++++ app/src/main/res/values/strings.xml | 1 + 7 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodDriverState.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt index 0cd2758482..c077cdd009 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/OmnipodFragment.kt @@ -22,11 +22,12 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyL import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus +import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefreshButtonState -import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus -import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin @@ -214,21 +215,27 @@ class OmnipodFragment : Fragment() { MainApp.gs(it.getResourceId(RileyLinkTargetDevice.Omnipod)) } ?: "-" - if (pumpStatus.podSessionState == null) { + val driverState = OmnipodUtil.getDriverState(); + + if (driverState == OmnipodDriverState.NotInitalized) { + omnipod_pod_address.text = MainApp.gs(R.string.omnipod_pod_name_no_info) + omnipod_pod_expiry.text = "-" + omnipod_pod_status.text = MainApp.gs(R.string.omnipod_pod_not_initalized) + pumpStatus.podAvailable = false + pumpStatus.podNumber == null + } else if (driverState == OmnipodDriverState.Initalized_NoPod) { omnipod_pod_address.text = MainApp.gs(R.string.omnipod_pod_name_no_info) omnipod_pod_expiry.text = "-" omnipod_pod_status.text = MainApp.gs(R.string.omnipod_pod_no_pod_connected) pumpStatus.podAvailable = false pumpStatus.podNumber == null } else { - //podAvailable = true pumpStatus.podLotNumber = "" + pumpStatus.podSessionState.lot pumpStatus.podAvailable = true omnipod_pod_address.text = pumpStatus.podSessionState.address.toString() omnipod_pod_expiry.text = pumpStatus.podSessionState.expiryDateAsString pumpStatus.podNumber = pumpStatus.podSessionState.address.toString() - //pumpStatus.podSessionState = checkStatusSet(pumpStatus.podSessionState, // OmnipodUtil.getPodSessionState()) as PodSessionState? @@ -332,7 +339,7 @@ class OmnipodFragment : Fragment() { setDeviceStatus() if (pumpStatus.podAvailable) { - // last connection + // last connection if (pumpStatus.lastConnection != 0L) { val minAgo = DateUtil.minAgo(pumpStatus.lastConnection) val min = (System.currentTimeMillis() - pumpStatus.lastConnection) / 1000 / 60 @@ -415,7 +422,7 @@ class OmnipodFragment : Fragment() { private fun updateAcknowledgeAlerts(pumpStatus: OmnipodPumpStatus) { - if (pumpStatus!=null) { + if (pumpStatus != null) { omnipod_pod_active_alerts_ack.isEnabled = pumpStatus.ackAlertsAvailable omnipod_pod_active_alerts.text = pumpStatus.ackAlertsText } 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 56808be5c8..366796c63e 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 @@ -58,6 +58,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPodType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm; @@ -107,6 +108,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump boolean omnipodServiceRunning = false; private long nextPodCheck = 0L; + OmnipodDriverState driverState = OmnipodDriverState.NotInitalized; private OmnipodPumpPlugin() { @@ -123,7 +125,10 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump displayConnectionMessages = false; OmnipodUtil.setOmnipodPodType(OmnipodPodType.Eros); - OmnipodUtil.setPlugin(this); + + if (OmnipodUtil.isOmnipodEros()) { + OmnipodUtil.setPlugin(this); + } serviceConnection = new ServiceConnection() { @@ -371,7 +376,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump public boolean isConnected() { if (isLoggingEnabled() && displayConnectionMessages) LOG.debug(getLogPrefix() + "isConnected"); - return isServiceSet() && omnipodService.isInitialized(); + return isServiceSet() && this.omnipodService.isInitialized() && isInitialized; } @@ -379,14 +384,17 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump public boolean isConnecting() { if (isLoggingEnabled() && displayConnectionMessages) LOG.debug(getLogPrefix() + "isConnecting"); - return !isServiceSet() || !omnipodService.isInitialized(); + return !isServiceSet() || (!omnipodService.isInitialized() || (!isInitialized)); } @Override public boolean isSuspended() { - return (pumpStatusLocal != null && !pumpStatusLocal.podAvailable) || + return (driverState == OmnipodDriverState.Initalized_NoPod) || (OmnipodUtil.getPodSessionState() != null && OmnipodUtil.getPodSessionState().isSuspended()); +// +// return (pumpStatusLocal != null && !pumpStatusLocal.podAvailable) || +// (OmnipodUtil.getPodSessionState() != null && OmnipodUtil.getPodSessionState().isSuspended()); } @Override @@ -464,6 +472,9 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump // TODO read pod status LOG.error("getPodPumpStatus() NOT IMPLEMENTED"); + //getPodPumpStatusObject().driverState = OmnipodDriverState.Initalized_PodAvailable; + //driverState = OmnipodDriverState.Initalized_PodAvailable; + OmnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodAvailable); // we would probably need to read Basal Profile here too } @@ -478,6 +489,11 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump } } + @Override + public void setDriverState(OmnipodDriverState state) { + this.driverState = state; + } + public void resetStatusState() { firstRun = true; @@ -495,6 +511,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump if (isLoggingEnabled()) LOG.info(getLogPrefix() + "initializePump - start"); + OmnipodPumpStatus podPumpStatus = getPodPumpStatusObject(); setRefreshButtonEnabled(false); @@ -511,14 +528,13 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump } } + if (podSessionState != null) { LOG.debug("PodSessionState (saved): " + podSessionState); // TODO handle if session state too old - // TODO handle basal - - // TODO handle time + // TODO load session if (!isRefresh) { pumpState = PumpDriverState.Initialized; @@ -531,6 +547,8 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump } else { LOG.debug("No PodSessionState found. Pod probably not running."); + //podPumpStatus.driverState = OmnipodDriverState.Initalized_NoPod; + OmnipodUtil.setDriverState(OmnipodDriverState.Initalized_NoPod); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodPumpPluginInterface.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodPumpPluginInterface.java index 50cfec2d88..8a97ebbbd3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodPumpPluginInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/defs/OmnipodPumpPluginInterface.java @@ -1,9 +1,12 @@ package info.nightscout.androidaps.plugins.pump.omnipod.defs; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState; public interface OmnipodPumpPluginInterface extends PumpInterface { void addPodStatusRequest(OmnipodStatusRequest pumpStatusRequest); + void setDriverState(OmnipodDriverState state); + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodDriverState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodDriverState.java new file mode 100644 index 0000000000..8e619dcecb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodDriverState.java @@ -0,0 +1,9 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.driver; + +public enum OmnipodDriverState { + + NotInitalized, + Initalized_NoPod, + Initalized_PodAvailable, + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java index d83a8a81ea..dac4c91844 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver; -import org.jetbrains.annotations.NotNull; import org.joda.time.LocalDateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,6 +62,8 @@ public class OmnipodPumpStatus extends PumpStatus { public boolean podDebuggingOptionsEnabled = false; public String podLotNumber = "???"; + public OmnipodDriverState driverState = OmnipodDriverState.NotInitalized; + public OmnipodPumpStatus(PumpDescription pumpDescription) { super(pumpDescription); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java index 09f0bde336..8e8ea7ab3a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java @@ -31,6 +31,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPodType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState; import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange; import info.nightscout.androidaps.plugins.pump.omnipod.service.RileyLinkOmnipodService; @@ -54,6 +55,7 @@ public class OmnipodUtil extends RileyLinkUtil { //private static PodDeviceState podDeviceState; private static OmnipodPumpPluginInterface omnipodPumpPlugin; private static OmnipodPodType omnipodPodType; + private static OmnipodDriverState driverState; public static Gson getGsonInstance() { return gsonInstance; @@ -149,6 +151,26 @@ public class OmnipodUtil extends RileyLinkUtil { return omnipodPumpStatus; } + public static OmnipodDriverState getDriverState() { + return OmnipodUtil.driverState; + } + + public static void setDriverState(OmnipodDriverState state) { + if (OmnipodUtil.driverState == state) + return; + + OmnipodUtil.driverState = state; + + // TODO maybe remove + if (OmnipodUtil.omnipodPumpStatus != null) { + OmnipodUtil.omnipodPumpStatus.driverState = state; + } + + if (OmnipodUtil.omnipodPumpPlugin != null) { + OmnipodUtil.omnipodPumpPlugin.setDriverState(state); + } + } + public static void setPumpStatus(OmnipodPumpStatus omnipodPumpStatus) { OmnipodUtil.omnipodPumpStatus = omnipodPumpStatus; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1c72b45296..bbdf136083 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1667,6 +1667,7 @@ Pod Expires No info No Pod connected + Not initialized Active Pod Alerts Ack Alerts