From 960cb92789debc2b5a5ca651077a0a9db594d517 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 5 Dec 2017 22:57:06 +0100 Subject: [PATCH] Remove idle-disconnect-monitor and let the command queue take care of that. --- .../plugins/PumpCombo/ComboPlugin.java | 6 ++-- .../de/jotomo/ruffy/spi/RuffyCommands.java | 2 ++ .../ruffyscripter/RuffyCommandsV1Impl.java | 5 +++ .../jotomo/ruffyscripter/RuffyScripter.java | 34 +++++-------------- 4 files changed, 20 insertions(+), 27 deletions(-) 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 ed7cca6181..b4240f6f96 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 @@ -226,12 +226,12 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf @Override public void connect(String reason) { - // we're not doing that + // ruffyscripter establishes a connection as needed } @Override public void disconnect(String reason) { - // we're not doing that + ruffyScripter.disconnect(); } @Override @@ -676,6 +676,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } + // Pass this to qeueue?? + // hm, now that each PumpInterface method is basically one RuffyCommand again .... commandResult = commandExecution.execute(); if (!commandResult.success && retries > 0) { diff --git a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java index 88e4b0da02..93562009da 100644 --- a/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java +++ b/ruffy-spi/src/main/java/de/jotomo/ruffy/spi/RuffyCommands.java @@ -26,6 +26,8 @@ public interface RuffyCommands { /** Whether there's an active BT connection to the pump. */ boolean isConnected(); + void disconnect(); + /** Read the state of the pump, which encompasses all information displayed on the main menu. */ CommandResult readPumpState(); diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java index fbdac36438..79ab969a27 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java @@ -73,6 +73,11 @@ public class RuffyCommandsV1Impl implements RuffyCommands { return delegate.isConnected(); } + @Override + public void disconnect() { + delegate.disconnect(); + } + @Override public CommandResult readPumpState() { return delegate.readPumpState(); diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index 22967a0481..295aef8272 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -53,8 +53,6 @@ import de.jotomo.ruffyscripter.commands.SetTbrCommand; public class RuffyScripter implements RuffyCommands { private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class); - private static final long DISCONNECT_TIME_OUT_MS = 5000; - private IRuffyService ruffyService; @Nullable @@ -151,7 +149,6 @@ public class RuffyScripter implements RuffyCommands { } catch (Exception e) { log.error("Ruffy handler has issues", e); } - idleDisconnectMonitorThread.start(); started = true; } @@ -175,28 +172,6 @@ public class RuffyScripter implements RuffyCommands { return started; } - private Thread idleDisconnectMonitorThread = new Thread(new Runnable() { - @Override - public void run() { - while (!Thread.currentThread().isInterrupted()) { - try { - long now = System.currentTimeMillis(); - if (ruffyService.isConnected() && activeCmd == null - && now > lastCmdExecutionTime + DISCONNECT_TIME_OUT_MS) { - log.debug("Disconnecting after " + (DISCONNECT_TIME_OUT_MS / 1000) + "s inactivity timeout"); - ruffyService.doRTDisconnect(); - // don't attempt anything fancy in the next 10s, let the pump settle - SystemClock.sleep(10 * 1000); - } - } catch (Exception e) { - log.debug("Exception in idle disconnect monitor thread, taking a break and then carrying on", e); - SystemClock.sleep(10 * 1000); - } - SystemClock.sleep(1000); - } - } - }, "idle-disconnect-monitor"); - @Override public boolean isPumpBusy() { return activeCmd != null; @@ -211,6 +186,15 @@ public class RuffyScripter implements RuffyCommands { } } + @Override + public void disconnect() { + try { + ruffyService.doRTDisconnect(); + } catch (RemoteException e) { + throw new CommandException("Disconnect failed", e); + } + } + @Override public CommandResult readPumpState() { return runCommand(new ReadPumpStateCommand());