From c27ceb0a72907a7af70752c34799f8f4c54a18d6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 21 Apr 2018 00:02:15 +0200 Subject: [PATCH] better bolus error handling for Dana pumps --- .../plugins/PumpDanaR/DanaRPlugin.java | 18 +++-- .../plugins/PumpDanaR/comm/MsgBolusStart.java | 10 ++- .../comm/MsgBolusStartWithSpeed.java | 10 ++- .../services/DanaRExecutionService.java | 2 +- .../PumpDanaRKorean/DanaRKoreanPlugin.java | 20 +++-- .../services/DanaRKoreanExecutionService.java | 2 +- .../plugins/PumpDanaRS/DanaRSPlugin.java | 38 +++++---- ...aRS_Packet_Bolus_Set_Step_Bolus_Start.java | 81 ++++++++++--------- .../PumpDanaRS/services/DanaRSService.java | 2 +- .../plugins/PumpDanaRv2/DanaRv2Plugin.java | 28 ++++--- .../services/DanaRv2ExecutionService.java | 2 +- app/src/main/res/values/strings.xml | 1 + 12 files changed, 120 insertions(+), 94 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index cbcf21cd48..280d37c273 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -18,6 +18,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventPreferenceChange; @@ -129,7 +130,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { // Plugin base interface @Override public String getName() { - return MainApp.instance().getString(R.string.danarpump); + return MainApp.gs(R.string.danarpump); } @Override @@ -158,10 +159,13 @@ public class DanaRPlugin extends AbstractDanaRPlugin { if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t); PumpEnactResult result = new PumpEnactResult(); - result.success = connectionOK; + result.success = connectionOK && detailedBolusInfo.insulin == t.insulin; result.bolusDelivered = t.insulin; result.carbsDelivered = detailedBolusInfo.carbs; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + if (!result.success) + result.comment = String.format(MainApp.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, MsgBolusStartWithSpeed.errorCode); + else + result.comment = MainApp.gs(R.string.virtualpump_resultok); if (Config.logPumpActions) log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); detailedBolusInfo.insulin = t.insulin; @@ -173,7 +177,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { result.success = false; result.bolusDelivered = 0d; result.carbsDelivered = 0d; - result.comment = MainApp.instance().getString(R.string.danar_invalidinput); + result.comment = MainApp.gs(R.string.danar_invalidinput); log.error("deliverTreatment: Invalid input"); return result; } @@ -342,7 +346,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { PumpEnactResult result = new PumpEnactResult(); result.success = true; result.enacted = false; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); result.isTempCancel = true; return result; } @@ -358,13 +362,13 @@ public class DanaRPlugin extends AbstractDanaRPlugin { if (!pump.isTempBasalInProgress) { result.success = true; result.isTempCancel = true; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); if (Config.logPumpActions) log.debug("cancelRealTempBasal: OK"); return result; } else { result.success = false; - result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + result.comment = MainApp.gs(R.string.danar_valuenotsetproperly); result.isTempCancel = true; log.error("cancelRealTempBasal: Failed to cancel temp basal"); return result; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStart.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStart.java index 9173794199..7586edf825 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStart.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStart.java @@ -11,6 +11,8 @@ import info.nightscout.utils.HardLimits; public class MsgBolusStart extends MessageBase { private static Logger log = LoggerFactory.getLogger(MsgBolusStart.class); + public static int errorCode; + public MsgBolusStart() { SetCommand(0x0102); } @@ -29,13 +31,13 @@ public class MsgBolusStart extends MessageBase { @Override public void handleMessage(byte[] bytes) { - int result = intFromBuff(bytes, 0, 1); - if (result != 2) { + errorCode = intFromBuff(bytes, 0, 1); + if (errorCode != 2) { failed = true; - log.debug("Messsage response: " + result + " FAILED!!"); + log.debug("Messsage response: " + errorCode + " FAILED!!"); } else { if (Config.logDanaMessageDetail) - log.debug("Messsage response: " + result); + log.debug("Messsage response: " + errorCode + " OK"); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java index 3a33e9f866..dd4251a350 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java @@ -11,6 +11,8 @@ import info.nightscout.utils.HardLimits; public class MsgBolusStartWithSpeed extends MessageBase { private static Logger log = LoggerFactory.getLogger(MsgBolusStartWithSpeed.class); + public static int errorCode; + public MsgBolusStartWithSpeed() { SetCommand(0x0104); } @@ -30,13 +32,13 @@ public class MsgBolusStartWithSpeed extends MessageBase { @Override public void handleMessage(byte[] bytes) { - int result = intFromBuff(bytes, 0, 1); - if (result != 2) { + errorCode = intFromBuff(bytes, 0, 1); + if (errorCode != 2) { failed = true; - log.debug("Messsage response: " + result + " FAILED!!"); + log.debug("Messsage response: " + errorCode + " FAILED!!"); } else { if (Config.logDanaMessageDetail) - log.debug("Messsage response: " + result); + log.debug("Messsage response: " + errorCode + " OK"); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index eabf4fc94a..bee8dd1662 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -339,7 +339,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService{ } else { ConfigBuilderPlugin.getCommandQueue().readStatus("bolusOK", null); } - return true; + return !start.failed; } public boolean carbsEntry(int amount) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index a3a39a30f1..f2150ebb7d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -18,14 +18,15 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; +import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.Round; import info.nightscout.utils.SP; @@ -130,7 +131,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { // Plugin base interface @Override public String getName() { - return MainApp.instance().getString(R.string.danarkoreanpump); + return MainApp.gs(R.string.danarkoreanpump); } @Override @@ -159,10 +160,13 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t); PumpEnactResult result = new PumpEnactResult(); - result.success = connectionOK; + result.success = connectionOK && detailedBolusInfo.insulin == t.insulin; result.bolusDelivered = t.insulin; result.carbsDelivered = detailedBolusInfo.carbs; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + if (!result.success) + result.comment = String.format(MainApp.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, MsgBolusStart.errorCode); + else + result.comment = MainApp.gs(R.string.virtualpump_resultok); if (Config.logPumpActions) log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); detailedBolusInfo.insulin = t.insulin; @@ -174,7 +178,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { result.success = false; result.bolusDelivered = 0d; result.carbsDelivered = 0d; - result.comment = MainApp.instance().getString(R.string.danar_invalidinput); + result.comment = MainApp.gs(R.string.danar_invalidinput); log.error("deliverTreatment: Invalid input"); return result; } @@ -343,7 +347,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { PumpEnactResult result = new PumpEnactResult(); result.success = true; result.enacted = false; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); result.isTempCancel = true; return result; } @@ -359,13 +363,13 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { if (!pump.isTempBasalInProgress) { result.success = true; result.isTempCancel = true; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); if (Config.logPumpActions) log.debug("cancelRealTempBasal: OK"); return result; } else { result.success = false; - result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + result.comment = MainApp.gs(R.string.danar_valuenotsetproperly); result.isTempCancel = true; log.error("cancelRealTempBasal: Failed to cancel temp basal"); return result; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index c136666d5e..2619453df7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -286,7 +286,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { mBolusingTreatment = null; ConfigBuilderPlugin.getCommandQueue().readStatus("bolusOK", null); - return true; + return !start.failed; } public boolean carbsEntry(int amount) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index de1f146a51..a2ec13d184 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -26,6 +26,7 @@ import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.interfaces.Constraint; @@ -369,7 +370,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte } // RS stores end time for bolus, we need to adjust time // default delivery speed is 12 sec/U - detailedBolusInfo.date = DateUtil.now() + (long)(speed * detailedBolusInfo.insulin * 1000); + detailedBolusInfo.date = DateUtil.now() + (long) (speed * detailedBolusInfo.insulin * 1000); // clean carbs to prevent counting them as twice because they will picked up as another record // I don't think it's necessary to copy DetailedBolusInfo right now for carbs records double carbs = detailedBolusInfo.carbs; @@ -385,10 +386,13 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (detailedBolusInfo.insulin > 0 || carbs > 0) connectionOK = danaRSService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + carbTime * 60 * 1000, t); PumpEnactResult result = new PumpEnactResult(); - result.success = connectionOK; + result.success = connectionOK && detailedBolusInfo.insulin == t.insulin; result.bolusDelivered = t.insulin; result.carbsDelivered = detailedBolusInfo.carbs; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + if (!result.success) + result.comment = String.format(MainApp.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, DanaRS_Packet_Bolus_Set_Step_Bolus_Start.errorCode); + else + result.comment = MainApp.gs(R.string.virtualpump_resultok); if (Config.logPumpActions) log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); return result; @@ -397,7 +401,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte result.success = false; result.bolusDelivered = 0d; result.carbsDelivered = 0d; - result.comment = MainApp.instance().getString(R.string.danar_invalidinput); + result.comment = MainApp.gs(R.string.danar_invalidinput); log.error("deliverTreatment: Invalid input"); return result; } @@ -501,7 +505,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte result.isTempCancel = false; result.enacted = false; result.success = false; - result.comment = MainApp.instance().getString(R.string.danar_invalidinput); + result.comment = MainApp.gs(R.string.danar_invalidinput); log.error("setTempBasalPercent: Invalid input"); return result; } @@ -513,7 +517,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte result.enacted = false; result.success = true; result.isTempCancel = false; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); result.duration = pump.tempBasalRemainingMin; result.percent = pump.tempBasalPercent; result.isPercent = true; @@ -531,7 +535,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { result.enacted = true; result.success = true; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); result.isTempCancel = false; result.duration = pump.tempBasalRemainingMin; result.percent = pump.tempBasalPercent; @@ -542,7 +546,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte } result.enacted = false; result.success = false; - result.comment = MainApp.instance().getString(R.string.tempbasaldeliveryerror); + result.comment = MainApp.gs(R.string.tempbasaldeliveryerror); log.error("setTempBasalPercent: Failed to set temp basal"); return result; } @@ -553,7 +557,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { result.enacted = true; result.success = true; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); result.isTempCancel = false; result.duration = pump.tempBasalRemainingMin; result.percent = pump.tempBasalPercent; @@ -564,7 +568,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte } result.enacted = false; result.success = false; - result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + result.comment = MainApp.gs(R.string.danar_valuenotsetproperly); log.error("setHighTempBasalPercent: Failed to set temp basal"); return result; } @@ -580,7 +584,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) { result.enacted = false; result.success = true; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); result.duration = pump.extendedBolusRemainingMinutes; result.absolute = pump.extendedBolusAbsoluteRate; result.isPercent = false; @@ -593,7 +597,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAbsoluteRate - insulin) < getPumpDescription().extendedBolusStep) { result.enacted = true; result.success = true; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); result.isTempCancel = false; result.duration = pump.extendedBolusRemainingMinutes; result.absolute = pump.extendedBolusAbsoluteRate; @@ -605,7 +609,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte } result.enacted = false; result.success = false; - result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + result.comment = MainApp.gs(R.string.danar_valuenotsetproperly); log.error("setExtendedBolus: Failed to extended bolus"); return result; } @@ -622,13 +626,13 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (!pump.isTempBasalInProgress) { result.success = true; result.isTempCancel = true; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); if (Config.logPumpActions) log.debug("cancelRealTempBasal: OK"); return result; } else { result.success = false; - result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + result.comment = MainApp.gs(R.string.danar_valuenotsetproperly); result.isTempCancel = true; log.error("cancelRealTempBasal: Failed to cancel temp basal"); return result; @@ -646,13 +650,13 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte } if (!pump.isExtendedInProgress) { result.success = true; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); if (Config.logPumpActions) log.debug("cancelExtendedBolus: OK"); return result; } else { result.success = false; - result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + result.comment = MainApp.gs(R.string.danar_valuenotsetproperly); log.error("cancelExtendedBolus: Failed to cancel extended bolus"); return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java index 12f2fa95c6..f90dd77b74 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_Start.java @@ -7,58 +7,63 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.Constraint; -import info.nightscout.utils.HardLimits; +import info.nightscout.androidaps.plugins.Overview.notifications.Notification; public class DanaRS_Packet_Bolus_Set_Step_Bolus_Start extends DanaRS_Packet { - private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Set_Step_Bolus_Start.class); + private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Bolus_Set_Step_Bolus_Start.class); - private double amount; - private int speed; + private double amount; + private int speed; - public boolean failed; + public boolean failed; + public static int errorCode; - public DanaRS_Packet_Bolus_Set_Step_Bolus_Start() { + public DanaRS_Packet_Bolus_Set_Step_Bolus_Start() { super(); opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BOLUS__SET_STEP_BOLUS_START; } // Speed 0 => 12 sec/U, 1 => 30 sec/U, 2 => 60 sec/U - public DanaRS_Packet_Bolus_Set_Step_Bolus_Start(double amount, int speed) { - this(); + public DanaRS_Packet_Bolus_Set_Step_Bolus_Start(double amount, int speed) { + this(); - // HARDCODED LIMIT - amount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value(); + // HARDCODED LIMIT + amount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value(); - this.amount = amount; - this.speed = speed; + this.amount = amount; + this.speed = speed; - if (Config.logDanaMessageDetail) - log.debug("Bolus start : " + amount + " speed: " + speed); - } + if (Config.logDanaMessageDetail) + log.debug("Bolus start : " + amount + " speed: " + speed); + } - @Override - public byte[] getRequestParams() { - int stepBolusRate = (int) (amount * 100); - byte[] request = new byte[3]; - request[0] = (byte) (stepBolusRate & 0xff); - request[1] = (byte) ((stepBolusRate >>> 8) & 0xff); - request[2] = (byte) (speed & 0xff); - return request; - } - @Override - public void handleMessage(byte[] data) { - int result = intFromBuff(data, 0, 1); - if (Config.logDanaMessageDetail) { - if (result == 0) - log.debug("Result OK"); - else - log.error("Result Error: " + result); - } - } + @Override + public byte[] getRequestParams() { + int stepBolusRate = (int) (amount * 100); + byte[] request = new byte[3]; + request[0] = (byte) (stepBolusRate & 0xff); + request[1] = (byte) ((stepBolusRate >>> 8) & 0xff); + request[2] = (byte) (speed & 0xff); + return request; + } - @Override - public String getFriendlyName() { - return "BOLUS__SET_STEP_BOLUS_START"; - } + @Override + public void handleMessage(byte[] data) { + errorCode = intFromBuff(data, 0, 1); + if (Config.logDanaMessageDetail) { + if (errorCode == 0) + log.debug("Result OK"); + else { + failed = true; + log.error("Result Error: " + errorCode); + } + } + } + + @Override + public String getFriendlyName() { + return "BOLUS__SET_STEP_BOLUS_START"; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java index 384c1a3772..91859c759a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -273,7 +273,7 @@ public class DanaRSService extends Service { MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting))); } }); - return true; + return !start.failed; } public void bolusStop() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 81c5d4d944..0ea6f192e4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed; import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; @@ -119,7 +120,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { // Plugin base interface @Override public String getName() { - return MainApp.instance().getString(R.string.danarv2pump); + return MainApp.gs(R.string.danarv2pump); } @Override @@ -173,10 +174,13 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { if (detailedBolusInfo.insulin > 0 || carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + carbTime * 60 * 1000, t); PumpEnactResult result = new PumpEnactResult(); - result.success = connectionOK; + result.success = connectionOK && detailedBolusInfo.insulin == t.insulin; result.bolusDelivered = t.insulin; result.carbsDelivered = detailedBolusInfo.carbs; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + if (!result.success) + result.comment = String.format(MainApp.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, MsgBolusStartWithSpeed.errorCode); + else + result.comment = MainApp.gs(R.string.virtualpump_resultok); if (Config.logPumpActions) log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); // remove carbs because it's get from history seprately @@ -186,7 +190,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { result.success = false; result.bolusDelivered = 0d; result.carbsDelivered = 0d; - result.comment = MainApp.instance().getString(R.string.danar_invalidinput); + result.comment = MainApp.gs(R.string.danar_invalidinput); log.error("deliverTreatment: Invalid input"); return result; } @@ -287,7 +291,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { result.isTempCancel = false; result.enacted = false; result.success = false; - result.comment = MainApp.instance().getString(R.string.danar_invalidinput); + result.comment = MainApp.gs(R.string.danar_invalidinput); log.error("setTempBasalPercent: Invalid input"); return result; } @@ -299,7 +303,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { result.enacted = false; result.success = true; result.isTempCancel = false; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); result.duration = pump.tempBasalRemainingMin; result.percent = pump.tempBasalPercent; result.isPercent = true; @@ -317,7 +321,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { result.enacted = true; result.success = true; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); result.isTempCancel = false; result.duration = pump.tempBasalRemainingMin; result.percent = pump.tempBasalPercent; @@ -328,7 +332,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { } result.enacted = false; result.success = false; - result.comment = MainApp.instance().getString(R.string.tempbasaldeliveryerror); + result.comment = MainApp.gs(R.string.tempbasaldeliveryerror); log.error("setTempBasalPercent: Failed to set temp basal"); return result; } @@ -339,7 +343,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { result.enacted = true; result.success = true; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); result.isTempCancel = false; result.duration = pump.tempBasalRemainingMin; result.percent = pump.tempBasalPercent; @@ -350,7 +354,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { } result.enacted = false; result.success = false; - result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + result.comment = MainApp.gs(R.string.danar_valuenotsetproperly); log.error("setHighTempBasalPercent: Failed to set temp basal"); return result; } @@ -367,13 +371,13 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { if (!pump.isTempBasalInProgress) { result.success = true; result.isTempCancel = true; - result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); + result.comment = MainApp.gs(R.string.virtualpump_resultok); if (Config.logPumpActions) log.debug("cancelRealTempBasal: OK"); return result; } else { result.success = false; - result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); + result.comment = MainApp.gs(R.string.danar_valuenotsetproperly); result.isTempCancel = true; log.error("cancelRealTempBasal: Failed to cancel temp basal"); return result; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 551c2684c0..25cac9da1c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -386,7 +386,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting))); } }); - return true; + return !start.failed; } public void bolusStop() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1e8d21ac37..c2839b19d8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1005,4 +1005,5 @@ show_notes_entry_dialogs Show notes field in treatment dialogs openapsama_min_5m_carbimpact + Asked: %.2fU Delivered: %.2fU Error code: %d