diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java
index 7f6d8e9627..1c5ee83834 100644
--- a/app/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java
+++ b/app/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java
@@ -7,5 +7,6 @@ import info.nightscout.androidaps.data.PumpEnactResult;
*/
public interface DanaRInterface {
- PumpEnactResult loadHistory(byte type);
+ PumpEnactResult loadHistory(byte type); // for history browser
+ PumpEnactResult loadEvents(); // events history to build treatments from
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java
index 2ad7974b89..403c80332f 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java
@@ -51,6 +51,7 @@ public class Notification {
public static final int TOAST_ALARM = 22;
public static final int WRONGBASALSTEP = 23;
public static final int BOLUS_DELIVERY_ERROR = 24;
+ public static final int WRONG_DRIVER = 24;
public int id;
public Date date;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java
index f4fa88711f..335d655913 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java
@@ -756,6 +756,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
return sExecutionService.loadHistory(type);
}
+ @Override
+ public PumpEnactResult loadEvents() {
+ return null; // no history, not needed
+ }
+
/**
* Constraint interface
*/
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgCheckValue.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgCheckValue.java
index 785e90650a..3f0c306940 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgCheckValue.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgCheckValue.java
@@ -31,8 +31,7 @@ public class MsgCheckValue extends MessageBase {
pump.protocol = intFromBuff(bytes, 1, 1);
pump.productCode = intFromBuff(bytes, 2, 1);
if (pump.model != DanaRPump.EXPORT_MODEL) {
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
- ((DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class)).disconnect("Wrong Model");
+ MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
log.debug("Wrong model selected");
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java
index 2b2667f92c..787051f6d4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java
@@ -8,8 +8,12 @@ import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.Overview.Notification;
+import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
@@ -25,8 +29,9 @@ public class MsgInitConnStatusTime extends MessageBase {
@Override
public void handleMessage(byte[] bytes) {
if (bytes.length - 10 > 7) {
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
- ((DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class)).disconnect("Wrong Model");
+ Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
+ MainApp.bus().post(new EventNewNotification(notification));
+ MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
log.debug("Wrong model selected. Switching to Korean DanaR");
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, true);
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true);
@@ -41,7 +46,8 @@ public class MsgInitConnStatusTime extends MessageBase {
}
MainApp.getConfigBuilder().storeSettings();
- MainApp.bus().post(new EventRefreshOverview("MsgInitConnStatusTime"));
+ MainApp.bus().post(new EventRefreshGui());
+ ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
return;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java
index e7b1cf6b91..2070444f96 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java
@@ -758,6 +758,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
return sExecutionService.loadHistory(type);
}
+ @Override
+ public PumpEnactResult loadEvents() {
+ return null; // no history, not needed
+ }
+
/**
* Constraint interface
*/
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgCheckValue_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgCheckValue_k.java
index f048c07f20..684fa30997 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgCheckValue_k.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgCheckValue_k.java
@@ -32,7 +32,6 @@ public class MsgCheckValue_k extends MessageBase {
pump.protocol = intFromBuff(bytes, 1, 1);
pump.productCode = intFromBuff(bytes, 2, 1);
if (pump.model != DanaRPump.DOMESTIC_MODEL) {
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
log.debug("Wrong model selected");
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java
index c72be877d4..3bfd08c64d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java
@@ -8,8 +8,11 @@ import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.events.EventRefreshOverview;
+import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.Overview.Notification;
+import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
@@ -27,7 +30,8 @@ public class MsgInitConnStatusTime_k extends MessageBase {
public void handleMessage(byte[] bytes) {
if (bytes.length - 10 < 10) {
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
+ Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
+ MainApp.bus().post(new EventNewNotification(notification));
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
log.debug("Wrong model selected. Switching to export DanaR");
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, false);
@@ -37,13 +41,14 @@ public class MsgInitConnStatusTime_k extends MessageBase {
DanaRPump.getInstance().lastConnection = new Date(0); // mark not initialized
//If profile coming from pump, switch it as well
- if(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PROFILE)){
+ if (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PROFILE)) {
(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, false);
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, true);
}
MainApp.getConfigBuilder().storeSettings();
- MainApp.bus().post(new EventRefreshOverview("MsgInitConnStatusTime_k"));
+ MainApp.bus().post(new EventRefreshGui());
+ ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
return;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java
index 202e7bd260..c9c23650dd 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java
@@ -262,6 +262,11 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
return danaRSService.loadHistory(type);
}
+ @Override
+ public PumpEnactResult loadEvents() {
+ return danaRSService.loadEvents();
+ }
+
// Constraints interface
@Override
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java
index 113ce6a5d2..c59d43e7f9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java
@@ -25,6 +25,7 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
+import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
@@ -70,6 +71,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_D
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_Pump_Time;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_Pump_Time;
+import info.nightscout.androidaps.queue.Callback;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP;
@@ -171,7 +173,7 @@ public class DanaRSService extends Service {
log.debug("Pump status loaded");
}
- public void loadEvents() {
+ public PumpEnactResult loadEvents() {
DanaRS_Packet_APS_History_Events msg;
if (lastHistoryFetched == 0) {
msg = new DanaRS_Packet_APS_History_Events(0);
@@ -186,6 +188,7 @@ public class DanaRSService extends Service {
}
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded;
log.debug("Events loaded");
+ return new PumpEnactResult().success(true);
}
@@ -227,7 +230,7 @@ public class DanaRSService extends Service {
}
}
- EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
+ final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
bolusingEvent.t = t;
bolusingEvent.percent = 99;
@@ -252,14 +255,16 @@ public class DanaRSService extends Service {
MainApp.bus().post(bolusingEvent);
SystemClock.sleep(1000);
}
- if (!(isConnected()))
- DanaRSPlugin.getPlugin().connect("loadEvents");
- loadEvents();
- // reread bolus status
- MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
- bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus
- bolusingEvent.percent = 100;
- MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
+ ConfigBuilderPlugin.getCommandQueue().loadEvents(new Callback() {
+ @Override
+ public void run() {
+ // reread bolus status
+ MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
+ bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus
+ bolusingEvent.percent = 100;
+ MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
+ }
+ });
return true;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java
index 8786654cea..c01d49a12c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java
@@ -361,9 +361,10 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
// Recheck pump status if older than 30 min
- if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
- connect("setTempBasalAbsolute old data");
- }
+ //This should not be needed while using queue because connection should be done before calling this
+ //if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
+ // connect("setTempBasalAbsolute old data");
+ //}
PumpEnactResult result = new PumpEnactResult();
@@ -625,12 +626,12 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
@Override
public void stopConnecting() {
- // TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ if (sExecutionService != null) sExecutionService.stopConnecting();
}
@Override
public void getPumpStatus() {
- // TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ if (sExecutionService != null) sExecutionService.getPumpStatus();
}
@Override
@@ -700,6 +701,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
return sExecutionService.loadHistory(type);
}
+ @Override
+ public PumpEnactResult loadEvents() {
+ return sExecutionService.loadEvents();
+ }
+
/**
* Constraint interface
*/
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java
index e31a1a3443..6106780618 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java
@@ -3,11 +3,17 @@ package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Date;
+
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.plugins.Overview.Notification;
+import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
@@ -36,13 +42,31 @@ public class MsgCheckValue_v2 extends MessageBase {
pump.protocol = intFromBuff(bytes, 1, 1);
pump.productCode = intFromBuff(bytes, 2, 1);
if (pump.model != DanaRPump.EXPORT_MODEL) {
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
- DanaRv2Plugin.getPlugin().disconnect("Wrong Model");
- log.debug("Wrong model selected");
+ Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
+ MainApp.bus().post(new EventNewNotification(notification));
+ MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
+ log.debug("Wrong model selected. Switching to Korean DanaR");
+ MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, true);
+ MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true);
+ MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentEnabled(PluginBase.PUMP, false);
+ MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginBase.PUMP, false);
+ DanaRPump.getInstance().lastConnection = new Date(0); // mark not initialized
+
+ //If profile coming from pump, switch it as well
+ if(MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PROFILE)){
+ (MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, false);
+ (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, true);
+ }
+
+ MainApp.getConfigBuilder().storeSettings();
+ MainApp.bus().post(new EventRefreshGui());
+ ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
+ return;
}
if (pump.protocol != 2) {
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
+ Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
+ MainApp.bus().post(new EventNewNotification(notification));
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
log.debug("Wrong model selected. Switching to non APS DanaR");
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentEnabled(PluginBase.PUMP, false);
@@ -57,7 +81,8 @@ public class MsgCheckValue_v2 extends MessageBase {
}
MainApp.getConfigBuilder().storeSettings();
- MainApp.bus().post(new EventRefreshOverview("MsgCheckValue_v2"));
+ MainApp.bus().post(new EventRefreshGui());
+ ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
return;
}
if (Config.logDanaMessageDetail) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java
index 5bd9e4bdbe..b6a5732014 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java
@@ -35,6 +35,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.data.Profile;
+import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
@@ -49,6 +50,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetHistoryEntry_v2
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue_v2;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusBolusExtended_v2;
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusTempBasal_v2;
+import info.nightscout.androidaps.queue.Callback;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils;
@@ -62,14 +64,12 @@ public class DanaRv2ExecutionService extends Service {
private BluetoothSocket mRfcommSocket;
private BluetoothDevice mBTDevice;
- private PowerManager.WakeLock mWakeLock;
private IBinder mBinder = new LocalBinder();
private DanaRPump danaRPump;
private Treatment bolusingTreatment = null;
private static Boolean connectionInProgress = false;
- private static final Object connectionLock = new Object();
private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
@@ -96,9 +96,6 @@ public class DanaRv2ExecutionService extends Service {
registerBus();
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
danaRPump = DanaRPump.getInstance();
-
- PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
- mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRv2ExecutionService");
}
public class LocalBinder extends Binder {
@@ -160,35 +157,28 @@ public class DanaRv2ExecutionService extends Service {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
return;
}
- while (isConnected() || isConnecting()) {
- if (Config.logDanaBTComm)
- log.debug("already connected/connecting from: " + from);
- waitMsec(3000);
- }
- final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
- synchronized (connectionLock) {
- //log.debug("entering connection while loop");
- connectionInProgress = true;
- mWakeLock.acquire();
- getBTSocketForSelectedPump();
- if (mRfcommSocket == null || mBTDevice == null)
- return; // Device not found
- long startTime = System.currentTimeMillis();
- while (!isConnected() && startTime + maxConnectionTime >= System.currentTimeMillis()) {
- long secondsElapsed = (System.currentTimeMillis() - startTime) / 1000L;
- MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
- if (Config.logDanaBTComm)
- log.debug("connect waiting " + secondsElapsed + "sec from: " + from);
+
+ if (connectionInProgress)
+ return;
+
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ connectionInProgress = true;
+ getBTSocketForSelectedPump();
+ if (mRfcommSocket == null || mBTDevice == null) {
+ connectionInProgress = false;
+ return; // Device not found
+ }
+
try {
mRfcommSocket.connect();
} catch (IOException e) {
//log.error("Unhandled exception", e);
if (e.getMessage().contains("socket closed")) {
log.error("Unhandled exception", e);
- break;
}
}
- waitMsec(1000);
if (isConnected()) {
if (mSerialIOThread != null) {
@@ -196,23 +186,16 @@ public class DanaRv2ExecutionService extends Service {
}
mSerialIOThread = new SerialIOThread(mRfcommSocket);
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
- if (!getPumpStatus()) {
- mSerialIOThread.disconnect("getPumpStatus failed");
- waitMsec(3000);
- if (!MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginBase.PUMP))
- return;
- getBTSocketForSelectedPump();
- startTime = System.currentTimeMillis();
- }
}
+
+ connectionInProgress = false;
}
- if (!isConnected()) {
- MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
- log.error("Pump connection timed out");
- }
- connectionInProgress = false;
- mWakeLock.release();
- }
+ }).start();
+ }
+
+ public void stopConnecting() {
+ if (mSerialIOThread != null)
+ mSerialIOThread.disconnect("stopConnecting");
}
private void getBTSocketForSelectedPump() {
@@ -247,7 +230,7 @@ public class DanaRv2ExecutionService extends Service {
mSerialIOThread.disconnect("EventPreferenceChange");
}
- private boolean getPumpStatus() {
+ public void getPumpStatus() {
try {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
MsgStatus statusMsg = new MsgStatus();
@@ -259,7 +242,7 @@ public class DanaRv2ExecutionService extends Service {
if (danaRPump.isNewPump) {
mSerialIOThread.sendMessage(checkValue);
if (!checkValue.received) {
- return false;
+ return;
}
}
@@ -271,28 +254,6 @@ public class DanaRv2ExecutionService extends Service {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingextendedbolusstatus)));
mSerialIOThread.sendMessage(exStatusMsg);
- if (!statusMsg.received) {
- mSerialIOThread.sendMessage(statusMsg);
- }
- if (!statusBasicMsg.received) {
- mSerialIOThread.sendMessage(statusBasicMsg);
- }
- if (!tempStatusMsg.received) {
- // Load of status of current basal rate failed, give one more try
- mSerialIOThread.sendMessage(tempStatusMsg);
- }
- if (!exStatusMsg.received) {
- // Load of status of current extended bolus failed, give one more try
- mSerialIOThread.sendMessage(exStatusMsg);
- }
-
- // Check we have really current status of pump
- if (!statusMsg.received || !statusBasicMsg.received || !tempStatusMsg.received || !exStatusMsg.received) {
- waitMsec(10 * 1000);
- log.debug("getPumpStatus failed");
- return false;
- }
-
Date now = new Date();
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRv2Plugin.class).isInitialized()) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings)));
@@ -334,11 +295,10 @@ public class DanaRv2ExecutionService extends Service {
} catch (Exception e) {
log.error("Unhandled exception", e);
}
- return true;
+ return;
}
public boolean tempBasal(int percent, int durationInHours) {
- connect("tempBasal");
if (!isConnected()) return false;
if (danaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
@@ -354,7 +314,6 @@ public class DanaRv2ExecutionService extends Service {
}
public boolean highTempBasal(int percent) {
- connect("highTempBasal");
if (!isConnected()) return false;
if (danaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
@@ -370,7 +329,6 @@ public class DanaRv2ExecutionService extends Service {
}
public boolean tempBasalStop() {
- connect("tempBasalStop");
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
@@ -381,7 +339,6 @@ public class DanaRv2ExecutionService extends Service {
}
public boolean extendedBolus(double insulin, int durationInHalfHours) {
- connect("extendedBolus");
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
@@ -392,7 +349,6 @@ public class DanaRv2ExecutionService extends Service {
}
public boolean extendedBolusStop() {
- connect("extendedBolusStop");
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
@@ -402,7 +358,7 @@ public class DanaRv2ExecutionService extends Service {
return true;
}
- public boolean bolus(final double amount, int carbs, long carbtime, Treatment t) {
+ public boolean bolus(final double amount, int carbs, long carbtime, final Treatment t) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.startingbolus)));
bolusingTreatment = t;
final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
@@ -413,7 +369,6 @@ public class DanaRv2ExecutionService extends Service {
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed);
MsgBolusStop stop = new MsgBolusStop(amount, t);
- connect("bolus");
if (!isConnected()) return false;
if (carbs > 0) {
@@ -436,7 +391,7 @@ public class DanaRv2ExecutionService extends Service {
}
while (!stop.stopped && !start.failed) {
waitMsec(100);
- if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
+ if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm
stop.stopped = true;
stop.forced = true;
log.debug("Communication stopped");
@@ -444,7 +399,7 @@ public class DanaRv2ExecutionService extends Service {
}
}
- EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
+ final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
bolusingEvent.t = t;
bolusingEvent.percent = 99;
@@ -469,16 +424,18 @@ public class DanaRv2ExecutionService extends Service {
MainApp.bus().post(bolusingEvent);
SystemClock.sleep(1000);
}
- if (!(isConnected()))
- connect("loadEvents");
- loadEvents();
- // load last bolus status
- MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
- mSerialIOThread.sendMessage(new MsgStatus());
- bolusingEvent.percent = 100;
- MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
+ ConfigBuilderPlugin.getCommandQueue().loadEvents(new Callback() {
+ @Override
+ public void run() {
+ // load last bolus status
+ MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
+ mSerialIOThread.sendMessage(new MsgStatus());
+ bolusingEvent.percent = 100;
+ MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
+ }
+ });
return true;
-}
+ }
public void bolusStop() {
if (Config.logDanaBTComm)
@@ -497,7 +454,6 @@ public class DanaRv2ExecutionService extends Service {
}
public boolean carbsEntry(int amount, long time) {
- connect("carbsEntry");
if (!isConnected()) return false;
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount);
mSerialIOThread.sendMessage(msg);
@@ -509,7 +465,6 @@ public class DanaRv2ExecutionService extends Service {
public PumpEnactResult loadHistory(byte type) {
PumpEnactResult result = new PumpEnactResult();
- connect("loadHistory");
if (!isConnected()) return result;
MessageBase msg = null;
switch (type) {
@@ -555,8 +510,9 @@ public class DanaRv2ExecutionService extends Service {
return result;
}
- public boolean loadEvents() {
- if (!isConnected()) return false;
+ public PumpEnactResult loadEvents() {
+ if (!isConnected())
+ return new PumpEnactResult().success(false);
waitMsec(300);
MsgHistoryEvents_v2 msg;
if (lastHistoryFetched == 0) {
@@ -572,11 +528,10 @@ public class DanaRv2ExecutionService extends Service {
}
waitMsec(200);
lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded;
- return true;
+ return new PumpEnactResult().success(true);
}
public boolean updateBasalsInPump(final Profile profile) {
- connect("updateBasalsInPump");
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java
index f0a34334ab..b1f6d35e78 100644
--- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java
+++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java
@@ -28,6 +28,7 @@ import info.nightscout.androidaps.queue.commands.CommandBolus;
import info.nightscout.androidaps.queue.commands.CommandCancelExtendedBolus;
import info.nightscout.androidaps.queue.commands.CommandCancelTempBasal;
import info.nightscout.androidaps.queue.commands.CommandExtendedBolus;
+import info.nightscout.androidaps.queue.commands.CommandLoadEvents;
import info.nightscout.androidaps.queue.commands.CommandLoadHistory;
import info.nightscout.androidaps.queue.commands.CommandReadStatus;
import info.nightscout.androidaps.queue.commands.CommandSetProfile;
@@ -358,6 +359,25 @@ public class CommandQueue {
return true;
}
+ // returns true if command is queued
+ public boolean loadEvents(Callback callback) {
+ if (isRunning(Command.CommandType.LOADEVENTS)) {
+ if (callback != null)
+ callback.result(executingNowError()).run();
+ return false;
+ }
+
+ // remove all unfinished
+ removeAll(Command.CommandType.LOADEVENTS);
+
+ // add new command to queue
+ add(new CommandLoadEvents(callback));
+
+ notifyAboutNewCommand();
+
+ return true;
+ }
+
public Spanned spannedStatus() {
String s = "";
int line = 0;
diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java
index 7dda80a0da..36b43d2181 100644
--- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java
+++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java
@@ -43,10 +43,10 @@ public class QueueThread extends Thread {
mWakeLock.acquire();
MainApp.bus().post(new EventQueueChanged());
connectionStartTime = System.currentTimeMillis();
- PumpInterface pump = ConfigBuilderPlugin.getActivePump();
try {
while (true) {
+ PumpInterface pump = ConfigBuilderPlugin.getActivePump();
log.debug("Looping ...");
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
if (pump.isConnecting()) {
diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java
index 763de9e840..4624e2385f 100644
--- a/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java
+++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java
@@ -15,7 +15,8 @@ public abstract class Command {
EXTENDEDBOLUS,
BASALPROFILE,
READSTATUS,
- LOADHISTORY // so far only Dana specific
+ LOADHISTORY, // so far only Dana specific
+ LOADEVENTS // so far only Dana specific
}
public CommandType commandType;
diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadEvents.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadEvents.java
new file mode 100644
index 0000000000..2d6bc5b5fc
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadEvents.java
@@ -0,0 +1,34 @@
+package info.nightscout.androidaps.queue.commands;
+
+import info.nightscout.androidaps.data.PumpEnactResult;
+import info.nightscout.androidaps.interfaces.DanaRInterface;
+import info.nightscout.androidaps.interfaces.PumpInterface;
+import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
+import info.nightscout.androidaps.queue.Callback;
+
+/**
+ * Created by mike on 10.11.2017.
+ */
+
+public class CommandLoadEvents extends Command {
+ public CommandLoadEvents(Callback callback) {
+ commandType = CommandType.LOADEVENTS;
+ this.callback = callback;
+ }
+
+ @Override
+ public void execute() {
+ PumpInterface pump = ConfigBuilderPlugin.getActivePump();
+ if (pump instanceof DanaRInterface) {
+ DanaRInterface danaPump = (DanaRInterface) pump;
+ PumpEnactResult r = danaPump.loadEvents();
+ if (callback != null)
+ callback.result(r).run();
+ }
+ }
+
+ @Override
+ public String status() {
+ return "LOADEVENTS";
+ }
+}
diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml
index 03266a5b4a..75d2cb20c2 100644
--- a/app/src/main/res/values-bg/strings.xml
+++ b/app/src/main/res/values-bg/strings.xml
@@ -371,7 +371,6 @@
Помпата е изключена
Батерията на помпата е изтощена
DanaR Korean
- Избран е грешен тип помпа
Базал:
Неуспешно задаване на базален профил
Профила на помпата е обновен
diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml
index 66a2d76862..c619655866 100644
--- a/app/src/main/res/values-cs/strings.xml
+++ b/app/src/main/res/values-cs/strings.xml
@@ -352,7 +352,6 @@
Nastavení bazálního profilu selhalo
Bazální profil aktualizován
Pumpa není inicializována, profil nenastaven!
- Vybrán špatný ovladač pumpy
Hodnota bazálu pod povoleným minimem. Nenastaveno!
Pera
Glykémie:
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index b8c561c6c6..9a4d839fec 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -290,7 +290,6 @@
Pumpenfehler
Zielbereich:
Einheiten:
- Falscher Pumpentreiber ausgewählt
Befüllen
EasyUI Modus in der Pumpe deaktivieren
Basal-Stunde
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index fcc51152ff..f52357dd0a 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -421,7 +421,6 @@
Attesa Micro. Clicca per rinnovare
Visualizza BGI
Password Errata
- Driver Micro Errato
Password Micro Errata
Xdrip
xDrip non installato
diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml
index 003f16edb7..b4bd725ce4 100644
--- a/app/src/main/res/values-ko/strings.xml
+++ b/app/src/main/res/values-ko/strings.xml
@@ -373,7 +373,6 @@
펌프 중지
펌프배터리 방전
다나R 한글
- 펌프 드라이버가 잘못 선택되었습니다
기초주입량:
기초주입 프로파일 설정이 실패하였습니다
기초주입 프로파일이 펌프에 업데이트 되었습니다
diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml
index f1388b4af7..1bcfc2736f 100644
--- a/app/src/main/res/values-nl/strings.xml
+++ b/app/src/main/res/values-nl/strings.xml
@@ -24,7 +24,6 @@
xDrip+ niet geïnstalleerd
xDrip
Verkeerd pomp wachtwoord!
- Verkeerde pomp driver geselecteerd
Verkeerd wachtwoord
Toon BGI
Voeg BGI toe aan status lijn
diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml
index e78328e5cf..ce50495e73 100644
--- a/app/src/main/res/values-ru/strings.xml
+++ b/app/src/main/res/values-ru/strings.xml
@@ -553,7 +553,6 @@
добавить BGI в строку состояния
показать BGI
неверный пароль
- неправильно выбран драйвер помпы
неверный пароль помпы
xdrip
xdrip+ не установлен
diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml
index 03ac2aee36..b7527f85ad 100644
--- a/app/src/main/res/values-sv/strings.xml
+++ b/app/src/main/res/values-sv/strings.xml
@@ -293,7 +293,6 @@
xDrip+ inte installerat
xDrip
Fel lösenord för pump
- Fel pump program vald
Fel lösenord
Visa BGI
Visa BGI i statusfält
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index adc54ba340..3833fee5de 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -384,7 +384,6 @@
Pump Shutdown
Pump Battery Discharged
DanaR Korean
- Wrong pump driver selected
Basal rate:
Setting of basal profile failed
Basal profile in pump updated
@@ -758,5 +757,6 @@
Processing event
Starting bolus delivery
Command is executed right now
+ Pump driver corrected