allow 15 & 30 pump disconnection

This commit is contained in:
Milos Kozak 2018-03-01 23:59:44 +01:00
parent e93cfacb4f
commit c61fcdbe3f
30 changed files with 358 additions and 141 deletions

View file

@ -27,6 +27,8 @@ public class PumpDescription {
public double tempAbsoluteStep = 0.05d; public double tempAbsoluteStep = 0.05d;
public int tempDurationStep = 60; public int tempDurationStep = 60;
public boolean tempDurationStep15mAllowed = false;
public boolean tempDurationStep30mAllowed = false;
public int tempMaxDuration = 12 * 60; public int tempMaxDuration = 12 * 60;

View file

@ -49,6 +49,7 @@ import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.CommandQueue; import info.nightscout.androidaps.queue.CommandQueue;
import info.nightscout.utils.NSUpload; import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
@ -814,4 +815,40 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
} }
return null; return null;
} }
public void disconnectPump(int durationInMinutes) {
getActiveLoop().disconnectTo(System.currentTimeMillis() + durationInMinutes * 60 * 1000L);
getCommandQueue().tempBasalPercent(0, durationInMinutes, true, new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.tempbasaldeliveryerror));
}
}
});
if (getActivePump().getPumpDescription().isExtendedBolusCapable && isInHistoryExtendedBoluslInProgress()) {
getCommandQueue().cancelExtended(new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.extendedbolusdeliveryerror));
}
}
});
}
NSUpload.uploadOpenAPSOffline(durationInMinutes);
}
public void suspendLoop(int durationInMinutes) {
getActiveLoop().suspendTo(System.currentTimeMillis() + durationInMinutes * 60 * 1000);
getCommandQueue().cancelTempBasal(true, new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.tempbasaldeliveryerror));
}
}
});
NSUpload.uploadOpenAPSOffline(durationInMinutes);
}
} }

View file

@ -383,7 +383,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
menu.add(MainApp.sResources.getString(R.string.suspendloopfor2h)); menu.add(MainApp.sResources.getString(R.string.suspendloopfor2h));
menu.add(MainApp.sResources.getString(R.string.suspendloopfor3h)); menu.add(MainApp.sResources.getString(R.string.suspendloopfor3h));
menu.add(MainApp.sResources.getString(R.string.suspendloopfor10h)); menu.add(MainApp.sResources.getString(R.string.suspendloopfor10h));
if (pumpDescription.tempDurationStep <= 30) if (pumpDescription.tempDurationStep15mAllowed)
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor15m));
if (pumpDescription.tempDurationStep30mAllowed)
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor30m)); menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor30m));
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor1h)); menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor1h));
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor2h)); menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor2h));
@ -438,7 +440,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
activeloop.setFragmentVisible(PluginBase.LOOP, false); activeloop.setFragmentVisible(PluginBase.LOOP, false);
MainApp.getConfigBuilder().storeSettings(); MainApp.getConfigBuilder().storeSettings();
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {
@ -446,7 +448,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} }
} }
}); });
NSUpload.uploadOpenAPSOffline(60); // upload 60 min, we don;t know real duration NSUpload.uploadOpenAPSOffline(24 * 60); // upload 24h, we don't know real duration
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.enableloop))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.enableloop))) {
activeloop.setFragmentEnabled(PluginBase.LOOP, true); activeloop.setFragmentEnabled(PluginBase.LOOP, true);
@ -458,7 +460,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.resume))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.resume))) {
activeloop.suspendTo(0L); activeloop.suspendTo(0L);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {
@ -469,148 +471,40 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
NSUpload.uploadOpenAPSOffline(0); NSUpload.uploadOpenAPSOffline(0);
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor1h))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor1h))) {
activeloop.suspendTo(System.currentTimeMillis() + 60L * 60 * 1000); MainApp.getConfigBuilder().suspendLoop(60);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
}
}
});
NSUpload.uploadOpenAPSOffline(60);
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor2h))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor2h))) {
activeloop.suspendTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); MainApp.getConfigBuilder().suspendLoop(120);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
}
}
});
NSUpload.uploadOpenAPSOffline(120);
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor3h))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor3h))) {
activeloop.suspendTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000); MainApp.getConfigBuilder().suspendLoop(180);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
}
}
});
NSUpload.uploadOpenAPSOffline(180);
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor10h))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor10h))) {
activeloop.suspendTo(System.currentTimeMillis() + 10 * 60L * 60 * 1000); MainApp.getConfigBuilder().suspendLoop(600);
updateGUI("suspendmenu");
return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor15m))) {
MainApp.getConfigBuilder().disconnectPump(15);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
}
}
});
NSUpload.uploadOpenAPSOffline(600);
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) {
activeloop.disconnectTo(System.currentTimeMillis() + 30L * 60 * 1000); MainApp.getConfigBuilder().disconnectPump(30);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 30, true, new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
}
}
});
if (MainApp.getConfigBuilder().getActivePump().getPumpDescription().isExtendedBolusCapable && MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
ConfigBuilderPlugin.getCommandQueue().cancelExtended( new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.extendedbolusdeliveryerror));
}
}
});
}
NSUpload.uploadOpenAPSOffline(30);
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) {
activeloop.disconnectTo(System.currentTimeMillis() + 1 * 60L * 60 * 1000); MainApp.getConfigBuilder().disconnectPump(60);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 60, true, new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
}
}
});
if (MainApp.getConfigBuilder().getActivePump().getPumpDescription().isExtendedBolusCapable && MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
ConfigBuilderPlugin.getCommandQueue().cancelExtended( new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.extendedbolusdeliveryerror));
}
}
});
}
NSUpload.uploadOpenAPSOffline(60);
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) {
activeloop.disconnectTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); MainApp.getConfigBuilder().disconnectPump(120);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 2 * 60, true, new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
}
}
});
if (MainApp.getConfigBuilder().getActivePump().getPumpDescription().isExtendedBolusCapable && MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
ConfigBuilderPlugin.getCommandQueue().cancelExtended( new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.extendedbolusdeliveryerror));
}
}
});
}
NSUpload.uploadOpenAPSOffline(120);
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) {
activeloop.disconnectTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000); MainApp.getConfigBuilder().disconnectPump(180);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 3 * 60, true, new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
}
}
});
if (MainApp.getConfigBuilder().getActivePump().getPumpDescription().isExtendedBolusCapable && MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
ConfigBuilderPlugin.getCommandQueue().cancelExtended( new Callback() {
@Override
public void run() {
if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.extendedbolusdeliveryerror));
}
}
});
}
NSUpload.uploadOpenAPSOffline(180);
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.careportal_profileswitch))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.careportal_profileswitch))) {
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
@ -1288,7 +1182,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// **** Various treatment buttons **** // **** Various treatment buttons ****
if (carbsButton != null) { if (carbsButton != null) {
if (SP.getBoolean(R.string.key_show_carbs_button, true) if (SP.getBoolean(R.string.key_show_carbs_button, true)
&& !ConfigBuilderPlugin.getActivePump().getPumpDescription().storesCarbInfo || && !ConfigBuilderPlugin.getActivePump().getPumpDescription().storesCarbInfo ||
(pump.isInitialized() && !pump.isSuspended())) { (pump.isInitialized() && !pump.isSuspended())) {
carbsButton.setVisibility(View.VISIBLE); carbsButton.setVisibility(View.VISIBLE);
} else { } else {
@ -1297,7 +1191,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} }
if (pump.isInitialized() && !pump.isSuspended()) { if (pump.isInitialized() && !pump.isSuspended()) {
if (treatmentButton != null){ if (treatmentButton != null) {
if (SP.getBoolean(R.string.key_show_treatment_button, false)) { if (SP.getBoolean(R.string.key_show_treatment_button, false)) {
treatmentButton.setVisibility(View.VISIBLE); treatmentButton.setVisibility(View.VISIBLE);
} else { } else {

View file

@ -23,7 +23,7 @@ import info.nightscout.utils.CRC;
public class MessageBase { public class MessageBase {
private static Logger log = LoggerFactory.getLogger(MessageBase.class); private static Logger log = LoggerFactory.getLogger(MessageBase.class);
private byte[] buffer = new byte[512]; protected byte[] buffer = new byte[512];
private int position = 6; private int position = 6;
public boolean received = false; public boolean received = false;
@ -34,6 +34,10 @@ public class MessageBase {
this.buffer[5] = (byte) (cmd & 0xFF); this.buffer[5] = (byte) (cmd & 0xFF);
} }
public void resetBuffer() {
position = 6;
}
public void AddParamByte(byte data) { public void AddParamByte(byte data) {
this.buffer[this.position++] = data; this.buffer[this.position++] = data;
} }

View file

@ -78,6 +78,8 @@ public abstract class AbstractDanaRExecutionService extends Service {
public abstract boolean highTempBasal(int percent); // Rv2 only public abstract boolean highTempBasal(int percent); // Rv2 only
public abstract boolean tempBasalShortDuration(int percent, int durationInMinutes); // Rv2 only
public abstract boolean tempBasal(int percent, int durationInHours); public abstract boolean tempBasal(int percent, int durationInHours);
public abstract boolean tempBasalStop(); public abstract boolean tempBasalStop();

View file

@ -354,6 +354,11 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService{
return false; return false;
} }
@Override
public boolean tempBasalShortDuration(int percent, int durationInMinutes) {
return false;
}
public boolean updateBasalsInPump(final Profile profile) { public boolean updateBasalsInPump(final Profile profile) {
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));

View file

@ -301,6 +301,11 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
return false; return false;
} }
@Override
public boolean tempBasalShortDuration(int percent, int durationInMinutes) {
return false;
}
public boolean updateBasalsInPump(final Profile profile) { public boolean updateBasalsInPump(final Profile profile) {
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));

View file

@ -181,6 +181,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
pumpDescription.tempPercentStep = 10; pumpDescription.tempPercentStep = 10;
pumpDescription.tempDurationStep = 60; pumpDescription.tempDurationStep = 60;
pumpDescription.tempDurationStep15mAllowed = true;
pumpDescription.tempDurationStep30mAllowed = true;
pumpDescription.tempMaxDuration = 24 * 60; pumpDescription.tempMaxDuration = 24 * 60;
@ -367,7 +369,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
return pump.lastConnection > 0 && pump.maxBasal > 0; return pump.lastConnection > 0 && pump.maxBasal > 0;
} }
@Override @Override
@ -618,8 +620,13 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
log.debug("setTempBasalPercent: Correct value already set"); log.debug("setTempBasalPercent: Correct value already set");
return result; return result;
} }
int durationInHours = Math.max(durationInMinutes / 60, 1); boolean connectionOK;
boolean connectionOK = danaRSService.tempBasal(percent, durationInHours); if (durationInMinutes == 15 || durationInMinutes == 30) {
connectionOK = danaRSService.tempBasalShortDuration(percent, durationInMinutes);
} else {
int durationInHours = Math.max(durationInMinutes / 60, 1);
connectionOK = danaRSService.tempBasal(percent, durationInHours);
}
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;

View file

@ -10,33 +10,60 @@ import info.nightscout.androidaps.Config;
public class DanaRS_Packet_APS_Basal_Set_Temporary_Basal extends DanaRS_Packet { public class DanaRS_Packet_APS_Basal_Set_Temporary_Basal extends DanaRS_Packet {
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_APS_Basal_Set_Temporary_Basal.class); private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_APS_Basal_Set_Temporary_Basal.class);
private int temporaryBasalRatio; int temporaryBasalRatio;
private int temporaryBasalDuration; int temporaryBasalDuration;
public int error; public int error;
public DanaRS_Packet_APS_Basal_Set_Temporary_Basal() { final int PARAM30MIN = 160;
final int PARAM15MIN = 150;
DanaRS_Packet_APS_Basal_Set_Temporary_Basal() {
super(); super();
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__APS_SET_TEMPORARY_BASAL; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__APS_SET_TEMPORARY_BASAL;
} }
public DanaRS_Packet_APS_Basal_Set_Temporary_Basal(int percent) { public DanaRS_Packet_APS_Basal_Set_Temporary_Basal(int percent) {
this(); this();
setParams(percent);
}
protected void setParams(int percent) {
//HARDCODED LIMITS //HARDCODED LIMITS
if (percent < 0) percent = 0; if (percent < 0) percent = 0;
if (percent > 500) percent = 500; if (percent > 500) percent = 500;
temporaryBasalRatio = percent; temporaryBasalRatio = percent;
if (percent < 100) { if (percent < 100) {
temporaryBasalDuration = 160; temporaryBasalDuration = PARAM30MIN;
if (Config.logDanaMessageDetail) if (Config.logDanaMessageDetail)
log.debug("APS Temp basal start percent: " + percent + " duration 30 min"); log.debug("APS Temp basal start percent: " + percent + " duration 30 min");
} else { } else {
temporaryBasalDuration = 150; temporaryBasalDuration = PARAM15MIN;
if (Config.logDanaMessageDetail) if (Config.logDanaMessageDetail)
log.debug("APS Temp basal start percent: " + percent + " duration 15 min"); log.debug("APS Temp basal start percent: " + percent + " duration 15 min");
} }
}
public DanaRS_Packet_APS_Basal_Set_Temporary_Basal(int percent, boolean fifteenMinutes, boolean thirtyMinutes ) {
this();
setParams(percent, fifteenMinutes, thirtyMinutes);
}
protected void setParams(int percent, boolean fifteenMinutes, boolean thirtyMinutes) {
//HARDCODED LIMITS
if (percent < 0) percent = 0;
if (percent > 500) percent = 500;
temporaryBasalRatio = percent;
if (thirtyMinutes && percent <= 200) { // 30 min is allowed up to 200%
temporaryBasalDuration = PARAM30MIN;
if (Config.logDanaMessageDetail)
log.debug("APS Temp basal start percent: " + percent + " duration 30 min");
} else {
temporaryBasalDuration = PARAM15MIN;
if (Config.logDanaMessageDetail)
log.debug("APS Temp basal start percent: " + percent + " duration 15 min");
}
} }
@Override @Override
@ -55,6 +82,7 @@ public class DanaRS_Packet_APS_Basal_Set_Temporary_Basal extends DanaRS_Packet {
failed = true; failed = true;
log.error("Set APS temp basal start result: " + result + " FAILED!!!"); log.error("Set APS temp basal start result: " + result + " FAILED!!!");
} else { } else {
failed = false;
if (Config.logDanaMessageDetail) if (Config.logDanaMessageDetail)
log.debug("Set APS temp basal start result: " + result); log.debug("Set APS temp basal start result: " + result);
} }

View file

@ -318,6 +318,25 @@ public class DanaRSService extends Service {
return true; return true;
} }
public boolean tempBasalShortDuration(Integer percent, int durationInMinutes) {
if (durationInMinutes != 15 && durationInMinutes != 30) {
log.error("Wrong duration param");
return false;
}
if (danaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
bleComm.sendMessage(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal());
SystemClock.sleep(500);
}
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.settingtempbasal)));
bleComm.sendMessage(new DanaRS_Packet_APS_Basal_Set_Temporary_Basal(percent, durationInMinutes == 15, durationInMinutes == 30));
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State());
loadEvents();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
public boolean tempBasalStop() { public boolean tempBasalStop() {
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));

View file

@ -63,6 +63,8 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
pumpDescription.tempPercentStep = 10; pumpDescription.tempPercentStep = 10;
pumpDescription.tempDurationStep = 60; pumpDescription.tempDurationStep = 60;
pumpDescription.tempDurationStep15mAllowed = true;
pumpDescription.tempDurationStep30mAllowed = true;
pumpDescription.tempMaxDuration = 24 * 60; pumpDescription.tempMaxDuration = 24 * 60;
@ -275,7 +277,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
} }
if (percent > getPumpDescription().maxTempPercent) if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent; percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (runningTB != null && runningTB.percentRate == percent && !enforceNew) { if (runningTB != null && runningTB.percentRate == percent && !enforceNew) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
@ -289,8 +291,13 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
log.debug("setTempBasalPercent: Correct value already set"); log.debug("setTempBasalPercent: Correct value already set");
return result; return result;
} }
int durationInHours = Math.max(durationInMinutes / 60, 1); boolean connectionOK;
boolean connectionOK = sExecutionService.tempBasal(percent, durationInHours); if (durationInMinutes == 15 || durationInMinutes == 30) {
connectionOK = sExecutionService.tempBasalShortDuration(percent, durationInMinutes);
} else {
int durationInHours = Math.max(durationInMinutes / 60, 1);
connectionOK = sExecutionService.tempBasal(percent, durationInHours);
}
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;
@ -336,7 +343,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
@Override @Override
public PumpEnactResult cancelTempBasal(boolean force) { public PumpEnactResult cancelTempBasal(boolean force) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
if (runningTB != null) { if (runningTB != null) {
sExecutionService.tempBasalStop(); sExecutionService.tempBasalStop();
result.enacted = true; result.enacted = true;

View file

@ -9,28 +9,55 @@ import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
public class MsgSetAPSTempBasalStart_v2 extends MessageBase { public class MsgSetAPSTempBasalStart_v2 extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgSetAPSTempBasalStart_v2.class); private static Logger log = LoggerFactory.getLogger(MsgSetAPSTempBasalStart_v2.class);
protected final int PARAM30MIN = 160;
protected final int PARAM15MIN = 150;
public MsgSetAPSTempBasalStart_v2() { public MsgSetAPSTempBasalStart_v2() {
SetCommand(0xE002); SetCommand(0xE002);
} }
public MsgSetAPSTempBasalStart_v2(int percent) { public MsgSetAPSTempBasalStart_v2(int percent) {
this(); this();
setParams(percent);
}
protected void setParams(int percent) {
//HARDCODED LIMITS //HARDCODED LIMITS
if (percent < 0) percent = 0; if (percent < 0) percent = 0;
if (percent > 500) percent = 500; if (percent > 500) percent = 500;
AddParamInt(percent); AddParamInt(percent);
if (percent < 100) { if (percent < 100) {
AddParamByte((byte) 0xA0); // 160 AddParamByte((byte) PARAM30MIN);
if (Config.logDanaMessageDetail) if (Config.logDanaMessageDetail)
log.debug("APS Temp basal start percent: " + percent + " duration 30 min"); log.debug("APS Temp basal start percent: " + percent + " duration 30 min");
} else { } else {
AddParamByte((byte) 0x96); // 150 AddParamByte((byte) PARAM15MIN);
if (Config.logDanaMessageDetail) if (Config.logDanaMessageDetail)
log.debug("APS Temp basal start percent: " + percent + " duration 15 min"); log.debug("APS Temp basal start percent: " + percent + " duration 15 min");
} }
}
public MsgSetAPSTempBasalStart_v2(int percent, boolean fifteenMinutes, boolean thirtyMinutes) {
this();
setParams(percent, fifteenMinutes, thirtyMinutes);
}
protected void setParams(int percent, boolean fifteenMinutes, boolean thirtyMinutes) {
//HARDCODED LIMITS
if (percent < 0) percent = 0;
if (percent > 500) percent = 500;
AddParamInt(percent);
if (thirtyMinutes && percent <= 200) { // 30 min is allowed up to 200%
AddParamByte((byte) PARAM30MIN);
if (Config.logDanaMessageDetail)
log.debug("APS Temp basal start percent: " + percent + " duration 30 min");
} else {
AddParamByte((byte) PARAM15MIN);
if (Config.logDanaMessageDetail)
log.debug("APS Temp basal start percent: " + percent + " duration 15 min");
}
} }
public void handleMessage(byte[] bytes) { public void handleMessage(byte[] bytes) {
@ -39,6 +66,7 @@ public class MsgSetAPSTempBasalStart_v2 extends MessageBase {
failed = true; failed = true;
log.debug("Set APS temp basal start result: " + result + " FAILED!!!"); log.debug("Set APS temp basal start result: " + result + " FAILED!!!");
} else { } else {
failed = false;
if (Config.logDanaMessageDetail) if (Config.logDanaMessageDetail)
log.debug("Set APS temp basal start result: " + result); log.debug("Set APS temp basal start result: " + result);
} }

View file

@ -254,6 +254,26 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
return true; return true;
} }
public boolean tempBasalShortDuration(int percent, int durationInMinutes) {
if (durationInMinutes != 15 && durationInMinutes != 30) {
log.error("Wrong duration param");
return false;
}
if (!isConnected()) return false;
if (mDanaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
SystemClock.sleep(500);
}
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.settingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart_v2(percent, durationInMinutes == 15, durationInMinutes == 30));
mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2());
loadEvents();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
public boolean tempBasalStop() { public boolean tempBasalStop() {
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));

View file

@ -138,6 +138,8 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
pumpDescription.tempPercentStep = 10; pumpDescription.tempPercentStep = 10;
pumpDescription.tempDurationStep = 15; // 15 minutes up to 24 hours pumpDescription.tempDurationStep = 15; // 15 minutes up to 24 hours
pumpDescription.tempDurationStep15mAllowed = true;
pumpDescription.tempDurationStep30mAllowed = true;
pumpDescription.tempMaxDuration = 24 * 60; pumpDescription.tempMaxDuration = 24 * 60;
pumpDescription.isSetBasalProfileCapable = false; // leave this for now pumpDescription.isSetBasalProfileCapable = false; // leave this for now

View file

@ -89,6 +89,8 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
pumpDescription.tempPercentStep = 10; pumpDescription.tempPercentStep = 10;
pumpDescription.tempDurationStep = 30; pumpDescription.tempDurationStep = 30;
pumpDescription.tempDurationStep15mAllowed = true;
pumpDescription.tempDurationStep30mAllowed = true;
pumpDescription.tempMaxDuration = 24 * 60; pumpDescription.tempMaxDuration = 24 * 60;

View file

@ -513,6 +513,7 @@
<string name="suspendloopfor2h">Изключи Loop за 2ч</string> <string name="suspendloopfor2h">Изключи Loop за 2ч</string>
<string name="suspendloopfor3h">Изключи Loop за 3ч</string> <string name="suspendloopfor3h">Изключи Loop за 3ч</string>
<string name="suspendloopfor10h">Изключи Loop за 10 ч</string> <string name="suspendloopfor10h">Изключи Loop за 10 ч</string>
<string name="disconnectpumpfor15m">Изключи помпата за 15 мин.</string>
<string name="disconnectpumpfor30m">Изключи помпата за 30 мин.</string> <string name="disconnectpumpfor30m">Изключи помпата за 30 мин.</string>
<string name="disconnectpumpfor1h">Изключи помпата за 1 ч</string> <string name="disconnectpumpfor1h">Изключи помпата за 1 ч</string>
<string name="disconnectpumpfor2h">Изключи помпата за 2 ч</string> <string name="disconnectpumpfor2h">Изключи помпата за 2 ч</string>

View file

@ -494,6 +494,7 @@
<string name="disconnectpumpfor10h">Odpojit pumpu na 10 h</string> <string name="disconnectpumpfor10h">Odpojit pumpu na 10 h</string>
<string name="disconnectpumpfor1h">Odpojit pumpu na 1 h</string> <string name="disconnectpumpfor1h">Odpojit pumpu na 1 h</string>
<string name="disconnectpumpfor2h">Odpojit pumpu na 2 h</string> <string name="disconnectpumpfor2h">Odpojit pumpu na 2 h</string>
<string name="disconnectpumpfor15m">Odpojit pumpu na 15 min</string>
<string name="disconnectpumpfor30m">Odpojit pumpu na 30 min</string> <string name="disconnectpumpfor30m">Odpojit pumpu na 30 min</string>
<string name="disconnectpumpfor3h">Odpojit pumpu na 3 h</string> <string name="disconnectpumpfor3h">Odpojit pumpu na 3 h</string>
<string name="enableloop">Povolit smyčku</string> <string name="enableloop">Povolit smyčku</string>

View file

@ -413,6 +413,7 @@
<string name="disconnectpumpfor10h">Trenne Pumpe für 10 h</string> <string name="disconnectpumpfor10h">Trenne Pumpe für 10 h</string>
<string name="disconnectpumpfor1h">Trenne Pumpe für 1 h</string> <string name="disconnectpumpfor1h">Trenne Pumpe für 1 h</string>
<string name="disconnectpumpfor2h">Trenne Pumpe für 2 h</string> <string name="disconnectpumpfor2h">Trenne Pumpe für 2 h</string>
<string name="disconnectpumpfor15m">Trenne Pumpe für 15 Min.</string>
<string name="disconnectpumpfor30m">Trenne Pumpe für 30 Min.</string> <string name="disconnectpumpfor30m">Trenne Pumpe für 30 Min.</string>
<string name="disconnectpumpfor3h">Trenne Pumpe für 3 h</string> <string name="disconnectpumpfor3h">Trenne Pumpe für 3 h</string>
<string name="do_not_track_profile_switch">Ignoriere Profilwechsel</string> <string name="do_not_track_profile_switch">Ignoriere Profilwechsel</string>

View file

@ -510,6 +510,7 @@
<string name="suspendloopfor2h">Κύκλωμα σε παύση για 2h</string> <string name="suspendloopfor2h">Κύκλωμα σε παύση για 2h</string>
<string name="suspendloopfor3h">Κύκλωμα σε παύση για 3h</string> <string name="suspendloopfor3h">Κύκλωμα σε παύση για 3h</string>
<string name="suspendloopfor10h">Κύκλωμα σε παύση για 10h</string> <string name="suspendloopfor10h">Κύκλωμα σε παύση για 10h</string>
<string name="disconnectpumpfor15m">Αποσύνδεση αντλίας για 15 λεπτά</string>
<string name="disconnectpumpfor30m">Αποσύνδεση αντλίας για 30 λεπτά</string> <string name="disconnectpumpfor30m">Αποσύνδεση αντλίας για 30 λεπτά</string>
<string name="disconnectpumpfor1h">Αποσύνδεση αντλίας για 1h</string> <string name="disconnectpumpfor1h">Αποσύνδεση αντλίας για 1h</string>
<string name="disconnectpumpfor2h">Αποσύνδεση αντλίας για 2h</string> <string name="disconnectpumpfor2h">Αποσύνδεση αντλίας για 2h</string>

View file

@ -525,6 +525,7 @@
<string name="suspendloopfor2h">Desactivar loop por 2h</string> <string name="suspendloopfor2h">Desactivar loop por 2h</string>
<string name="suspendloopfor3h">Desactivar loop por 3h</string> <string name="suspendloopfor3h">Desactivar loop por 3h</string>
<string name="suspendloopfor10h">Desactivar loop por 10 h</string> <string name="suspendloopfor10h">Desactivar loop por 10 h</string>
<string name="disconnectpumpfor15m">Desconectar bomba por 15 min</string>
<string name="disconnectpumpfor30m">Desconectar bomba por 30 min</string> <string name="disconnectpumpfor30m">Desconectar bomba por 30 min</string>
<string name="disconnectpumpfor1h">Desconectar bomba por 1 h</string> <string name="disconnectpumpfor1h">Desconectar bomba por 1 h</string>
<string name="disconnectpumpfor2h">Desconectar bomba por 2 h</string> <string name="disconnectpumpfor2h">Desconectar bomba por 2 h</string>

View file

@ -508,6 +508,7 @@
<string name="suspendloopfor2h">Suspendre Loop pour 2h</string> <string name="suspendloopfor2h">Suspendre Loop pour 2h</string>
<string name="suspendloopfor3h">Suspendre Loop pour 3h</string> <string name="suspendloopfor3h">Suspendre Loop pour 3h</string>
<string name="suspendloopfor10h">Suspendre Loop pour 10h</string> <string name="suspendloopfor10h">Suspendre Loop pour 10h</string>
<string name="disconnectpumpfor15m">Déconnecter la pompe 15min</string>
<string name="disconnectpumpfor30m">Déconnecter la pompe 30min</string> <string name="disconnectpumpfor30m">Déconnecter la pompe 30min</string>
<string name="disconnectpumpfor1h">Déconnecter la pompe 1h</string> <string name="disconnectpumpfor1h">Déconnecter la pompe 1h</string>
<string name="disconnectpumpfor2h">Déconnecter la pompe 2h</string> <string name="disconnectpumpfor2h">Déconnecter la pompe 2h</string>

View file

@ -145,6 +145,7 @@
<string name="disconnectpumpfor10h">Sconnetti Micro per 10H</string> <string name="disconnectpumpfor10h">Sconnetti Micro per 10H</string>
<string name="disconnectpumpfor1h">Sconnetti Micro per 1 H</string> <string name="disconnectpumpfor1h">Sconnetti Micro per 1 H</string>
<string name="disconnectpumpfor2h">Sconnetti Micro per 2 H</string> <string name="disconnectpumpfor2h">Sconnetti Micro per 2 H</string>
<string name="disconnectpumpfor15m">Sconnetti Micro per 15min</string>
<string name="disconnectpumpfor30m">Sconnetti Micro per 30min</string> <string name="disconnectpumpfor30m">Sconnetti Micro per 30min</string>
<string name="disconnectpumpfor3h">Sconnetti Micro per 3 H</string> <string name="disconnectpumpfor3h">Sconnetti Micro per 3 H</string>
<string name="dismiss">Respingere</string> <string name="dismiss">Respingere</string>

View file

@ -522,6 +522,7 @@
<string name="suspendloopfor2h">2시간동안 Loop 일시중지</string> <string name="suspendloopfor2h">2시간동안 Loop 일시중지</string>
<string name="suspendloopfor3h">3시간동안 Loop 일시중지</string> <string name="suspendloopfor3h">3시간동안 Loop 일시중지</string>
<string name="suspendloopfor10h">10시간동안 Loop 일시중지</string> <string name="suspendloopfor10h">10시간동안 Loop 일시중지</string>
<string name="disconnectpumpfor15m">15분동안 펌프 일시중지</string>
<string name="disconnectpumpfor30m">30분동안 펌프 일시중지</string> <string name="disconnectpumpfor30m">30분동안 펌프 일시중지</string>
<string name="disconnectpumpfor1h">1시간동안 펌프 일시중지</string> <string name="disconnectpumpfor1h">1시간동안 펌프 일시중지</string>
<string name="disconnectpumpfor2h">2시간동안 펌프 일시중지</string> <string name="disconnectpumpfor2h">2시간동안 펌프 일시중지</string>

View file

@ -250,6 +250,7 @@
<string name="disconnectpumpfor10h">Verbreek verbinding 10u met pomp</string> <string name="disconnectpumpfor10h">Verbreek verbinding 10u met pomp</string>
<string name="disconnectpumpfor1h">Verbreek verbinding 1u met pomp</string> <string name="disconnectpumpfor1h">Verbreek verbinding 1u met pomp</string>
<string name="disconnectpumpfor2h">Verbreek verbinding 2u met pomp</string> <string name="disconnectpumpfor2h">Verbreek verbinding 2u met pomp</string>
<string name="disconnectpumpfor15m">Verbreek verbinding 15min met pomp</string>
<string name="disconnectpumpfor30m">Verbreek verbinding 30min met pomp</string> <string name="disconnectpumpfor30m">Verbreek verbinding 30min met pomp</string>
<string name="disconnectpumpfor3h">Verbreek verbinding 3u met pomp</string> <string name="disconnectpumpfor3h">Verbreek verbinding 3u met pomp</string>
<string name="dismiss">NEGEER</string> <string name="dismiss">NEGEER</string>

View file

@ -547,6 +547,7 @@
<string name="suspendloopfor2h">Suspendă bucla pentru 2h</string> <string name="suspendloopfor2h">Suspendă bucla pentru 2h</string>
<string name="suspendloopfor3h">Suspendă bucla pentru 3h</string> <string name="suspendloopfor3h">Suspendă bucla pentru 3h</string>
<string name="suspendloopfor10h">Suspendă bucla pentru 10 h</string> <string name="suspendloopfor10h">Suspendă bucla pentru 10 h</string>
<string name="disconnectpumpfor15m">Deconectează pompa pentru 15 min</string>
<string name="disconnectpumpfor30m">Deconectează pompa pentru 30 min</string> <string name="disconnectpumpfor30m">Deconectează pompa pentru 30 min</string>
<string name="disconnectpumpfor1h">Deconectează pompa pentru 1h</string> <string name="disconnectpumpfor1h">Deconectează pompa pentru 1h</string>
<string name="disconnectpumpfor2h">Deconectează pompa pentru 2h</string> <string name="disconnectpumpfor2h">Deconectează pompa pentru 2h</string>

View file

@ -179,6 +179,7 @@
<string name="disconnectpumpfor10h">отсоединить помпу на 10 час</string> <string name="disconnectpumpfor10h">отсоединить помпу на 10 час</string>
<string name="disconnectpumpfor1h">отсоединить помпу на 1 час</string> <string name="disconnectpumpfor1h">отсоединить помпу на 1 час</string>
<string name="disconnectpumpfor2h">отсоединить помпу на 2 часа</string> <string name="disconnectpumpfor2h">отсоединить помпу на 2 часа</string>
<string name="disconnectpumpfor15m">отсоединить помпу на 15 мин</string>
<string name="disconnectpumpfor30m">отсоединить помпу на 30 мин</string> <string name="disconnectpumpfor30m">отсоединить помпу на 30 мин</string>
<string name="disconnectpumpfor3h">отсоединить помпу на 3 часа</string> <string name="disconnectpumpfor3h">отсоединить помпу на 3 часа</string>
<string name="dismiss">отклонить</string> <string name="dismiss">отклонить</string>

View file

@ -165,6 +165,7 @@
<string name="disconnecting">Frånkopplar</string> <string name="disconnecting">Frånkopplar</string>
<string name="disconnectpumpfor10h">Frånkoppla pump i 10 h</string> <string name="disconnectpumpfor10h">Frånkoppla pump i 10 h</string>
<string name="disconnectpumpfor2h">Frånkoppla pump i 2 h</string> <string name="disconnectpumpfor2h">Frånkoppla pump i 2 h</string>
<string name="disconnectpumpfor15m">Frånkoppla pump i 15 min</string>
<string name="disconnectpumpfor30m">Frånkoppla pump i 30 min</string> <string name="disconnectpumpfor30m">Frånkoppla pump i 30 min</string>
<string name="disconnectpumpfor3h">Frånkoppla pump i 3 h</string> <string name="disconnectpumpfor3h">Frånkoppla pump i 3 h</string>
<string name="dismiss">TA BORT</string> <string name="dismiss">TA BORT</string>

View file

@ -562,6 +562,7 @@
<string name="suspendloopfor2h">Suspend loop for 2h</string> <string name="suspendloopfor2h">Suspend loop for 2h</string>
<string name="suspendloopfor3h">Suspend loop for 3h</string> <string name="suspendloopfor3h">Suspend loop for 3h</string>
<string name="suspendloopfor10h">Suspend loop for 10 h</string> <string name="suspendloopfor10h">Suspend loop for 10 h</string>
<string name="disconnectpumpfor15m">Disconnect pump for 15 min</string>
<string name="disconnectpumpfor30m">Disconnect pump for 30 min</string> <string name="disconnectpumpfor30m">Disconnect pump for 30 min</string>
<string name="disconnectpumpfor1h">Disconnect pump for 1 h</string> <string name="disconnectpumpfor1h">Disconnect pump for 1 h</string>
<string name="disconnectpumpfor2h">Disconnect pump for 2 h</string> <string name="disconnectpumpfor2h">Disconnect pump for 2 h</string>

View file

@ -0,0 +1,70 @@
package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Created by mike on 20.11.2017.
*/
public class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest extends DanaRS_Packet_APS_Basal_Set_Temporary_Basal {
@Test
public void runTest() throws Exception {
// under 100% should last 30 min
setParams(0);
assertEquals(0, temporaryBasalRatio);
assertEquals(PARAM30MIN, temporaryBasalDuration);
// over 100% should last 15 min
setParams(150);
assertEquals(150, temporaryBasalRatio);
assertEquals(PARAM15MIN, temporaryBasalDuration);
// test low hard limit
setParams(-1);
assertEquals(0, temporaryBasalRatio);
assertEquals(PARAM30MIN, temporaryBasalDuration);
// test high hard limit
setParams(550);
assertEquals(500, temporaryBasalRatio);
assertEquals(PARAM15MIN, temporaryBasalDuration);
// test setting 15 min
setParams(50, true, false);
assertEquals(50, temporaryBasalRatio);
assertEquals(PARAM15MIN, temporaryBasalDuration);
// test setting 30 min
setParams(50, false, true);
assertEquals(50, temporaryBasalRatio);
assertEquals(PARAM30MIN, temporaryBasalDuration);
// over 200% set always 15 min
setParams(250, false, true);
assertEquals(250, temporaryBasalRatio);
assertEquals(PARAM15MIN, temporaryBasalDuration);
// test low hard limit
setParams(-1, false, true);
assertEquals(0, temporaryBasalRatio);
assertEquals(PARAM30MIN, temporaryBasalDuration);
// test high hard limit
setParams(550, false,true);
assertEquals(500, temporaryBasalRatio);
assertEquals(PARAM15MIN, temporaryBasalDuration);
// test message generation
setParams(260, true, false);
byte[] generatedCode = getRequestParams();
assertEquals(3 , generatedCode.length);
assertEquals((byte)4 , generatedCode[0]);
assertEquals((byte)1 , generatedCode[1]);
assertEquals((byte)PARAM15MIN, generatedCode[2]);
// test message decoding
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
assertEquals(false, failed);
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
assertEquals(true, failed);
assertEquals("BASAL__APS_SET_TEMPORARY_BASAL", getFriendlyName());
}
}

View file

@ -0,0 +1,72 @@
package info.nightscout.androidaps.plugins.PumpdanaRv2.comm;
import org.junit.Test;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_APS_Basal_Set_Temporary_Basal;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetAPSTempBasalStart_v2;
import static org.junit.Assert.assertEquals;
/**
* Created by mike on 20.11.2017.
*/
public class MsgSetAPSTempBasalStart_v2Test extends MsgSetAPSTempBasalStart_v2 {
@Test
public void runTest() throws Exception {
// under 100% should last 30 min
setParams(0);
assertEquals(0, intFromBuff(buffer, 0, 2));
assertEquals(PARAM30MIN, intFromBuff(buffer, 2, 1));
resetBuffer();
// over 100% should last 15 min
setParams(150);
assertEquals(150, intFromBuff(buffer, 0, 2));
assertEquals(PARAM15MIN, intFromBuff(buffer, 2, 1));
resetBuffer();
// test low hard limit
setParams(-1);
assertEquals(0, intFromBuff(buffer, 0, 2));
assertEquals(PARAM30MIN, intFromBuff(buffer, 2, 1));
resetBuffer();
// test high hard limit
setParams(550);
assertEquals(500, intFromBuff(buffer, 0, 2));
assertEquals(PARAM15MIN, intFromBuff(buffer, 2, 1));
resetBuffer();
// test setting 15 min
setParams(50, true, false);
assertEquals(50, intFromBuff(buffer, 0, 2));
assertEquals(PARAM15MIN, intFromBuff(buffer, 2, 1));
resetBuffer();
// test setting 30 min
setParams(50, false, true);
assertEquals(50, intFromBuff(buffer, 0, 2));
assertEquals(PARAM30MIN, intFromBuff(buffer, 2, 1));
resetBuffer();
// over 200% set always 15 min
setParams(250, false, true);
assertEquals(250, intFromBuff(buffer, 0, 2));
assertEquals(PARAM15MIN, intFromBuff(buffer, 2, 1));
resetBuffer();
// test low hard limit
setParams(-1, false, true);
assertEquals(0, intFromBuff(buffer, 0, 2));
assertEquals(PARAM30MIN, intFromBuff(buffer, 2, 1));
resetBuffer();
// test high hard limit
setParams(550, false, true);
assertEquals(500, intFromBuff(buffer, 0, 2));
assertEquals(PARAM15MIN, intFromBuff(buffer, 2, 1));
resetBuffer();
// test message decoding
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0});
assertEquals(true, failed);
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 1});
assertEquals(false, failed);
}
}