do not use last record in DetailedBolusInfoStorage

This commit is contained in:
Milos Kozak 2021-05-25 18:31:01 +02:00
parent bee6d289c0
commit 5ef92462a7
2 changed files with 15 additions and 12 deletions

View file

@ -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
}
}

View file

@ -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)