From 7cb0268afc652370c5aa4db987ddd09e4a6894ce Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 13 Jul 2017 20:17:20 +0200 Subject: [PATCH] Disconnect after issuing comand to Combo. --- .../plugins/PumpCombo/ComboPlugin.java | 75 +++++++++++-------- 1 file changed, 45 insertions(+), 30 deletions(-) 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 ffc4657254..5cbc914996 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 @@ -50,6 +50,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { private ServiceConnection mRuffyServiceConnection; private static PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult(); + static { OPERATION_NOT_SUPPORTED.success = false; OPERATION_NOT_SUPPORTED.enacted = false; @@ -94,7 +95,7 @@ public class ComboPlugin implements PluginBase, PumpInterface { }; boolean success = context.bindService(intent, mRuffyServiceConnection, Context.BIND_AUTO_CREATE); - if(!success) { + if (!success) { log.error("Binding to ruffy service failed"); } } @@ -189,7 +190,8 @@ public class ComboPlugin implements PluginBase, PumpInterface { @Override public boolean isInitialized() { // TODO - return ruffyScripter != null; + // hm, lastCmdDate > 0, like the DanaR does it? + return true; // scripter does this as needed; ruffyScripter != null; } @Override @@ -239,16 +241,19 @@ public class ComboPlugin implements PluginBase, PumpInterface { @Override public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { - Command command = new BolusCommand(detailedBolusInfo.insulin); - CommandResult commandResult = ruffyScripter.runCommand(command); + try { + Command command = new BolusCommand(detailedBolusInfo.insulin); + CommandResult commandResult = ruffyScripter.runCommand(command); - PumpEnactResult pumpEnactResult = new PumpEnactResult(); - pumpEnactResult.success = commandResult.success; - pumpEnactResult.enacted = commandResult.enacted; - pumpEnactResult.comment = commandResult.message; - pumpEnactResult.bolusDelivered = detailedBolusInfo.insulin; - - return pumpEnactResult; + PumpEnactResult pumpEnactResult = new PumpEnactResult(); + pumpEnactResult.success = commandResult.success; + pumpEnactResult.enacted = commandResult.enacted; + pumpEnactResult.comment = commandResult.message; + pumpEnactResult.bolusDelivered = detailedBolusInfo.insulin; + return pumpEnactResult; + } finally { + ruffyScripter.disconnect(); + } } @Override @@ -267,19 +272,24 @@ public class ComboPlugin implements PluginBase, PumpInterface { @Override public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { // TODO make each cmd return all the data the main screen displays and cache here ? - Command command = new SetTbrCommand(percent, durationInMinutes); - CommandResult commandResult = ruffyScripter.runCommand(command); + try { + Command command = new SetTbrCommand(percent, durationInMinutes); + CommandResult commandResult = ruffyScripter.runCommand(command); - PumpEnactResult pumpEnactResult = new PumpEnactResult(); - pumpEnactResult.success = commandResult.success; - pumpEnactResult.enacted = commandResult.enacted; - pumpEnactResult.comment = commandResult.message; - pumpEnactResult.isPercent = true; - pumpEnactResult.percent = percent; + PumpEnactResult pumpEnactResult = new PumpEnactResult(); + pumpEnactResult.success = commandResult.success; + pumpEnactResult.enacted = commandResult.enacted; + pumpEnactResult.comment = commandResult.message; + pumpEnactResult.isPercent = true; + pumpEnactResult.percent = percent; - fakeBasalRate = fakeBasalRate * percent / 100; + //TODO + fakeBasalRate = fakeBasalRate * percent / 100; - return pumpEnactResult; + return pumpEnactResult; + } finally { + ruffyScripter.disconnect(); + } } // TODO @@ -291,18 +301,23 @@ public class ComboPlugin implements PluginBase, PumpInterface { // TODO @Override public PumpEnactResult cancelTempBasal() { - Command command = new CancelTbrCommand(); - CommandResult commandResult = ruffyScripter.runCommand(command); + try { + Command command = new CancelTbrCommand(); + CommandResult commandResult = ruffyScripter.runCommand(command); - PumpEnactResult pumpEnactResult = new PumpEnactResult(); - pumpEnactResult.success = commandResult.success; - pumpEnactResult.enacted = commandResult.enacted; - pumpEnactResult.comment = commandResult.message; - pumpEnactResult.isTempCancel = true; + PumpEnactResult pumpEnactResult = new PumpEnactResult(); + pumpEnactResult.success = commandResult.success; + pumpEnactResult.enacted = commandResult.enacted; + pumpEnactResult.comment = commandResult.message; + pumpEnactResult.isTempCancel = true; - fakeBasalRate = 0.5d; + //TODO + fakeBasalRate = 0.5d; - return pumpEnactResult; + return pumpEnactResult; + } finally { + ruffyScripter.disconnect(); + } } // TODO