RS synchronized change
This commit is contained in:
parent
e545f75d69
commit
01d6f1594a
1 changed files with 33 additions and 11 deletions
|
@ -49,6 +49,7 @@ import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.Round;
|
import info.nightscout.utils.Round;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
@ -218,7 +219,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
connect(from);
|
connect(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void connect(String from) {
|
public static void connect(String from) {
|
||||||
log.debug("RS connect from: " + from);
|
log.debug("RS connect from: " + from);
|
||||||
if (danaRSService != null && !mDeviceAddress.equals("") && !mDeviceName.equals("")) {
|
if (danaRSService != null && !mDeviceAddress.equals("") && !mDeviceName.equals("")) {
|
||||||
final Object o = new Object();
|
final Object o = new Object();
|
||||||
|
@ -375,7 +376,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int setNewBasalProfile(Profile profile) {
|
public synchronized int setNewBasalProfile(Profile profile) {
|
||||||
if (danaRSService == null) {
|
if (danaRSService == null) {
|
||||||
log.error("setNewBasalProfile sExecutionService is null");
|
log.error("setNewBasalProfile sExecutionService is null");
|
||||||
return FAILED;
|
return FAILED;
|
||||||
|
@ -426,7 +427,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshDataFromPump(String reason) {
|
public synchronized void refreshDataFromPump(String reason) {
|
||||||
log.debug("Refreshing data from pump");
|
log.debug("Refreshing data from pump");
|
||||||
if (!isConnected() && !isConnecting()) {
|
if (!isConnected() && !isConnecting()) {
|
||||||
connect(reason);
|
connect(reason);
|
||||||
|
@ -440,7 +441,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public synchronized PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||||
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
|
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
|
||||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
|
@ -504,7 +505,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
|
|
||||||
// This is called from APS
|
// This is called from APS
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
public synchronized PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||||
// Recheck pump status if older than 30 min
|
// Recheck pump status if older than 30 min
|
||||||
if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
connect("setTempBasalAbsolute old data");
|
connect("setTempBasalAbsolute old data");
|
||||||
|
@ -581,7 +582,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
|
public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||||
percent = configBuilderPlugin.applyBasalConstraints(percent);
|
percent = configBuilderPlugin.applyBasalConstraints(percent);
|
||||||
|
@ -632,7 +633,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PumpEnactResult setHighTempBasalPercent(Integer percent) {
|
public synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
connectIfNotConnected("hightempbasal");
|
connectIfNotConnected("hightempbasal");
|
||||||
boolean connectionOK = danaRSService.highTempBasal(percent);
|
boolean connectionOK = danaRSService.highTempBasal(percent);
|
||||||
|
@ -656,7 +657,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
public synchronized PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||||
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
||||||
// needs to be rounded
|
// needs to be rounded
|
||||||
|
@ -699,7 +700,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult cancelTempBasal(boolean force) {
|
public synchronized PumpEnactResult cancelTempBasal(boolean force) {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (runningTB != null) {
|
if (runningTB != null) {
|
||||||
|
@ -725,7 +726,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult cancelExtendedBolus() {
|
public synchronized PumpEnactResult cancelExtendedBolus() {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||||
if (runningEB != null) {
|
if (runningEB != null) {
|
||||||
|
@ -808,7 +809,28 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String shortStatus(boolean veryShort) {
|
public String shortStatus(boolean veryShort) {
|
||||||
return null;
|
String ret = "";
|
||||||
|
if (pump.lastConnection.getTime() != 0) {
|
||||||
|
Long agoMsec = System.currentTimeMillis() - pump.lastConnection.getTime();
|
||||||
|
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||||
|
ret += "LastConn: " + agoMin + " minago\n";
|
||||||
|
}
|
||||||
|
if (pump.lastBolusTime.getTime() != 0) {
|
||||||
|
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
|
||||||
|
}
|
||||||
|
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||||
|
ret += "Temp: " + MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull() + "\n";
|
||||||
|
}
|
||||||
|
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
||||||
|
ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString() + "\n";
|
||||||
|
}
|
||||||
|
if (!veryShort) {
|
||||||
|
ret += "TDD: " + DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U\n";
|
||||||
|
}
|
||||||
|
ret += "IOB: " + pump.iob + "U\n";
|
||||||
|
ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + "U\n";
|
||||||
|
ret += "Batt: " + pump.batteryRemaining + "\n";
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue