RS BLE modifications

This commit is contained in:
AdrianLxM 2017-12-25 20:39:14 +01:00
parent 2bdda9af43
commit e50c6fc8ed
2 changed files with 22 additions and 6 deletions

View file

@ -164,6 +164,8 @@ public class BLEComm {
scheduledDisconnection = null; scheduledDisconnection = null;
if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) {
log.debug("disconnect not possible: (mBluetoothAdapter == null) " + (mBluetoothAdapter == null));
log.debug("disconnect not possible: (mBluetoothGatt == null) " + (mBluetoothGatt == null));
return; return;
} }
setCharacteristicNotification(getUARTReadBTGattChar(), false); setCharacteristicNotification(getUARTReadBTGattChar(), false);

View file

@ -16,6 +16,8 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.queue.events.EventQueueChanged; import info.nightscout.androidaps.queue.events.EventQueueChanged;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -52,12 +54,6 @@ public class QueueThread extends Thread {
while (true) { while (true) {
PumpInterface pump = ConfigBuilderPlugin.getActivePump(); PumpInterface pump = ConfigBuilderPlugin.getActivePump();
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000; long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
if (pump.isConnecting()) {
log.debug("QUEUE: connecting " + secondsElapsed);
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
SystemClock.sleep(1000);
continue;
}
if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) { if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {
MainApp.bus().post(new EventDismissBolusprogressIfRunning(new PumpEnactResult())); MainApp.bus().post(new EventDismissBolusprogressIfRunning(new PumpEnactResult()));
@ -74,19 +70,37 @@ public class QueueThread extends Thread {
//write time //write time
SP.putLong(R.string.key_btwatchdog_lastbark, System.currentTimeMillis()); SP.putLong(R.string.key_btwatchdog_lastbark, System.currentTimeMillis());
//toggle BT //toggle BT
pump.stopConnecting();
pump.disconnect("watchdog");
SystemClock.sleep(1000);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.disable(); mBluetoothAdapter.disable();
SystemClock.sleep(1000); SystemClock.sleep(1000);
mBluetoothAdapter.enable(); mBluetoothAdapter.enable();
SystemClock.sleep(1000); SystemClock.sleep(1000);
//start over again once after watchdog barked //start over again once after watchdog barked
//Notification notification = new Notification(Notification.OLD_NSCLIENT, "Watchdog", Notification.URGENT);
//MainApp.bus().post(new EventNewNotification(notification));
connectionStartTime = lastCommandTime = System.currentTimeMillis(); connectionStartTime = lastCommandTime = System.currentTimeMillis();
pump.connect("watchdog");
} else { } else {
queue.clear(); queue.clear();
log.debug("QUEUE: no connection possible");
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
pump.disconnect("Queue empty");
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
return; return;
} }
} }
if (pump.isConnecting()) {
log.debug("QUEUE: connecting " + secondsElapsed);
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
SystemClock.sleep(1000);
continue;
}
if (!pump.isConnected()) { if (!pump.isConnected()) {
log.debug("QUEUE: connect"); log.debug("QUEUE: connect");
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed)); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));