From 77711b21745a6f30cace0dc81aa39035629b5fc0 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 15 Jul 2017 15:00:27 +0200 Subject: [PATCH] ComboPlugin.runCommand: wait if pump is busy with a command. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 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 86272be29e..d1b05151b5 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 @@ -319,10 +319,17 @@ public class ComboPlugin implements PluginBase, PumpInterface { private CommandResult runCommand(Command command, boolean keepConnectionOpen) { // TODO use this to dispatch methods to a service thread, like DanaRs executionService try { + long timeout = System.currentTimeMillis() + 10 * 1000; + while (ruffyScripter.isPumpBusy()) { + if (System.currentTimeMillis() < timeout) { + return new CommandResult().success(false).enacted(false).message("Timeout waiting for the pump to be ready"); + } + SystemClock.sleep(200); + } return ruffyScripter.runCommand(command); } finally { lastCmdTime = new Date(); - if(!keepConnectionOpen) { + if (!keepConnectionOpen) { ruffyScripter.disconnect(); } } @@ -340,7 +347,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) { log.debug("setTempBasalAbsolute called with a rate of " + absoluteRate + " for " + durationInMinutes + " min."); int unroundedPercentage = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); - int roundedPercentage = (int) (Math.round(absoluteRate/ getBaseBasalRate() * 10) * 10); + int roundedPercentage = (int) (Math.round(absoluteRate / getBaseBasalRate() * 10) * 10); if (unroundedPercentage != roundedPercentage) { log.debug("Rounded requested rate " + unroundedPercentage + "% -> " + roundedPercentage + "%"); }