diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.java b/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.java index 7d810702b9..6729a4e703 100644 --- a/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.java +++ b/app/src/main/java/info/nightscout/androidaps/events/EventPumpStatusChanged.java @@ -10,9 +10,10 @@ import info.nightscout.androidaps.R; public class EventPumpStatusChanged extends Event { public static final int CONNECTING = 0; public static final int CONNECTED = 1; - public static final int PERFORMING = 2; - public static final int DISCONNECTING = 3; - public static final int DISCONNECTED = 4; + public static final int HANDSHAKING = 2; + public static final int PERFORMING = 3; + public static final int DISCONNECTING = 4; + public static final int DISCONNECTED = 5; public int sStatus = DISCONNECTED; public int sSecondsElapsed = 0; @@ -47,6 +48,8 @@ public class EventPumpStatusChanged extends Event { public String textStatus() { if (sStatus == CONNECTING) return String.format(MainApp.gs(R.string.danar_history_connectingfor), sSecondsElapsed); + else if (sStatus == HANDSHAKING) + return MainApp.gs(R.string.handshaking); else if (sStatus == CONNECTED) return MainApp.gs(R.string.connected); else if (sStatus == PERFORMING) 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 6b2810564e..614c6033d3 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -11,11 +11,13 @@ import info.nightscout.androidaps.data.PumpEnactResult; */ public interface PumpInterface { - boolean isInitialized(); - boolean isSuspended(); - boolean isBusy(); - boolean isConnected(); - boolean isConnecting(); + boolean isInitialized(); // true if pump status has been read and is ready to accept commands + boolean isSuspended(); // true if suspended (not delivering insulin) + boolean isBusy(); // if true pump is not ready to accept commands right now + boolean isConnected(); // true if BT connection is established + boolean isConnecting(); // true if BT connection is in progress + boolean isHandshakeInProgress(); // true if BT is connected but initial handshake is still in progress + void finishHandshaking(); // set initial handshake completed void connect(String reason); void disconnect(String reason); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 56b349da55..1887356876 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -250,6 +250,15 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint return false; } + @Override + public boolean isHandshakeInProgress() { + return false; + } + + @Override + public void finishHandshaking() { + } + @Override public void connect(String reason) { // ruffyscripter establishes a connection as needed. diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index c55460acb0..27e3cbc611 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -175,6 +175,16 @@ public class DanaRPlugin extends AbstractDanaRPlugin { return pump.lastConnection > 0 && pump.isExtendedBolusEnabled && pump.maxBasal > 0; } + @Override + public boolean isHandshakeInProgress() { + return sExecutionService != null && sExecutionService.isHandshakeInProgress(); + } + + @Override + public void finishHandshaking() { + sExecutionService.finishHandshaking(); + } + @Override public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java index c3b73c0ae1..188e12ffa8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java @@ -4,6 +4,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; /** @@ -34,6 +35,9 @@ public class MsgInitConnStatusOption extends MessageBase { if (L.isEnabled(L.PUMPCOMM)) log.debug("Pump password: " + DanaRPump.getInstance().password); } + + // This is last message of initial sequence + ConfigBuilderPlugin.getPlugin().getActivePump().finishHandshaking(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java index d800301cfc..88745f66b5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java @@ -58,7 +58,8 @@ public abstract class AbstractDanaRExecutionService extends Service { protected DanaRPump mDanaRPump = DanaRPump.getInstance(); protected Treatment mBolusingTreatment = null; - protected Boolean mConnectionInProgress = false; + protected boolean mConnectionInProgress = false; + protected boolean mHandshakeInProgress = false; protected AbstractSerialIOThread mSerialIOThread; @@ -131,6 +132,15 @@ public abstract class AbstractDanaRExecutionService extends Service { return mConnectionInProgress; } + public boolean isHandshakeInProgress() { + return isConnected() && mHandshakeInProgress; + } + + public void finishHandshaking() { + mHandshakeInProgress = false; + MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0)); + } + public void disconnect(String from) { if (mSerialIOThread != null) mSerialIOThread.disconnect(from); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index 3b80ac41d1..a2b15d8f2f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -111,6 +111,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { return; new Thread(() -> { + mHandshakeInProgress = false; mConnectionInProgress = true; getBTSocketForSelectedPump(); if (mRfcommSocket == null || mBTDevice == null) { @@ -132,7 +133,8 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.disconnect("Recreate SerialIOThread"); } mSerialIOThread = new SerialIOThread(mRfcommSocket); - MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0)); + mHandshakeInProgress = true; + MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.HANDSHAKING, 0)); } mConnectionInProgress = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 78affd6ca3..8e56097fde 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -179,6 +179,16 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { return pump.lastConnection > 0 && pump.maxBasal > 0 && !pump.isConfigUD && !pump.isEasyModeEnabled && pump.isExtendedBolusEnabled; } + @Override + public boolean isHandshakeInProgress() { + return sExecutionService != null && sExecutionService.isHandshakeInProgress(); + } + + @Override + public void finishHandshaking() { + sExecutionService.finishHandshaking(); + } + @Override public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index 0ca38cc71c..59eab2d384 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -115,6 +115,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { return; new Thread(() -> { + mHandshakeInProgress = false; mConnectionInProgress = true; getBTSocketForSelectedPump(); if (mRfcommSocket == null || mBTDevice == null) { @@ -136,7 +137,8 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.disconnect("Recreate SerialIOThread"); } mSerialIOThread = new SerialIOThread(mRfcommSocket); - MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0)); + mHandshakeInProgress = true; + MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.HANDSHAKING, 0)); } mConnectionInProgress = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index 2b8a2881cf..42c64e1f88 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -221,6 +221,15 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte return danaRSService != null && danaRSService.isConnecting(); } + @Override + public boolean isHandshakeInProgress() { + return false; + } + + @Override + public void finishHandshaking() { + } + @Override public void disconnect(String from) { if (L.isEnabled(L.PUMP)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 78d7055f4c..f251c59638 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -144,6 +144,16 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { return DanaRPump.getInstance().lastConnection > 0 && DanaRPump.getInstance().maxBasal > 0; } + @Override + public boolean isHandshakeInProgress() { + return sExecutionService != null && sExecutionService.isHandshakeInProgress(); + } + + @Override + public void finishHandshaking() { + sExecutionService.finishHandshaking(); + } + @Override public void switchAllowed(ConfigBuilderFragment.PluginViewHolder.PluginSwitcher pluginSwitcher, FragmentActivity context) { boolean allowHardwarePump = SP.getBoolean("allow_hardware_pump", false); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 97c0b80d50..609783bec5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -134,6 +134,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { return; new Thread(() -> { + mHandshakeInProgress = false; mConnectionInProgress = true; getBTSocketForSelectedPump(); if (mRfcommSocket == null || mBTDevice == null) { @@ -155,7 +156,8 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.disconnect("Recreate SerialIOThread"); } mSerialIOThread = new SerialIOThread(mRfcommSocket); - MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0)); + mHandshakeInProgress = true; + MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.HANDSHAKING, 0)); } mConnectionInProgress = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java index d207157835..81b9dd6409 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java @@ -259,6 +259,15 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai return Connector.get().isPumpConnecting(); } + @Override + public boolean isHandshakeInProgress() { + return false; + } + + @Override + public void finishHandshaking() { + } + @Override public void connect(String reason) { log("InsightPlugin::connect()"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java index 9f40092653..27651a7cfb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java @@ -88,6 +88,15 @@ public class MDIPlugin extends PluginBase implements PumpInterface { return false; } + @Override + public boolean isHandshakeInProgress() { + return false; + } + + @Override + public void finishHandshaking() { + } + @Override public void connect(String reason) { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index 98a9799d18..f5d1faab77 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -147,6 +147,15 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { return false; } + @Override + public boolean isHandshakeInProgress() { + return false; + } + + @Override + public void finishHandshaking() { + } + @Override public void connect(String reason) { if (!Config.NSCLIENT) diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java index 83414b23fe..c8b2574974 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java @@ -101,6 +101,14 @@ public class QueueThread extends Thread { } } + if (pump.isHandshakeInProgress()) { + if (L.isEnabled(L.PUMPQUEUE)) + log.debug("handshaking " + secondsElapsed); + MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.HANDSHAKING, (int) secondsElapsed)); + SystemClock.sleep(100); + continue; + } + if (pump.isConnecting()) { if (L.isEnabled(L.PUMPQUEUE)) log.debug("connecting " + secondsElapsed); @@ -109,7 +117,6 @@ public class QueueThread extends Thread { continue; } - if (!pump.isConnected()) { if (L.isEnabled(L.PUMPQUEUE)) log.debug("connect"); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 39c3561a14..a43bc5d54b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1187,6 +1187,7 @@ Preferred APS mode Total Calc + Handshaking %1$d day