fix DanaR reading history

This commit is contained in:
Milos Kozak 2020-07-01 22:31:35 +02:00
parent a08c1d5269
commit 8cf2d3aeb1

View file

@ -17,8 +17,6 @@ open class MsgHistoryAll(
override fun handleMessage(bytes: ByteArray) { override fun handleMessage(bytes: ByteArray) {
val recordCode = intFromBuff(bytes, 0, 1).toByte() val recordCode = intFromBuff(bytes, 0, 1).toByte()
val date = dateFromBuff(bytes, 1) // 3 bytes val date = dateFromBuff(bytes, 1) // 3 bytes
val datetime = dateTimeFromBuff(bytes, 1) // 5 bytes
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
val dailyBasal = intFromBuff(bytes, 4, 2) * 0.01 val dailyBasal = intFromBuff(bytes, 4, 2) * 0.01
val dailyBolus = intFromBuff(bytes, 6, 2) * 0.01 val dailyBolus = intFromBuff(bytes, 6, 2) * 0.01
//val paramByte5 = intFromBuff(bytes, 4, 1).toByte() //val paramByte5 = intFromBuff(bytes, 4, 1).toByte()
@ -32,6 +30,7 @@ open class MsgHistoryAll(
var messageType = "" var messageType = ""
when (recordCode) { when (recordCode) {
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BOLUS -> { info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BOLUS -> {
val datetime = dateTimeFromBuff(bytes, 1) // 5 bytes
danaRHistoryRecord.recordDate = datetime danaRHistoryRecord.recordDate = datetime
when (0xF0 and paramByte8.toInt()) { when (0xF0 and paramByte8.toInt()) {
0xA0 -> { 0xA0 -> {
@ -69,48 +68,56 @@ open class MsgHistoryAll(
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_PRIME -> { info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_PRIME -> {
messageType += "prime" messageType += "prime"
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
danaRHistoryRecord.recordDate = datetimewihtsec danaRHistoryRecord.recordDate = datetimewihtsec
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
} }
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ERROR -> { info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ERROR -> {
messageType += "error" messageType += "error"
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
danaRHistoryRecord.recordDate = datetimewihtsec danaRHistoryRecord.recordDate = datetimewihtsec
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
} }
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_REFILL -> { info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_REFILL -> {
messageType += "refill" messageType += "refill"
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
danaRHistoryRecord.recordDate = datetimewihtsec danaRHistoryRecord.recordDate = datetimewihtsec
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
} }
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BASALHOUR -> { info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BASALHOUR -> {
messageType += "basal hour" messageType += "basal hour"
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
danaRHistoryRecord.recordDate = datetimewihtsec danaRHistoryRecord.recordDate = datetimewihtsec
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
} }
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_TB -> { info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_TB -> {
messageType += "tb" messageType += "tb"
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
danaRHistoryRecord.recordDate = datetimewihtsec danaRHistoryRecord.recordDate = datetimewihtsec
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
} }
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_GLUCOSE -> { info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_GLUCOSE -> {
messageType += "glucose" messageType += "glucose"
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
danaRHistoryRecord.recordDate = datetimewihtsec danaRHistoryRecord.recordDate = datetimewihtsec
danaRHistoryRecord.recordValue = value danaRHistoryRecord.recordValue = value
} }
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_CARBO -> { info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_CARBO -> {
messageType += "carbo" messageType += "carbo"
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
danaRHistoryRecord.recordDate = datetimewihtsec danaRHistoryRecord.recordDate = datetimewihtsec
danaRHistoryRecord.recordValue = value danaRHistoryRecord.recordValue = value
} }
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ALARM -> { info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ALARM -> {
messageType += "alarm" messageType += "alarm"
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
danaRHistoryRecord.recordDate = datetimewihtsec danaRHistoryRecord.recordDate = datetimewihtsec
var strAlarm = "None" var strAlarm = "None"
when (paramByte8.toInt()) { when (paramByte8.toInt()) {
@ -125,6 +132,7 @@ open class MsgHistoryAll(
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_SUSPEND -> { info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_SUSPEND -> {
messageType += "suspend" messageType += "suspend"
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
danaRHistoryRecord.recordDate = datetimewihtsec danaRHistoryRecord.recordDate = datetimewihtsec
var strRecordValue = "Off" var strRecordValue = "Off"
if (paramByte8.toInt() == 79) strRecordValue = "On" if (paramByte8.toInt() == 79) strRecordValue = "On"