Added options Max Bolus and Max Basal

Little bit of refactoring in Medtronic code
This commit is contained in:
Andy Rozman 2018-05-12 00:41:44 +01:00
parent c03b4f6780
commit 2cc4fe4450
9 changed files with 206 additions and 155 deletions

View file

@ -28,12 +28,13 @@ import info.nightscout.androidaps.plugins.PumpCommon.driver.PumpDriverInterface;
* Created by andy on 23.04.18.
*/
public abstract class PumpPluginAbstract extends PluginBase implements PumpInterface, ConstraintsInterface, ProfileInterface {
public abstract class PumpPluginAbstract extends PluginBase implements PumpInterface, ConstraintsInterface {
protected boolean fragmentVisible = false;
protected boolean fragmentEnabled = false;
// , ProfileInterface
//protected boolean fragmentVisible = false;
//protected boolean fragmentEnabled = false;
protected boolean pumpServiceRunning = false;
private static final String TAG = "PumpPluginAbstract";
//private static final String TAG = "PumpPluginAbstract";
//protected PumpStatus pumpStatus;
@ -75,11 +76,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
// return true;
// }
//
//
// @Override
// public boolean hasFragment() {
// return true;
// }
//
//
// @Override
@ -88,25 +85,6 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
// }
// @Override
// public void setFragmentEnabled(int type, boolean fragmentEnabled) {
// if (type == PUMP) {
// this.fragmentEnabled = fragmentEnabled;
//
// if (fragmentEnabled) {
// if (!pumpServiceRunning)
// startPumpService();
// else
// Log.d(TAG, "Can't start, Pump service (" + getInternalName() + "is already running.");
// }
// else {
// if (pumpServiceRunning)
// stopPumpService();
// else
// Log.d(TAG, "Can't stop, Pump service (" + getInternalName() + "is already stopped.");
// }
// }
// }
// @Override
@ -204,17 +182,15 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
}
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew){
//return pumpDriver.setTempBasalAbsolute(absoluteRate, durationInMinutes, enforceNew);
// FIXME
return null;
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
return pumpDriver.setTempBasalAbsolute(absoluteRate, durationInMinutes, profile, enforceNew);
}
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew){
//return pumpDriver.setTempBasalPercent(percent, durationInMinutes, enforceNew);
// FIXME
return null;
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
return pumpDriver.setTempBasalPercent(percent, durationInMinutes, profile, enforceNew);
}
@ -342,4 +318,10 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
return this.pumpStatus.activeProfileName;
}
@Override
public PumpEnactResult loadTDDs() {
return this.pumpDriver.loadTDDs();
}
}

View file

@ -54,6 +54,6 @@ public abstract class PumpStatus {
public abstract String getErrorInfo();
public abstract void refreshConfiguration();
}

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.PumpMedtronic;
import com.gxwtech.roundtrip2.ServiceClientConnection;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
@ -13,17 +11,13 @@ import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.PumpCommon.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.PumpMedtronic.medtronic.MedtronicPumpDriver;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpDriver;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP;
/**
* Created by andy on 23.04.18.
@ -33,7 +27,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
private static final Logger LOG = LoggerFactory.getLogger(MedtronicPumpPlugin.class);
private ServiceClientConnection serviceClientConnection;
//private ServiceClientConnection serviceClientConnection;
public static PumpPluginAbstract getPlugin() {
@ -44,11 +38,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
public MedtronicPumpPlugin()
{
private MedtronicPumpPlugin() {
super(new MedtronicPumpDriver(), //
"MedtronicPump", //
MedtronicFragment.class.getName(), //
@ -58,36 +48,25 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
@Override
protected String getInternalName() {
return "MedtronicPump";
}
@Override
protected void startPumpService() {
//serviceClientConnection = new ServiceClientConnection();
}
@Override
protected void stopPumpService() {
}
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
return null;
}
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
return null;
}
@Override
public JSONObject getJSONStatus(Profile profile, String profileName) {
//if (!SP.getBoolean("virtualpump_uploadstatus", false)) {
@ -139,33 +118,16 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
@Override
public String shortStatus(boolean veryShort) {
return "Medtronic Pump";
}
//@Override
//public String shortStatus(boolean veryShort) {
// return "Medtronic Pump";
//}
@Override
public boolean isFakingTempsByExtendedBoluses() {
return false;
}
@Override
public PumpEnactResult loadTDDs() {
return null;
}
// @Override
// public boolean isEnabled(int type) {
// // TODO might need tweaking
// if (type == PluginBase.PUMP)
// return fragmentEnabled;
// else if (type == PluginBase.CONSTRAINTS)
// return fragmentEnabled;
// return false;
// }
@Override
public int getPreferencesId() {
@ -173,10 +135,4 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
// @Override
// public boolean isLoopEnabled() {
// // FIXME check if we need to override
// return getPumpStatusData().validBasalRateProfileSelectedOnPump;
// }
}

View file

@ -1,8 +1,21 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.medtronic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpCommon.utils.PumpUtil;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpDriver;
import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
/**
* Created by andy on 4/28/18.
@ -10,45 +23,29 @@ import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpDriver;
public class MedtronicPumpDriver extends VirtualPumpDriver /*implements PumpInterface*/ {
private static final Logger LOG = LoggerFactory.getLogger(MedtronicPumpDriver.class);
MedtronicPumpStatus pumpStatusLocal;
public MedtronicPumpDriver()
{
// bolus
pumpStatusLocal = new MedtronicPumpStatus(pumpDescription);
pumpStatusLocal.verifyConfiguration();
this.pumpStatusData = pumpStatusLocal;
if (pumpStatusLocal.pumpType!=null)
PumpUtil.setPumpDescription(pumpDescription, pumpStatusLocal.pumpType);
if (pumpStatusLocal.maxBasal!=null)
pumpDescription.maxTempAbsolute = (pumpStatusLocal.maxBasal!=null) ? pumpStatusLocal.maxBasal : 35.0d;
// needs to be changed in configuration, after all functionalities are done
pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.1d; // this needs to be reconfigurable
// TBR
pumpDescription.isTempBasalCapable = true;
pumpDescription.tempBasalStyle = PumpDescription.ABSOLUTE;
pumpDescription.maxTempAbsolute = 35.0d;
//pumpDescription.maxTempPercent = 200;
//pumpDescription.tempPercentStep = 1;
pumpDescription.tempDurationStep = 30;
pumpDescription.tempMaxDuration = 24 * 60;
// extended bolus
pumpDescription.isExtendedBolusCapable = false;
pumpDescription.extendedBolusStep = 0.1d; // 0 - 25
pumpDescription.extendedBolusDurationStep = 30;
pumpDescription.extendedBolusMaxDuration = 8 * 60;
// set basal profile
pumpDescription.isSetBasalProfileCapable = true;
pumpDescription.basalStep = 0.05d;
pumpDescription.basalMinimumRate = 0.05d;
// ?
pumpDescription.isRefillingCapable = false;
// ?
pumpDescription.storesCarbInfo = false;
this.pumpStatusData = new MedtronicPumpStatus(pumpDescription);
// take care of validBasalRateProfileSelectedOnPump
}
@ -82,6 +79,35 @@ public class MedtronicPumpDriver extends VirtualPumpDriver /*implements PumpInte
return super.cancelTempBasal(enforceNew);
}
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
TemporaryBasal tempBasal = new TemporaryBasal()
.date(System.currentTimeMillis())
.absolute(absoluteRate)
.duration(durationInMinutes)
.source(Source.USER);
PumpEnactResult result = new PumpEnactResult();
result.success = true;
result.enacted = true;
result.isTempCancel = false;
result.absolute = absoluteRate;
result.duration = durationInMinutes;
result.comment = MainApp.gs(R.string.virtualpump_resultok);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
if (Config.logPumpComm)
LOG.debug("Setting temp basal absolute: " + result);
MainApp.bus().post(new EventVirtualPumpUpdateGui());
pumpStatusData.setLastDataTimeToNow();
return result;
}
}

View file

@ -3,10 +3,14 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.medtronic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpMedtronic.medtronic.defs.MedtronicPumpType;
import info.nightscout.utils.SP;
@ -30,13 +34,18 @@ public class MedtronicPumpStatus extends PumpStatus {
public String errorDescription = null;
public String serialNumber;
public MedtronicPumpType pumpType = null;
public PumpType pumpType = null;
public String pumpFrequency = null;
public String rileyLinkAddress = null;
public Integer maxBolus;
public Integer maxBasal;
private String[] frequencies;
private boolean isFrequencyUS = false;
String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
String regexSN = "[0-9]{6}";
private Map<String,PumpType> medtronicPumpMap = null;
public MedtronicPumpStatus(PumpDescription pumpDescription)
@ -47,53 +56,86 @@ public class MedtronicPumpStatus extends PumpStatus {
@Override
public void initSettings() {
this.activeProfileName = "A";
this.activeProfileName = "STD";
this.reservoirRemainingUnits = 75d;
this.batteryRemaining = 75d;
if (this.medtronicPumpMap==null)
createMedtronicPumpMap();
}
private void createMedtronicPumpMap() {
//
// //public static MedtronicPumpStatus getInstance()
// {
// return medtronicPumpStatus;
// }
medtronicPumpMap = new HashMap<>();
medtronicPumpMap.put("512", PumpType.Minimed_512_712);
medtronicPumpMap.put("712", PumpType.Minimed_512_712);
medtronicPumpMap.put("515", PumpType.Minimed_515_715);
medtronicPumpMap.put("715", PumpType.Minimed_515_715);
medtronicPumpMap.put("522", PumpType.Minimed_522_722);
medtronicPumpMap.put("722", PumpType.Minimed_522_722);
medtronicPumpMap.put("523", PumpType.Minimed_523_723);
medtronicPumpMap.put("723", PumpType.Minimed_523_723);
medtronicPumpMap.put("554", PumpType.Minimed_554_754_Veo);
medtronicPumpMap.put("754", PumpType.Minimed_554_754_Veo);
frequencies = new String[2];
frequencies[0] = MainApp.gs(R.string.medtronic_pump_frequency_us);
frequencies[1] = MainApp.gs(R.string.medtronic_pump_frequency_worldwide);
}
public void verifyConfiguration()
{
try {
if (this.medtronicPumpMap==null)
createMedtronicPumpMap();
this.errorDescription = null;
this.serialNumber = null;
this.pumpType = null;
this.pumpFrequency = null;
this.rileyLinkAddress = null;
this.maxBolus = null;
this.maxBasal = null;
String serialNr = SP.getString("pref_medtronic_serial", null);
if (serialNr == null) {
this.errorDescription = MainApp.sResources.getString(R.string.medtronic_error_serial_not_set);
this.errorDescription = MainApp.gs(R.string.medtronic_error_serial_not_set);
return;
} else {
if (!serialNr.matches(regexSN)) {
this.errorDescription = MainApp.sResources.getString(R.string.medtronic_error_serial_invalid);
this.errorDescription = MainApp.gs(R.string.medtronic_error_serial_invalid);
return;
} else {
serialNumber = serialNr;
this.serialNumber = serialNr;
}
}
String pumpType = SP.getString("pref_medtronic_pump_type", null);
if (pumpType == null) {
this.errorDescription = MainApp.sResources.getString(R.string.medtronic_error_pump_type_not_set);
this.errorDescription = MainApp.gs(R.string.medtronic_error_pump_type_not_set);
return;
} else {
String pumpTypePart = pumpType.substring(0, 3);
if (!pumpTypePart.matches("[0-9]{3}")) {
this.errorDescription = MainApp.sResources.getString(R.string.medtronic_error_pump_type_invalid);
this.errorDescription = MainApp.gs(R.string.medtronic_error_pump_type_invalid);
return;
} else {
this.pumpType = MedtronicPumpType.getByCode(pumpTypePart);
setDescriptionFromPumpType();
this.pumpType = medtronicPumpMap.get(pumpTypePart);
if (pumpTypePart.startsWith("7"))
this.reservoirFullUnits = "300";
else
this.reservoirFullUnits = "180";
}
}
@ -101,14 +143,15 @@ public class MedtronicPumpStatus extends PumpStatus {
String pumpFrequency = SP.getString("pref_medtronic_frequency", null);
if (pumpFrequency == null) {
this.errorDescription = MainApp.sResources.getString(R.string.medtronic_error_pump_frequency_not_set);
this.errorDescription = MainApp.gs(R.string.medtronic_error_pump_frequency_not_set);
return;
} else {
if (!pumpFrequency.equals("US") && !pumpFrequency.equals("EU")) {
this.errorDescription = MainApp.sResources.getString(R.string.medtronic_error_pump_frequency_invalid);
if (!pumpFrequency.equals(frequencies[0]) && !pumpFrequency.equals(frequencies[1])) {
this.errorDescription = MainApp.gs(R.string.medtronic_error_pump_frequency_invalid);
return;
} else {
this.pumpFrequency = pumpFrequency;
this.isFrequencyUS = pumpFrequency.equals(frequencies[0]);
}
}
@ -116,15 +159,35 @@ public class MedtronicPumpStatus extends PumpStatus {
String rileyLinkAddress = SP.getString("pref_medtronic_rileylink_mac", null);
if (rileyLinkAddress == null) {
this.errorDescription = MainApp.sResources.getString(R.string.medtronic_error_rileylink_address_invalid);
this.errorDescription = MainApp.gs(R.string.medtronic_error_rileylink_address_invalid);
return;
} else {
if (!rileyLinkAddress.matches(regexMac)) {
this.errorDescription = MainApp.sResources.getString(R.string.medtronic_error_rileylink_address_invalid);
this.errorDescription = MainApp.gs(R.string.medtronic_error_rileylink_address_invalid);
} else {
this.rileyLinkAddress = rileyLinkAddress;
}
}
String value = SP.getString("pref_medtronic_max_bolus", "25");
maxBolus = Integer.parseInt(value);
if (maxBolus> 25)
{
SP.putString("pref_medtronic_max_bolus", "25");
}
value = SP.getString("pref_medtronic_max_basal", "35");
maxBasal = Integer.parseInt(value);
if (maxBasal> 35)
{
SP.putString("pref_medtronic_max_basal", "35");
}
}
catch(Exception ex)
{
@ -133,13 +196,6 @@ public class MedtronicPumpStatus extends PumpStatus {
}
}
private void setDescriptionFromPumpType() {
if (this.pumpType==MedtronicPumpType.Unknown)
return;
this.reservoirFullUnits = "" + this.pumpType.getReservoir();
}
public String getErrorInfo()
{
@ -149,4 +205,10 @@ public class MedtronicPumpStatus extends PumpStatus {
}
@Override
public void refreshConfiguration() {
verifyConfiguration();
}
}

View file

@ -22,4 +22,9 @@ public class VirtualPumpStatus extends PumpStatus {
public String getErrorInfo() {
return null;
}
@Override
public void refreshConfiguration() {
}
}

View file

@ -148,8 +148,8 @@
</string-array>
<string-array name="medtronicPumpFreqArray">
<item>US</item>
<item>EU</item>
<item>@string/medtronic_pump_frequency_us</item>
<item>@string/medtronic_pump_frequency_worldwide</item>
</string-array>

View file

@ -1062,6 +1062,8 @@
<string name="medtronic_serial_number">Pump Serial Number</string>
<string name="medtronic_pump_type">Pump Type</string>
<string name="medtronic_pump_frequency">Pump Frequency</string>
<string name="medtronic_pump_max_bolus">Max Bolus on Pump</string>
<string name="medtronic_pump_max_basal">Max Basal on Pump</string>
<string name="medtronic_rileylink_mac_address">RileyLink MAC Address</string>
<string name="medtronic_errors">Errors</string>
<string name="medtronic_error_serial_not_set">Serial # not set.</string>
@ -1071,6 +1073,8 @@
<string name="medtronic_error_pump_frequency_not_set">Pump Frequency not set.</string>
<string name="medtronic_error_pump_frequency_invalid">Pump Frequency unsupported.</string>
<string name="medtronic_error_rileylink_address_invalid">RileyLink Address invalid.</string>
<string name="medtronic_pump_frequency_us">US (916 MHz)</string>
<string name="medtronic_pump_frequency_worldwide">Worldwide (868 Mhz)</string>
</resources>

View file

@ -4,13 +4,6 @@
<PreferenceCategory
android:title="@string/medtronic_name">
<Preference
android:enabled="false"
android:key="blescannner"
android:title="RileyLink Configuration (maybe)">
<intent android:action="info.nightscout.androidaps.plugins.PumpDanaRS.activities.BLEScanActivity" />
</Preference>
<EditTextPreference
android:defaultValue="000000"
@ -35,6 +28,29 @@
android:selectable="true"
android:title="@string/medtronic_pump_frequency" />
<EditTextPreference
android:defaultValue="35"
android:key="pref_medtronic_max_basal"
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="number"
android:title="@string/medtronic_pump_max_basal" />
<EditTextPreference
android:defaultValue="25"
android:key="pref_medtronic_max_bolus"
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="number"
android:title="@string/medtronic_pump_max_bolus" />
<Preference
android:enabled="false"
android:key="rileylink_scanner"
android:title="RileyLink Configuration">
<intent android:action="info.nightscout.androidaps.plugins.PumpDanaRS.activities.BLEScanActivity" />
</Preference>
<EditTextPreference
android:defaultValue="xx:xx:xx:xx:xx:xx"
android:editable="false"