Don't rebind ruffy and retry command in case of failure.

RuffyService is now immeditately rebound when connection was lost,
therefore retrying a command after blindly rebinding the service
doesn't make sense anymore,more so given that ruffy is less prone
to crashing now.
This commit is contained in:
Johannes Mockenhaupt 2017-08-15 14:03:01 +02:00
parent 8178b6ff00
commit f0d9f0e86a
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -208,6 +208,8 @@ public class ComboPlugin implements PluginBase, PumpInterface {
public void onServiceDisconnected(ComponentName name) {
ruffyScripter.stop();
log.debug("ruffy service disconnected");
// try to reconnect ruffy service unless unbind was explicitely requested
// via unbindRuffyService
if(!keepUnbound) {
SystemClock.sleep(250);
bindRuffyService();
@ -427,41 +429,6 @@ public class ComboPlugin implements PluginBase, PumpInterface {
MainApp.bus().post(new EventComboPumpUpdateGUI());
CommandResult commandResult = ruffyScripter.runCommand(command);
// TODO extract this into a recovery method and check the logic of restarting and rebinding ruffy
if (!commandResult.success && commandResult.exception != null) {
log.error("CommandResult has exception, rebinding ruffy service", commandResult.exception);
// attempt to rebind the ruffy service, will start ruffy again if it crashed
try {
unbindRuffyService();
SystemClock.sleep(5000);
} catch (Exception e) {
/*String msg = "No connection to ruffy. Pump control not available.";
statusSummary = msg;
return new CommandResult().message(msg);*/
}
try {
bindRuffyService();
SystemClock.sleep(5000);
} catch (Exception e) {
String msg = "No connection to ruffy. Pump control not available.";
statusSummary = msg;
return new CommandResult().message(msg);
}
if (ruffyScripter == null) {
log.error("Rebinding failed");
} else if (!commandResult.enacted && !(command instanceof BolusCommand)) {
// retry command, but make sure it wasn't enacted and don't retry
// bolus commands (user is interacting with AAPS right now so he can
// deal with it and we don't want to deliver a bolus twice)
CommandResult retriedCommandResult = ruffyScripter.runCommand(command);
if (retriedCommandResult.success) {
commandResult = retriedCommandResult;
}
}
}
log.debug("RuffyScripter returned from command invocation, result: " + commandResult);
if (commandResult.exception != null) {
log.error("Exception received from pump", commandResult.exception);