MDT: warn if history error detected

This commit is contained in:
Milos Kozak 2021-11-25 11:47:32 +01:00
parent 95deaf8b98
commit 3ac6320128
5 changed files with 36 additions and 14 deletions

View file

@ -127,6 +127,7 @@ open class Notification {
const val NSCLIENT_VERSION_DOES_NOT_MATCH = 73 const val NSCLIENT_VERSION_DOES_NOT_MATCH = 73
const val VERSION_EXPIRE = 74 const val VERSION_EXPIRE = 74
const val INVALID_PROFILE_NOT_ACCEPTED = 75 const val INVALID_PROFILE_NOT_ACCEPTED = 75
const val MDT_INVALID_HISTORY_DATA = 76
const val USER_MESSAGE = 1000 const val USER_MESSAGE = 1000

View file

@ -579,7 +579,11 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
fun getTemporaryBasal(): TempBasalPair? { fun getTemporaryBasal(): TempBasalPair? {
return sendAndGetResponseWithCheck(MedtronicCommandType.ReadTemporaryBasal) { _, _, rawContent -> return sendAndGetResponseWithCheck(MedtronicCommandType.ReadTemporaryBasal) { _, _, rawContent ->
TempBasalPair(aapsLogger, rawContent) if (rawContent.size >= 5) TempBasalPair(aapsLogger, rawContent)
else {
aapsLogger.debug(LTag.PUMPBTCOMM, "Received invalid TempBasal response" + ByteUtil.getHex(rawContent))
null
}
} }
} }

View file

@ -8,12 +8,16 @@ import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntry
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryBolus import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryBolus
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
import info.nightscout.androidaps.plugins.pump.medtronic.R
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryType import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryType
@ -24,6 +28,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpBolusType
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.StringUtils
import org.joda.time.LocalDateTime import org.joda.time.LocalDateTime
@ -40,12 +45,13 @@ import javax.inject.Singleton
// all times that time changed (TZ, DST, etc.). Data needs to be returned in batches (time_changed batches, so that we can // all times that time changed (TZ, DST, etc.). Data needs to be returned in batches (time_changed batches, so that we can
// handle it. It would help to assign sort_ids to items (from oldest (1) to newest (x) // handle it. It would help to assign sort_ids to items (from oldest (1) to newest (x)
// //
@Suppress("DEPRECATION")
@Singleton @Singleton
class MedtronicHistoryData @Inject constructor( class MedtronicHistoryData @Inject constructor(
val injector: HasAndroidInjector, val injector: HasAndroidInjector,
val aapsLogger: AAPSLogger, val aapsLogger: AAPSLogger,
val sp: SP, val sp: SP,
val rh: ResourceHelper,
val rxBus: RxBus,
val activePlugin: ActivePlugin, val activePlugin: ActivePlugin,
val medtronicUtil: MedtronicUtil, val medtronicUtil: MedtronicUtil,
val medtronicPumpHistoryDecoder: MedtronicPumpHistoryDecoder, val medtronicPumpHistoryDecoder: MedtronicPumpHistoryDecoder,
@ -207,7 +213,7 @@ class MedtronicHistoryData @Inject constructor(
allPumpIds.remove(pumpHistoryEntry.pumpId) allPumpIds.remove(pumpHistoryEntry.pumpId)
} }
} }
allHistory.removeAll(removeList) allHistory.removeAll(removeList.toSet())
this.sort(allHistory) this.sort(allHistory)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "All History records [afterFilterCount=%d, removedItemsCount=%d, newItemsCount=%d]", aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "All History records [afterFilterCount=%d, removedItemsCount=%d, newItemsCount=%d]",
allHistory.size, removeList.size, newHistory.size)) allHistory.size, removeList.size, newHistory.size))
@ -659,6 +665,10 @@ class MedtronicHistoryData @Inject constructor(
"pumpId=${tempBasalProcessDTO.pumpId}, rate=${tbrEntry.insulinRate} U, " + "pumpId=${tempBasalProcessDTO.pumpId}, rate=${tbrEntry.insulinRate} U, " +
"duration=${tempBasalProcessDTO.durationAsSeconds} s, pumpSerial=${medtronicPumpStatus.serialNumber}]") "duration=${tempBasalProcessDTO.durationAsSeconds} s, pumpSerial=${medtronicPumpStatus.serialNumber}]")
if (tempBasalProcessDTO.durationAsSeconds == 0) {
rxBus.send(EventNewNotification(Notification(Notification.MDT_INVALID_HISTORY_DATA, rh.gs(R.string.invalid_history_data), Notification.URGENT)))
aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId - Skipped")
} else {
val result = pumpSync.syncTemporaryBasalWithPumpId( val result = pumpSync.syncTemporaryBasalWithPumpId(
tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
tbrEntry.insulinRate, tbrEntry.insulinRate,
@ -667,9 +677,11 @@ class MedtronicHistoryData @Inject constructor(
PumpSync.TemporaryBasalType.NORMAL, PumpSync.TemporaryBasalType.NORMAL,
tempBasalProcessDTO.pumpId, tempBasalProcessDTO.pumpId,
medtronicPumpStatus.pumpType, medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber) medtronicPumpStatus.serialNumber
)
aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId - Result: $result") aapsLogger.debug(LTag.PUMP, "syncTemporaryBasalWithPumpId - Result: $result")
}
if (medtronicPumpStatus.runningTBR != null) { if (medtronicPumpStatus.runningTBR != null) {
if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) { if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) {

View file

@ -122,5 +122,6 @@
<string name="set_neutral_temps_summary">If enabled, it will cancel a temporary basal before the end of each hour. This method can help stop some pumps beeping/vibrating on the hour.</string> <string name="set_neutral_temps_summary">If enabled, it will cancel a temporary basal before the end of each hour. This method can help stop some pumps beeping/vibrating on the hour.</string>
<string name="mdt_tbr_remaining">%1$.1f U/h (%2$d min remaining)</string> <string name="mdt_tbr_remaining">%1$.1f U/h (%2$d min remaining)</string>
<string name="sixdigitnumber" translatable="false">^\\d{6}</string> <string name="sixdigitnumber" translatable="false">^\\d{6}</string>
<string name="invalid_history_data">Invalid pump history data detected. Open new issue and provide logs.</string>
</resources> </resources>

View file

@ -11,12 +11,14 @@ import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.hamcrest.Matchers.notNullValue import org.hamcrest.Matchers.notNullValue
import org.junit.Assert.* import org.junit.Assert.*
@ -35,6 +37,8 @@ class MedtronicHistoryDataUTest : TestBase() {
@Mock lateinit var pumpSync: PumpSync @Mock lateinit var pumpSync: PumpSync
@Mock lateinit var pumpSyncStorage: PumpSyncStorage @Mock lateinit var pumpSyncStorage: PumpSyncStorage
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var rh: ResourceHelper
@Mock lateinit var rxBus: RxBus
private val packetInjector = HasAndroidInjector { private val packetInjector = HasAndroidInjector {
@ -48,7 +52,7 @@ class MedtronicHistoryDataUTest : TestBase() {
@Test @Test
fun createTBRProcessList() { fun createTBRProcessList() {
var unitToTest = MedtronicHistoryData(packetInjector, aapsLogger, sp, activePlugin, var unitToTest = MedtronicHistoryData(packetInjector, aapsLogger, sp, rh, rxBus, activePlugin,
medtronicUtil, medtronicPumpHistoryDecoder, medtronicUtil, medtronicPumpHistoryDecoder,
medtronicPumpStatus, medtronicPumpStatus,
pumpSync, pumpSync,