From 2cc4fe4450a83a15fb1c0fbb94af402ae7a5f371 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sat, 12 May 2018 00:41:44 +0100 Subject: [PATCH] Added options Max Bolus and Max Basal Little bit of refactoring in Medtronic code --- .../PumpCommon/PumpPluginAbstract.java | 56 +++------ .../plugins/PumpCommon/data/PumpStatus.java | 2 +- .../PumpMedtronic/MedtronicPumpPlugin.java | 60 ++------- .../medtronic/MedtronicPumpDriver.java | 86 ++++++++----- .../medtronic/MedtronicPumpStatus.java | 114 ++++++++++++++---- .../PumpVirtual/VirtualPumpStatus.java | 5 + app/src/main/res/values/arrays.xml | 4 +- app/src/main/res/values/strings.xml | 4 + app/src/main/res/xml/pref_medtronic.xml | 30 +++-- 9 files changed, 206 insertions(+), 155 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/PumpPluginAbstract.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/PumpPluginAbstract.java index 7ea8bb11f2..7277877d73 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/PumpPluginAbstract.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/PumpPluginAbstract.java @@ -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(); + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/data/PumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/data/PumpStatus.java index ea85dc7271..62b8be1314 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/data/PumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/data/PumpStatus.java @@ -54,6 +54,6 @@ public abstract class PumpStatus { public abstract String getErrorInfo(); - + public abstract void refreshConfiguration(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java index 6a2e485845..a2a78aff83 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java @@ -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; -// } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/medtronic/MedtronicPumpDriver.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/medtronic/MedtronicPumpDriver.java index fa7f97c414..9da31668cc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/medtronic/MedtronicPumpDriver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/medtronic/MedtronicPumpDriver.java @@ -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; + } + + + + + + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/medtronic/MedtronicPumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/medtronic/MedtronicPumpStatus.java index e45e32a1a0..843e5a1887 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/medtronic/MedtronicPumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/medtronic/MedtronicPumpStatus.java @@ -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 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(); + } + + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpStatus.java index 8db42ba407..1e1acb6783 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpStatus.java @@ -22,4 +22,9 @@ public class VirtualPumpStatus extends PumpStatus { public String getErrorInfo() { return null; } + + @Override + public void refreshConfiguration() { + + } } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 7cd2a0a8ed..1418126e4b 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -148,8 +148,8 @@ - US - EU + @string/medtronic_pump_frequency_us + @string/medtronic_pump_frequency_worldwide diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4bd563c795..0818134d49 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1062,6 +1062,8 @@ Pump Serial Number Pump Type Pump Frequency + Max Bolus on Pump + Max Basal on Pump RileyLink MAC Address Errors Serial # not set. @@ -1071,6 +1073,8 @@ Pump Frequency not set. Pump Frequency unsupported. RileyLink Address invalid. + US (916 MHz) + Worldwide (868 Mhz) diff --git a/app/src/main/res/xml/pref_medtronic.xml b/app/src/main/res/xml/pref_medtronic.xml index f563c976b5..4d44fc3dc5 100644 --- a/app/src/main/res/xml/pref_medtronic.xml +++ b/app/src/main/res/xml/pref_medtronic.xml @@ -4,13 +4,6 @@ - - - - + + + + + + + +