CB.applySMBRequest: return reason when skipping due to frequency.

This commit is contained in:
Johannes Mockenhaupt 2018-03-18 23:44:33 +01:00
parent 94d862fb81
commit 379df79bf8
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 51 additions and 39 deletions

View file

@ -355,11 +355,13 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
* expect absolute request and allow both absolute and percent response based on pump capabilities * expect absolute request and allow both absolute and percent response based on pump capabilities
*/ */
public void applyTBRRequest(APSResult request, Profile profile, Callback callback) { public void applyTBRRequest(APSResult request, Profile profile, Callback callback) {
if (!request.tempBasalReqested) {
return;
}
PumpInterface pump = getActivePump(); PumpInterface pump = getActivePump();
request.rate = applyBasalConstraints(request.rate); request.rate = applyBasalConstraints(request.rate);
long now = System.currentTimeMillis();
if (!pump.isInitialized()) { if (!pump.isInitialized()) {
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized)); log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized));
if (callback != null) { if (callback != null) {
@ -379,37 +381,50 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
if (Config.logCongigBuilderActions) if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: " + request.toString()); log.debug("applyAPSRequest: " + request.toString());
if (request.tempBasalReqested) { long now = System.currentTimeMillis();
TemporaryBasal activeTemp = getTempBasalFromHistory(now); TemporaryBasal activeTemp = getTempBasalFromHistory(now);
if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - pump.getBaseBasalRate()) < pump.getPumpDescription().basalStep) { if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - pump.getBaseBasalRate()) < pump.getPumpDescription().basalStep) {
if (activeTemp != null) { if (activeTemp != null) {
if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: cancelTempBasal()");
getCommandQueue().cancelTempBasal(false, callback);
} else {
if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: Basal set correctly");
if (callback != null) {
callback.result(new PumpEnactResult().absolute(request.rate).duration(0).enacted(false).success(true).comment("Basal set correctly")).run();
}
}
} else if (activeTemp != null
&& activeTemp.getPlannedRemainingMinutes() > 5
&& Math.abs(request.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < pump.getPumpDescription().basalStep) {
if (Config.logCongigBuilderActions) if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: Temp basal set correctly"); log.debug("applyAPSRequest: cancelTempBasal()");
if (callback != null) { getCommandQueue().cancelTempBasal(false, callback);
callback.result(new PumpEnactResult().absolute(activeTemp.tempBasalConvertedToAbsolute(now, profile)).duration(activeTemp.getPlannedRemainingMinutes()).enacted(false).success(true).comment("Temp basal set correctly")).run();
}
} else { } else {
if (Config.logCongigBuilderActions) if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: setTempBasalAbsolute()"); log.debug("applyAPSRequest: Basal set correctly");
getCommandQueue().tempBasalAbsolute(request.rate, request.duration, false, callback); if (callback != null) {
callback.result(new PumpEnactResult().absolute(request.rate).duration(0).enacted(false).success(true).comment("Basal set correctly")).run();
}
} }
} else if (activeTemp != null
&& activeTemp.getPlannedRemainingMinutes() > 5
&& Math.abs(request.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < pump.getPumpDescription().basalStep) {
if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: Temp basal set correctly");
if (callback != null) {
callback.result(new PumpEnactResult().absolute(activeTemp.tempBasalConvertedToAbsolute(now, profile)).duration(activeTemp.getPlannedRemainingMinutes()).enacted(false).success(true).comment("Temp basal set correctly")).run();
}
} else {
if (Config.logCongigBuilderActions)
log.debug("applyAPSRequest: setTempBasalAbsolute()");
getCommandQueue().tempBasalAbsolute(request.rate, request.duration, false, callback);
} }
} }
public void applySMBRequest(APSResult request, Callback callback) { public void applySMBRequest(APSResult request, Callback callback) {
if (!request.bolusRequested) {
return;
}
long lastBolusTime = getLastBolusTime();
if (lastBolusTime != 0 && lastBolusTime + 3 * 60 * 1000 > System.currentTimeMillis()) {
log.debug("SMB requested but still in 3 min interval");
if (callback != null) {
callback.result(new PumpEnactResult()
.comment(MainApp.gs(R.string.smb_frequency_exceeded))
.enacted(false).success(false)).run();
}
}
PumpInterface pump = getActivePump(); PumpInterface pump = getActivePump();
if (!pump.isInitialized()) { if (!pump.isInitialized()) {
@ -431,20 +446,16 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
if (Config.logCongigBuilderActions) if (Config.logCongigBuilderActions)
log.debug("applySMBRequest: " + request.toString()); log.debug("applySMBRequest: " + request.toString());
if (request.bolusRequested) { // deliver SMB
long lastBolusTime = getLastBolusTime(); DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
if (lastBolusTime != 0 && lastBolusTime + 3 * 60 * 1000 > System.currentTimeMillis()) { detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS;
log.debug("SMB requsted but still in 3 min interval"); detailedBolusInfo.insulin = request.smb;
} else { detailedBolusInfo.isSMB = true;
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo.source = Source.USER;
detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS; detailedBolusInfo.deliverAt = request.deliverAt;
detailedBolusInfo.insulin = request.smb; if (Config.logCongigBuilderActions)
detailedBolusInfo.isSMB = true; log.debug("applyAPSRequest: bolus()");
detailedBolusInfo.source = Source.USER; getCommandQueue().bolus(detailedBolusInfo, callback);
detailedBolusInfo.deliverAt = request.deliverAt;
getCommandQueue().bolus(detailedBolusInfo, callback);
}
}
} }
/** /**

View file

@ -962,5 +962,6 @@
<string name="profileswitch_ismissing">ProfileSwitch missing. Please do a profile switch or press \"Activate Profile\" in the LocalProfile.</string> <string name="profileswitch_ismissing">ProfileSwitch missing. Please do a profile switch or press \"Activate Profile\" in the LocalProfile.</string>
<string name="combo_bolus_count">Bolus count</string> <string name="combo_bolus_count">Bolus count</string>
<string name="combo_tbr_count">TBR count</string> <string name="combo_tbr_count">TBR count</string>
<string name="smb_frequency_exceeded">A bolus was delivered within the last 3 minutes, skipping SMB</string>
</resources> </resources>