fix Dana history parsing

This commit is contained in:
Milos Kozak 2021-05-28 08:50:45 +02:00
parent 2845bc8714
commit 763c0bb766

View file

@ -102,13 +102,16 @@ open class DanaRS_Packet_APS_History_Events(
if (!danaPump.usingUTC) dateTimeSecFromBuff(data, 1) // 6 bytes if (!danaPump.usingUTC) dateTimeSecFromBuff(data, 1) // 6 bytes
else intFromBuffMsbLsb(data, 3, 4) * 1000L else intFromBuffMsbLsb(data, 3, 4) * 1000L
fun recordCode(data: ByteArray): Int = private fun recordCode(data: ByteArray): Int =
intFromBuff(data, 0, 1).toInt() if (!danaPump.usingUTC)
intFromBuff(data, 0, 1)
else
intFromBuff(data, 2, 1)
fun processMessage(data: ByteArray) { fun processMessage(data: ByteArray) {
var recordCode = intFromBuff(data, 0, 1).toByte() val recordCode = recordCode(data)
// Last record // Last record
if (recordCode == 0xFF.toByte()) { if (recordCode == 0xFF) {
return return
} }
val datetime: Long val datetime: Long
@ -121,12 +124,11 @@ open class DanaRS_Packet_APS_History_Events(
pumpId = datetime pumpId = datetime
} else { } else {
datetime = intFromBuffMsbLsb(data, 3, 4) * 1000L datetime = intFromBuffMsbLsb(data, 3, 4) * 1000L
recordCode = intFromBuff(data, 2, 1).toByte()
id = intFromBuffMsbLsb(data, 0, 2) // range only 1-2000 id = intFromBuffMsbLsb(data, 0, 2) // range only 1-2000
pumpId = datetime shl 16 + id pumpId = datetime shl 16 + id
} }
val status: String val status: String
when (recordCode.toInt()) { when (recordCode) {
DanaPump.TEMPSTART -> { DanaPump.TEMPSTART -> {
val temporaryBasalInfo = temporaryBasalStorage.findTemporaryBasal(datetime, param1.toDouble()) val temporaryBasalInfo = temporaryBasalStorage.findTemporaryBasal(datetime, param1.toDouble())
val newRecord = pumpSync.syncTemporaryBasalWithPumpId( val newRecord = pumpSync.syncTemporaryBasalWithPumpId(