- minor kotlin refactorings removed some !! and refactored some code to that effect

- removed non aapsLogger
This commit is contained in:
Andy Rozman 2021-05-22 13:03:33 +01:00
parent d50ef68d33
commit 59a3bf8883
9 changed files with 119 additions and 135 deletions

View file

@ -869,7 +869,7 @@ class MedtronicPumpPlugin @Inject constructor(
if (latestEntry == null) // no new history to read
return
lastPumpHistoryEntry = latestEntry
sp.putLong(MedtronicConst.Statistics.LastPumpHistoryEntry, latestEntry.atechDateTime!!)
sp.putLong(MedtronicConst.Statistics.LastPumpHistoryEntry, latestEntry.atechDateTime)
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: History: valid=" + historyResult.validEntries.size + ", unprocessed=" + historyResult.unprocessedEntries.size)
medtronicHistoryData.addNewHistory(historyResult)
medtronicHistoryData.filterNewEntries()
@ -1153,13 +1153,10 @@ class MedtronicPumpPlugin @Inject constructor(
MedtronicCustomActionType.ResetRileyLinkConfiguration -> {
serviceTaskExecutor.startTask(ResetRileyLinkConfigurationTask(injector))
}
else -> {
}
}
}
override fun timezoneOrDSTChanged(changeType: TimeChangeType) {
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {
aapsLogger.warn(LTag.PUMP, logPrefix + "Time or TimeZone changed. ")
hasTimeDateOrTimeZoneChanged = true
}

View file

@ -6,5 +6,5 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history
interface MedtronicHistoryDecoderInterface<T> {
fun decodeRecord(record: T): RecordDecodeStatus?
fun createRecords(dataClear: MutableList<Byte>): MutableList<T>
fun createRecords(dataClearInput: MutableList<Byte>): MutableList<T>
}

View file

@ -37,14 +37,15 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
get() = field
@Expose
var atechDateTime: Long? = null
var atechDateTime: Long = 0L
get() = field
set(value) {
field = value
DT = DateTimeUtil.toString(value)
}
@Expose
var decodedData: MutableMap<String, Any?>? = null
var decodedData: MutableMap<String, Any> = mutableMapOf()
get() = field
/**
@ -112,10 +113,10 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
get() = if (DT == null) "Unknown" else DT!!
val decodedDataAsString: String
get() = if (decodedData == null) if (isNoDataEntry) "No data" else "" else decodedData.toString()
get() = if (decodedData.size == 0) if (isNoDataEntry) "No data" else "" else decodedData.toString()
fun hasData(): Boolean {
return decodedData != null || isNoDataEntry || entryTypeName == "UnabsorbedInsulin"
return decodedData.size == 0 || isNoDataEntry || entryTypeName == "UnabsorbedInsulin"
}
val isNoDataEntry: Boolean
@ -126,11 +127,11 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
// }
fun getDecodedDataEntry(key: String?): Any? {
return if (decodedData != null) decodedData!![key] else null
return if (decodedData.containsKey(key)) decodedData[key] else null
}
fun hasDecodedDataEntry(key: String?): Boolean {
return decodedData!!.containsKey(key)
return decodedData.containsKey(key)
}
fun showRaw(): Boolean {
@ -148,9 +149,9 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
override fun toString(): String {
val sb = StringBuilder()
if (DT == null) {
Log.e("", "DT is null. RawData=" + ByteUtil.getHex(rawData))
}
// if (DT == null) {
// Log.e("", "DT is null. RawData=" + ByteUtil.getHex(rawData))
// }
sb.append(toStringStart)
sb.append(", DT: " + if (DT == null) "null" else StringUtil.getStringInLength(DT, 19))
sb.append(", length=")
@ -208,14 +209,8 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
return ByteUtil.convertUnsignedByteToInt(rawData!![index])
}
fun setAtechDateTime(dt: Long) {
atechDateTime = dt
DT = DateTimeUtil.toString(atechDateTime!!)
}
fun addDecodedData(key: String, value: Any?) {
if (decodedData == null) decodedData = HashMap()
decodedData!![key] = value
fun addDecodedData(key: String, value: Any) {
decodedData.put(key, value)
}
fun toShortString(): String {
@ -227,7 +222,7 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
}
fun containsDecodedData(key: String?): Boolean {
return if (decodedData == null) false else decodedData!!.containsKey(key)
return decodedData.containsKey(key)
} // if we extend to CGMS this need to be changed back
// public abstract PumpHistoryEntryType getEntryType();
}

View file

@ -50,6 +50,6 @@ class CGMSHistoryEntry : MedtronicHistoryEntry() {
+ StringUtils.leftPad("" + opCode, 3) + ", 0x" + ByteUtil.getCorrectHexValue(opCode!!) + "]")
fun setDateTime(timeStamp: LocalDateTime, getIndex: Int) {
setAtechDateTime(DateTimeUtil.toATechDate(timeStamp.plusMinutes(getIndex * 5)))
atechDateTime = (DateTimeUtil.toATechDate(timeStamp.plusMinutes(getIndex * 5)))
}
}

View file

@ -27,7 +27,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
return try {
decodeRecordInternal(record)
} catch (ex: Exception) {
LOG.error(" Error decoding: type={}, ex={}", record.entryType!!.name, ex.message, ex)
aapsLogger.error(LTag.PUMPCOMM," Error decoding: type={}, ex={}", record.entryType!!.name, ex.message, ex)
RecordDecodeStatus.Error
}
}
@ -81,7 +81,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
entryType = getByCode(opCode)
if (entryType === CGMSHistoryEntryType.None) {
unknownOpCodes!![opCode] = opCode
LOG.warn("GlucoseHistoryEntry with unknown code: $opCode")
aapsLogger.warn(LTag.PUMPCOMM, "GlucoseHistoryEntry with unknown code: $opCode")
val pe = CGMSHistoryEntry()
pe.setEntryType(CGMSHistoryEntryType.None)
pe.opCode = opCode.toByte()
@ -112,14 +112,14 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
} while (counter < dataClear.size)
outList.reverse()
val reversedOutList = outList // reverseList(outList, CGMSHistoryEntry::class.java)
var timeStamp: Long? = null
//var timeStamp: Long? = null
var dateTime: LocalDateTime? = null
var getIndex = 0
for (entry in reversedOutList) {
decodeRecord(entry)
if (entry.hasTimeStamp()) {
timeStamp = entry.atechDateTime
dateTime = DateTimeUtil.toLocalDateTime(timeStamp!!)
//timeStamp = entry.atechDateTime
dateTime = DateTimeUtil.toLocalDateTime(entry.atechDateTime)
getIndex = 0
} else if (entry.entryType == CGMSHistoryEntryType.GlucoseSensorData) {
getIndex++
@ -127,7 +127,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
} else {
if (dateTime != null) entry.setDateTime(dateTime, getIndex)
}
LOG.debug("Record: {}", entry)
aapsLogger.debug(LTag.PUMPCOMM,"Record: {}", entry)
}
return reversedOutList
}
@ -168,10 +168,10 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
return if (entry.entryType!!.dateType === CGMSHistoryEntryType.DateType.MinuteSpecific) {
val atechDateTime = DateTimeUtil.toATechDate(parseYear(data!![3].toInt()), parseMonths(data[0].toInt(), data[1].toInt()),
parseDay(data[2].toInt()), parseHours(data[0].toInt()), parseMinutes(data[1].toInt()), 0)
entry.setAtechDateTime(atechDateTime)
entry.atechDateTime = atechDateTime
atechDateTime
} else if (entry.entryType!!.dateType === CGMSHistoryEntryType.DateType.SecondSpecific) {
LOG.warn("parseDate for SecondSpecific type is not implemented.")
aapsLogger.warn(LTag.PUMPCOMM,"parseDate for SecondSpecific type is not implemented.")
throw RuntimeException()
// return null;
} else null
@ -268,7 +268,4 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
showStatistics()
}
companion object {
private val LOG: Logger = getLogger1("MedtronicCGMSHistoryDecoder")
}
}

View file

@ -6,7 +6,6 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryDecoder
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RecordDecodeStatus
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryType
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryType.Companion.getByCode
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BolusDTO
@ -34,22 +33,22 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
medtronicUtil: MedtronicUtil
) : MedtronicHistoryDecoder<PumpHistoryEntry>() {
private var tbrPreviousRecord: PumpHistoryEntry? = null
//private var tbrPreviousRecord: PumpHistoryEntry? = null
private var changeTimeRecord: PumpHistoryEntry? = null
override fun createRecords(dataClear: MutableList<Byte>): MutableList<PumpHistoryEntry> {
override fun createRecords(dataClearInput: MutableList<Byte>): MutableList<PumpHistoryEntry> {
prepareStatistics()
var counter = 0
var record = 0
var incompletePacket: Boolean
val outList: MutableList<PumpHistoryEntry> = mutableListOf()
var skipped: String? = null
if (dataClear.size == 0) {
if (dataClearInput.size == 0) {
aapsLogger.error(LTag.PUMPBTCOMM, "Empty page.")
return outList
}
do {
val opCode: Int = dataClear[counter].toInt()
val opCode: Int = dataClearInput[counter].toInt()
var special = false
incompletePacket = false
var skippedRecords = false
@ -79,13 +78,13 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
listRawData.add(opCode.toByte())
if (entryType === PumpHistoryEntryType.UnabsorbedInsulin
|| entryType === PumpHistoryEntryType.UnabsorbedInsulin512) {
val elements: Int = dataClear[counter].toInt()
val elements: Int = dataClearInput[counter].toInt()
listRawData.add(elements.toByte())
counter++
val els = getUnsignedInt(elements)
for (k in 0 until els - 2) {
if (counter < 1022) {
listRawData.add(dataClear[counter])
listRawData.add(dataClearInput[counter])
counter++
}
}
@ -93,7 +92,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
} else {
for (j in 0 until entryType.getTotalLength(medtronicUtil.medtronicPumpModel!!) - 1) {
try {
listRawData.add(dataClear[counter])
listRawData.add(dataClearInput[counter])
counter++
} catch (ex: Exception) {
aapsLogger.error(LTag.PUMPBTCOMM, "OpCode: " + ByteUtil.shortHexString(opCode.toByte()) + ", Invalid package: "
@ -126,7 +125,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
outList.add(pe)
}
}
} while (counter < dataClear.size)
} while (counter < dataClearInput.size)
return outList
}
@ -272,9 +271,9 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
dto.bolusTotal = ((body[12].toInt() shl 8) + body[13]) / bolusStrokes
} else {
dto.bloodGlucose = (body.get(1) and 0x0F).toInt() shl 8 or entry.head!!.get(0).toInt()
dto.carbs = body.get(0).toInt()
dto.carbRatio = body.get(2).toFloat()
dto.insulinSensitivity = body.get(3).toFloat()
dto.carbs = body[0].toInt()
dto.carbRatio = body[2].toFloat()
dto.insulinSensitivity = body[3].toFloat()
dto.bgTargetLow = body.get(4).toInt()
dto.bgTargetHigh = body.get(12).toInt()
dto.bolusTotal = body.get(11) / bolusStrokes
@ -283,10 +282,10 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
dto.bolusTotal = body.get(11) / bolusStrokes
dto.correctionEstimate = (body.get(7) + (body.get(5) and 0x0F)) / bolusStrokes
}
if (dto.bloodGlucose != null && dto.bloodGlucose < 0) {
if (dto.bloodGlucose < 0) {
dto.bloodGlucose = ByteUtil.convertUnsignedByteToInt(dto.bloodGlucose.toByte())
}
dto.atechDateTime = entry.atechDateTime!!
dto.atechDateTime = entry.atechDateTime
entry.addDecodedData("Object", dto)
entry.displayableValue = dto.displayableValue
return RecordDecodeStatus.OK
@ -306,10 +305,10 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
dto.unabsorbedInsulin = body.get(9) / bolusStrokes
dto.bolusTotal = body.get(11) / bolusStrokes
dto.bgTargetHigh = dto.bgTargetLow
if (dto.bloodGlucose != null && dto.bloodGlucose < 0) {
if (dto.bloodGlucose < 0) {
dto.bloodGlucose = ByteUtil.convertUnsignedByteToInt(dto.bloodGlucose.toByte())
}
dto.atechDateTime = entry.atechDateTime!!
dto.atechDateTime = entry.atechDateTime
entry.addDecodedData("Object", dto)
entry.displayableValue = dto.displayableValue
return RecordDecodeStatus.OK
@ -371,7 +370,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
bolus.duration = ByteUtil.asUINT8(data.get(2)) * 30
}
bolus.bolusType = if (bolus.duration != null && bolus.duration!! > 0) PumpBolusType.Extended else PumpBolusType.Normal
bolus.atechDateTime = entry.atechDateTime!!
bolus.atechDateTime = entry.atechDateTime
entry.addDecodedData("Object", bolus)
entry.displayableValue = bolus.displayableValue
}
@ -431,9 +430,9 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
val dayOfMonth: Int = (dt.get(3) and 0x1F).toInt()
val year = fix2DigitYear((dt.get(4) and 0x3F.toByte()).toInt()) // Assuming this is correct, need to verify. Otherwise this will be
// a problem in 2016.
entry.setAtechDateTime(DateTimeUtil.toATechDate(year, month, dayOfMonth, hour, minutes, seconds))
entry.atechDateTime = DateTimeUtil.toATechDate(year, month, dayOfMonth, hour, minutes, seconds)
} else if (entry.dateTimeLength == 2) {
val low = ByteUtil.asUINT8(dt.get(0)) and 0x1F
//val low = ByteUtil.asUINT8(dt.get(0)) and 0x1F
val mhigh = ByteUtil.asUINT8(dt.get(0)) and 0xE0 shr 4
val mlow = ByteUtil.asUINT8(dt.get(1)) and 0x80 shr 7
val month = mhigh + mlow
@ -454,7 +453,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
minutes = 59
seconds = 59
}
entry.setAtechDateTime(DateTimeUtil.toATechDate(year, month, dayOfMonth, hour, minutes, seconds))
entry.atechDateTime = DateTimeUtil.toATechDate(year, month, dayOfMonth, hour, minutes, seconds)
} else {
aapsLogger.warn(LTag.PUMPBTCOMM, "Unknown datetime format: " + entry.dateTimeLength)
}

View file

@ -41,11 +41,11 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
sizes[0] = entryType.getHeadLength(medtronicDeviceType)
sizes[1] = entryType.dateLength
sizes[2] = entryType.getBodyLength(medtronicDeviceType)
if (this.entryType != null && atechDateTime != null) generatePumpId()
if (this.entryType != null && atechDateTime != 0L) generatePumpId()
}
private fun generatePumpId() : Long {
return entryType!!.code + atechDateTime!! * 1000L
return entryType!!.code + atechDateTime * 1000L
}
override val toStringStart: String
@ -91,16 +91,16 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
// return this.dateTime.isAfter(dateTimeIn);
// }
fun isAfter(atechDateTime: Long): Boolean {
if (this.atechDateTime == null) {
Log.e("PumpHistoryEntry", "Date is null. Show object: " + toString())
if (this.atechDateTime == 0L) {
// Log.e("PumpHistoryEntry", "Date is null. Show object: " + toString())
return false // FIXME shouldn't happen
}
return atechDateTime < this.atechDateTime!!
return atechDateTime < this.atechDateTime
}
class Comparator : java.util.Comparator<PumpHistoryEntry> {
override fun compare(o1: PumpHistoryEntry, o2: PumpHistoryEntry): Int {
val data = (o2.atechDateTime!! - o1.atechDateTime!!).toInt()
val data = (o2.atechDateTime - o1.atechDateTime).toInt()
return if (data != 0) data else o2.entryType!!.code - o1.entryType!!.code
}
}
@ -116,17 +116,13 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
fun hasBolusChanged(entry: PumpHistoryEntry) : Boolean {
if (entryType!=null && entryType == PumpHistoryEntryType.Bolus) {
val thisOne: BolusDTO? = this.decodedData!!["Object"]!! as BolusDTO?
val otherOne: BolusDTO? = entry.decodedData!!["Object"]!! as BolusDTO?
if (thisOne==null || otherOne==null) {
return false;
}
return false // TODO needs to be implemented
val thisOne: BolusDTO = this.decodedData["Object"] as BolusDTO
if (entry.entryType!=null && entry.entryType == PumpHistoryEntryType.Bolus) {
val otherOne: BolusDTO = entry.decodedData["Object"] as BolusDTO
return (thisOne.value.equals(otherOne.value))
} else
return false
}
return false

View file

@ -133,7 +133,7 @@ class MedtronicHistoryData @Inject constructor(
newHistory2.add(pumpHistoryEntry)
} else {
if (type === PumpHistoryEntryType.EndResultTotals) {
if (!DateTimeUtil.isSameDay(atechDate, pumpHistoryEntry.atechDateTime!!)) {
if (!DateTimeUtil.isSameDay(atechDate, pumpHistoryEntry.atechDateTime)) {
newHistory2.add(pumpHistoryEntry)
}
} else {
@ -168,7 +168,7 @@ class MedtronicHistoryData @Inject constructor(
for (bolusEstimate in bolusEstimates) {
for (bolus in boluses) {
if (bolusEstimate.atechDateTime == bolus.atechDateTime) {
bolus.addDecodedData("Estimate", bolusEstimate.decodedData!!["Object"])
bolus.addDecodedData("Estimate", bolusEstimate.decodedData["Object"]!!)
}
}
}
@ -180,7 +180,7 @@ class MedtronicHistoryData @Inject constructor(
// find last entry
for (pumpHistoryEntry in newHistory) {
if (pumpHistoryEntry.atechDateTime != null && pumpHistoryEntry.isAfter(pheLast.atechDateTime!!)) {
if (pumpHistoryEntry.atechDateTime != 0L && pumpHistoryEntry.isAfter(pheLast.atechDateTime)) {
pheLast = pumpHistoryEntry
}
}
@ -196,10 +196,10 @@ class MedtronicHistoryData @Inject constructor(
}
}
sp.putLong(MedtronicConst.Statistics.LastPumpHistoryEntry, pheLast.atechDateTime!!)
sp.putLong(MedtronicConst.Statistics.LastPumpHistoryEntry, pheLast.atechDateTime)
var dt: LocalDateTime? = null
try {
dt = DateTimeUtil.toLocalDateTime(pheLast.atechDateTime!!)
dt = DateTimeUtil.toLocalDateTime(pheLast.atechDateTime)
} catch (ex: Exception) {
aapsLogger.error("Problem decoding date from last record: $pheLast")
}
@ -396,9 +396,9 @@ class MedtronicHistoryData @Inject constructor(
// so skip the prime entry if it was not a fixed prime
continue
}
if (primeRecord.atechDateTime!! > maxAllowedTimeInPast) {
if (lastPrimeRecordTime < primeRecord.atechDateTime!!) {
lastPrimeRecordTime = primeRecord.atechDateTime!!
if (primeRecord.atechDateTime > maxAllowedTimeInPast) {
if (lastPrimeRecordTime!=0L && lastPrimeRecordTime < primeRecord.atechDateTime) {
lastPrimeRecordTime = primeRecord.atechDateTime
lastPrimeRecord = primeRecord
}
}
@ -410,14 +410,14 @@ class MedtronicHistoryData @Inject constructor(
}
}
private fun processRewind(rewindRecords: List<PumpHistoryEntry?>) {
private fun processRewind(rewindRecords: List<PumpHistoryEntry>) {
val maxAllowedTimeInPast = DateTimeUtil.getATDWithAddedMinutes(GregorianCalendar(), -30)
var lastRewindRecordTime = 0L
var lastRewindRecord: PumpHistoryEntry? = null
for (rewindRecord in rewindRecords) {
if (rewindRecord!!.atechDateTime!! > maxAllowedTimeInPast) {
if (lastRewindRecordTime < rewindRecord.atechDateTime!!) {
lastRewindRecordTime = rewindRecord.atechDateTime!!
if (rewindRecord.atechDateTime > maxAllowedTimeInPast) {
if (lastRewindRecordTime < rewindRecord.atechDateTime) {
lastRewindRecordTime = rewindRecord.atechDateTime
lastRewindRecord = rewindRecord
}
}
@ -434,17 +434,17 @@ class MedtronicHistoryData @Inject constructor(
val lastPrimeFromAAPS = sp.getLong(eventSP, 0L)
if (historyRecord.atechDateTime != lastPrimeFromAAPS) {
var result = pumpSync.insertTherapyEventIfNewWithTimestamp(
DateTimeUtil.toMillisFromATD(historyRecord.atechDateTime!!),
DateTimeUtil.toMillisFromATD(historyRecord.atechDateTime),
eventType, null,
historyRecord.pumpId,
medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber!!)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ROOT, "insertTherapyEventIfNewWithTimestamp [date=%d, eventType=%s, pumpId=%d, pumpSerial=%s] - Result: %b",
historyRecord.atechDateTime!!, eventType, historyRecord.pumpId,
historyRecord.atechDateTime, eventType, historyRecord.pumpId,
medtronicPumpStatus.serialNumber!!, result))
sp.putLong(eventSP, historyRecord.atechDateTime!!)
sp.putLong(eventSP, historyRecord.atechDateTime)
}
}
@ -456,10 +456,10 @@ class MedtronicHistoryData @Inject constructor(
tdds.size, gson.toJson(tdds)))
for (tdd in tdds) {
val totalsDTO = tdd.decodedData!!["Object"] as DailyTotalsDTO
val totalsDTO = tdd.decodedData["Object"] as DailyTotalsDTO
pumpSync.createOrUpdateTotalDailyDose(
DateTimeUtil.toMillisFromATD(tdd.atechDateTime!!),
DateTimeUtil.toMillisFromATD(tdd.atechDateTime),
totalsDTO.insulinBolus,
totalsDTO.insulinBasal!!,
totalsDTO.insulinTotal,
@ -484,7 +484,7 @@ class MedtronicHistoryData @Inject constructor(
for (bolus in entryList) {
val bolusDTO = bolus.decodedData!!["Object"]!! as BolusDTO
val bolusDTO = bolus.decodedData["Object"] as BolusDTO
var type: DetailedBolusInfo.BolusType = DetailedBolusInfo.BolusType.NORMAL
var multiwave = false
@ -516,7 +516,7 @@ class MedtronicHistoryData @Inject constructor(
if (temporaryId!=null) {
val result = pumpSync.syncBolusWithTempId(
tryToGetByLocalTime(bolus.atechDateTime!!),
tryToGetByLocalTime(bolus.atechDateTime),
deliveredAmount,
temporaryId,
type,
@ -525,11 +525,11 @@ class MedtronicHistoryData @Inject constructor(
medtronicPumpStatus.serialNumber!!)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncBolusWithTempId [date=%d, temporaryId=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b",
bolus.atechDateTime!!, temporaryId, bolus.pumpId, deliveredAmount,
bolus.atechDateTime, temporaryId, bolus.pumpId, deliveredAmount,
medtronicPumpStatus.serialNumber!!, result))
} else {
val result = pumpSync.syncBolusWithPumpId(
tryToGetByLocalTime(bolus.atechDateTime!!),
tryToGetByLocalTime(bolus.atechDateTime),
deliveredAmount,
type,
bolus.pumpId!!,
@ -537,7 +537,7 @@ class MedtronicHistoryData @Inject constructor(
medtronicPumpStatus.serialNumber!!)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncBolusWithPumpId [date=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b",
bolus.atechDateTime!!, bolus.pumpId, deliveredAmount,
bolus.atechDateTime, bolus.pumpId, deliveredAmount,
medtronicPumpStatus.serialNumber!!, result))
}
@ -550,7 +550,7 @@ class MedtronicHistoryData @Inject constructor(
val durationMs : Long = bolusDTO.duration!! * 60L * 1000L
val result = pumpSync.syncExtendedBolusWithPumpId(
tryToGetByLocalTime(bolus.atechDateTime!!),
tryToGetByLocalTime(bolus.atechDateTime),
bolusDTO.deliveredAmount!!,
durationMs,
false,
@ -559,17 +559,17 @@ class MedtronicHistoryData @Inject constructor(
medtronicPumpStatus.serialNumber!!)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncExtendedBolusWithPumpId [date=%d, amount=%.2f, duration=%d, pumpId=%d, pumpSerial=%s, multiwave=%b] - Result: %b",
bolus.atechDateTime!!, bolusDTO.deliveredAmount!!, bolusDTO.duration, bolus.pumpId,
bolus.atechDateTime, bolusDTO.deliveredAmount!!, bolusDTO.duration, bolus.pumpId,
medtronicPumpStatus.serialNumber!!, isMultiwave, result))
}
private fun addCarbs(bolus: PumpHistoryEntry) {
if (bolus.containsDecodedData("Estimate")) {
val bolusWizard = bolus.decodedData!!["Estimate"] as BolusWizardDTO
val bolusWizard = bolus.decodedData["Estimate"] as BolusWizardDTO
pumpSyncStorage.addCarbs(PumpDbEntryCarbs(
tryToGetByLocalTime(bolus.atechDateTime!!),
tryToGetByLocalTime(bolus.atechDateTime),
bolusWizard.carbs.toDouble(),
medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber!!,
@ -615,9 +615,9 @@ class MedtronicHistoryData @Inject constructor(
if (processDTO != null) {
processList.add(processDTO)
}
processDTO = TempBasalProcessDTO()
processDTO.itemOne = treatment
processDTO.processOperation = TempBasalProcessDTO.Operation.Add
processDTO = TempBasalProcessDTO(
itemOne= treatment,
processOperation = TempBasalProcessDTO.Operation.Add)
}
}
if (processDTO != null) {
@ -630,7 +630,7 @@ class MedtronicHistoryData @Inject constructor(
aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (if (entryWithTempId==null) "null" else entryWithTempId.toString()))
val tbrEntry = tempBasalProcessDTO.itemOne!!.getDecodedDataEntry("Object") as TempBasalPair
val tbrEntry = tempBasalProcessDTO.itemOne.getDecodedDataEntry("Object") as TempBasalPair
aapsLogger.debug(LTag.PUMP, String.format("DD: tbrEntry=%s, tempBasalProcessDTO=%s", gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO)))
@ -737,7 +737,7 @@ class MedtronicHistoryData @Inject constructor(
return null
}
var proposedTime = DateTimeUtil.toMillisFromATD(treatment!!.atechDateTime!!)
var proposedTime = DateTimeUtil.toMillisFromATD(treatment!!.atechDateTime)
// pumpTime should never be null, but it can theoretically happen if reading of time from pump fails
this.pumpTime?.let { proposedTime += (it.timeDifference * 1000) }
@ -793,18 +793,19 @@ class MedtronicHistoryData @Inject constructor(
for (tempBasalProcess in tempBasalProcessList) {
val result = pumpSync.syncTemporaryBasalWithPumpId(
tryToGetByLocalTime(tempBasalProcess.itemOne!!.atechDateTime!!),
tryToGetByLocalTime(tempBasalProcess.itemOne.atechDateTime),
0.0,
tempBasalProcess.duration * 60 * 1000L,
true,
PumpSync.TemporaryBasalType.PUMP_SUSPEND,
tempBasalProcess.itemOne!!.pumpId!!,
tempBasalProcess.itemOne.pumpId!!,
medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber!!)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "processSuspends::syncTemporaryBasalWithPumpId [date=%d, rate=%.2f, duration=%d, pumpId=%d, pumpSerial=%s] - Result: %b",
tempBasalProcess.itemOne!!.atechDateTime!!, 0.0, tempBasalProcess.duration, tempBasalProcess.itemOne!!.pumpId!!,
tempBasalProcess.itemOne.atechDateTime, 0.0, tempBasalProcess.duration, tempBasalProcess.itemOne.pumpId!!,
medtronicPumpStatus.serialNumber!!, result))
}
}
@ -862,11 +863,11 @@ class MedtronicHistoryData @Inject constructor(
Collections.reverse(filtered2Items)
var i = 0
while (i < filtered2Items.size) {
val dto = TempBasalProcessDTO()
dto.itemOne = filtered2Items[i]
dto.itemTwo = filtered2Items[i + 1]
dto.processOperation = TempBasalProcessDTO.Operation.Add
outList.add(dto)
outList.add(TempBasalProcessDTO(
itemOne= filtered2Items[i],
itemTwo= filtered2Items[i + 1],
processOperation = TempBasalProcessDTO.Operation.Add))
i += 2
}
}
@ -925,20 +926,20 @@ class MedtronicHistoryData @Inject constructor(
}
showLogs("NoDeliveryRewindPrimeRecords: Records to evaluate: ", gson.toJson(tempData))
var items: MutableList<PumpHistoryEntry> = getFilteredItems(tempData, PumpHistoryEntryType.Prime)
val processDTO = TempBasalProcessDTO()
processDTO.itemTwo = items[0]
var itemTwo = items[0]
items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm)
if (items.size > 0) {
processDTO.itemOne = items[items.size - 1]
processDTO.processOperation = TempBasalProcessDTO.Operation.Add
outList.add(processDTO)
outList.add(TempBasalProcessDTO(
itemOne=items[items.size - 1],
itemTwo= itemTwo,
processOperation=TempBasalProcessDTO.Operation.Add))
return outList
}
items = getFilteredItems(tempData, PumpHistoryEntryType.Rewind)
if (items.size > 0) {
processDTO.itemOne = items[0]
processDTO.processOperation = TempBasalProcessDTO.Operation.Add
outList.add(processDTO)
outList.add(TempBasalProcessDTO(
itemOne=items[0],
processOperation=TempBasalProcessDTO.Operation.Add))
return outList
}
return outList
@ -991,8 +992,8 @@ class MedtronicHistoryData @Inject constructor(
}
fun processLastBasalProfileChange(pumpType: PumpType?, mdtPumpStatus: MedtronicPumpStatus) {
val filteredItems: List<PumpHistoryEntry?> = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile)
fun processLastBasalProfileChange(pumpType: PumpType, mdtPumpStatus: MedtronicPumpStatus) {
val filteredItems: List<PumpHistoryEntry> = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile)
aapsLogger.debug(LTag.PUMP, "processLastBasalProfileChange. Items: $filteredItems")
var newProfile: PumpHistoryEntry? = null
var lastDate: Long? = null
@ -1000,16 +1001,16 @@ class MedtronicHistoryData @Inject constructor(
newProfile = filteredItems[0]
} else if (filteredItems.size > 1) {
for (filteredItem in filteredItems) {
if (lastDate == null || lastDate < filteredItem!!.atechDateTime!!) {
if (lastDate == null || lastDate < filteredItem.atechDateTime) {
newProfile = filteredItem
lastDate = newProfile!!.atechDateTime
lastDate = newProfile.atechDateTime
}
}
}
if (newProfile != null) {
aapsLogger.debug(LTag.PUMP, "processLastBasalProfileChange. item found, setting new basalProfileLocally: $newProfile")
val basalProfile = newProfile.decodedData!!["Object"] as BasalProfile?
mdtPumpStatus.basalsByHour = basalProfile!!.getProfilesByHour(pumpType!!)
val basalProfile = newProfile.decodedData["Object"] as BasalProfile
mdtPumpStatus.basalsByHour = basalProfile.getProfilesByHour(pumpType)
}
}

View file

@ -3,24 +3,23 @@ package info.nightscout.androidaps.plugins.pump.medtronic.data.dto
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
class TempBasalProcessDTO {
var itemOne: PumpHistoryEntry? = null
var itemTwo: PumpHistoryEntry? = null
var processOperation = Operation.None
class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
var itemTwo: PumpHistoryEntry? = null,
var processOperation: Operation = Operation.None) {
var cancelPresent: Boolean = false
val atechDateTime: Long
get() = if (itemOne==null) 0L else itemOne!!.atechDateTime!!
get() = itemOne.atechDateTime
val pumpId: Long
get() = if (itemOne==null) 0L else itemOne!!.pumpId!!
get() = itemOne.pumpId!!
val duration: Int
get() = if (itemTwo == null) {
val tbr = itemOne!!.getDecodedDataEntry("Object") as TempBasalPair?
tbr!!.durationMinutes
val tbr = itemOne.getDecodedDataEntry("Object") as TempBasalPair
tbr.durationMinutes
} else {
DateTimeUtil.getATechDateDiferenceAsMinutes(itemOne!!.atechDateTime, itemTwo!!.atechDateTime)
DateTimeUtil.getATechDateDiferenceAsMinutes(itemOne.atechDateTime, itemTwo!!.atechDateTime)
}
enum class Operation {