From 3156efaaf6e543976f1b7cd91326bd7229083016 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 13 Dec 2017 11:07:57 +0100 Subject: [PATCH 1/4] SetTbr: wait if an existing TBR is about to run out. See code comment. --- .../ruffyscripter/commands/SetTbrCommand.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index 6f95d0d0ee..3b02caee91 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import de.jotomo.ruffy.spi.PumpState; import de.jotomo.ruffy.spi.PumpWarningCodes; import de.jotomo.ruffy.spi.WarningOrErrorCode; @@ -63,6 +64,25 @@ public class SetTbrCommand extends BaseCommand { boolean cancellingTbr = percentage == 100; try { + // When programming a new TBR while an existing TBR runs out, a TBR CANCELLED + // alert is raised (failing the command, requiring a reconnect and confirming alert + // and all). To avoid this, wait until the active TBR runs out if the active TBR + // is about to end + long timeout = System.currentTimeMillis() + 65 * 1000; + PumpState state = scripter.readPumpStateInternal(); + if (state.tbrRemainingDuration == 1) { + while (state.tbrActive && System.currentTimeMillis() < timeout) { + log.debug("Waiting for existing TBR to run out to avoid alert while setting TBR"); + scripter.waitForScreenUpdate(); + state = scripter.readPumpStateInternal(); + } + // if we waited above and a cancellation was requested, we already completed the request + if (!state.tbrActive && cancellingTbr) { + result.success = true; + return; + } + } + enterTbrMenu(); boolean increasingPercentage = inputTbrPercentage(); verifyDisplayedTbrPercentage(increasingPercentage); From 7ed64c5a7d549609078712500d03d29ccadc53ce Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 13 Dec 2017 14:22:01 +0100 Subject: [PATCH 2/4] SetTbrCommand: verify current menu when checking running TBR. --- .../java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index 3b02caee91..ee7f78632a 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -69,6 +69,7 @@ public class SetTbrCommand extends BaseCommand { // and all). To avoid this, wait until the active TBR runs out if the active TBR // is about to end long timeout = System.currentTimeMillis() + 65 * 1000; + scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); PumpState state = scripter.readPumpStateInternal(); if (state.tbrRemainingDuration == 1) { while (state.tbrActive && System.currentTimeMillis() < timeout) { From 5b31d39f2838c0841a1f823f8bcbc398df813d1a Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 13 Dec 2017 14:26:41 +0100 Subject: [PATCH 3/4] Extract method checkAndWaitIfExistingTbrIsAboutToEnd. --- .../ruffyscripter/commands/SetTbrCommand.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index ee7f78632a..ca3cdd7cff 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -64,24 +64,8 @@ public class SetTbrCommand extends BaseCommand { boolean cancellingTbr = percentage == 100; try { - // When programming a new TBR while an existing TBR runs out, a TBR CANCELLED - // alert is raised (failing the command, requiring a reconnect and confirming alert - // and all). To avoid this, wait until the active TBR runs out if the active TBR - // is about to end - long timeout = System.currentTimeMillis() + 65 * 1000; - scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); - PumpState state = scripter.readPumpStateInternal(); - if (state.tbrRemainingDuration == 1) { - while (state.tbrActive && System.currentTimeMillis() < timeout) { - log.debug("Waiting for existing TBR to run out to avoid alert while setting TBR"); - scripter.waitForScreenUpdate(); - state = scripter.readPumpStateInternal(); - } - // if we waited above and a cancellation was requested, we already completed the request - if (!state.tbrActive && cancellingTbr) { - result.success = true; - return; - } + if (checkAndWaitIfExistingTbrIsAboutToEnd(cancellingTbr)) { + return; } enterTbrMenu(); @@ -121,6 +105,33 @@ public class SetTbrCommand extends BaseCommand { result.success = true; } + /** + * When programming a new TBR while an existing TBR runs out, a TBR CANCELLED + * alert is raised (failing the command, requiring a reconnect and confirming alert + * and all). To avoid this, wait until the active TBR runs out if the active TBR + * is about to end. + * + * @return If we waited till the TBR ended an cancellation was request so all work is done. + */ + private boolean checkAndWaitIfExistingTbrIsAboutToEnd(boolean cancellingTbr) { + scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); + long timeout = System.currentTimeMillis() + 65 * 1000; + PumpState state = scripter.readPumpStateInternal(); + if (state.tbrRemainingDuration == 1) { + while (state.tbrActive && System.currentTimeMillis() < timeout) { + log.debug("Waiting for existing TBR to run out to avoid alert while setting TBR"); + scripter.waitForScreenUpdate(); + state = scripter.readPumpStateInternal(); + } + // if we waited above and a cancellation was requested, we already completed the request + if (!state.tbrActive && cancellingTbr) { + result.success = true; + return true; + } + } + return false; + } + private void enterTbrMenu() { scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU); scripter.navigateToMenu(MenuType.TBR_MENU); From 03e75ab23fee642ed20b4b694aa6194f84059dbc Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 13 Dec 2017 15:44:07 +0100 Subject: [PATCH 4/4] Typos. --- .../java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index ca3cdd7cff..aea5da5a0b 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -111,7 +111,7 @@ public class SetTbrCommand extends BaseCommand { * and all). To avoid this, wait until the active TBR runs out if the active TBR * is about to end. * - * @return If we waited till the TBR ended an cancellation was request so all work is done. + * @return true wf we waited till the TBR ended and cancellation was request so all work is done. */ private boolean checkAndWaitIfExistingTbrIsAboutToEnd(boolean cancellingTbr) { scripter.verifyMenuIsDisplayed(MenuType.MAIN_MENU);