add deliverAt safety
This commit is contained in:
parent
890ef5978b
commit
c714fead24
3 changed files with 16 additions and 2 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue