From 621d0f305759f66607f953dfc495a2efb4ee1e00 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 8 Dec 2022 11:38:50 +0100 Subject: [PATCH] DiaconnG8: pump log sync bug fix --- .../nightscout/pump/diaconn/service/BLECommonService.kt | 8 ++++++++ .../nightscout/pump/diaconn/service/DiaconnG8Service.kt | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/BLECommonService.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/BLECommonService.kt index a89787b58f..102b456358 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/BLECommonService.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/BLECommonService.kt @@ -104,6 +104,14 @@ class BLECommonService @Inject internal constructor( return false } + bluetoothGatt?.let { + it.disconnect() + SystemClock.sleep(200) + it.close() + SystemClock.sleep(200) + bluetoothGatt = null + } + val device = bluetoothAdapter?.getRemoteDevice(address) if (device == null) { aapsLogger.error("Device not found. Unable to connect from: $from") diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt index 772d4f5f32..ca627bb3fd 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt @@ -295,18 +295,21 @@ class DiaconnG8Service : DaggerService() { if (apsWrappingCount == -1 && apsLastLogNum == 9999) { apsWrappingCount = pumpWrappingCount apsLastLogNum = if (pumpLastNum - 1 < 0) 0 else pumpLastNum - 2 + aapsLogger.debug(LTag.PUMPCOMM, "first install app apsWrappingCount : $apsWrappingCount, apsLastLogNum : $apsLastLogNum") } // if another pump if (pumpSerialNo != diaconnG8Pump.serialNo) { apsWrappingCount = pumpWrappingCount apsLastLogNum = if (pumpLastNum - 1 < 0) 0 else pumpLastNum - 2 sp.putInt(rh.gs(R.string.pumpserialno), diaconnG8Pump.serialNo) + aapsLogger.debug(LTag.PUMPCOMM, "Pump serialNo is different apsWrappingCount : $apsWrappingCount, apsLastLogNum : $apsLastLogNum") } // if pump reset if (apsIncarnationNum != diaconnG8Pump.pumpIncarnationNum) { apsWrappingCount = pumpWrappingCount apsLastLogNum = if (pumpLastNum - 1 < 0) 0 else pumpLastNum - 2 - sp.putInt(R.string.apsIncarnationNo, apsIncarnationNum) + sp.putInt(R.string.apsIncarnationNo, diaconnG8Pump.pumpIncarnationNum) + aapsLogger.debug(LTag.PUMPCOMM, "Pump incarnationNum is different apsWrappingCount : $apsWrappingCount, apsLastLogNum : $apsLastLogNum") } aapsLogger.debug(LTag.PUMPCOMM, "apsWrappingCount : $apsWrappingCount, apsLastLogNum : $apsLastLogNum") @@ -375,7 +378,7 @@ class DiaconnG8Service : DaggerService() { val end: Int // log sync end number1311 aapsLogger.debug(LTag.PUMPCOMM, "lastLogNum : $lastLogNum, wrappingCount : $wrappingCount , pumpLastNum: $pumpLastNum, pumpWrappingCount : $pumpWrappingCount") - if (pumpWrappingCount > wrappingCount && lastLogNum < 9999) { + if (pumpWrappingCount > wrappingCount) { start = (lastLogNum + 1) end = 10000 } else {