better bolus error handling for Dana pumps

This commit is contained in:
Milos Kozak 2018-04-21 00:02:15 +02:00
parent 883da922e5
commit c27ceb0a72
12 changed files with 120 additions and 94 deletions

View file

@ -18,6 +18,7 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal; 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.plugins.Treatments.Treatment;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
@ -129,7 +130,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
// Plugin base interface // Plugin base interface
@Override @Override
public String getName() { public String getName() {
return MainApp.instance().getString(R.string.danarpump); return MainApp.gs(R.string.danarpump);
} }
@Override @Override
@ -158,10 +159,13 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t); connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK; result.success = connectionOK && detailedBolusInfo.insulin == t.insulin;
result.bolusDelivered = t.insulin; result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs; 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) if (Config.logPumpActions)
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
detailedBolusInfo.insulin = t.insulin; detailedBolusInfo.insulin = t.insulin;
@ -173,7 +177,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
result.success = false; result.success = false;
result.bolusDelivered = 0d; result.bolusDelivered = 0d;
result.carbsDelivered = 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"); log.error("deliverTreatment: Invalid input");
return result; return result;
} }
@ -342,7 +346,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = true; result.success = true;
result.enacted = false; result.enacted = false;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.gs(R.string.virtualpump_resultok);
result.isTempCancel = true; result.isTempCancel = true;
return result; return result;
} }
@ -358,13 +362,13 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
if (!pump.isTempBasalInProgress) { if (!pump.isTempBasalInProgress) {
result.success = true; result.success = true;
result.isTempCancel = true; result.isTempCancel = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.gs(R.string.virtualpump_resultok);
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("cancelRealTempBasal: OK"); log.debug("cancelRealTempBasal: OK");
return result; return result;
} else { } else {
result.success = false; result.success = false;
result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); result.comment = MainApp.gs(R.string.danar_valuenotsetproperly);
result.isTempCancel = true; result.isTempCancel = true;
log.error("cancelRealTempBasal: Failed to cancel temp basal"); log.error("cancelRealTempBasal: Failed to cancel temp basal");
return result; return result;

View file

@ -11,6 +11,8 @@ import info.nightscout.utils.HardLimits;
public class MsgBolusStart extends MessageBase { public class MsgBolusStart extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgBolusStart.class); private static Logger log = LoggerFactory.getLogger(MsgBolusStart.class);
public static int errorCode;
public MsgBolusStart() { public MsgBolusStart() {
SetCommand(0x0102); SetCommand(0x0102);
} }
@ -29,13 +31,13 @@ public class MsgBolusStart extends MessageBase {
@Override @Override
public void handleMessage(byte[] bytes) { public void handleMessage(byte[] bytes) {
int result = intFromBuff(bytes, 0, 1); errorCode = intFromBuff(bytes, 0, 1);
if (result != 2) { if (errorCode != 2) {
failed = true; failed = true;
log.debug("Messsage response: " + result + " FAILED!!"); log.debug("Messsage response: " + errorCode + " FAILED!!");
} else { } else {
if (Config.logDanaMessageDetail) if (Config.logDanaMessageDetail)
log.debug("Messsage response: " + result); log.debug("Messsage response: " + errorCode + " OK");
} }
} }
} }

View file

@ -11,6 +11,8 @@ import info.nightscout.utils.HardLimits;
public class MsgBolusStartWithSpeed extends MessageBase { public class MsgBolusStartWithSpeed extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgBolusStartWithSpeed.class); private static Logger log = LoggerFactory.getLogger(MsgBolusStartWithSpeed.class);
public static int errorCode;
public MsgBolusStartWithSpeed() { public MsgBolusStartWithSpeed() {
SetCommand(0x0104); SetCommand(0x0104);
} }
@ -30,13 +32,13 @@ public class MsgBolusStartWithSpeed extends MessageBase {
@Override @Override
public void handleMessage(byte[] bytes) { public void handleMessage(byte[] bytes) {
int result = intFromBuff(bytes, 0, 1); errorCode = intFromBuff(bytes, 0, 1);
if (result != 2) { if (errorCode != 2) {
failed = true; failed = true;
log.debug("Messsage response: " + result + " FAILED!!"); log.debug("Messsage response: " + errorCode + " FAILED!!");
} else { } else {
if (Config.logDanaMessageDetail) if (Config.logDanaMessageDetail)
log.debug("Messsage response: " + result); log.debug("Messsage response: " + errorCode + " OK");
} }
} }
} }

View file

@ -339,7 +339,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService{
} else { } else {
ConfigBuilderPlugin.getCommandQueue().readStatus("bolusOK", null); ConfigBuilderPlugin.getCommandQueue().readStatus("bolusOK", null);
} }
return true; return !start.failed;
} }
public boolean carbsEntry(int amount) { public boolean carbsEntry(int amount) {

View file

@ -18,14 +18,15 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; 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.PumpDanaRKorean.services.DanaRKoreanExecutionService;
import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -130,7 +131,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
// Plugin base interface // Plugin base interface
@Override @Override
public String getName() { public String getName() {
return MainApp.instance().getString(R.string.danarkoreanpump); return MainApp.gs(R.string.danarkoreanpump);
} }
@Override @Override
@ -159,10 +160,13 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t); connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK; result.success = connectionOK && detailedBolusInfo.insulin == t.insulin;
result.bolusDelivered = t.insulin; result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs; 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) if (Config.logPumpActions)
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
detailedBolusInfo.insulin = t.insulin; detailedBolusInfo.insulin = t.insulin;
@ -174,7 +178,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
result.success = false; result.success = false;
result.bolusDelivered = 0d; result.bolusDelivered = 0d;
result.carbsDelivered = 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"); log.error("deliverTreatment: Invalid input");
return result; return result;
} }
@ -343,7 +347,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = true; result.success = true;
result.enacted = false; result.enacted = false;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.gs(R.string.virtualpump_resultok);
result.isTempCancel = true; result.isTempCancel = true;
return result; return result;
} }
@ -359,13 +363,13 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
if (!pump.isTempBasalInProgress) { if (!pump.isTempBasalInProgress) {
result.success = true; result.success = true;
result.isTempCancel = true; result.isTempCancel = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.gs(R.string.virtualpump_resultok);
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("cancelRealTempBasal: OK"); log.debug("cancelRealTempBasal: OK");
return result; return result;
} else { } else {
result.success = false; result.success = false;
result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); result.comment = MainApp.gs(R.string.danar_valuenotsetproperly);
result.isTempCancel = true; result.isTempCancel = true;
log.error("cancelRealTempBasal: Failed to cancel temp basal"); log.error("cancelRealTempBasal: Failed to cancel temp basal");
return result; return result;

View file

@ -286,7 +286,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
mBolusingTreatment = null; mBolusingTreatment = null;
ConfigBuilderPlugin.getCommandQueue().readStatus("bolusOK", null); ConfigBuilderPlugin.getCommandQueue().readStatus("bolusOK", null);
return true; return !start.failed;
} }
public boolean carbsEntry(int amount) { public boolean carbsEntry(int amount) {

View file

@ -26,6 +26,7 @@ import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal; 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.plugins.Treatments.Treatment;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
@ -385,10 +386,13 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
if (detailedBolusInfo.insulin > 0 || carbs > 0) if (detailedBolusInfo.insulin > 0 || carbs > 0)
connectionOK = danaRSService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + carbTime * 60 * 1000, t); connectionOK = danaRSService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + carbTime * 60 * 1000, t);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK; result.success = connectionOK && detailedBolusInfo.insulin == t.insulin;
result.bolusDelivered = t.insulin; result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs; 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) if (Config.logPumpActions)
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
return result; return result;
@ -397,7 +401,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
result.success = false; result.success = false;
result.bolusDelivered = 0d; result.bolusDelivered = 0d;
result.carbsDelivered = 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"); log.error("deliverTreatment: Invalid input");
return result; return result;
} }
@ -501,7 +505,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
result.isTempCancel = false; result.isTempCancel = false;
result.enacted = false; result.enacted = false;
result.success = 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"); log.error("setTempBasalPercent: Invalid input");
return result; return result;
} }
@ -513,7 +517,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
result.isTempCancel = false; 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.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
result.isPercent = true; result.isPercent = true;
@ -531,7 +535,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
result.enacted = true; result.enacted = true;
result.success = 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.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
@ -542,7 +546,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
} }
result.enacted = false; result.enacted = false;
result.success = 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"); log.error("setTempBasalPercent: Failed to set temp basal");
return result; return result;
} }
@ -553,7 +557,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
result.enacted = true; result.enacted = true;
result.success = 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.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
@ -564,7 +568,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
} }
result.enacted = false; result.enacted = false;
result.success = 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"); log.error("setHighTempBasalPercent: Failed to set temp basal");
return result; return result;
} }
@ -580,7 +584,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) { if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) {
result.enacted = false; result.enacted = false;
result.success = true; 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.duration = pump.extendedBolusRemainingMinutes;
result.absolute = pump.extendedBolusAbsoluteRate; result.absolute = pump.extendedBolusAbsoluteRate;
result.isPercent = false; 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) { if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAbsoluteRate - insulin) < getPumpDescription().extendedBolusStep) {
result.enacted = true; result.enacted = true;
result.success = 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.isTempCancel = false;
result.duration = pump.extendedBolusRemainingMinutes; result.duration = pump.extendedBolusRemainingMinutes;
result.absolute = pump.extendedBolusAbsoluteRate; result.absolute = pump.extendedBolusAbsoluteRate;
@ -605,7 +609,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
} }
result.enacted = false; result.enacted = false;
result.success = 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"); log.error("setExtendedBolus: Failed to extended bolus");
return result; return result;
} }
@ -622,13 +626,13 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
if (!pump.isTempBasalInProgress) { if (!pump.isTempBasalInProgress) {
result.success = true; result.success = true;
result.isTempCancel = true; result.isTempCancel = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.gs(R.string.virtualpump_resultok);
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("cancelRealTempBasal: OK"); log.debug("cancelRealTempBasal: OK");
return result; return result;
} else { } else {
result.success = false; result.success = false;
result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); result.comment = MainApp.gs(R.string.danar_valuenotsetproperly);
result.isTempCancel = true; result.isTempCancel = true;
log.error("cancelRealTempBasal: Failed to cancel temp basal"); log.error("cancelRealTempBasal: Failed to cancel temp basal");
return result; return result;
@ -646,13 +650,13 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
} }
if (!pump.isExtendedInProgress) { if (!pump.isExtendedInProgress) {
result.success = true; result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.gs(R.string.virtualpump_resultok);
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("cancelExtendedBolus: OK"); log.debug("cancelExtendedBolus: OK");
return result; return result;
} else { } else {
result.success = false; 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"); log.error("cancelExtendedBolus: Failed to cancel extended bolus");
return result; return result;
} }

View file

@ -7,8 +7,9 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.Constraint; 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 { 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);
@ -17,6 +18,7 @@ public class DanaRS_Packet_Bolus_Set_Step_Bolus_Start extends DanaRS_Packet {
private int speed; 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(); super();
@ -46,14 +48,17 @@ public class DanaRS_Packet_Bolus_Set_Step_Bolus_Start extends DanaRS_Packet {
request[2] = (byte) (speed & 0xff); request[2] = (byte) (speed & 0xff);
return request; return request;
} }
@Override @Override
public void handleMessage(byte[] data) { public void handleMessage(byte[] data) {
int result = intFromBuff(data, 0, 1); errorCode = intFromBuff(data, 0, 1);
if (Config.logDanaMessageDetail) { if (Config.logDanaMessageDetail) {
if (result == 0) if (errorCode == 0)
log.debug("Result OK"); log.debug("Result OK");
else else {
log.error("Result Error: " + result); failed = true;
log.error("Result Error: " + errorCode);
}
} }
} }

View file

@ -273,7 +273,7 @@ public class DanaRSService extends Service {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
} }
}); });
return true; return !start.failed;
} }
public void bolusStop() { public void bolusStop() {

View file

@ -22,6 +22,7 @@ import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; 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.PumpDanaRv2.services.DanaRv2ExecutionService;
import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
@ -119,7 +120,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
// Plugin base interface // Plugin base interface
@Override @Override
public String getName() { public String getName() {
return MainApp.instance().getString(R.string.danarv2pump); return MainApp.gs(R.string.danarv2pump);
} }
@Override @Override
@ -173,10 +174,13 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
if (detailedBolusInfo.insulin > 0 || carbs > 0) if (detailedBolusInfo.insulin > 0 || carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + carbTime * 60 * 1000, t); connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + carbTime * 60 * 1000, t);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK; result.success = connectionOK && detailedBolusInfo.insulin == t.insulin;
result.bolusDelivered = t.insulin; result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs; 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) if (Config.logPumpActions)
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
// remove carbs because it's get from history seprately // remove carbs because it's get from history seprately
@ -186,7 +190,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.success = false; result.success = false;
result.bolusDelivered = 0d; result.bolusDelivered = 0d;
result.carbsDelivered = 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"); log.error("deliverTreatment: Invalid input");
return result; return result;
} }
@ -287,7 +291,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.isTempCancel = false; result.isTempCancel = false;
result.enacted = false; result.enacted = false;
result.success = 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"); log.error("setTempBasalPercent: Invalid input");
return result; return result;
} }
@ -299,7 +303,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
result.isTempCancel = false; 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.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
result.isPercent = true; result.isPercent = true;
@ -317,7 +321,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
result.enacted = true; result.enacted = true;
result.success = 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.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
@ -328,7 +332,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
} }
result.enacted = false; result.enacted = false;
result.success = 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"); log.error("setTempBasalPercent: Failed to set temp basal");
return result; return result;
} }
@ -339,7 +343,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
result.enacted = true; result.enacted = true;
result.success = 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.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent; result.percent = pump.tempBasalPercent;
@ -350,7 +354,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
} }
result.enacted = false; result.enacted = false;
result.success = 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"); log.error("setHighTempBasalPercent: Failed to set temp basal");
return result; return result;
} }
@ -367,13 +371,13 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
if (!pump.isTempBasalInProgress) { if (!pump.isTempBasalInProgress) {
result.success = true; result.success = true;
result.isTempCancel = true; result.isTempCancel = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.gs(R.string.virtualpump_resultok);
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("cancelRealTempBasal: OK"); log.debug("cancelRealTempBasal: OK");
return result; return result;
} else { } else {
result.success = false; result.success = false;
result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); result.comment = MainApp.gs(R.string.danar_valuenotsetproperly);
result.isTempCancel = true; result.isTempCancel = true;
log.error("cancelRealTempBasal: Failed to cancel temp basal"); log.error("cancelRealTempBasal: Failed to cancel temp basal");
return result; return result;

View file

@ -386,7 +386,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
} }
}); });
return true; return !start.failed;
} }
public void bolusStop() { public void bolusStop() {

View file

@ -1005,4 +1005,5 @@
<string name="key_show_notes_entry_dialogs">show_notes_entry_dialogs</string> <string name="key_show_notes_entry_dialogs">show_notes_entry_dialogs</string>
<string name="overview_show_notes_field_in_dialogs_title">Show notes field in treatment dialogs</string> <string name="overview_show_notes_field_in_dialogs_title">Show notes field in treatment dialogs</string>
<string name="key_openapsama_min_5m_carbimpact" translatable="false">openapsama_min_5m_carbimpact</string> <string name="key_openapsama_min_5m_carbimpact" translatable="false">openapsama_min_5m_carbimpact</string>
<string name="boluserrorcode">Asked: %.2fU Delivered: %.2fU Error code: %d</string>
</resources> </resources>