DanaR: ignore history records with invalid date

This commit is contained in:
Milos Kozak 2023-01-21 14:48:56 +01:00
parent 2b7c082979
commit c1fca211bf

View file

@ -7,6 +7,7 @@ import info.nightscout.rx.events.EventDanaRSyncStatus
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
@Suppress("SpellCheckingInspection")
open class MsgHistoryAll( open class MsgHistoryAll(
injector: HasAndroidInjector injector: HasAndroidInjector
) : MessageBase(injector) { ) : MessageBase(injector) {
@ -17,6 +18,7 @@ open class MsgHistoryAll(
} }
override fun handleMessage(bytes: ByteArray) { override fun handleMessage(bytes: ByteArray) {
try {
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 dailyBasal = intFromBuff(bytes, 4, 2) * 0.01 val dailyBasal = intFromBuff(bytes, 4, 2) * 0.01
@ -148,5 +150,11 @@ open class MsgHistoryAll(
if (recordCode == RecordTypes.RECORD_TYPE_DAILY) if (recordCode == RecordTypes.RECORD_TYPE_DAILY)
pumpSync.createOrUpdateTotalDailyDose(date, dailyBolus, dailyBasal, dailyBolus + dailyBasal, date, activePlugin.activePump.model(), danaPump.serialNumber) pumpSync.createOrUpdateTotalDailyDose(date, dailyBolus, dailyBasal, dailyBolus + dailyBasal, date, activePlugin.activePump.model(), danaPump.serialNumber)
rxBus.send(EventDanaRSyncStatus(dateUtil.dateAndTimeString(danaHistoryRecord.timestamp) + " " + messageType)) rxBus.send(EventDanaRSyncStatus(dateUtil.dateAndTimeString(danaHistoryRecord.timestamp) + " " + messageType))
} catch (e: Exception) {
// DanaR id sometimes producing invalid date in history
// ignore these records
aapsLogger.error(e.stackTraceToString())
return
}
} }
} }