This commit is contained in:
Johannes Mockenhaupt 2017-10-22 10:40:09 +02:00
parent 300a4609f8
commit 2d8b3a7cb8
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
5 changed files with 38 additions and 25 deletions

View file

@ -51,6 +51,7 @@ public class Notification {
public static final int TOAST_ALARM = 22; public static final int TOAST_ALARM = 22;
public static final int WRONGBASALSTEP = 23; public static final int WRONGBASALSTEP = 23;
public static final int BOLUS_DELIVERY_ERROR = 24; public static final int BOLUS_DELIVERY_ERROR = 24;
public static final int COMBO_PUMP_ERROR = 25;
public int id; public int id;
public Date date; public Date date;

View file

@ -22,6 +22,7 @@ import de.jotomo.ruffy.spi.CommandResult;
import de.jotomo.ruffy.spi.PumpState; import de.jotomo.ruffy.spi.PumpState;
import de.jotomo.ruffy.spi.RuffyCommands; import de.jotomo.ruffy.spi.RuffyCommands;
import de.jotomo.ruffy.spi.history.Bolus; 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.PumpHistoryRequest;
import de.jotomo.ruffy.spi.history.Tbr; import de.jotomo.ruffy.spi.history.Tbr;
import de.jotomo.ruffyscripter.RuffyCommandsV1Impl; import de.jotomo.ruffyscripter.RuffyCommandsV1Impl;
@ -103,7 +104,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
pumpDescription.tempMaxDuration = 24 * 60; pumpDescription.tempMaxDuration = 24 * 60;
pumpDescription.isSetBasalProfileCapable = false; // TODO GL#14 pumpDescription.isSetBasalProfileCapable = false;
pumpDescription.basalStep = 0.01d; pumpDescription.basalStep = 0.01d;
pumpDescription.basalMinimumRate = 0.0d; pumpDescription.basalMinimumRate = 0.0d;
@ -653,12 +654,25 @@ public class ComboPlugin implements PluginBase, PumpInterface {
MainApp.bus().post(new EventComboPumpUpdateGUI(status)); MainApp.bus().post(new EventComboPumpUpdateGUI(status));
CommandResult commandResult = commandExecution.execute(); CommandResult commandResult = commandExecution.execute();
if (commandResult.state.errorMsg != null) { // TODO hm... automatically confirm messages and return them and handle them here proper?
CommandResult takeOverAlarmResult = ruffyScripter.takeOverAlarm(); // 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 // option how to deal with errors on connect; allow to explicitely be okay with e.g. TBR CANCELLED after interruption?!
/*ainApp.sResources.getString(R.string.icmissing)*/, Notification.URGENT); // or a separate command to check and deal with pump state? run a check command before all operations?
MainApp.bus().post(new EventNewNotification(notification));
// 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; commandResult.state = takeOverAlarmResult.state;
} }

View file

@ -14,11 +14,8 @@ public interface RuffyCommands {
CommandResult cancelTbr(); CommandResult cancelTbr();
/** Confirms an active alarm on the pump. The state returned is the state after the alarm /** 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 * has been confirmed. Confirmed alerts are returned in history.errorHistory. */
* confirmed. */ CommandResult takeOverAlarms();
// TODO multiple alarms can occur -> empty battery, stops pump -> tbr cancelled
// return them as history.errors?
CommandResult takeOverAlarm();
boolean isPumpAvailable(); boolean isPumpAvailable();

View file

@ -23,8 +23,8 @@ public class RuffyCommandsV1Impl implements RuffyCommands {
} }
@Override @Override
public CommandResult takeOverAlarm() { public CommandResult takeOverAlarms() {
return delegate.takeOverAlarm(); return delegate.takeOverAlarms();
} }
@Override @Override

View file

@ -29,6 +29,7 @@ import de.jotomo.ruffy.spi.BolusProgressReporter;
import de.jotomo.ruffy.spi.CommandResult; import de.jotomo.ruffy.spi.CommandResult;
import de.jotomo.ruffy.spi.PumpState; import de.jotomo.ruffy.spi.PumpState;
import de.jotomo.ruffy.spi.RuffyCommands; import de.jotomo.ruffy.spi.RuffyCommands;
import de.jotomo.ruffy.spi.history.Error;
import de.jotomo.ruffy.spi.history.PumpHistoryRequest; import de.jotomo.ruffy.spi.history.PumpHistoryRequest;
import de.jotomo.ruffyscripter.commands.BolusCommand; import de.jotomo.ruffyscripter.commands.BolusCommand;
import de.jotomo.ruffyscripter.commands.CancelTbrCommand; import de.jotomo.ruffyscripter.commands.CancelTbrCommand;
@ -265,16 +266,7 @@ public class RuffyScripter implements RuffyCommands {
class CommandRunner { class CommandRunner {
public void run() { public void run() {
try { 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. // 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 // 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 // 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); waitForScreenUpdate(1000);
retries--; retries--;
if (retries == 0) { 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; return (T) value;
@ -843,10 +835,19 @@ public class RuffyScripter implements RuffyCommands {
} }
@Override @Override
public CommandResult takeOverAlarm() { public CommandResult takeOverAlarms() {
if (getCurrentMenu().getType() != MenuType.WARNING_OR_ERROR) { if (getCurrentMenu().getType() != MenuType.WARNING_OR_ERROR) {
return new CommandResult().success(false).enacted(false).message("No alarm active on the pump"); 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 // confirm alert
verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR); verifyMenuIsDisplayed(MenuType.WARNING_OR_ERROR);
pressCheckKey(); pressCheckKey();