Little bit of refactoring.

This commit is contained in:
Andy Rozman 2018-05-12 14:29:02 +01:00
parent f0e51c72a6
commit 7a388a5715
7 changed files with 152 additions and 152 deletions

View file

@ -1,28 +1,32 @@
package info.nightscout.androidaps.plugins.PumpCommon; package info.nightscout.androidaps.plugins.PumpCommon;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore; 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.TemporaryBasal;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.PumpCombo.ComboFragment;
import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus; import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus;
import info.nightscout.androidaps.plugins.PumpCommon.driver.PumpDriverInterface; import info.nightscout.androidaps.plugins.PumpCommon.driver.PumpDriverInterface;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
/** /**
* Created by andy on 23.04.18. * Created by andy on 23.04.18.
@ -30,26 +34,21 @@ import info.nightscout.androidaps.plugins.PumpCommon.driver.PumpDriverInterface;
public abstract class PumpPluginAbstract extends PluginBase implements PumpInterface, ConstraintsInterface { public abstract class PumpPluginAbstract extends PluginBase implements PumpInterface, ConstraintsInterface {
// , ProfileInterface private static final Logger LOG = LoggerFactory.getLogger(PumpPluginAbstract.class);
//protected boolean fragmentVisible = false;
//protected boolean fragmentEnabled = false;
protected boolean pumpServiceRunning = false; protected boolean pumpServiceRunning = false;
//private static final String TAG = "PumpPluginAbstract";
//protected PumpStatus pumpStatus;
protected static PumpPluginAbstract plugin = null; protected static PumpPluginAbstract plugin = null;
protected PumpDriverInterface pumpDriver; protected PumpDriverInterface pumpDriver;
protected PumpStatus pumpStatus; protected PumpStatus pumpStatus;
protected String internalName;
protected PumpPluginAbstract(PumpDriverInterface pumpDriverInterface, // protected PumpPluginAbstract(PumpDriverInterface pumpDriverInterface, //
String internalName, // String internalName, //
String fragmentClassName, // String fragmentClassName, //
int pluginName, // int pluginName, //
int pluginShortName) int pluginShortName) {
{
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.PUMP) .mainType(PluginType.PUMP)
.fragmentClass(fragmentClassName) .fragmentClass(fragmentClassName)
@ -59,55 +58,25 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
this.pumpDriver = pumpDriverInterface; this.pumpDriver = pumpDriverInterface;
this.pumpStatus = this.pumpDriver.getPumpStatusData(); this.pumpStatus = this.pumpDriver.getPumpStatusData();
this.internalName = internalName;
} }
protected String getInternalName() {
return this.internalName;
}
// @Override
// public boolean isVisibleInTabs(int type) {
// return type == PUMP && fragmentVisible;
// }
//
//
// @Override
// public boolean canBeHidden(int type) {
// return true;
// }
//
//
//
// @Override
// public boolean showInList(int type) {
// return type == PUMP;
// }
// @Override
// public void setFragmentVisible(int type, boolean fragmentVisible) {
// if (type == PUMP)
// this.fragmentVisible = fragmentVisible;
// }
protected abstract String getInternalName();
protected abstract void startPumpService(); protected abstract void startPumpService();
protected abstract void stopPumpService(); protected abstract void stopPumpService();
public PumpStatus getPumpStatusData() public PumpStatus getPumpStatusData() {
{
return pumpDriver.getPumpStatusData(); return pumpDriver.getPumpStatusData();
} }
public boolean isInitialized() public boolean isInitialized() {
{
return pumpDriver.isInitialized(); return pumpDriver.isInitialized();
} }
@ -171,7 +140,6 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
} // base basal rate, not temp basal } // base basal rate, not temp basal
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
return pumpDriver.deliverTreatment(detailedBolusInfo); return pumpDriver.deliverTreatment(detailedBolusInfo);
} }
@ -182,7 +150,6 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
} }
@Override @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
return pumpDriver.setTempBasalAbsolute(absoluteRate, durationInMinutes, profile, enforceNew); return pumpDriver.setTempBasalAbsolute(absoluteRate, durationInMinutes, profile, enforceNew);
@ -213,9 +180,9 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
// Status to be passed to NS // Status to be passed to NS
public JSONObject getJSONStatus(Profile profile, String profileName){ // public JSONObject getJSONStatus(Profile profile, String profileName) {
return pumpDriver.getJSONStatus( profile, profileName); // return pumpDriver.getJSONStatus(profile, profileName);
} // }
public String deviceID() { public String deviceID() {
@ -237,12 +204,16 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
} }
public boolean isFakingTempsByExtendedBoluses() { public boolean isFakingTempsByExtendedBoluses() {
return pumpDriver.isInitialized(); return pumpDriver.isInitialized();
} }
@Override
public PumpEnactResult loadTDDs() {
return this.pumpDriver.loadTDDs();
}
// Constraints interface // Constraints interface
// @Override // @Override
@ -300,28 +271,73 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
// return maxIob; // return maxIob;
// } // }
@Override
public JSONObject getJSONStatus(Profile profile, String profileName) {
//if (!SP.getBoolean("virtualpump_uploadstatus", false)) {
// return null;
//}
long now = System.currentTimeMillis();
if ((pumpStatus.lastConnection + 5 * 60 * 1000L) < System.currentTimeMillis()) {
return null;
}
JSONObject pump = new JSONObject();
JSONObject battery = new JSONObject();
JSONObject status = new JSONObject();
JSONObject extended = new JSONObject();
try {
battery.put("percent", pumpStatus.batteryRemaining);
status.put("status", pumpStatus.pumpStatusType != null ? pumpStatus.pumpStatusType.getStatus() : "normal");
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
try {
extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName());
} catch (Exception e) {
}
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
if (tb != null) {
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile));
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
}
ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate());
extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date));
extended.put("ExtendedBolusRemaining", eb.getPlannedRemainingMinutes());
}
status.put("timestamp", DateUtil.toISOString(new Date()));
pump.put("battery", battery);
pump.put("status", status);
pump.put("extended", extended);
pump.put("reservoir", pumpStatus.reservoirRemainingUnits);
pump.put("clock", DateUtil.toISOString(new Date()));
} catch (JSONException e) {
LOG.error("Unhandled exception", e);
}
return pump;
}
// Profile interface // Profile interface
@Nullable @Nullable
public ProfileStore getProfile() public ProfileStore getProfile() {
{
return this.pumpStatus.profileStore; return this.pumpStatus.profileStore;
} }
public String getUnits() public String getUnits() {
{
return this.pumpStatus.units; return this.pumpStatus.units;
} }
public String getProfileName() public String getProfileName() {
{
return this.pumpStatus.activeProfileName; return this.pumpStatus.activeProfileName;
} }
@Override
public PumpEnactResult loadTDDs() {
return this.pumpDriver.loadTDDs();
}
} }

View file

@ -4,6 +4,7 @@ import java.util.Date;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpStatusType;
/** /**
* Created by andy on 4/28/18. * Created by andy on 4/28/18.
@ -17,14 +18,16 @@ public abstract class PumpStatus {
public String activeProfileName = "0"; public String activeProfileName = "0";
public double reservoirRemainingUnits = 0d; public double reservoirRemainingUnits = 0d;
public String reservoirFullUnits = "???"; public String reservoirFullUnits = "???";
public double batteryRemaining = 0d; public int batteryRemaining = 0; // percent, so 0-100
public String iob = "0"; public String iob = "0";
protected PumpDescription pumpDescription; protected PumpDescription pumpDescription;
public boolean validBasalRateProfileSelectedOnPump = true; public boolean validBasalRateProfileSelectedOnPump = true;
public ProfileStore profileStore; public ProfileStore profileStore;
public String units; // Constants.MGDL or Constants.MMOL public String units; // Constants.MGDL or Constants.MMOL
public PumpStatusType pumpStatusType = PumpStatusType.Running;
// TODO maybe not needed anymore in 2.0
public Double constraintBasalRateAbsolute; public Double constraintBasalRateAbsolute;
public Integer constraintBasalRatePercent; public Integer constraintBasalRatePercent;
public Double constraintBolus; public Double constraintBolus;
@ -32,10 +35,7 @@ public abstract class PumpStatus {
public Double constraintMaxIob; public Double constraintMaxIob;
public PumpStatus(PumpDescription pumpDescription) {
public PumpStatus(PumpDescription pumpDescription)
{
this.pumpDescription = pumpDescription; this.pumpDescription = pumpDescription;
this.initSettings(); this.initSettings();

View file

@ -0,0 +1,21 @@
package info.nightscout.androidaps.plugins.PumpCommon.defs;
/**
* Created by andy on 5/12/18.
*/
public enum PumpStatusType {
Running("normal"), //
Suspended("suspended") //
;
private String statusString;
PumpStatusType(String statusString) {
this.statusString = statusString;
}
public String getStatus() {
return statusString;
}
}

View file

@ -33,7 +33,6 @@ import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog; import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity; import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.events.EventQueueChanged; import info.nightscout.androidaps.queue.events.EventQueueChanged;
@ -81,14 +80,14 @@ public class MedtronicFragment extends SubscriberFragment {
TextView errorsView; TextView errorsView;
@BindView(R.id.medtronic_queue) @BindView(R.id.medtronic_queue)
TextView queueView; TextView queueView;
@BindView(R.id.overview_pumpstatuslayout) @BindView(R.id.overview_pumpstatuslayout)
LinearLayout pumpStatusLayout; LinearLayout pumpStatusLayout;
@BindView(R.id.overview_pumpstatus) TextView pumpStatusView; @BindView(R.id.overview_pumpstatus)
TextView pumpStatusView;
public MedtronicFragment() { public MedtronicFragment() {
} }
@ -241,10 +240,6 @@ public class MedtronicFragment extends SubscriberFragment {
} }
} }
reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / " + pump.reservoirFullUnits + " U"); reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / " + pump.reservoirFullUnits + " U");
SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d); SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d);
batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}"); batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}");

View file

@ -15,7 +15,7 @@ import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.PumpCommon.PumpPluginAbstract; import info.nightscout.androidaps.plugins.PumpCommon.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.PumpMedtronic.medtronic.MedtronicPumpDriver; import info.nightscout.androidaps.plugins.PumpMedtronic.driver.MedtronicPumpDriver;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
@ -48,12 +48,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} }
@Override
protected String getInternalName() {
return "MedtronicPump";
}
@Override @Override
protected void startPumpService() { protected void startPumpService() {

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.medtronic; package info.nightscout.androidaps.plugins.PumpMedtronic.driver;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -10,8 +10,6 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal; 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.PumpCommon.utils.PumpUtil;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpDriver; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpDriver;
import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui; import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui;
@ -26,8 +24,7 @@ public class MedtronicPumpDriver extends VirtualPumpDriver /*implements PumpInte
private static final Logger LOG = LoggerFactory.getLogger(MedtronicPumpDriver.class); private static final Logger LOG = LoggerFactory.getLogger(MedtronicPumpDriver.class);
MedtronicPumpStatus pumpStatusLocal; MedtronicPumpStatus pumpStatusLocal;
public MedtronicPumpDriver() public MedtronicPumpDriver() {
{
pumpStatusLocal = new MedtronicPumpStatus(pumpDescription); pumpStatusLocal = new MedtronicPumpStatus(pumpDescription);
pumpStatusLocal.verifyConfiguration(); pumpStatusLocal.verifyConfiguration();
@ -71,8 +68,7 @@ public class MedtronicPumpDriver extends VirtualPumpDriver /*implements PumpInte
@Override @Override
public PumpEnactResult cancelTempBasal(boolean enforceNew) public PumpEnactResult cancelTempBasal(boolean enforceNew) {
{
// FIXME // FIXME
// send Cancel Temp Basal // send Cancel Temp Basal
@ -104,10 +100,4 @@ public class MedtronicPumpDriver extends VirtualPumpDriver /*implements PumpInte
} }
} }

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.medtronic; package info.nightscout.androidaps.plugins.PumpMedtronic.driver;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -11,7 +11,6 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus; import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpMedtronic.medtronic.defs.MedtronicPumpType;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
/** /**
@ -24,14 +23,6 @@ public class MedtronicPumpStatus extends PumpStatus {
//private static MedtronicPumpStatus medtronicPumpStatus = new MedtronicPumpStatus(); //private static MedtronicPumpStatus medtronicPumpStatus = new MedtronicPumpStatus();
private static Logger LOG = LoggerFactory.getLogger(MedtronicPumpStatus.class); private static Logger LOG = LoggerFactory.getLogger(MedtronicPumpStatus.class);
//public Date lastDataTime;
//public long lastConnection = 0L;
//public Date lastBolusTime;
//public String activeProfileName = "A";
//public double reservoirRemainingUnits = 50d;
//public double batteryRemaining = 75d;
//public String iob = "0";
public String errorDescription = null; public String errorDescription = null;
public String serialNumber; public String serialNumber;
public PumpType pumpType = null; public PumpType pumpType = null;
@ -48,8 +39,7 @@ public class MedtronicPumpStatus extends PumpStatus {
private Map<String, PumpType> medtronicPumpMap = null; private Map<String, PumpType> medtronicPumpMap = null;
public MedtronicPumpStatus(PumpDescription pumpDescription) public MedtronicPumpStatus(PumpDescription pumpDescription) {
{
super(pumpDescription); super(pumpDescription);
} }
@ -59,7 +49,7 @@ public class MedtronicPumpStatus extends PumpStatus {
this.activeProfileName = "STD"; this.activeProfileName = "STD";
this.reservoirRemainingUnits = 75d; this.reservoirRemainingUnits = 75d;
this.batteryRemaining = 75d; this.batteryRemaining = 75;
if (this.medtronicPumpMap == null) if (this.medtronicPumpMap == null)
createMedtronicPumpMap(); createMedtronicPumpMap();
@ -86,8 +76,7 @@ public class MedtronicPumpStatus extends PumpStatus {
} }
public void verifyConfiguration() public void verifyConfiguration() {
{
try { try {
if (this.medtronicPumpMap == null) if (this.medtronicPumpMap == null)
@ -174,8 +163,7 @@ public class MedtronicPumpStatus extends PumpStatus {
maxBolus = Integer.parseInt(value); maxBolus = Integer.parseInt(value);
if (maxBolus> 25) if (maxBolus > 25) {
{
SP.putString("pref_medtronic_max_bolus", "25"); SP.putString("pref_medtronic_max_bolus", "25");
} }
@ -183,22 +171,18 @@ public class MedtronicPumpStatus extends PumpStatus {
maxBasal = Integer.parseInt(value); maxBasal = Integer.parseInt(value);
if (maxBasal> 35) if (maxBasal > 35) {
{
SP.putString("pref_medtronic_max_basal", "35"); SP.putString("pref_medtronic_max_basal", "35");
} }
} } catch (Exception ex) {
catch(Exception ex)
{
this.errorDescription = ex.getMessage(); this.errorDescription = ex.getMessage();
LOG.error("Error on Verification: " + ex.getMessage(), ex); LOG.error("Error on Verification: " + ex.getMessage(), ex);
} }
} }
public String getErrorInfo() public String getErrorInfo() {
{
verifyConfiguration(); verifyConfiguration();
return (this.errorDescription == null) ? "-" : this.errorDescription; return (this.errorDescription == null) ? "-" : this.errorDescription;