From d06c5fdcc8ea42683f0dcb587eeaf369f7c0b9ad Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Wed, 7 Aug 2019 11:48:37 +0100 Subject: [PATCH 1/2] - fixed 4 (or more) crashalytics problems --- .../common/hw/rileylink/ble/RileyLinkBLE.java | 39 +++++++++++++------ .../pump/medtronic/MedtronicPumpPlugin.java | 9 +++++ .../medtronic/comm/ui/MedtronicUITask.java | 1 + 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java index b639c61aec..aab5e35142 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java @@ -370,13 +370,21 @@ public class RileyLinkBLE { rileyLinkDevice = bluetoothAdapter.getRemoteDevice(RileyLinkAddress); // if this succeeds, we get a connection state change callback? - if (rileyLinkDevice!=null) + if (rileyLinkDevice!=null) { connectGatt(); + } else { + LOG.error("RileyLink device not found with address: " + RileyLinkAddress); + } } // This function must be run on UI thread. public void connectGatt() { + if (this.rileyLinkDevice==null) { + LOG.error("RileyLink device is null, can't do connectGatt."); + return; + } + bluetoothConnectionGatt = rileyLinkDevice.connectGatt(context, true, bluetoothGattCallback); // , BluetoothDevice.TRANSPORT_LE if (bluetoothConnectionGatt == null) { @@ -384,7 +392,7 @@ public class RileyLinkBLE { } else { if (gattDebugEnabled) { if (isLogEnabled()) - LOG.debug("Gatt Connected?"); + LOG.debug("Gatt Connected."); } } } @@ -527,17 +535,24 @@ public class RileyLinkBLE { if (mCurrentOperation != null) { rval.resultCode = BLECommOperationResult.RESULT_BUSY; } else { - BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic( - charaUUID); - mCurrentOperation = new CharacteristicReadOperation(bluetoothConnectionGatt, chara); - mCurrentOperation.execute(this); - if (mCurrentOperation.timedOut) { - rval.resultCode = BLECommOperationResult.RESULT_TIMEOUT; - } else if (mCurrentOperation.interrupted) { - rval.resultCode = BLECommOperationResult.RESULT_INTERRUPTED; + if (bluetoothConnectionGatt.getService(serviceUUID) == null) { + // Catch if the service is not supported by the BLE device + rval.resultCode = BLECommOperationResult.RESULT_NONE; + LOG.error("BT Device not supported"); + // TODO: 11/07/2016 UI update for user } else { - rval.resultCode = BLECommOperationResult.RESULT_SUCCESS; - rval.value = mCurrentOperation.getValue(); + BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic( + charaUUID); + mCurrentOperation = new CharacteristicReadOperation(bluetoothConnectionGatt, chara); + mCurrentOperation.execute(this); + if (mCurrentOperation.timedOut) { + rval.resultCode = BLECommOperationResult.RESULT_TIMEOUT; + } else if (mCurrentOperation.interrupted) { + rval.resultCode = BLECommOperationResult.RESULT_INTERRUPTED; + } else { + rval.resultCode = BLECommOperationResult.RESULT_SUCCESS; + rval.value = mCurrentOperation.getValue(); + } } } mCurrentOperation = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index d197431190..595e546a93 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -742,6 +742,15 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter ClockDTO clock = MedtronicUtil.getPumpTime(); + if (clock==null) { // retry + medtronicUIComm.executeCommand(MedtronicCommandType.GetRealTimeClock); + + clock = MedtronicUtil.getPumpTime(); + } + + if (clock==null) + return; + int timeDiff = Math.abs(clock.timeDifference); if (timeDiff > 20) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUITask.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUITask.java index 3d39a82749..38bbb11ae2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUITask.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUITask.java @@ -68,6 +68,7 @@ public class MedtronicUITask { case GetRealTimeClock: { returnData = communicationManager.getPumpTime(); + MedtronicUtil.setPumpTime(null); } break; From 163c043492d4d7f8c07779a3d104d454192b013d Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Wed, 7 Aug 2019 11:59:47 +0100 Subject: [PATCH 2/2] - preliminary fix for #1940 (if calculated voltage is under 0, we set it to 1%) --- .../plugins/pump/medtronic/data/dto/BatteryStatusDTO.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java index d12260bb75..c8bd2347d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BatteryStatusDTO.java @@ -27,6 +27,9 @@ public class BatteryStatusDTO { int percentInt = (int) (percent * 100.0d); + if (percentInt<0) + percentInt = 1; + if (percentInt > 100) percentInt = 100;