Fix detecting error state on connection and fix cancelling TBR.
When there's an error, timing is crucial. Waiting for the blinking error code to be readable hangs the thread running the command.
This commit is contained in:
parent
f6c8f3638b
commit
99830b05b6
2 changed files with 9 additions and 17 deletions
|
@ -129,8 +129,7 @@ public class RuffyScripter {
|
||||||
// check if pump is an an error state
|
// check if pump is an an error state
|
||||||
if (currentMenu != null && currentMenu.getType() == MenuType.WARNING_OR_ERROR) {
|
if (currentMenu != null && currentMenu.getType() == MenuType.WARNING_OR_ERROR) {
|
||||||
try {
|
try {
|
||||||
PumpAlert alert = readDisplayPumpAlert();
|
return new CommandResult().message("Pump is in an error state: " + currentMenu.getAttribute(MenuAttribute.MESSAGE));
|
||||||
return new CommandResult().message("Pump is in an error state: " + alert + " (" + alert.code + ")");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new CommandResult().message("Pump is in an error state, reading the error state resulted in the attached exception").exception(e);
|
return new CommandResult().message("Pump is in an error state, reading the error state resulted in the attached exception").exception(e);
|
||||||
}
|
}
|
||||||
|
@ -344,14 +343,4 @@ public class RuffyScripter {
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PumpAlert readDisplayPumpAlert() {
|
|
||||||
Object errorObj = currentMenu.getAttribute(MenuAttribute.ERROR);
|
|
||||||
while (errorObj == null) {
|
|
||||||
SystemClock.sleep(10);
|
|
||||||
errorObj = currentMenu.getAttribute(MenuAttribute.ERROR);
|
|
||||||
}
|
|
||||||
String errorMsg = (String) currentMenu.getAttribute(MenuAttribute.MESSAGE);
|
|
||||||
return new PumpAlert((int) errorObj, errorMsg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,19 +190,22 @@ public class SetTbrCommand implements Command {
|
||||||
scripter.pressCheckKey();
|
scripter.pressCheckKey();
|
||||||
|
|
||||||
// we could read remaining duration from MAIN_MENU, but but the time we're here,
|
// we could read remaining duration from MAIN_MENU, but but the time we're here,
|
||||||
// we could have moved from 0:02 to 0:01, so instead,/ check if a TBR CANCELLED alert
|
// we could have moved from 0:02 to 0:01, so instead, check if a "TBR CANCELLED alert"
|
||||||
// is raised and if so dismiss it
|
// is raised and if so dismiss it
|
||||||
scripter.waitForMenuToBeLeft(MenuType.TBR_SET);
|
scripter.waitForMenuToBeLeft(MenuType.TBR_SET);
|
||||||
long inTwoSeconds = System.currentTimeMillis() + 2 * 1000;
|
long inTwoSeconds = System.currentTimeMillis() + 2 * 1000;
|
||||||
boolean alertProcessed = false;
|
boolean alertProcessed = false;
|
||||||
while (System.currentTimeMillis() < inTwoSeconds && !alertProcessed) {
|
while (System.currentTimeMillis() < inTwoSeconds && !alertProcessed) {
|
||||||
if (scripter.currentMenu.getType() == MenuType.WARNING_OR_ERROR) {
|
if (scripter.currentMenu.getType() == MenuType.WARNING_OR_ERROR) {
|
||||||
// check the raised alarm is TBR CANCELLED
|
// check the raised alarm is TBR CANCELLED.
|
||||||
PumpAlert alert = scripter.readDisplayPumpAlert();
|
// note that the message is permanently displayed, while the error code is blinking.
|
||||||
if (alert.code != 6 || Objects.equals(alert.msg, "TBR CANCELLED")) {
|
// wait till the error code can be read results in the code hanging, despite
|
||||||
|
// menu updates coming in, so just check the message
|
||||||
|
String errorMsg = (String) scripter.currentMenu.getAttribute(MenuAttribute.MESSAGE);
|
||||||
|
if (!errorMsg.equals("TBR CANCELLED")) {
|
||||||
throw new CommandException().success(false).enacted(false)
|
throw new CommandException().success(false).enacted(false)
|
||||||
.message("An alert other than the expected TBR CANCELLED was raised by the pump: "
|
.message("An alert other than the expected TBR CANCELLED was raised by the pump: "
|
||||||
+ alert.code + "(" + alert.msg + "). Please check the pump.");
|
+ errorMsg + ". Please check the pump.");
|
||||||
}
|
}
|
||||||
// confirm "TBR CANCELLED alert"
|
// confirm "TBR CANCELLED alert"
|
||||||
scripter.pressCheckKey();
|
scripter.pressCheckKey();
|
||||||
|
|
Loading…
Reference in a new issue