From 5ef92462a7750a0e528b8bf8dc0282f10a880e7b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 25 May 2021 18:31:01 +0200 Subject: [PATCH] do not use last record in DetailedBolusInfoStorage --- .../bolusInfo/DetailedBolusInfoStorage.kt | 22 +++++++++---------- .../androidaps/danars/services/BLEComm.kt | 5 ++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt index 062d41191f..57a732cbc3 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt @@ -29,7 +29,7 @@ class DetailedBolusInfoStorage @Inject constructor( val d = store[i] //aapsLogger.debug(LTag.PUMP, "Existing bolus info: " + store[i]) if (bolusTime > d.timestamp - T.mins(1).msecs() && bolusTime < d.timestamp + T.mins(1).msecs() && abs(store[i].insulin - bolus) < 0.01) { - aapsLogger.debug(LTag.PUMP, "Using & removing bolus info: ${store[i]}") + aapsLogger.debug(LTag.PUMP, "Using & removing bolus info for time $bolusTime: ${store[i]}") store.removeAt(i) return d } @@ -38,22 +38,22 @@ class DetailedBolusInfoStorage @Inject constructor( for (i in store.indices) { val d = store[i] if (bolusTime > d.timestamp - T.mins(1).msecs() && bolusTime < d.timestamp + T.mins(1).msecs() && bolus <= store[i].insulin + 0.01) { - aapsLogger.debug(LTag.PUMP, "Using TIME-ONLY & removing bolus info: ${store[i]}") + aapsLogger.debug(LTag.PUMP, "Using TIME-ONLY & removing bolus info for time $bolusTime: ${store[i]}") store.removeAt(i) return d } } // If not found, use last record if amount is the same - if (store.size > 0) { - val d = store[store.size - 1] - if (abs(d.insulin - bolus) < 0.01) { - aapsLogger.debug(LTag.PUMP, "Using LAST & removing bolus info: $d") - store.removeAt(store.size - 1) - return d - } - } + // if (store.size > 0) { + // val d = store[store.size - 1] + // if (abs(d.insulin - bolus) < 0.01) { + // aapsLogger.debug(LTag.PUMP, "Using LAST & removing bolus info for time $bolusTime: $d") + // store.removeAt(store.size - 1) + // return d + // } + // } //Not found - //aapsLogger.debug(LTag.PUMP, "Bolus info not found") + aapsLogger.debug(LTag.PUMP, "Bolus info not found for time $bolusTime") return null } } \ No newline at end of file diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt b/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt index 83996f4504..d5aa72269a 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt @@ -323,13 +323,16 @@ class BLEComm @Inject internal constructor( } private val readBuffer = ByteArray(1024) - private var bufferLength = 0 + @Volatile private var bufferLength = 0 private fun addToReadBuffer(buffer: ByteArray) { //log.debug("addToReadBuffer " + DanaRS_Packet.toHexString(buffer)); if (buffer.isEmpty()) { return } + if (bufferLength == 1024) { + aapsLogger.debug(LTag.PUMPBTCOMM, "1024 XXXXXXXXXXXXXX") + } synchronized(readBuffer) { // Append incoming data to input buffer System.arraycopy(buffer, 0, readBuffer, bufferLength, buffer.size)