kotlin lints

This commit is contained in:
Milos Kozak 2023-08-26 23:39:36 +02:00
parent 3640a751cb
commit 2cd5686556
8 changed files with 241 additions and 210 deletions

View file

@ -20,9 +20,9 @@ abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?>(var aapsLogge
) : MedtronicHistoryDecoderInterface<T> { ) : MedtronicHistoryDecoderInterface<T> {
// STATISTICS (remove at later time or not) // STATISTICS (remove at later time or not)
protected var statisticsEnabled = true private var statisticsEnabled = true
protected var unknownOpCodes: MutableMap<Int, Int?> = mutableMapOf() protected var unknownOpCodes: MutableMap<Int, Int?> = mutableMapOf()
protected var mapStatistics: MutableMap<RecordDecodeStatus, MutableMap<String, String>> = mutableMapOf() private var mapStatistics: MutableMap<RecordDecodeStatus, MutableMap<String, String>> = mutableMapOf()
abstract fun postProcess() abstract fun postProcess()
protected abstract fun runPostDecodeTasks() protected abstract fun runPostDecodeTasks()
@ -63,7 +63,7 @@ abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?>(var aapsLogge
} }
} }
protected fun addToStatistics(pumpHistoryEntry: MedtronicHistoryEntryInterface, status: RecordDecodeStatus, opCode: Int?) { protected fun addToStatistics(pumpHistoryEntry: MedtronicHistoryEntryInterface, status: RecordDecodeStatus, @Suppress("SameParameterValue") opCode: Int?) {
if (!statisticsEnabled) return if (!statisticsEnabled) return
if (opCode != null) { if (opCode != null) {
if (!unknownOpCodes.containsKey(opCode)) { if (!unknownOpCodes.containsKey(opCode)) {
@ -71,8 +71,8 @@ abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?>(var aapsLogge
} }
return return
} }
if (!mapStatistics[status]!!.containsKey(pumpHistoryEntry.entryTypeName)) { if (mapStatistics[status]?.containsKey(pumpHistoryEntry.entryTypeName) == false) {
mapStatistics[status]!!.put(pumpHistoryEntry.entryTypeName, "") mapStatistics[status]?.put(pumpHistoryEntry.entryTypeName, "")
} }
} }
@ -82,13 +82,13 @@ abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?>(var aapsLogge
StringUtil.appendToStringBuilder(sb, "" + key, ", ") StringUtil.appendToStringBuilder(sb, "" + key, ", ")
} }
aapsLogger.info(LTag.PUMPCOMM, "STATISTICS OF PUMP DECODE") aapsLogger.info(LTag.PUMPCOMM, "STATISTICS OF PUMP DECODE")
if (unknownOpCodes.size > 0) { if (unknownOpCodes.isNotEmpty()) {
aapsLogger.warn(LTag.PUMPCOMM, "Unknown Op Codes: $sb") aapsLogger.warn(LTag.PUMPCOMM, "Unknown Op Codes: $sb")
} }
for ((key, value) in mapStatistics) { for ((key, value) in mapStatistics) {
sb = StringBuilder() sb = StringBuilder()
if (key !== RecordDecodeStatus.OK) { if (key !== RecordDecodeStatus.OK) {
if (value.size == 0) continue if (value.isEmpty()) continue
for ((key1) in value) { for ((key1) in value) {
StringUtil.appendToStringBuilder(sb, key1, ", ") StringUtil.appendToStringBuilder(sb, key1, ", ")
} }

View file

@ -12,7 +12,11 @@ enum class CGMSHistoryEntryType(val code: Int, val description: String, val head
DataEnd(0x01, "DataEnd", 1, 0, 0, DateType.PreviousTimeStamp), // DataEnd(0x01, "DataEnd", 1, 0, 0, DateType.PreviousTimeStamp), //
SensorWeakSignal(0x02, "SensorWeakSignal", 1, 0, 0, DateType.PreviousTimeStamp), // SensorWeakSignal(0x02, "SensorWeakSignal", 1, 0, 0, DateType.PreviousTimeStamp), //
SensorCal(0x03, "SensorCal", 1, 0, 1, DateType.PreviousTimeStamp), // SensorCal(0x03, "SensorCal", 1, 0, 1, DateType.PreviousTimeStamp), //
SensorPacket(0x04, "SensorPacket", 1, 0, 1, DateType.PreviousTimeStamp), SensorError(0x05, "SensorError", 1, 0, 1, DateType.PreviousTimeStamp), SensorDataLow(0x06, "SensorDataLow", 1, 0, 1, DateType.PreviousTimeStamp), SensorDataHigh(0x07, "SensorDataHigh", 1, 0, 1, DateType.PreviousTimeStamp), SensorTimestamp(0x08, "SensorTimestamp", 1, 4, 0, DateType.MinuteSpecific), // SensorPacket(0x04, "SensorPacket", 1, 0, 1, DateType.PreviousTimeStamp),
SensorError(0x05, "SensorError", 1, 0, 1, DateType.PreviousTimeStamp),
SensorDataLow(0x06, "SensorDataLow", 1, 0, 1, DateType.PreviousTimeStamp),
SensorDataHigh(0x07, "SensorDataHigh", 1, 0, 1, DateType.PreviousTimeStamp),
SensorTimestamp(0x08, "SensorTimestamp", 1, 4, 0, DateType.MinuteSpecific), //
BatteryChange(0x0a, "BatteryChange", 1, 4, 0, DateType.MinuteSpecific), // BatteryChange(0x0a, "BatteryChange", 1, 4, 0, DateType.MinuteSpecific), //
SensorStatus(0x0b, "SensorStatus", 1, 4, 0, DateType.MinuteSpecific), // SensorStatus(0x0b, "SensorStatus", 1, 4, 0, DateType.MinuteSpecific), //
DateTimeChange(0x0c, "DateTimeChange", 1, 4, 0, DateType.SecondSpecific), // DateTimeChange(0x0c, "DateTimeChange", 1, 4, 0, DateType.SecondSpecific), //
@ -20,19 +24,16 @@ enum class CGMSHistoryEntryType(val code: Int, val description: String, val head
CalBGForGH(0x0e, "CalBGForGH',packet_size=5", 1, 4, 1, DateType.MinuteSpecific), // CalBGForGH(0x0e, "CalBGForGH',packet_size=5", 1, 4, 1, DateType.MinuteSpecific), //
SensorCalFactor(0x0f, "SensorCalFactor", 1, 4, 2, DateType.MinuteSpecific), // SensorCalFactor(0x0f, "SensorCalFactor", 1, 4, 2, DateType.MinuteSpecific), //
Something10(0x10, "10-Something", 1, 4, 0, DateType.MinuteSpecific), // Something10(0x10, "10-Something", 1, 4, 0, DateType.MinuteSpecific), //
Something19(0x13, "19-Something", 1, 0, 0, DateType.PreviousTimeStamp), GlucoseSensorData(0xFF, "GlucoseSensorData", 1, 0, 0, DateType.PreviousTimeStamp), Something19(0x13, "19-Something", 1, 0, 0, DateType.PreviousTimeStamp),
GlucoseSensorData(0xFF, "GlucoseSensorData", 1, 0, 0, DateType.PreviousTimeStamp),
UnknownOpCode(0xFF, "Unknown", 0, 0, 0, DateType.None); UnknownOpCode(0xFF, "Unknown", 0, 0, 0, DateType.None);
companion object { companion object {
private val opCodeMap: MutableMap<Int, CGMSHistoryEntryType> = mutableMapOf() private val opCodeMap: MutableMap<Int, CGMSHistoryEntryType> = mutableMapOf()
fun getByCode(opCode: Int): CGMSHistoryEntryType { fun getByCode(opCode: Int): CGMSHistoryEntryType =
return if (opCodeMap.containsKey(opCode)) opCodeMap[opCode] ?: UnknownOpCode
opCodeMap[opCode]!!
else
UnknownOpCode
}
init { init {
for (type in values()) { for (type in values()) {
@ -41,8 +42,8 @@ enum class CGMSHistoryEntryType(val code: Int, val description: String, val head
} }
} }
var schemaSet: Boolean var schemaSet: Boolean = true
val totalLength: Int val totalLength: Int = headLength + dateLength + bodyLength
val dateType: DateType val dateType: DateType
fun hasDate(): Boolean { fun hasDate(): Boolean {
@ -57,8 +58,6 @@ enum class CGMSHistoryEntryType(val code: Int, val description: String, val head
} }
init { init {
totalLength = headLength + dateLength + bodyLength
schemaSet = true
this.dateType = dateType this.dateType = dateType
} }
} }

View file

@ -10,13 +10,14 @@ import info.nightscout.pump.common.defs.PumpHistoryEntryGroup
* *
* Author: Andy {andy.rozman@gmail.com} * Author: Andy {andy.rozman@gmail.com}
*/ */
enum class PumpHistoryEntryType // implements CodeEnum enum class PumpHistoryEntryType(
constructor(var code: Byte, var code: Byte,
var description: String, var description: String,
var group: PumpHistoryEntryGroup, var group: PumpHistoryEntryGroup,
var headLength: Int = 2, private var headLength: Int = 2,
var dateLength: Int = 5, var dateLength: Int = 5,
var bodyLength: Int = 0) { private var bodyLength: Int = 0
) {
// all commented out are probably not the real items // all commented out are probably not the real items
None(0, "None", PumpHistoryEntryGroup.Unknown, 1, 0, 0), None(0, "None", PumpHistoryEntryGroup.Unknown, 1, 0, 0),
@ -25,7 +26,9 @@ constructor(var code: Byte,
// /**/EventUnknown_MM522_0x05((byte) 0x05, "Unknown Event 0x05", PumpHistoryEntryGroup.Unknown, 2, 5, 28), // // /**/EventUnknown_MM522_0x05((byte) 0x05, "Unknown Event 0x05", PumpHistoryEntryGroup.Unknown, 2, 5, 28), //
NoDeliveryAlarm(0x06, "No Delivery", PumpHistoryEntryGroup.Alarm, 4, 5, 0), // NoDeliveryAlarm(0x06, "No Delivery", PumpHistoryEntryGroup.Alarm, 4, 5, 0), //
EndResultTotals(0x07, "End Result Totals", PumpHistoryEntryGroup.Statistic, 5, 2, 0), ChangeBasalProfile_OldProfile(0x08, "Change Basal Profile (Old)", PumpHistoryEntryGroup.Basal, 2, 5, 145), ChangeBasalProfile_NewProfile(0x09, "Change Basal Profile (New)", PumpHistoryEntryGroup.Basal, 2, 5, 145), // EndResultTotals(0x07, "End Result Totals", PumpHistoryEntryGroup.Statistic, 5, 2, 0),
ChangeBasalProfile_OldProfile(0x08, "Change Basal Profile (Old)", PumpHistoryEntryGroup.Basal, 2, 5, 145),
ChangeBasalProfile_NewProfile(0x09, "Change Basal Profile (New)", PumpHistoryEntryGroup.Basal, 2, 5, 145), //
// /**/EventUnknown_MM512_0x10(0x10, "Unknown Event 0x10", PumpHistoryEntryGroup.Unknown), // 29, 5, 0 // /**/EventUnknown_MM512_0x10(0x10, "Unknown Event 0x10", PumpHistoryEntryGroup.Unknown), // 29, 5, 0
CalBGForPH(0x0a, "BG Capture", PumpHistoryEntryGroup.Glucose), // CalBGForPH(0x0a, "BG Capture", PumpHistoryEntryGroup.Glucose), //
@ -144,7 +147,7 @@ constructor(var code: Byte,
companion object { companion object {
private val opCodeMap: MutableMap<Byte, PumpHistoryEntryType?> = HashMap() private val opCodeMap: MutableMap<Byte, PumpHistoryEntryType?> = HashMap()
fun setSpecialRulesForEntryTypes() { private fun setSpecialRulesForEntryTypes() {
EndResultTotals.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 3)) EndResultTotals.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 3))
Bolus.addSpecialRuleHead(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 8)) Bolus.addSpecialRuleHead(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 8))
BolusWizardSetup.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 137)) BolusWizardSetup.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 137))
@ -153,41 +156,8 @@ constructor(var code: Byte,
ChangeSensorSetup2.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 34)) ChangeSensorSetup2.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 34))
} }
fun getByCode(opCode: Byte): PumpHistoryEntryType { fun getByCode(opCode: Byte): PumpHistoryEntryType =
return if (opCodeMap.containsKey(opCode)) { opCodeMap[opCode] ?: UnknownBasePacket
opCodeMap[opCode]!!
} else {
UnknownBasePacket
}
}
fun isAAPSRelevantEntry(entryType: PumpHistoryEntryType): Boolean {
return entryType == Bolus || // Treatments
entryType == TempBasalRate || //
entryType == TempBasalDuration || //
entryType == Prime || // Pump Status Change
entryType == SuspendPump || //
entryType == ResumePump || //
entryType == Rewind || //
entryType == NoDeliveryAlarm || // no delivery
entryType == BasalProfileStart || //
entryType == ChangeTime || // Time Change
entryType == NewTimeSet || //
entryType == ChangeBasalPattern || // Configuration
entryType == ClearSettings || //
entryType == SaveSettings || //
entryType == ChangeMaxBolus || //
entryType == ChangeMaxBasal || //
entryType == ChangeTempBasalType || //
entryType == ChangeBasalProfile_NewProfile || // Basal profile
entryType == DailyTotals515 || // Daily Totals
entryType == DailyTotals522 || //
entryType == DailyTotals523 || //
entryType == EndResultTotals
}
val isRelevantEntry: Boolean
get() = true
init { init {
for (type in values()) { for (type in values()) {
@ -197,7 +167,7 @@ constructor(var code: Byte,
} }
} }
private val totalLength: Int private val totalLength: Int = headLength + dateLength + bodyLength
// special rules need to be put in list from highest to lowest (e.g.: // special rules need to be put in list from highest to lowest (e.g.:
// 523andHigher=12, 515andHigher=10 and default (set in cnstr) would be 8) // 523andHigher=12, 515andHigher=10 and default (set in cnstr) would be 8)
@ -259,7 +229,4 @@ constructor(var code: Byte,
class SpecialRule internal constructor(var deviceType: MedtronicDeviceType, var size: Int) class SpecialRule internal constructor(var deviceType: MedtronicDeviceType, var size: Int)
init {
totalLength = headLength + dateLength + bodyLength
}
} }

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BatteryStatusDTO import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BatteryStatusDTO
@ -12,9 +11,9 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicNotificat
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicUIResponseType import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicUIResponseType
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.rx.bus.RxBus
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper
import org.joda.time.DateTimeZone import org.joda.time.DateTimeZone
import org.joda.time.Duration import org.joda.time.Duration
import java.util.Date import java.util.Date
@ -28,11 +27,11 @@ import javax.inject.Singleton
@Singleton @Singleton
class MedtronicUIPostprocessor @Inject constructor( class MedtronicUIPostprocessor @Inject constructor(
private val aapsLogger: AAPSLogger, private val aapsLogger: AAPSLogger,
private val rxBus: RxBus,
private val rh: ResourceHelper, private val rh: ResourceHelper,
private val medtronicUtil: MedtronicUtil, private val medtronicUtil: MedtronicUtil,
private val medtronicPumpStatus: MedtronicPumpStatus, private val medtronicPumpStatus: MedtronicPumpStatus,
private val medtronicPumpPlugin: MedtronicPumpPlugin) { private val medtronicPumpPlugin: MedtronicPumpPlugin
) {
// this is mostly intended for command that return certain statuses (Remaining Insulin, ...), and // this is mostly intended for command that return certain statuses (Remaining Insulin, ...), and
// where responses won't be directly used // where responses won't be directly used
@ -66,7 +65,7 @@ class MedtronicUIPostprocessor @Inject constructor(
} }
} }
} catch (ex: Exception) { } catch (ex: Exception) {
aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Basal Profile was returned, but was invalid. [%s]", basalProfile!!.basalProfileToStringError())) aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Basal Profile was returned, but was invalid. [%s]", basalProfile?.basalProfileToStringError()))
uiTask.responseType = MedtronicUIResponseType.Error uiTask.responseType = MedtronicUIResponseType.Error
uiTask.errorDescription = "No profile found." uiTask.errorDescription = "No profile found."
} }
@ -95,7 +94,7 @@ class MedtronicUIPostprocessor @Inject constructor(
val response = uiTask.result as Boolean val response = uiTask.result as Boolean
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "New time was %s set.", if (response) "" else "NOT")) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "New time was %s set.", if (response) "" else "NOT"))
if (response) { if (response) {
medtronicUtil.pumpTime!!.timeDifference = 0 medtronicUtil.pumpTime?.timeDifference = 0
} }
} }
@ -132,13 +131,16 @@ class MedtronicUIPostprocessor @Inject constructor(
private fun processTime(uiTask: MedtronicUITask) { private fun processTime(uiTask: MedtronicUITask) {
val clockDTO = uiTask.result as ClockDTO? val clockDTO = uiTask.result as ClockDTO?
if (clockDTO != null) { if (clockDTO != null) {
val dur = Duration(clockDTO.pumpTime.toDateTime(DateTimeZone.UTC), val dur = Duration(
clockDTO.localDeviceTime.toDateTime(DateTimeZone.UTC)) clockDTO.pumpTime.toDateTime(DateTimeZone.UTC),
clockDTO.localDeviceTime.toDateTime(DateTimeZone.UTC)
)
clockDTO.timeDifference = dur.standardSeconds.toInt() clockDTO.timeDifference = dur.standardSeconds.toInt()
medtronicUtil.pumpTime = clockDTO medtronicUtil.pumpTime = clockDTO
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, "Pump Time: " + clockDTO.localDeviceTime + ", DeviceTime=" + clockDTO.pumpTime + // LTag.PUMP, "Pump Time: " + clockDTO.localDeviceTime + ", DeviceTime=" + clockDTO.pumpTime + //
", diff: " + dur.standardSeconds + " s") ", diff: " + dur.standardSeconds + " s"
)
} else { } else {
aapsLogger.debug(LTag.PUMP, "Problem with returned data: " + medtronicUtil.gsonInstance.toJson(uiTask.result)) aapsLogger.debug(LTag.PUMP, "Problem with returned data: " + medtronicUtil.gsonInstance.toJson(uiTask.result))
} }
@ -148,18 +150,18 @@ class MedtronicUIPostprocessor @Inject constructor(
@Suppress("UNCHECKED_CAST") val settings = uiTask.result as? Map<String, PumpSettingDTO> ?: return @Suppress("UNCHECKED_CAST") val settings = uiTask.result as? Map<String, PumpSettingDTO> ?: return
medtronicUtil.settings = settings medtronicUtil.settings = settings
var checkValue: PumpSettingDTO var checkValue: PumpSettingDTO?
medtronicPumpPlugin.rileyLinkService?.verifyConfiguration() medtronicPumpPlugin.rileyLinkService?.verifyConfiguration()
// check profile // check profile
if (settings.containsKey("PCFG_BASAL_PROFILES_ENABLED") && settings.containsKey("PCFG_ACTIVE_BASAL_PROFILE")) { if (settings.containsKey("PCFG_BASAL_PROFILES_ENABLED") && settings.containsKey("PCFG_ACTIVE_BASAL_PROFILE")) {
checkValue = settings["PCFG_BASAL_PROFILES_ENABLED"]!! checkValue = settings["PCFG_BASAL_PROFILES_ENABLED"]
if ("Yes" != checkValue.value) { if ("Yes" != checkValue?.value) {
aapsLogger.error(LTag.PUMP, "Basal profiles are not enabled on pump.") aapsLogger.error(LTag.PUMP, "Basal profiles are not enabled on pump.")
medtronicUtil.sendNotification(MedtronicNotificationType.PumpBasalProfilesNotEnabled, rh) medtronicUtil.sendNotification(MedtronicNotificationType.PumpBasalProfilesNotEnabled, rh)
} else { } else {
checkValue = settings["PCFG_ACTIVE_BASAL_PROFILE"]!! checkValue = settings["PCFG_ACTIVE_BASAL_PROFILE"]
if ("STD" != checkValue.value) { if ("STD" != checkValue?.value) {
aapsLogger.error("Basal profile set on pump is incorrect (must be STD).") aapsLogger.error("Basal profile set on pump is incorrect (must be STD).")
medtronicUtil.sendNotification(MedtronicNotificationType.PumpIncorrectBasalProfileSelected, rh) medtronicUtil.sendNotification(MedtronicNotificationType.PumpIncorrectBasalProfileSelected, rh)
} }
@ -168,7 +170,7 @@ class MedtronicUIPostprocessor @Inject constructor(
// TBR // TBR
if (settings.containsKey("PCFG_TEMP_BASAL_TYPE")) { if (settings.containsKey("PCFG_TEMP_BASAL_TYPE")) {
if ("Units" != settings["PCFG_TEMP_BASAL_TYPE"]!!.value) { if ("Units" != settings["PCFG_TEMP_BASAL_TYPE"]?.value) {
aapsLogger.error("Wrong TBR type set on pump (must be Absolute).") aapsLogger.error("Wrong TBR type set on pump (must be Absolute).")
medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongTBRTypeSet, rh) medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongTBRTypeSet, rh)
} }
@ -176,17 +178,17 @@ class MedtronicUIPostprocessor @Inject constructor(
// MAXes // MAXes
if (settings.containsKey("PCFG_MAX_BOLUS")) { if (settings.containsKey("PCFG_MAX_BOLUS")) {
checkValue = settings["PCFG_MAX_BOLUS"]!! checkValue = settings["PCFG_MAX_BOLUS"]
if (!MedtronicUtil.isSame(checkValue.value.toDouble(), medtronicPumpStatus.maxBolus!!)) { if (!MedtronicUtil.isSame(checkValue?.value?.toDouble(), medtronicPumpStatus.maxBolus)) {
aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Wrong Max Bolus set on Pump (current=%s, required=%.2f).", checkValue.value, medtronicPumpStatus.maxBolus)) aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Wrong Max Bolus set on Pump (current=%s, required=%.2f).", checkValue?.value, medtronicPumpStatus.maxBolus))
medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBolusSet, rh, medtronicPumpStatus.maxBolus) medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBolusSet, rh, medtronicPumpStatus.maxBolus)
} }
} }
if (settings.containsKey("PCFG_MAX_BASAL")) { if (settings.containsKey("PCFG_MAX_BASAL")) {
checkValue = settings["PCFG_MAX_BASAL"]!! checkValue = settings["PCFG_MAX_BASAL"]
if (!MedtronicUtil.isSame(checkValue.value.toDouble(), medtronicPumpStatus.maxBasal!!)) { if (!MedtronicUtil.isSame(checkValue?.value?.toDouble(), medtronicPumpStatus.maxBasal)) {
aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Wrong Max Basal set on Pump (current=%s, required=%.2f).", checkValue.value, medtronicPumpStatus.maxBasal)) aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Wrong Max Basal set on Pump (current=%s, required=%.2f).", checkValue?.value, medtronicPumpStatus.maxBasal))
medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBasalSet, rh, medtronicPumpStatus.maxBasal) medtronicUtil.sendNotification(MedtronicNotificationType.PumpWrongMaxBasalSet, rh, medtronicPumpStatus.maxBasal)
} }
} }

View file

@ -226,8 +226,11 @@ class MedtronicHistoryData @Inject constructor(
allHistory.removeAll(removeList.toSet()) allHistory.removeAll(removeList.toSet())
this.sort(allHistory) this.sort(allHistory)
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, String.format(Locale.ENGLISH, "All History records [afterFilterCount=%d, removedItemsCount=%d, newItemsCount=%d]", LTag.PUMP, String.format(
allHistory.size, removeList.size, newHistory.size)) Locale.ENGLISH, "All History records [afterFilterCount=%d, removedItemsCount=%d, newItemsCount=%d]",
allHistory.size, removeList.size, newHistory.size
)
)
} else { } else {
aapsLogger.error("Since we couldn't determine date, we don't clean full history. This is just workaround.") aapsLogger.error("Since we couldn't determine date, we don't clean full history. This is just workaround.")
} }
@ -236,12 +239,15 @@ class MedtronicHistoryData @Inject constructor(
fun hasRelevantConfigurationChanged(): Boolean { fun hasRelevantConfigurationChanged(): Boolean {
return getStateFromFilteredList( // return getStateFromFilteredList( //
setOf(PumpHistoryEntryType.ChangeBasalPattern, // setOf(
PumpHistoryEntryType.ChangeBasalPattern, //
PumpHistoryEntryType.ClearSettings, // PumpHistoryEntryType.ClearSettings, //
PumpHistoryEntryType.SaveSettings, // PumpHistoryEntryType.SaveSettings, //
PumpHistoryEntryType.ChangeMaxBolus, // PumpHistoryEntryType.ChangeMaxBolus, //
PumpHistoryEntryType.ChangeMaxBasal, // PumpHistoryEntryType.ChangeMaxBasal, //
PumpHistoryEntryType.ChangeTempBasalType)) PumpHistoryEntryType.ChangeTempBasalType
)
)
} }
private fun isCollectionEmpty(col: List<*>?): Boolean { private fun isCollectionEmpty(col: List<*>?): Boolean {
@ -282,8 +288,10 @@ class MedtronicHistoryData @Inject constructor(
} }
if (newAndAll.isEmpty()) return newAndAll if (newAndAll.isEmpty()) return newAndAll
this.sort(newAndAll) this.sort(newAndAll)
var newAndAll2: MutableList<PumpHistoryEntry> = getFilteredItems(newAndAll, // var newAndAll2: MutableList<PumpHistoryEntry> = getFilteredItems(
setOf(PumpHistoryEntryType.Bolus, // newAndAll, //
setOf(
PumpHistoryEntryType.Bolus, //
PumpHistoryEntryType.TempBasalCombined, // PumpHistoryEntryType.TempBasalCombined, //
PumpHistoryEntryType.Prime, // PumpHistoryEntryType.Prime, //
PumpHistoryEntryType.SuspendPump, // PumpHistoryEntryType.SuspendPump, //
@ -291,7 +299,9 @@ class MedtronicHistoryData @Inject constructor(
PumpHistoryEntryType.Rewind, // PumpHistoryEntryType.Rewind, //
PumpHistoryEntryType.NoDeliveryAlarm, // PumpHistoryEntryType.NoDeliveryAlarm, //
PumpHistoryEntryType.BatteryChange, // PumpHistoryEntryType.BatteryChange, //
PumpHistoryEntryType.BasalProfileStart)) PumpHistoryEntryType.BasalProfileStart
)
)
newAndAll2 = filterPumpSuspend(newAndAll2, 10) newAndAll2 = filterPumpSuspend(newAndAll2, 10)
return newAndAll2 return newAndAll2
} }
@ -382,8 +392,11 @@ class MedtronicHistoryData @Inject constructor(
throw ex throw ex
} }
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, String.format(Locale.ENGLISH, "ProcessHistoryData: 'Delivery Suspend' Processed [count=%d, items=%s]", suspends.size, LTag.PUMP, String.format(
gson.toJson(suspends))) Locale.ENGLISH, "ProcessHistoryData: 'Delivery Suspend' Processed [count=%d, items=%s]", suspends.size,
gson.toJson(suspends)
)
)
if (suspends.isNotEmpty()) { if (suspends.isNotEmpty()) {
try { try {
processSuspends(suspends) // TODO not tested yet processSuspends(suspends) // TODO not tested yet
@ -414,7 +427,8 @@ class MedtronicHistoryData @Inject constructor(
} }
} }
if (lastPrimeRecord != null) { if (lastPrimeRecord != null) {
uploadCareportalEventIfFoundInHistory(lastPrimeRecord, uploadCareportalEventIfFoundInHistory(
lastPrimeRecord,
MedtronicConst.Statistics.LastPrime, MedtronicConst.Statistics.LastPrime,
DetailedBolusInfo.EventType.CANNULA_CHANGE DetailedBolusInfo.EventType.CANNULA_CHANGE
) )
@ -434,9 +448,11 @@ class MedtronicHistoryData @Inject constructor(
} }
} }
if (lastRewindRecord != null) { if (lastRewindRecord != null) {
uploadCareportalEventIfFoundInHistory(lastRewindRecord, uploadCareportalEventIfFoundInHistory(
lastRewindRecord,
MedtronicConst.Statistics.LastRewind, MedtronicConst.Statistics.LastRewind,
DetailedBolusInfo.EventType.INSULIN_CHANGE) DetailedBolusInfo.EventType.INSULIN_CHANGE
)
} }
} }
@ -448,12 +464,16 @@ class MedtronicHistoryData @Inject constructor(
eventType, null, eventType, null,
historyRecord.pumpId, historyRecord.pumpId,
medtronicPumpStatus.pumpType, medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber) medtronicPumpStatus.serialNumber
)
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, String.format(Locale.ROOT, "insertTherapyEventIfNewWithTimestamp [date=%d, eventType=%s, pumpId=%d, pumpSerial=%s] - Result: %b", LTag.PUMP, String.format(
historyRecord.atechDateTime, eventType, historyRecord.pumpId, Locale.ROOT, "insertTherapyEventIfNewWithTimestamp [date=%d, eventType=%s, pumpId=%d, pumpSerial=%s] - Result: %b",
medtronicPumpStatus.serialNumber, result)) historyRecord.atechDateTime, eventType, historyRecord.pumpId,
medtronicPumpStatus.serialNumber, result
)
)
sp.putLong(eventSP, historyRecord.atechDateTime) sp.putLong(eventSP, historyRecord.atechDateTime)
} }
@ -463,8 +483,11 @@ class MedtronicHistoryData @Inject constructor(
val tdds = filterTDDs(tddsIn) val tdds = filterTDDs(tddsIn)
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, String.format(Locale.ENGLISH, logPrefix + "TDDs found: %d.\n%s", LTag.PUMP, String.format(
tdds.size, gson.toJson(tdds))) Locale.ENGLISH, logPrefix + "TDDs found: %d.\n%s",
tdds.size, gson.toJson(tdds)
)
)
for (tdd in tdds) { for (tdd in tdds) {
val totalsDTO = tdd.decodedData["Object"] as DailyTotalsDTO val totalsDTO = tdd.decodedData["Object"] as DailyTotalsDTO
@ -483,6 +506,7 @@ class MedtronicHistoryData @Inject constructor(
@Suppress("unused") @Suppress("unused")
private enum class ProcessHistoryRecord(val description: String) { private enum class ProcessHistoryRecord(val description: String) {
Bolus("Bolus"), Bolus("Bolus"),
TBR("TBR"), TBR("TBR"),
Suspend("Suspend"); Suspend("Suspend");
@ -535,12 +559,16 @@ class MedtronicHistoryData @Inject constructor(
type = null, type = null,
pumpId = bolus.pumpId, pumpId = bolus.pumpId,
pumpType = medtronicPumpStatus.pumpType, pumpType = medtronicPumpStatus.pumpType,
pumpSerial = medtronicPumpStatus.serialNumber) pumpSerial = medtronicPumpStatus.serialNumber
)
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, String.format(Locale.ENGLISH, "syncBolusWithTempId [date=%d, temporaryId=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b", LTag.PUMP, String.format(
bolus.atechDateTime, temporaryId, bolus.pumpId, deliveredAmount, Locale.ENGLISH, "syncBolusWithTempId [date=%d, temporaryId=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b",
medtronicPumpStatus.serialNumber, result)) bolus.atechDateTime, temporaryId, bolus.pumpId, deliveredAmount,
medtronicPumpStatus.serialNumber, result
)
)
} else { } else {
val result = pumpSync.syncBolusWithPumpId( val result = pumpSync.syncBolusWithPumpId(
timestamp = tryToGetByLocalTime(bolus.atechDateTime), timestamp = tryToGetByLocalTime(bolus.atechDateTime),
@ -548,12 +576,16 @@ class MedtronicHistoryData @Inject constructor(
type = null, type = null,
pumpId = bolus.pumpId, pumpId = bolus.pumpId,
pumpType = medtronicPumpStatus.pumpType, pumpType = medtronicPumpStatus.pumpType,
pumpSerial = medtronicPumpStatus.serialNumber) pumpSerial = medtronicPumpStatus.serialNumber
)
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, String.format(Locale.ENGLISH, "syncBolusWithPumpId [date=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b", LTag.PUMP, String.format(
bolus.atechDateTime, bolus.pumpId, deliveredAmount, Locale.ENGLISH, "syncBolusWithPumpId [date=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b",
medtronicPumpStatus.serialNumber, result)) bolus.atechDateTime, bolus.pumpId, deliveredAmount,
medtronicPumpStatus.serialNumber, result
)
)
} }
addCarbs(bolus) addCarbs(bolus)
@ -570,12 +602,16 @@ class MedtronicHistoryData @Inject constructor(
false, false,
bolus.pumpId, bolus.pumpId,
medtronicPumpStatus.pumpType, medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber) medtronicPumpStatus.serialNumber
)
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, String.format(Locale.ENGLISH, "syncExtendedBolusWithPumpId [date=%d, amount=%.2f, duration=%d, pumpId=%d, pumpSerial=%s, multiwave=%b] - Result: %b", LTag.PUMP, String.format(
bolus.atechDateTime, bolusDTO.deliveredAmount, bolusDTO.duration, bolus.pumpId, Locale.ENGLISH, "syncExtendedBolusWithPumpId [date=%d, amount=%.2f, duration=%d, pumpId=%d, pumpSerial=%s, multiwave=%b] - Result: %b",
medtronicPumpStatus.serialNumber, isMultiwave, result)) bolus.atechDateTime, bolusDTO.deliveredAmount, bolusDTO.duration, bolus.pumpId,
medtronicPumpStatus.serialNumber, isMultiwave, result
)
)
} }
private fun addCarbs(bolus: PumpHistoryEntry) { private fun addCarbs(bolus: PumpHistoryEntry) {
@ -584,12 +620,12 @@ class MedtronicHistoryData @Inject constructor(
pumpSyncStorage.addCarbs( pumpSyncStorage.addCarbs(
PumpDbEntryCarbs( PumpDbEntryCarbs(
tryToGetByLocalTime(bolus.atechDateTime), tryToGetByLocalTime(bolus.atechDateTime),
bolusWizard.carbs.toDouble(), bolusWizard.carbs.toDouble(),
medtronicPumpStatus.pumpType, medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber, medtronicPumpStatus.serialNumber,
bolus.pumpId bolus.pumpId
) )
) )
} }
} }
@ -628,7 +664,7 @@ class MedtronicHistoryData @Inject constructor(
//aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemTwo: " + (if (tempBasalProcessDTO.itemTwo == null) "null" else gson.toJson(tempBasalProcessDTO.itemTwo!!))) //aapsLogger.debug(LTag.PUMP, "DD: tempBasalProcessDTO.itemTwo: " + (if (tempBasalProcessDTO.itemTwo == null) "null" else gson.toJson(tempBasalProcessDTO.itemTwo!!)))
@Suppress("Unchecked_Cast") @Suppress("Unchecked_Cast")
val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords as MutableList<PumpDbEntry>) as PumpDbEntryTBR? val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords as MutableList<PumpDbEntry>) as PumpDbEntryTBR?
aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (entryWithTempId?.toString() ?: "null")) aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (entryWithTempId?.toString() ?: "null"))
@ -641,17 +677,19 @@ class MedtronicHistoryData @Inject constructor(
if (tbrEntry != null) { if (tbrEntry != null) {
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, "DD: tempIdEntry=${entryWithTempId}, tbrEntry=${tbrEntry}, " + LTag.PUMP, "DD: tempIdEntry=${entryWithTempId}, tbrEntry=${tbrEntry}, " +
"tempBasalProcessDTO=${tempBasalProcessDTO}, " + "tempBasalProcessDTO=${tempBasalProcessDTO}, " +
"pumpType=${medtronicPumpStatus.pumpType}, serial=${medtronicPumpStatus.serialNumber}") "pumpType=${medtronicPumpStatus.pumpType}, serial=${medtronicPumpStatus.serialNumber}"
)
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, "syncTemporaryBasalWithTempId " + LTag.PUMP, "syncTemporaryBasalWithTempId " +
"[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " + "[date=${tempBasalProcessDTO.atechDateTime}, dateProcess=${tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime)}, " +
"tbrEntry.insulinRate=${tbrEntry.insulinRate}, " + "tbrEntry.insulinRate=${tbrEntry.insulinRate}, " +
"duration=${tempBasalProcessDTO.durationAsSeconds} s, " + "duration=${tempBasalProcessDTO.durationAsSeconds} s, " +
"isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " + "isAbsolute=${!tbrEntry.isPercent}, temporaryId=${entryWithTempId.temporaryId}, " +
"pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " + "pumpId=${tempBasalProcessDTO.pumpId}, pumpType=${medtronicPumpStatus.pumpType}, " +
"pumpSerial=${medtronicPumpStatus.serialNumber}]") "pumpSerial=${medtronicPumpStatus.serialNumber}]"
)
if (tempBasalProcessDTO.durationAsSeconds <= 0) { if (tempBasalProcessDTO.durationAsSeconds <= 0) {
uiInteraction.addNotification(Notification.MDT_INVALID_HISTORY_DATA, rh.gs(R.string.invalid_history_data), Notification.URGENT) uiInteraction.addNotification(Notification.MDT_INVALID_HISTORY_DATA, rh.gs(R.string.invalid_history_data), Notification.URGENT)
@ -691,8 +729,9 @@ class MedtronicHistoryData @Inject constructor(
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, "syncTemporaryBasalWithPumpId [date=${tempBasalProcessDTO.atechDateTime}, " + LTag.PUMP, "syncTemporaryBasalWithPumpId [date=${tempBasalProcessDTO.atechDateTime}, " +
"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) { if (tempBasalProcessDTO.durationAsSeconds <= 0) {
uiInteraction.addNotification(Notification.MDT_INVALID_HISTORY_DATA, rh.gs(R.string.invalid_history_data), Notification.URGENT) uiInteraction.addNotification(Notification.MDT_INVALID_HISTORY_DATA, rh.gs(R.string.invalid_history_data), Notification.URGENT)
@ -718,8 +757,11 @@ class MedtronicHistoryData @Inject constructor(
} }
} }
if (isTBRActive(startTimestamp = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime), if (isTBRActive(
durationSeconds = tempBasalProcessDTO.durationAsSeconds)) { startTimestamp = tryToGetByLocalTime(tempBasalProcessDTO.atechDateTime),
durationSeconds = tempBasalProcessDTO.durationAsSeconds
)
) {
if (medtronicPumpStatus.runningTBR == null) { if (medtronicPumpStatus.runningTBR == null) {
medtronicPumpStatus.runningTBR = PumpDbEntryTBR( medtronicPumpStatus.runningTBR = PumpDbEntryTBR(
temporaryId = 0L, temporaryId = 0L,
@ -730,7 +772,8 @@ class MedtronicHistoryData @Inject constructor(
isAbsolute = !tbrEntry.isPercent, isAbsolute = !tbrEntry.isPercent,
durationInSeconds = tempBasalProcessDTO.durationAsSeconds, durationInSeconds = tempBasalProcessDTO.durationAsSeconds,
tbrType = PumpSync.TemporaryBasalType.NORMAL, tbrType = PumpSync.TemporaryBasalType.NORMAL,
pumpId = tempBasalProcessDTO.pumpId) pumpId = tempBasalProcessDTO.pumpId
)
} }
} }
} else { } else {
@ -741,8 +784,7 @@ class MedtronicHistoryData @Inject constructor(
} // collection } // collection
} }
fun createTBRProcessList(entryList: MutableList<PumpHistoryEntry>): MutableList<TempBasalProcessDTO> {
fun createTBRProcessList(entryList: MutableList<PumpHistoryEntry>) : MutableList<TempBasalProcessDTO> {
aapsLogger.debug(LTag.PUMP, "${ProcessHistoryRecord.TBR.description} List (before filter): ${gson.toJson(entryList)}") aapsLogger.debug(LTag.PUMP, "${ProcessHistoryRecord.TBR.description} List (before filter): ${gson.toJson(entryList)}")
@ -772,11 +814,11 @@ class MedtronicHistoryData @Inject constructor(
} }
var previousItem: TempBasalProcessDTO? = null var previousItem: TempBasalProcessDTO? = null
val removalList : MutableList<TempBasalProcessDTO> = arrayListOf() val removalList: MutableList<TempBasalProcessDTO> = arrayListOf()
// fix for Zero TBRs // fix for Zero TBRs
for (tempBasalProcessDTO in processList) { for (tempBasalProcessDTO in processList) {
if (previousItem!=null) { if (previousItem != null) {
val pheEnd = PumpHistoryEntry() val pheEnd = PumpHistoryEntry()
pheEnd.atechDateTime = DateTimeUtil.getATDWithAddedSeconds(tempBasalProcessDTO.itemOne.atechDateTime, -2) pheEnd.atechDateTime = DateTimeUtil.getATDWithAddedSeconds(tempBasalProcessDTO.itemOne.atechDateTime, -2)
@ -786,7 +828,7 @@ class MedtronicHistoryData @Inject constructor(
previousItem.itemTwo = pheEnd previousItem.itemTwo = pheEnd
if (previousItem.durationAsSeconds <=0) { if (previousItem.durationAsSeconds <= 0) {
// if we have duration of 0 or less, then we have invalid entry which needs to be removed // if we have duration of 0 or less, then we have invalid entry which needs to be removed
removalList.add(previousItem) removalList.add(previousItem)
} else if (previousItem.durationAsSeconds > initialDuration) { } else if (previousItem.durationAsSeconds > initialDuration) {
@ -796,7 +838,7 @@ class MedtronicHistoryData @Inject constructor(
previousItem = null previousItem = null
} }
if (tempBasalProcessDTO.itemOneTbr!!.isZeroTBR && tempBasalProcessDTO.itemTwo == null ) { if (tempBasalProcessDTO.itemOneTbr!!.isZeroTBR && tempBasalProcessDTO.itemTwo == null) {
previousItem = tempBasalProcessDTO previousItem = tempBasalProcessDTO
} }
} }
@ -852,33 +894,14 @@ class MedtronicHistoryData @Inject constructor(
return processList return processList
} }
fun findNearestEntry(startTime: Long, endTime: Long, list: MutableList<PumpHistoryEntry>) : PumpHistoryEntry? {
val outList: MutableList<PumpHistoryEntry> = mutableListOf()
for (pumpHistoryEntry in list) {
if ((pumpHistoryEntry.atechDateTime > startTime) &&
(pumpHistoryEntry.atechDateTime < endTime)) {
outList.add(pumpHistoryEntry)
}
}
if (outList.size == 0) {
return null
} else if (outList.size==1) {
return outList[0]
} else {
// TODO
return null
}
}
fun isTBRActive(dbEntry: PumpDbEntryTBR): Boolean { fun isTBRActive(dbEntry: PumpDbEntryTBR): Boolean {
return isTBRActive( return isTBRActive(
startTimestamp = dbEntry.date, startTimestamp = dbEntry.date,
durationSeconds = dbEntry.durationInSeconds) durationSeconds = dbEntry.durationInSeconds
)
} }
fun isTBRActive(startTimestamp: Long, durationSeconds: Int): Boolean { private fun isTBRActive(startTimestamp: Long, durationSeconds: Int): Boolean {
val endDate = startTimestamp + (durationSeconds * 1000) val endDate = startTimestamp + (durationSeconds * 1000)
return (endDate > System.currentTimeMillis()) return (endDate > System.currentTimeMillis())
@ -936,15 +959,32 @@ class MedtronicHistoryData @Inject constructor(
} }
} }
if (outList.size == 1) { if (outList.size == 1) {
if (doubleBolusDebug) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}. Type=EntrySelected, AtTimeMin={}, AtTimeSec={}", treatment, outList[0], min, sec)) if (doubleBolusDebug) aapsLogger.debug(
LTag.PUMP,
String.format(
Locale.ENGLISH,
"DoubleBolusDebug: findDbEntry Treatment={}, FromDb={}. Type=EntrySelected, AtTimeMin={}, AtTimeSec={}",
treatment,
outList[0],
min,
sec
)
)
return outList[0] return outList[0]
} }
if (min == 0 && sec == 10 && outList.size > 1) { if (min == 0 && sec == 10 && outList.size > 1) {
aapsLogger.error(String.format(Locale.ENGLISH, "Too many entries (with too small diff): (timeDiff=[min=%d,sec=%d],count=%d,list=%s)", aapsLogger.error(
min, sec, outList.size, gson.toJson(outList))) String.format(
Locale.ENGLISH, "Too many entries (with too small diff): (timeDiff=[min=%d,sec=%d],count=%d,list=%s)",
min, sec, outList.size, gson.toJson(outList)
)
)
if (doubleBolusDebug) aapsLogger.debug( if (doubleBolusDebug) aapsLogger.debug(
LTag.PUMP, String.format(Locale.ENGLISH, "DoubleBolusDebug: findDbEntry Error - Too many entries (with too small diff): (timeDiff=[min=%d,sec=%d],count=%d,list=%s)", LTag.PUMP, String.format(
min, sec, outList.size, gson.toJson(outList))) Locale.ENGLISH, "DoubleBolusDebug: findDbEntry Error - Too many entries (with too small diff): (timeDiff=[min=%d,sec=%d],count=%d,list=%s)",
min, sec, outList.size, gson.toJson(outList)
)
)
} }
sec += 10 sec += 10
} }
@ -958,9 +998,10 @@ class MedtronicHistoryData @Inject constructor(
aapsLogger.debug( aapsLogger.debug(
LTag.PUMP, "processSuspends::syncTemporaryBasalWithPumpId [date=${tempBasalProcess.itemOne.atechDateTime}, " + LTag.PUMP, "processSuspends::syncTemporaryBasalWithPumpId [date=${tempBasalProcess.itemOne.atechDateTime}, " +
"rate=0.0, duration=${tempBasalProcess.durationAsSeconds} s, type=${PumpSync.TemporaryBasalType.PUMP_SUSPEND}, " + "rate=0.0, duration=${tempBasalProcess.durationAsSeconds} s, type=${PumpSync.TemporaryBasalType.PUMP_SUSPEND}, " +
"pumpId=${tempBasalProcess.itemOne.pumpId}, " + "pumpId=${tempBasalProcess.itemOne.pumpId}, " +
"pumpSerial=${medtronicPumpStatus.serialNumber}]") "pumpSerial=${medtronicPumpStatus.serialNumber}]"
)
if (tempBasalProcess.durationAsSeconds <= 0) { if (tempBasalProcess.durationAsSeconds <= 0) {
uiInteraction.addNotification(Notification.MDT_INVALID_HISTORY_DATA, rh.gs(R.string.invalid_history_data), Notification.URGENT) uiInteraction.addNotification(Notification.MDT_INVALID_HISTORY_DATA, rh.gs(R.string.invalid_history_data), Notification.URGENT)
@ -995,8 +1036,10 @@ class MedtronicHistoryData @Inject constructor(
} }
private fun getSuspendResumeRecordsList(): List<TempBasalProcessDTO> { private fun getSuspendResumeRecordsList(): List<TempBasalProcessDTO> {
val filteredItems = getFilteredItems(newHistory, // val filteredItems = getFilteredItems(
setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump)) newHistory, //
setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump)
)
aapsLogger.debug(LTag.PUMP, "SuspendResume Records: $filteredItems") aapsLogger.debug(LTag.PUMP, "SuspendResume Records: $filteredItems")
@ -1040,7 +1083,8 @@ class MedtronicHistoryData @Inject constructor(
val tbrProcess = TempBasalProcessDTO( val tbrProcess = TempBasalProcessDTO(
itemOne = filtered2Items[i], itemOne = filtered2Items[i],
aapsLogger = aapsLogger, aapsLogger = aapsLogger,
objectType = TempBasalProcessDTO.ObjectType.Suspend) objectType = TempBasalProcessDTO.ObjectType.Suspend
)
tbrProcess.itemTwo = filtered2Items[i + 1] tbrProcess.itemTwo = filtered2Items[i + 1]
@ -1055,19 +1099,24 @@ class MedtronicHistoryData @Inject constructor(
} }
private fun getNoDeliveryRewindPrimeRecordsList(): List<TempBasalProcessDTO> { private fun getNoDeliveryRewindPrimeRecordsList(): List<TempBasalProcessDTO> {
val primeItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, // val primeItems: MutableList<PumpHistoryEntry> = getFilteredItems(
setOf(PumpHistoryEntryType.Prime)) newHistory, //
setOf(PumpHistoryEntryType.Prime)
)
aapsLogger.debug(LTag.PUMP, "Prime Records: $primeItems") aapsLogger.debug(LTag.PUMP, "Prime Records: $primeItems")
val outList: MutableList<TempBasalProcessDTO> = ArrayList() val outList: MutableList<TempBasalProcessDTO> = ArrayList()
if (primeItems.size == 0) return outList if (primeItems.size == 0) return outList
val filteredItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, // val filteredItems: MutableList<PumpHistoryEntry> = getFilteredItems(
setOf(PumpHistoryEntryType.Prime, newHistory, //
setOf(
PumpHistoryEntryType.Prime,
PumpHistoryEntryType.Rewind, PumpHistoryEntryType.Rewind,
PumpHistoryEntryType.NoDeliveryAlarm, PumpHistoryEntryType.NoDeliveryAlarm,
PumpHistoryEntryType.Bolus, PumpHistoryEntryType.Bolus,
PumpHistoryEntryType.TempBasalCombined) PumpHistoryEntryType.TempBasalCombined
)
) )
aapsLogger.debug(LTag.PUMP, "Filtered Records: $filteredItems") aapsLogger.debug(LTag.PUMP, "Filtered Records: $filteredItems")
@ -1081,7 +1130,8 @@ class MedtronicHistoryData @Inject constructor(
} }
if (startedItems) { if (startedItems) {
if (filteredItem.entryType === PumpHistoryEntryType.Bolus || if (filteredItem.entryType === PumpHistoryEntryType.Bolus ||
filteredItem.entryType === PumpHistoryEntryType.TempBasalCombined) { filteredItem.entryType === PumpHistoryEntryType.TempBasalCombined
) {
finishedItems = true finishedItems = true
break break
} }
@ -1089,15 +1139,19 @@ class MedtronicHistoryData @Inject constructor(
} }
} }
if (!finishedItems) { if (!finishedItems) {
val filteredItemsOld: MutableList<PumpHistoryEntry> = getFilteredItems(allHistory, // val filteredItemsOld: MutableList<PumpHistoryEntry> = getFilteredItems(
setOf(PumpHistoryEntryType.Rewind, allHistory, //
setOf(
PumpHistoryEntryType.Rewind,
PumpHistoryEntryType.NoDeliveryAlarm, PumpHistoryEntryType.NoDeliveryAlarm,
PumpHistoryEntryType.Bolus, PumpHistoryEntryType.Bolus,
PumpHistoryEntryType.TempBasalCombined) PumpHistoryEntryType.TempBasalCombined
)
) )
for (filteredItem in filteredItemsOld) { for (filteredItem in filteredItemsOld) {
if (filteredItem.entryType === PumpHistoryEntryType.Bolus || if (filteredItem.entryType === PumpHistoryEntryType.Bolus ||
filteredItem.entryType === PumpHistoryEntryType.TempBasalCombined) { filteredItem.entryType === PumpHistoryEntryType.TempBasalCombined
) {
finishedItems = true finishedItems = true
break break
} }
@ -1117,7 +1171,8 @@ class MedtronicHistoryData @Inject constructor(
val tbrProcess = TempBasalProcessDTO( val tbrProcess = TempBasalProcessDTO(
itemOne = items[items.size - 1], itemOne = items[items.size - 1],
aapsLogger = aapsLogger, aapsLogger = aapsLogger,
objectType = TempBasalProcessDTO.ObjectType.Suspend) objectType = TempBasalProcessDTO.ObjectType.Suspend
)
tbrProcess.itemTwo = itemTwo tbrProcess.itemTwo = itemTwo
@ -1132,7 +1187,8 @@ class MedtronicHistoryData @Inject constructor(
val tbrProcess = TempBasalProcessDTO( val tbrProcess = TempBasalProcessDTO(
itemOne = items[0], itemOne = items[0],
aapsLogger = aapsLogger, aapsLogger = aapsLogger,
objectType = TempBasalProcessDTO.ObjectType.Suspend) objectType = TempBasalProcessDTO.ObjectType.Suspend
)
tbrProcess.itemTwo = itemTwo tbrProcess.itemTwo = itemTwo
@ -1170,8 +1226,10 @@ class MedtronicHistoryData @Inject constructor(
} else when (medtronicUtil.medtronicPumpModel) { } else when (medtronicUtil.medtronicPumpModel) {
MedtronicDeviceType.Medtronic_515, MedtronicDeviceType.Medtronic_515,
MedtronicDeviceType.Medtronic_715 -> PumpHistoryEntryType.DailyTotals515 MedtronicDeviceType.Medtronic_715 -> PumpHistoryEntryType.DailyTotals515
MedtronicDeviceType.Medtronic_522, MedtronicDeviceType.Medtronic_522,
MedtronicDeviceType.Medtronic_722 -> PumpHistoryEntryType.DailyTotals522 MedtronicDeviceType.Medtronic_722 -> PumpHistoryEntryType.DailyTotals522
MedtronicDeviceType.Medtronic_523_Revel, MedtronicDeviceType.Medtronic_523_Revel,
MedtronicDeviceType.Medtronic_723_Revel, MedtronicDeviceType.Medtronic_723_Revel,
MedtronicDeviceType.Medtronic_554_Veo, MedtronicDeviceType.Medtronic_554_Veo,
@ -1212,8 +1270,12 @@ class MedtronicHistoryData @Inject constructor(
} }
fun hasPumpTimeChanged(): Boolean { fun hasPumpTimeChanged(): Boolean {
return getStateFromFilteredList(setOf(PumpHistoryEntryType.NewTimeSet, // return getStateFromFilteredList(
PumpHistoryEntryType.ChangeTime)) setOf(
PumpHistoryEntryType.NewTimeSet, //
PumpHistoryEntryType.ChangeTime
)
)
} }
fun setIsInInit(init: Boolean) { fun setIsInInit(init: Boolean) {
@ -1228,10 +1290,10 @@ class MedtronicHistoryData @Inject constructor(
list.sortWith(PumpHistoryEntry.Comparator()) list.sortWith(PumpHistoryEntry.Comparator())
} }
private fun preProcessTBRs(TBRs_Input: MutableList<PumpHistoryEntry>): MutableList<PumpHistoryEntry> { private fun preProcessTBRs(tbrsInput: MutableList<PumpHistoryEntry>): MutableList<PumpHistoryEntry> {
val tbrs: MutableList<PumpHistoryEntry> = mutableListOf() val tbrs: MutableList<PumpHistoryEntry> = mutableListOf()
val map: MutableMap<String?, PumpHistoryEntry?> = HashMap() val map: MutableMap<String?, PumpHistoryEntry?> = HashMap()
for (pumpHistoryEntry in TBRs_Input) { for (pumpHistoryEntry in tbrsInput) {
if (map.containsKey(pumpHistoryEntry.DT)) { if (map.containsKey(pumpHistoryEntry.DT)) {
medtronicPumpHistoryDecoder.decodeTempBasal(map[pumpHistoryEntry.DT]!!, pumpHistoryEntry) medtronicPumpHistoryDecoder.decodeTempBasal(map[pumpHistoryEntry.DT]!!, pumpHistoryEntry)
pumpHistoryEntry.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.TempBasalCombined) pumpHistoryEntry.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.TempBasalCombined)
@ -1248,7 +1310,7 @@ class MedtronicHistoryData @Inject constructor(
return getFilteredItems(newHistory, entryTypes) return getFilteredItems(newHistory, entryTypes)
} }
fun getFilteredItems(entryType: PumpHistoryEntryType): MutableList<PumpHistoryEntry> { private fun getFilteredItems(entryType: PumpHistoryEntryType): MutableList<PumpHistoryEntry> {
return getFilteredItems(newHistory, setOf(entryType)) return getFilteredItems(newHistory, setOf(entryType))
} }

View file

@ -26,10 +26,11 @@ import javax.inject.Singleton
*/ */
@Singleton @Singleton
@OpenForTesting @OpenForTesting
class MedtronicPumpStatus @Inject constructor(private val rh: ResourceHelper, class MedtronicPumpStatus @Inject constructor(
private val sp: SP, private val rh: ResourceHelper,
private val rxBus: RxBus, private val sp: SP,
private val rileyLinkUtil: RileyLinkUtil private val rxBus: RxBus,
private val rileyLinkUtil: RileyLinkUtil
) : PumpStatus(PumpType.MEDTRONIC_522_722) { ) : PumpStatus(PumpType.MEDTRONIC_522_722) {
var errorDescription: String? = null var errorDescription: String? = null
@ -108,15 +109,13 @@ class MedtronicPumpStatus @Inject constructor(private val rh: ResourceHelper,
// Battery type // Battery type
private var batteryTypeByDescMap: MutableMap<String, BatteryType?> = HashMap() private var batteryTypeByDescMap: MutableMap<String, BatteryType?> = HashMap()
fun getBatteryTypeByDescription(batteryTypeStr: String?): BatteryType? { fun getBatteryTypeByDescription(batteryTypeStr: String?): BatteryType {
if (batteryTypeByDescMap.isEmpty()) { if (batteryTypeByDescMap.isEmpty()) {
for (value in BatteryType.values()) { for (value in BatteryType.values()) {
batteryTypeByDescMap[rh.gs(value.description)] = value batteryTypeByDescMap[rh.gs(value.description)] = value
} }
} }
return if (batteryTypeByDescMap.containsKey(batteryTypeStr)) { return batteryTypeByDescMap[batteryTypeStr] ?: BatteryType.None
batteryTypeByDescMap[batteryTypeStr]
} else BatteryType.None
} }
override val errorInfo: String override val errorInfo: String

View file

@ -158,8 +158,8 @@ class RileyLinkMedtronicService : RileyLinkService() {
medtronicPumpStatus.errorDescription = rh.gs(R.string.medtronic_error_pump_type_invalid) medtronicPumpStatus.errorDescription = rh.gs(R.string.medtronic_error_pump_type_invalid)
return false return false
} else { } else {
val pumpType = medtronicPumpStatus.medtronicPumpMap[pumpTypePart]!! val pumpType = medtronicPumpStatus.medtronicPumpMap[pumpTypePart] ?: return false
medtronicPumpStatus.medtronicDeviceType = medtronicPumpStatus.medtronicDeviceTypeMap[pumpTypePart]!! medtronicPumpStatus.medtronicDeviceType = medtronicPumpStatus.medtronicDeviceTypeMap[pumpTypePart] ?: return false
medtronicPumpStatus.pumpType = pumpType medtronicPumpStatus.pumpType = pumpType
medtronicPumpPlugin.pumpType = pumpType medtronicPumpPlugin.pumpType = pumpType
if (pumpTypePart.startsWith("7")) medtronicPumpStatus.reservoirFullUnits = 300 else medtronicPumpStatus.reservoirFullUnits = 176 if (pumpTypePart.startsWith("7")) medtronicPumpStatus.reservoirFullUnits = 300 else medtronicPumpStatus.reservoirFullUnits = 176
@ -223,8 +223,8 @@ class RileyLinkMedtronicService : RileyLinkService() {
val batteryTypeStr = sp.getStringOrNull(MedtronicConst.Prefs.BatteryType, null) val batteryTypeStr = sp.getStringOrNull(MedtronicConst.Prefs.BatteryType, null)
?: return false ?: return false
val batteryType = medtronicPumpStatus.getBatteryTypeByDescription(batteryTypeStr) val batteryType = medtronicPumpStatus.getBatteryTypeByDescription(batteryTypeStr)
if (medtronicPumpStatus.batteryType !== batteryType) { if (medtronicPumpStatus.batteryType != batteryType) {
medtronicPumpStatus.batteryType = batteryType!! medtronicPumpStatus.batteryType = batteryType
} }
//String bolusDebugEnabled = sp.getStringOrNull(MedtronicConst.Prefs.BolusDebugEnabled, null); //String bolusDebugEnabled = sp.getStringOrNull(MedtronicConst.Prefs.BolusDebugEnabled, null);

View file

@ -240,9 +240,9 @@ class MedtronicUtil @Inject constructor(
var pageNumber = 0 var pageNumber = 0
var frameNumber: Int? = null var frameNumber: Int? = null
fun setCurrentCommand(currentCommand: MedtronicCommandType, pageNumber_: Int, frameNumber_: Int?) { fun setCurrentCommand(currentCommand: MedtronicCommandType, pageNumber: Int, frameNumber: Int?) {
pageNumber = pageNumber_ this.pageNumber = pageNumber
frameNumber = frameNumber_ this.frameNumber = frameNumber
if (this.currentCommand !== currentCommand) { if (this.currentCommand !== currentCommand) {
setCurrentCommand(currentCommand) setCurrentCommand(currentCommand)
} }
@ -306,7 +306,9 @@ class MedtronicUtil @Inject constructor(
return strokes return strokes
} }
fun isSame(d1: Double, d2: Double): Boolean { fun isSame(d1: Double?, d2: Double?): Boolean {
d1 ?: return false
d2 ?: return false
val diff = d1 - d2 val diff = d1 - d2
return abs(diff) <= 0.000001 return abs(diff) <= 0.000001
} }