Make RuffyScripter.isConnected more robust, remove debug code.

This commit is contained in:
Johannes Mockenhaupt 2017-12-14 22:14:05 +01:00
parent e7e7c2a18d
commit cac38c2401
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -31,8 +31,8 @@ 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.PumpHistoryRequest;
import de.jotomo.ruffy.spi.WarningOrErrorCode; import de.jotomo.ruffy.spi.WarningOrErrorCode;
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;
import de.jotomo.ruffyscripter.commands.Command; import de.jotomo.ruffyscripter.commands.Command;
@ -184,7 +184,13 @@ public class RuffyScripter implements RuffyCommands {
return false; return false;
} }
try { try {
return ruffyService.isConnected() && System.currentTimeMillis() - menuLastUpdated < 5000; if (!ruffyService.isConnected()) {
return false;
}
if (System.currentTimeMillis() - menuLastUpdated > 500) {
waitForScreenUpdate();
}
return System.currentTimeMillis() - menuLastUpdated < 500;
} catch (RemoteException e) { } catch (RemoteException e) {
return false; return false;
} }
@ -278,15 +284,16 @@ public class RuffyScripter implements RuffyCommands {
// can retry if needed). // can retry if needed).
cmdThread.interrupt(); cmdThread.interrupt();
activeCmd.getResult().success = false; activeCmd.getResult().success = false;
for (int attempts = 4; attempts > 0; attempts--) { for (int attempts = 2; attempts > 0; attempts--) {
boolean reconnected = recoverFromConnectionLoss(); boolean reconnected = recoverFromConnectionLoss();
if (reconnected) { if (reconnected) {
break; break;
} }
// connect attempt times out after 30s, shortly wait and then retry; // connect attempt times out after 90s, shortly wait and then retry;
// (30s timeout + 5s wait) * 4 attempts = 140s // (90s timeout + 5s wait) * 2 attempts = 190s
SystemClock.sleep(5 * 1000); SystemClock.sleep(5 * 1000);
} }
break;
} }
if (System.currentTimeMillis() > overallTimeout) { if (System.currentTimeMillis() > overallTimeout) {
@ -392,15 +399,6 @@ public class RuffyScripter implements RuffyCommands {
boolean connected = isConnected(); boolean connected = isConnected();
if (connected) { if (connected) {
long menuTime = this.menuLastUpdated;
waitForScreenUpdate();
if (menuTime == this.menuLastUpdated) {
log.error("NOT RECEIVING UPDATES YET JOE");
}
while(currentMenu==null) {
log.warn("waiting for currentMenu to become != null");
waitForScreenUpdate();
}
MenuType menuType = getCurrentMenu().getType(); MenuType menuType = getCurrentMenu().getType();
if (menuType != MenuType.MAIN_MENU && menuType != MenuType.WARNING_OR_ERROR) { if (menuType != MenuType.MAIN_MENU && menuType != MenuType.WARNING_OR_ERROR) {
returnToRootMenu(); returnToRootMenu();