diff --git a/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java b/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java index 7720b03d3e..7d1dcac9ad 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java +++ b/app/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java @@ -29,6 +29,7 @@ public class DetailedBolusInfo { public Context context = null; // context for progress dialog public long pumpId = 0; // id of record if comming from pump history (not a newly created treatment) public boolean isSMB = false; // is a Super-MicroBolus + public long deliverAt = 0; // SMB should be delivered within 1 min from this time @Override public String toString() { @@ -37,6 +38,7 @@ public class DetailedBolusInfo { " carbs: " + carbs + " isValid: " + isValid + " carbTime: " + carbTime + - " isSMB: " + isSMB; + " isSMB: " + isSMB + + " deliverAt: " + new Date(deliverAt).toLocaleString(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 1d53c0b79f..3b72712b3b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -426,6 +426,7 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr detailedBolusInfo.insulin = request.smb; detailedBolusInfo.isSMB = true; detailedBolusInfo.source = Source.USER; + detailedBolusInfo.deliverAt = request.deliverAt; boolean smbDelivered = getCommandQueue().bolus(detailedBolusInfo, callback); if (smbDelivered) return true; diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.java index 4d3fc92883..d8fae1df32 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.java @@ -1,5 +1,8 @@ package info.nightscout.androidaps.queue.commands; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.PumpEnactResult; @@ -14,6 +17,7 @@ import info.nightscout.utils.DecimalFormatter; */ public class CommandSMBBolus extends Command { + private static Logger log = LoggerFactory.getLogger(CommandSMBBolus.class); DetailedBolusInfo detailedBolusInfo; public CommandSMBBolus(DetailedBolusInfo detailedBolusInfo, Callback callback) { @@ -24,7 +28,14 @@ public class CommandSMBBolus extends Command { @Override public void execute() { - PumpEnactResult r = ConfigBuilderPlugin.getActivePump().deliverTreatment(detailedBolusInfo); + PumpEnactResult r; + if (detailedBolusInfo.deliverAt != 0 && detailedBolusInfo.deliverAt + 60 * 1000L > System.currentTimeMillis()) + r = ConfigBuilderPlugin.getActivePump().deliverTreatment(detailedBolusInfo); + else { + r = new PumpEnactResult().enacted(false).success(false).comment("SMB request too old"); + log.debug("SMB bolus canceled. delivetAt=" + detailedBolusInfo.deliverAt + " now=" + System.currentTimeMillis()); + } + BolusProgressDialog.bolusEnded = true; MainApp.bus().post(new EventDismissBolusprogressIfRunning(r));