DanaRv2 queue & pump autodection
This commit is contained in:
parent
8818afe033
commit
a13661400f
26 changed files with 196 additions and 132 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -371,7 +371,6 @@
|
|||
<string name="pumpshutdown">Помпата е изключена</string>
|
||||
<string name="batterydischarged">Батерията на помпата е изтощена</string>
|
||||
<string name="danarkoreanpump">DanaR Korean</string>
|
||||
<string name="wrongpumpdriverselected">Избран е грешен тип помпа</string>
|
||||
<string name="basal_rate">Базал:</string>
|
||||
<string name="profile_set_failed">Неуспешно задаване на базален профил</string>
|
||||
<string name="profile_set_ok">Профила на помпата е обновен</string>
|
||||
|
|
|
@ -352,7 +352,6 @@
|
|||
<string name="profile_set_failed">Nastavení bazálního profilu selhalo</string>
|
||||
<string name="profile_set_ok">Bazální profil aktualizován</string>
|
||||
<string name="pumpNotInitializedProfileNotSet">Pumpa není inicializována, profil nenastaven!</string>
|
||||
<string name="wrongpumpdriverselected">Vybrán špatný ovladač pumpy</string>
|
||||
<string name="basalvaluebelowminimum">Hodnota bazálu pod povoleným minimem. Nenastaveno!</string>
|
||||
<string name="mdi">Pera</string>
|
||||
<string name="sms_actualbg">Glykémie:</string>
|
||||
|
|
|
@ -290,7 +290,6 @@
|
|||
<string name="pumperror">Pumpenfehler</string>
|
||||
<string name="target_range">Zielbereich:</string>
|
||||
<string name="units">Einheiten:</string>
|
||||
<string name="wrongpumpdriverselected">Falscher Pumpentreiber ausgewählt</string>
|
||||
<string name="danar_refill">Befüllen</string>
|
||||
<string name="danar_disableeasymode">EasyUI Modus in der Pumpe deaktivieren</string>
|
||||
<string name="danar_basalhour">Basal-Stunde</string>
|
||||
|
|
|
@ -421,7 +421,6 @@
|
|||
<string name="waitingforpumpclicktorefresh">Attesa Micro. Clicca per rinnovare</string>
|
||||
<string name="wear_showbgi_title">Visualizza BGI</string>
|
||||
<string name="wrongpassword">Password Errata</string>
|
||||
<string name="wrongpumpdriverselected">Driver Micro Errato</string>
|
||||
<string name="wrongpumppassword">Password Micro Errata</string>
|
||||
<string name="xdrip">Xdrip</string>
|
||||
<string name="xdripnotinstalled">xDrip non installato</string>
|
||||
|
|
|
@ -373,7 +373,6 @@
|
|||
<string name="pumpshutdown">펌프 중지</string>
|
||||
<string name="batterydischarged">펌프배터리 방전</string>
|
||||
<string name="danarkoreanpump">다나R 한글</string>
|
||||
<string name="wrongpumpdriverselected">펌프 드라이버가 잘못 선택되었습니다</string>
|
||||
<string name="basal_rate">기초주입량:</string>
|
||||
<string name="profile_set_failed">기초주입 프로파일 설정이 실패하였습니다</string>
|
||||
<string name="profile_set_ok">기초주입 프로파일이 펌프에 업데이트 되었습니다</string>
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
<string name="xdripnotinstalled">xDrip+ niet geïnstalleerd</string>
|
||||
<string name="xdrip">xDrip</string>
|
||||
<string name="wrongpumppassword">Verkeerd pomp wachtwoord!</string>
|
||||
<string name="wrongpumpdriverselected">Verkeerde pomp driver geselecteerd</string>
|
||||
<string name="wrongpassword">Verkeerd wachtwoord</string>
|
||||
<string name="wear_showbgi_title">Toon BGI</string>
|
||||
<string name="wear_showbgi_summary">Voeg BGI toe aan status lijn</string>
|
||||
|
|
|
@ -553,7 +553,6 @@
|
|||
<string name="wear_showbgi_summary">добавить BGI в строку состояния</string>
|
||||
<string name="wear_showbgi_title">показать BGI</string>
|
||||
<string name="wrongpassword">неверный пароль</string>
|
||||
<string name="wrongpumpdriverselected">неправильно выбран драйвер помпы</string>
|
||||
<string name="wrongpumppassword">неверный пароль помпы</string>
|
||||
<string name="xdrip">xdrip</string>
|
||||
<string name="xdripnotinstalled">xdrip+ не установлен</string>
|
||||
|
|
|
@ -293,7 +293,6 @@
|
|||
<string name="xdripnotinstalled">xDrip+ inte installerat</string>
|
||||
<string name="xdrip">xDrip</string>
|
||||
<string name="wrongpumppassword">Fel lösenord för pump</string>
|
||||
<string name="wrongpumpdriverselected">Fel pump program vald</string>
|
||||
<string name="wrongpassword">Fel lösenord</string>
|
||||
<string name="wear_showbgi_title">Visa BGI</string>
|
||||
<string name="wear_showbgi_summary">Visa BGI i statusfält</string>
|
||||
|
|
|
@ -384,7 +384,6 @@
|
|||
<string name="pumpshutdown">Pump Shutdown</string>
|
||||
<string name="batterydischarged">Pump Battery Discharged</string>
|
||||
<string name="danarkoreanpump">DanaR Korean</string>
|
||||
<string name="wrongpumpdriverselected">Wrong pump driver selected</string>
|
||||
<string name="basal_rate">Basal rate:</string>
|
||||
<string name="profile_set_failed">Setting of basal profile failed</string>
|
||||
<string name="profile_set_ok">Basal profile in pump updated</string>
|
||||
|
@ -758,5 +757,6 @@
|
|||
<string name="processinghistory">Processing event</string>
|
||||
<string name="startingbolus">Starting bolus delivery</string>
|
||||
<string name="executingrightnow">Command is executed right now</string>
|
||||
<string name="pumpdrivercorrected">Pump driver corrected</string>
|
||||
</resources>
|
||||
|
||||
|
|
Loading…
Reference in a new issue