synchronize danar and danarkorean plugins

This commit is contained in:
Milos Kozak 2017-05-26 13:28:27 +02:00
parent 4b39578d9c
commit b8b9827b61
6 changed files with 87 additions and 99 deletions

View file

@ -211,7 +211,7 @@ public class DanaRFragment extends Fragment {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
@Override @Override
public void run() { public void run() {
DanaRPump pump = DanaRPlugin.getDanaRPump(); DanaRPump pump = DanaRPump.getInstance();
if (pump.lastConnection.getTime() != 0) { if (pump.lastConnection.getTime() != 0) {
Long agoMsec = new Date().getTime() - pump.lastConnection.getTime(); Long agoMsec = new Date().getTime() - pump.lastConnection.getTime();
int agoMin = (int) (agoMsec / 60d / 1000d); int agoMin = (int) (agoMsec / 60d / 1000d);
@ -222,7 +222,7 @@ public class DanaRFragment extends Fragment {
Long agoMsec = new Date().getTime() - pump.lastBolusTime.getTime(); Long agoMsec = new Date().getTime() - pump.lastBolusTime.getTime();
double agoHours = agoMsec / 60d / 60d / 1000d; double agoHours = agoMsec / 60d / 60d / 1000d;
if (agoHours < 6) // max 6h back if (agoHours < 6) // max 6h back
lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(getPlugin().getDanaRPump().lastBolusAmount) + " U"); lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U");
else lastBolusView.setText(""); else lastBolusView.setText("");
} }

View file

@ -41,7 +41,6 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService; import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
@ -65,15 +64,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
public static DanaRExecutionService sExecutionService; public static DanaRExecutionService sExecutionService;
private static DanaRPump sDanaRPump = DanaRPump.getInstance(); private static DanaRPump pump = DanaRPump.getInstance();
private static boolean useExtendedBoluses = false; private static boolean useExtendedBoluses = false;
public static PumpDescription pumpDescription = new PumpDescription(); public static PumpDescription pumpDescription = new PumpDescription();
public static DanaRPump getDanaRPump() {
return sDanaRPump;
}
public DanaRPlugin() { public DanaRPlugin() {
useExtendedBoluses = SP.getBoolean("danar_useextended", false); useExtendedBoluses = SP.getBoolean("danar_useextended", false);
@ -157,7 +152,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public String getNameShort() { public String getNameShort() {
String name = MainApp.sResources.getString(R.string.danarpump_shortname); String name = MainApp.sResources.getString(R.string.danarpump_shortname);
if (!name.trim().isEmpty()){ if (!name.trim().isEmpty()) {
//only if translation exists //only if translation exists
return name; return name;
} }
@ -223,12 +218,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
return getDanaRPump().lastConnection.getTime() > 0 && getDanaRPump().isExtendedBolusEnabled; return pump.lastConnection.getTime() > 0 && pump.isExtendedBolusEnabled;
} }
@Override @Override
public boolean isSuspended() { public boolean isSuspended() {
return getDanaRPump().pumpSuspended; return pump.pumpSuspended;
} }
@Override @Override
@ -267,7 +262,6 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
public boolean isThisProfileSet(NSProfile profile) { public boolean isThisProfileSet(NSProfile profile) {
if (!isInitialized()) if (!isInitialized())
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
DanaRPump pump = getDanaRPump();
if (pump.pumpProfiles == null) if (pump.pumpProfiles == null)
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
int basalValues = pump.basal48Enable ? 48 : 24; int basalValues = pump.basal48Enable ? 48 : 24;
@ -286,7 +280,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public Date lastDataTime() { public Date lastDataTime() {
return getDanaRPump().lastConnection; return pump.lastConnection;
} }
@Override @Override
@ -298,7 +292,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public double getBaseBasalRate() { public double getBaseBasalRate() {
return getDanaRPump().currentBasal; return pump.currentBasal;
} }
@Override @Override
@ -341,7 +335,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) { public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
// Recheck pump status if older than 30 min // Recheck pump status if older than 30 min
if (getDanaRPump().lastConnection.getTime() + 30 * 60 * 1000L < new Date().getTime()) { if (pump.lastConnection.getTime() + 30 * 60 * 1000L < new Date().getTime()) {
doConnect("setTempBasalAbsolute old data"); doConnect("setTempBasalAbsolute old data");
} }
@ -398,7 +392,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
// Check if some temp is already in progress // Check if some temp is already in progress
if (MainApp.getConfigBuilder().isRealTempBasalInProgress()) { if (MainApp.getConfigBuilder().isRealTempBasalInProgress()) {
// Correct basal already set ? // Correct basal already set ?
if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percentRate == percentRate) { if (MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).percentRate == percentRate) {
result.success = true; result.success = true;
result.percent = percentRate; result.percent = percentRate;
result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRate(); result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRate();
@ -448,17 +442,17 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
// What is current rate of extended bolusing in u/h? // What is current rate of extended bolusing in u/h?
if (Config.logPumpActions) { if (Config.logPumpActions) {
log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isExtendedBoluslInProgress() + " rate: " + getDanaRPump().extendedBolusAbsoluteRate + "U/h duration remaining: " + getDanaRPump().extendedBolusRemainingMinutes + "min"); log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isExtendedBoluslInProgress() + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h"); log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
} }
// Compare with extended rate in progress // Compare with extended rate in progress
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && Math.abs(getDanaRPump().extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
// correct extended already set // correct extended already set
result.success = true; result.success = true;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate; result.absolute = pump.extendedBolusAbsoluteRate;
result.enacted = false; result.enacted = false;
result.duration = getDanaRPump().extendedBolusRemainingMinutes; result.duration = pump.extendedBolusRemainingMinutes;
result.isPercent = false; result.isPercent = false;
result.isTempCancel = false; result.isTempCancel = false;
if (Config.logPumpActions) if (Config.logPumpActions)
@ -501,14 +495,15 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
log.error("setTempBasalPercent: Invalid input"); log.error("setTempBasalPercent: Invalid input");
return result; return result;
} }
if (percent > getPumpDescription().maxHighTempPercent) percent = getPumpDescription().maxHighTempPercent; if (percent > getPumpDescription().maxHighTempPercent)
if (getDanaRPump().isTempBasalInProgress && getDanaRPump().tempBasalPercent == percent) { percent = getPumpDescription().maxHighTempPercent;
if (pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
result.isTempCancel = false; result.isTempCancel = false;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.duration = getDanaRPump().tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = getDanaRPump().tempBasalPercent; result.percent = pump.tempBasalPercent;
result.isPercent = true; result.isPercent = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalPercent: Correct value already set"); log.debug("setTempBasalPercent: Correct value already set");
@ -516,13 +511,13 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
int durationInHours = Math.max(durationInMinutes / 60, 1); int durationInHours = Math.max(durationInMinutes / 60, 1);
boolean connectionOK = sExecutionService.tempBasal(percent, durationInHours); boolean connectionOK = sExecutionService.tempBasal(percent, durationInHours);
if (connectionOK && getDanaRPump().isTempBasalInProgress && getDanaRPump().tempBasalPercent == percent) { if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
result.enacted = true; result.enacted = true;
result.success = true; result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.isTempCancel = false; result.isTempCancel = false;
result.duration = getDanaRPump().tempBasalRemainingMin; result.duration = pump.tempBasalRemainingMin;
result.percent = getDanaRPump().tempBasalPercent; result.percent = pump.tempBasalPercent;
result.isPercent = true; result.isPercent = true;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalPercent: OK"); log.debug("setTempBasalPercent: OK");
@ -543,28 +538,28 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep); insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (getDanaRPump().isExtendedInProgress && Math.abs(getDanaRPump().extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) { if (pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
result.enacted = false; result.enacted = false;
result.success = true; result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.duration = getDanaRPump().extendedBolusRemainingMinutes; result.duration = pump.extendedBolusRemainingMinutes;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate; result.absolute = pump.extendedBolusAbsoluteRate;
result.isPercent = false; result.isPercent = false;
result.isTempCancel = false; result.isTempCancel = false;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + getDanaRPump().extendedBolusAmount + " Asked: " + insulin); log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin);
return result; return result;
} }
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
boolean connectionOK = sExecutionService.extendedBolus(insulin, durationInHalfHours); boolean connectionOK = sExecutionService.extendedBolus(insulin, durationInHalfHours);
if (connectionOK && getDanaRPump().isExtendedInProgress && Math.abs(getDanaRPump().extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) { if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
result.enacted = true; result.enacted = true;
result.success = true; result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
result.isTempCancel = false; result.isTempCancel = false;
result.duration = getDanaRPump().extendedBolusRemainingMinutes; result.duration = pump.extendedBolusRemainingMinutes;
result.absolute = getDanaRPump().extendedBolusAbsoluteRate; result.absolute = pump.extendedBolusAbsoluteRate;
result.bolusDelivered = getDanaRPump().extendedBolusAmount; result.bolusDelivered = pump.extendedBolusAmount;
result.isPercent = false; result.isPercent = false;
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setExtendedBolus: OK"); log.debug("setExtendedBolus: OK");
@ -596,12 +591,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
public PumpEnactResult cancelRealTempBasal() { public PumpEnactResult cancelRealTempBasal() {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (getDanaRPump().isTempBasalInProgress) { if (pump.isTempBasalInProgress) {
sExecutionService.tempBasalStop(); sExecutionService.tempBasalStop();
result.enacted = true; result.enacted = true;
result.isTempCancel = true; result.isTempCancel = true;
} }
if (!getDanaRPump().isTempBasalInProgress) { if (!pump.isTempBasalInProgress) {
result.success = true; result.success = true;
result.isTempCancel = true; result.isTempCancel = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
@ -620,12 +615,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public PumpEnactResult cancelExtendedBolus() { public PumpEnactResult cancelExtendedBolus() {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (getDanaRPump().isExtendedInProgress) { if (pump.isExtendedInProgress) {
sExecutionService.extendedBolusStop(); sExecutionService.extendedBolusStop();
result.enacted = true; result.enacted = true;
result.isTempCancel = true; result.isTempCancel = true;
} }
if (!getDanaRPump().isExtendedInProgress) { if (!pump.isExtendedInProgress) {
result.success = true; result.success = true;
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
if (Config.logPumpActions) if (Config.logPumpActions)
@ -657,21 +652,23 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public JSONObject getJSONStatus() { public JSONObject getJSONStatus() {
if (getDanaRPump().lastConnection.getTime() + 5 * 60 * 1000L < new Date().getTime()) { if (pump.lastConnection.getTime() + 5 * 60 * 1000L < new Date().getTime()) {
return null; return null;
} }
JSONObject pump = new JSONObject(); JSONObject pumpjson = new JSONObject();
JSONObject battery = new JSONObject(); JSONObject battery = new JSONObject();
JSONObject status = new JSONObject(); JSONObject status = new JSONObject();
JSONObject extended = new JSONObject(); JSONObject extended = new JSONObject();
try { try {
battery.put("percent", getDanaRPump().batteryRemaining); battery.put("percent", pump.batteryRemaining);
status.put("status", getDanaRPump().pumpSuspended ? "suspended" : "normal"); status.put("status", pump.pumpSuspended ? "suspended" : "normal");
status.put("timestamp", DateUtil.toISOString(getDanaRPump().lastConnection)); status.put("timestamp", DateUtil.toISOString(pump.lastConnection));
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
extended.put("PumpIOB", getDanaRPump().iob); extended.put("PumpIOB", pump.iob);
extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString()); if (pump.lastBolusTime.getTime() != 0) {
extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
extended.put("LastBolusAmount", pump.lastBolusAmount);
}
TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()); TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime());
if (tb != null) { if (tb != null) {
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(new Date().getTime())); extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(new Date().getTime()));
@ -690,20 +687,20 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} catch (Exception e) { } catch (Exception e) {
} }
pump.put("battery", battery); pumpjson.put("battery", battery);
pump.put("status", status); pumpjson.put("status", status);
pump.put("extended", extended); pumpjson.put("extended", extended);
pump.put("reservoir", (int) getDanaRPump().reservoirRemainingUnits); pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits);
pump.put("clock", DateUtil.toISOString(new Date())); pumpjson.put("clock", DateUtil.toISOString(new Date()));
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
return pump; return pumpjson;
} }
@Override @Override
public String deviceID() { public String deviceID() {
return getDanaRPump().serialNumber; return pump.serialNumber;
} }
@Override @Override
@ -739,9 +736,9 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public Double applyBasalConstraints(Double absoluteRate) { public Double applyBasalConstraints(Double absoluteRate) {
double origAbsoluteRate = absoluteRate; double origAbsoluteRate = absoluteRate;
if (getDanaRPump() != null) { if (pump != null) {
if (absoluteRate > getDanaRPump().maxBasal) { if (absoluteRate > pump.maxBasal) {
absoluteRate = getDanaRPump().maxBasal; absoluteRate = pump.maxBasal;
if (Config.logConstraintsChanges && origAbsoluteRate != Constants.basalAbsoluteOnlyForCheckLimit) if (Config.logConstraintsChanges && origAbsoluteRate != Constants.basalAbsoluteOnlyForCheckLimit)
log.debug("Limiting rate " + origAbsoluteRate + "U/h by pump constraint to " + absoluteRate + "U/h"); log.debug("Limiting rate " + origAbsoluteRate + "U/h by pump constraint to " + absoluteRate + "U/h");
} }
@ -754,7 +751,8 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
public Integer applyBasalConstraints(Integer percentRate) { public Integer applyBasalConstraints(Integer percentRate) {
Integer origPercentRate = percentRate; Integer origPercentRate = percentRate;
if (percentRate < 0) percentRate = 0; if (percentRate < 0) percentRate = 0;
if (percentRate > getPumpDescription().maxHighTempPercent) percentRate = getPumpDescription().maxHighTempPercent; if (percentRate > getPumpDescription().maxHighTempPercent)
percentRate = getPumpDescription().maxHighTempPercent;
if (!Objects.equals(percentRate, origPercentRate) && Config.logConstraintsChanges && !Objects.equals(origPercentRate, Constants.basalPercentOnlyForCheckLimit)) if (!Objects.equals(percentRate, origPercentRate) && Config.logConstraintsChanges && !Objects.equals(origPercentRate, Constants.basalPercentOnlyForCheckLimit))
log.debug("Limiting percent rate " + origPercentRate + "% to " + percentRate + "%"); log.debug("Limiting percent rate " + origPercentRate + "% to " + percentRate + "%");
return percentRate; return percentRate;
@ -764,9 +762,9 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public Double applyBolusConstraints(Double insulin) { public Double applyBolusConstraints(Double insulin) {
double origInsulin = insulin; double origInsulin = insulin;
if (getDanaRPump() != null) { if (pump != null) {
if (insulin > getDanaRPump().maxBolus) { if (insulin > pump.maxBolus) {
insulin = getDanaRPump().maxBolus; insulin = pump.maxBolus;
if (Config.logConstraintsChanges && origInsulin != Constants.bolusOnlyForCheckLimit) if (Config.logConstraintsChanges && origInsulin != Constants.bolusOnlyForCheckLimit)
log.debug("Limiting bolus " + origInsulin + "U by pump constraint to " + insulin + "U"); log.debug("Limiting bolus " + origInsulin + "U by pump constraint to " + insulin + "U");
} }
@ -787,7 +785,6 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Nullable @Nullable
@Override @Override
public NSProfile getProfile() { public NSProfile getProfile() {
DanaRPump pump = getDanaRPump();
if (pump.lastSettingsRead.getTime() == 0) if (pump.lastSettingsRead.getTime() == 0)
return null; // no info now return null; // no info now
return pump.createConvertedProfile(); return pump.createConvertedProfile();
@ -796,13 +793,13 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
// Reply for sms communicator // Reply for sms communicator
public String shortStatus(boolean veryShort) { public String shortStatus(boolean veryShort) {
String ret = ""; String ret = "";
if (getDanaRPump().lastConnection.getTime() != 0) { if (pump.lastConnection.getTime() != 0) {
Long agoMsec = new Date().getTime() - getDanaRPump().lastConnection.getTime(); Long agoMsec = new Date().getTime() - pump.lastConnection.getTime();
int agoMin = (int) (agoMsec / 60d / 1000d); int agoMin = (int) (agoMsec / 60d / 1000d);
ret += "LastConn: " + agoMin + " minago\n"; ret += "LastConn: " + agoMin + " minago\n";
} }
if (getDanaRPump().lastBolusTime.getTime() != 0) { if (pump.lastBolusTime.getTime() != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n"; ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
} }
if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString() + "\n"; ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString() + "\n";
@ -810,15 +807,14 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString() + "\n"; ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString() + "\n";
} }
if (!veryShort){ if (!veryShort) {
ret += "TDD: " + DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U\n"; ret += "TDD: " + DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U\n";
} }
ret += "IOB: " + getDanaRPump().iob + "U\n"; ret += "IOB: " + pump.iob + "U\n";
ret += "Reserv: " + DecimalFormatter.to0Decimal(getDanaRPump().reservoirRemainingUnits) + "U\n"; ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + "U\n";
ret += "Batt: " + getDanaRPump().batteryRemaining + "\n"; ret += "Batt: " + pump.batteryRemaining + "\n";
return ret; return ret;
} }
// TODO: daily total constraint // TODO: daily total constraint
} }

View file

@ -19,6 +19,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
/** /**
@ -72,7 +73,7 @@ public class ProfileViewDialog extends DialogFragment {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
DanaRPlugin.getDanaRPump().lastSettingsRead = new Date(0); DanaRPump.getInstance().lastSettingsRead = new Date(0);
DanaRPlugin.doConnect("ProfileViewDialog"); DanaRPlugin.doConnect("ProfileViewDialog");
} }
}); });

View file

@ -177,7 +177,7 @@ public class SerialIOThread extends Thread {
if (!message.received) { if (!message.received) {
log.warn("Reply not received " + message.getMessageName()); log.warn("Reply not received " + message.getMessageName());
if (message.getCommand() == 0xF0F1) { if (message.getCommand() == 0xF0F1) {
DanaRPlugin.getDanaRPump().isNewPump = false; DanaRPump.getInstance().isNewPump = false;
log.debug("Old firmware detected"); log.debug("Old firmware detected");
} }
} }

View file

@ -124,7 +124,7 @@ public class DanaRExecutionService extends Service {
public DanaRExecutionService() { public DanaRExecutionService() {
registerBus(); registerBus();
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED)); MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
danaRPump = DanaRPlugin.getDanaRPump(); danaRPump = DanaRPump.getInstance();
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE); PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRExecutionService"); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRExecutionService");

View file

@ -42,7 +42,6 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
@ -237,13 +236,6 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
} }
// Pump interface // Pump interface
public boolean isTempBasalInProgress() {
if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()) != null) return true;
if (MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()) != null && useExtendedBoluses)
return true;
return false;
}
@Override @Override
public int setNewBasalProfile(NSProfile profile) { public int setNewBasalProfile(NSProfile profile) {
if (sExecutionService == null) { if (sExecutionService == null) {
@ -280,6 +272,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
for (int h = 0; h < basalValues; h++) { for (int h = 0; h < basalValues; h++) {
Double pumpValue = pump.pumpProfiles[pump.activeProfile][h]; Double pumpValue = pump.pumpProfiles[pump.activeProfile][h];
Double profileValue = profile.getBasal(h * basalIncrement); Double profileValue = profile.getBasal(h * basalIncrement);
if (profileValue == null) return true;
if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) { if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) {
log.debug("Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue); log.debug("Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue);
return false; return false;
@ -305,14 +298,6 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
return pump.currentBasal; return pump.currentBasal;
} }
public TemporaryBasal getTempBasal(long time) {
TemporaryBasal temp = MainApp.getConfigBuilder().getTempBasal(time);
if (temp != null) return temp;
if (useExtendedBoluses)
return new TemporaryBasal(MainApp.getConfigBuilder().getExtendedBolus(time));
return null;
}
@Override @Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
@ -490,6 +475,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Extended bolus set ok"); log.debug("setTempBasalAbsolute: Extended bolus set ok");
result.absolute = result.absolute + getBaseBasalRate(); result.absolute = result.absolute + getBaseBasalRate();
result.originalExtendedAmount = extendedAmount;
return result; return result;
} }
// We should never end here // We should never end here
@ -593,8 +579,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
public PumpEnactResult cancelTempBasal() { public PumpEnactResult cancelTempBasal() {
if (MainApp.getConfigBuilder().isRealTempBasalInProgress()) if (MainApp.getConfigBuilder().isRealTempBasalInProgress())
return cancelRealTempBasal(); return cancelRealTempBasal();
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) {
return cancelExtendedBolus(); PumpEnactResult cancelEx = cancelExtendedBolus();
cancelEx.isFakedTempBasal = true;
return cancelEx;
}
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = true; result.success = true;
result.enacted = false; result.enacted = false;
@ -675,12 +664,14 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
JSONObject extended = new JSONObject(); JSONObject extended = new JSONObject();
try { try {
battery.put("percent", pump.batteryRemaining); battery.put("percent", pump.batteryRemaining);
status.put("status", "normal"); status.put("status", pump.pumpSuspended ? "suspended" : "normal");
status.put("timestamp", DateUtil.toISOString(pump.lastConnection)); status.put("timestamp", DateUtil.toISOString(pump.lastConnection));
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
extended.put("PumpIOB", pump.iob); extended.put("PumpIOB", pump.iob);
// extended.put("LastBolus", pump.lastBolusTime.toLocaleString()); if (pump.lastBolusTime.getTime() != 0) {
// extended.put("LastBolusAmount", pump.lastBolusAmount); extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
extended.put("LastBolusAmount", pump.lastBolusAmount);
}
TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()); TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime());
if (tb != null) { if (tb != null) {
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(new Date().getTime())); extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(new Date().getTime()));
@ -810,9 +801,9 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
int agoMin = (int) (agoMsec / 60d / 1000d); int agoMin = (int) (agoMsec / 60d / 1000d);
ret += "LastConn: " + agoMin + " minago\n"; ret += "LastConn: " + agoMin + " minago\n";
} }
// if (pump.lastBolusTime.getTime() != 0) { if (pump.lastBolusTime.getTime() != 0) {
// ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n"; ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
// } }
if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString() + "\n"; ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString() + "\n";
} }