From 2d8b3a7cb827820876f98592082764b90aa60707 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 22 Oct 2017 10:40:09 +0200 Subject: [PATCH] wip --- .../plugins/Overview/Notification.java | 1 + .../plugins/PumpCombo/ComboPlugin.java | 26 ++++++++++++++----- .../de/jotomo/ruffy/spi/RuffyCommands.java | 7 ++--- .../ruffyscripter/RuffyCommandsV1Impl.java | 4 +-- .../jotomo/ruffyscripter/RuffyScripter.java | 25 +++++++++--------- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java index a857153c73..037018864e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java @@ -51,6 +51,7 @@ public class Notification { public static final int TOAST_ALARM = 22; public static final int WRONGBASALSTEP = 23; public static final int BOLUS_DELIVERY_ERROR = 24; + public static final int COMBO_PUMP_ERROR = 25; public int id; public Date date; 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 a64f51e2ad..e38128d1cf 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 @@ -22,6 +22,7 @@ import de.jotomo.ruffy.spi.CommandResult; import de.jotomo.ruffy.spi.PumpState; import de.jotomo.ruffy.spi.RuffyCommands; import de.jotomo.ruffy.spi.history.Bolus; +import de.jotomo.ruffy.spi.history.Error; import de.jotomo.ruffy.spi.history.PumpHistoryRequest; import de.jotomo.ruffy.spi.history.Tbr; import de.jotomo.ruffyscripter.RuffyCommandsV1Impl; @@ -103,7 +104,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { pumpDescription.tempMaxDuration = 24 * 60; - pumpDescription.isSetBasalProfileCapable = false; // TODO GL#14 + pumpDescription.isSetBasalProfileCapable = false; pumpDescription.basalStep = 0.01d; pumpDescription.basalMinimumRate = 0.0d; @@ -653,12 +654,25 @@ public class ComboPlugin implements PluginBase, PumpInterface { MainApp.bus().post(new EventComboPumpUpdateGUI(status)); CommandResult commandResult = commandExecution.execute(); - if (commandResult.state.errorMsg != null) { - CommandResult takeOverAlarmResult = ruffyScripter.takeOverAlarm(); + // TODO hm... automatically confirm messages and return them and handle them here proper? + // with an option to corfirm all messages, non-critical (letting occlusion alert ring on phone and pump) + // or let all alarms ring and don't try to control the pump in any way - Notification notification = new Notification(Notification.IC_MISSING, "Pump alarm: " + takeOverAlarmResult.message - /*ainApp.sResources.getString(R.string.icmissing)*/, Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + // option how to deal with errors on connect; allow to explicitely be okay with e.g. TBR CANCELLED after interruption?! + // or a separate command to check and deal with pump state? run a check command before all operations? + + // maybe think less in 'all in one command', but simpler commands? + // get the current state, then decide what makes sense to do further, if anything, + // send next request. + // then request state again ... ? + if (commandResult.state.errorMsg != null) { + CommandResult takeOverAlarmResult = ruffyScripter.takeOverAlarms(); + + for (Error error : takeOverAlarmResult.history.errorHistory) { + MainApp.bus().post(new EventNewNotification( + new Notification(Notification.COMBO_PUMP_ERROR, + "Pump alarm: " + error.message, Notification.URGENT))); + } commandResult.state = takeOverAlarmResult.state; } 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 9ec283af1d..42293944a1 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 @@ -14,11 +14,8 @@ public interface RuffyCommands { CommandResult cancelTbr(); /** Confirms an active alarm on the pump. The state returned is the state after the alarm - * has been confirmed. The message field contains the displayed error message that was - * confirmed. */ - // TODO multiple alarms can occur -> empty battery, stops pump -> tbr cancelled - // return them as history.errors? - CommandResult takeOverAlarm(); + * has been confirmed. Confirmed alerts are returned in history.errorHistory. */ + CommandResult takeOverAlarms(); boolean isPumpAvailable(); diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java index 12cd48602f..8d4d9b9db6 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyCommandsV1Impl.java @@ -23,8 +23,8 @@ public class RuffyCommandsV1Impl implements RuffyCommands { } @Override - public CommandResult takeOverAlarm() { - return delegate.takeOverAlarm(); + public CommandResult takeOverAlarms() { + return delegate.takeOverAlarms(); } @Override diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java index e7a2a6a576..3c69906ea2 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/RuffyScripter.java @@ -29,6 +29,7 @@ import de.jotomo.ruffy.spi.BolusProgressReporter; import de.jotomo.ruffy.spi.CommandResult; import de.jotomo.ruffy.spi.PumpState; import de.jotomo.ruffy.spi.RuffyCommands; +import de.jotomo.ruffy.spi.history.Error; import de.jotomo.ruffy.spi.history.PumpHistoryRequest; import de.jotomo.ruffyscripter.commands.BolusCommand; import de.jotomo.ruffyscripter.commands.CancelTbrCommand; @@ -265,16 +266,7 @@ public class RuffyScripter implements RuffyCommands { class CommandRunner { public void run() { try { - // check if pump is an an error state - if (currentMenu == null || currentMenu.getType() == MenuType.WARNING_OR_ERROR) { - try { - returnable.cmdResult = new CommandResult().message("Pump is in an error state: " + currentMenu.getAttribute(MenuAttribute.MESSAGE)); - return; - } catch (Exception e) { - returnable.cmdResult = new CommandResult().message("Pump is in an error state, reading the error state resulted in the attached exception").exception(e); - return; - } - } + // Except for GetPumpStateCommand: fail on all requests if the pump is suspended. // All trickery of not executing but returning success, so that AAPS can non-sensically TBR away when suspended // are dangerous in the current model where commands are dispatched without checking state beforehand, so @@ -814,7 +806,7 @@ public class RuffyScripter implements RuffyCommands { waitForScreenUpdate(1000); retries--; if (retries == 0) { - throw new CommandException().message("Failed to read blinkng value: " + attribute + "=" + value + " type=" + value.getClass()); + throw new CommandException().message("Failed to read blinkng value: " + attribute + "=" + value + " type=" + value); } } return (T) value; @@ -843,10 +835,19 @@ public class RuffyScripter implements RuffyCommands { } @Override - public CommandResult takeOverAlarm() { + public CommandResult takeOverAlarms() { if (getCurrentMenu().getType() != MenuType.WARNING_OR_ERROR) { return new CommandResult().success(false).enacted(false).message("No alarm active on the pump"); } + while (currentMenu.getType() == MenuType.WARNING_OR_ERROR) { + new Error(System.currentTimeMillis(), + "", + // TODO + // codes unqiue across W/E? +// (int) currentMenu.getAttribute(MenuAttribute.WARNING), +// (int) currentMenu.getAttribute(MenuAttribute.ERROR), + (String) currentMenu.getAttribute(MenuAttribute.MESSAGE)); + } // confirm alert verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR); pressCheckKey();