Merge remote-tracking branch 'origin/dev' into combo-scripter-v2

* origin/dev:
  log RS history
  RS: reset isConnected & isConnecting on error
  RS BLE modifications
This commit is contained in:
Johannes Mockenhaupt 2018-01-24 02:06:02 +01:00
commit ae1707ead3
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 33 additions and 6 deletions

View file

@ -9,6 +9,7 @@ import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.utils.DateUtil;
public class DanaRS_Packet_APS_Set_Event_History extends DanaRS_Packet { public class DanaRS_Packet_APS_Set_Event_History extends DanaRS_Packet {
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_APS_Set_Event_History.class); private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_APS_Set_Event_History.class);
@ -30,6 +31,8 @@ public class DanaRS_Packet_APS_Set_Event_History extends DanaRS_Packet {
this.time = time; this.time = time;
this.param1 = param1; this.param1 = param1;
this.param2 = param2; this.param2 = param2;
if (Config.logDanaMessageDetail)
log.debug("Set history entry: " + DateUtil.dateAndTimeString(time) + " type: " + type + " param1: " + param1 + " param2: " + param2);
} }
@Override @Override

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);
@ -257,6 +259,8 @@ public class BLEComm {
log.debug("setCharacteristicNotification"); log.debug("setCharacteristicNotification");
if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) {
log.debug("BluetoothAdapter not initialized_ERROR"); log.debug("BluetoothAdapter not initialized_ERROR");
isConnecting = false;
isConnected = false;
return; return;
} }
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
@ -266,6 +270,8 @@ public class BLEComm {
log.debug("readCharacteristic"); log.debug("readCharacteristic");
if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) {
log.debug("BluetoothAdapter not initialized_ERROR"); log.debug("BluetoothAdapter not initialized_ERROR");
isConnecting = false;
isConnected = false;
return; return;
} }
mBluetoothGatt.readCharacteristic(characteristic); mBluetoothGatt.readCharacteristic(characteristic);
@ -274,6 +280,8 @@ public class BLEComm {
public void writeCharacteristic_NO_RESPONSE(final BluetoothGattCharacteristic characteristic, final byte[] data) { public void writeCharacteristic_NO_RESPONSE(final BluetoothGattCharacteristic characteristic, final byte[] data) {
if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) {
log.debug("BluetoothAdapter not initialized_ERROR"); log.debug("BluetoothAdapter not initialized_ERROR");
isConnecting = false;
isConnected = false;
return; return;
} }
@ -306,6 +314,8 @@ public class BLEComm {
log.debug("getSupportedGattServices"); log.debug("getSupportedGattServices");
if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) {
log.debug("BluetoothAdapter not initialized_ERROR"); log.debug("BluetoothAdapter not initialized_ERROR");
isConnecting = false;
isConnected = false;
return null; return null;
} }

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;
@ -51,12 +53,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(null)); MainApp.bus().post(new EventDismissBolusprogressIfRunning(null));
@ -73,19 +69,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));