- minor kotlin refactorings removed some !! and refactored some code to that effect
- removed non aapsLogger
This commit is contained in:
parent
d50ef68d33
commit
59a3bf8883
9 changed files with 119 additions and 135 deletions
|
@ -869,7 +869,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
if (latestEntry == null) // no new history to read
|
if (latestEntry == null) // no new history to read
|
||||||
return
|
return
|
||||||
lastPumpHistoryEntry = latestEntry
|
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)
|
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: History: valid=" + historyResult.validEntries.size + ", unprocessed=" + historyResult.unprocessedEntries.size)
|
||||||
medtronicHistoryData.addNewHistory(historyResult)
|
medtronicHistoryData.addNewHistory(historyResult)
|
||||||
medtronicHistoryData.filterNewEntries()
|
medtronicHistoryData.filterNewEntries()
|
||||||
|
@ -1153,13 +1153,10 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
MedtronicCustomActionType.ResetRileyLinkConfiguration -> {
|
MedtronicCustomActionType.ResetRileyLinkConfiguration -> {
|
||||||
serviceTaskExecutor.startTask(ResetRileyLinkConfigurationTask(injector))
|
serviceTaskExecutor.startTask(ResetRileyLinkConfigurationTask(injector))
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun timezoneOrDSTChanged(changeType: TimeChangeType) {
|
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {
|
||||||
aapsLogger.warn(LTag.PUMP, logPrefix + "Time or TimeZone changed. ")
|
aapsLogger.warn(LTag.PUMP, logPrefix + "Time or TimeZone changed. ")
|
||||||
hasTimeDateOrTimeZoneChanged = true
|
hasTimeDateOrTimeZoneChanged = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,5 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history
|
||||||
interface MedtronicHistoryDecoderInterface<T> {
|
interface MedtronicHistoryDecoderInterface<T> {
|
||||||
|
|
||||||
fun decodeRecord(record: T): RecordDecodeStatus?
|
fun decodeRecord(record: T): RecordDecodeStatus?
|
||||||
fun createRecords(dataClear: MutableList<Byte>): MutableList<T>
|
fun createRecords(dataClearInput: MutableList<Byte>): MutableList<T>
|
||||||
}
|
}
|
|
@ -37,14 +37,15 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
|
||||||
get() = field
|
get() = field
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
var atechDateTime: Long? = null
|
var atechDateTime: Long = 0L
|
||||||
get() = field
|
get() = field
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
|
DT = DateTimeUtil.toString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
var decodedData: MutableMap<String, Any?>? = null
|
var decodedData: MutableMap<String, Any> = mutableMapOf()
|
||||||
get() = field
|
get() = field
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,10 +113,10 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
|
||||||
get() = if (DT == null) "Unknown" else DT!!
|
get() = if (DT == null) "Unknown" else DT!!
|
||||||
|
|
||||||
val decodedDataAsString: String
|
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 {
|
fun hasData(): Boolean {
|
||||||
return decodedData != null || isNoDataEntry || entryTypeName == "UnabsorbedInsulin"
|
return decodedData.size == 0 || isNoDataEntry || entryTypeName == "UnabsorbedInsulin"
|
||||||
}
|
}
|
||||||
|
|
||||||
val isNoDataEntry: Boolean
|
val isNoDataEntry: Boolean
|
||||||
|
@ -126,11 +127,11 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
fun getDecodedDataEntry(key: String?): Any? {
|
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 {
|
fun hasDecodedDataEntry(key: String?): Boolean {
|
||||||
return decodedData!!.containsKey(key)
|
return decodedData.containsKey(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showRaw(): Boolean {
|
fun showRaw(): Boolean {
|
||||||
|
@ -148,9 +149,9 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
if (DT == null) {
|
// if (DT == null) {
|
||||||
Log.e("", "DT is null. RawData=" + ByteUtil.getHex(rawData))
|
// Log.e("", "DT is null. RawData=" + ByteUtil.getHex(rawData))
|
||||||
}
|
// }
|
||||||
sb.append(toStringStart)
|
sb.append(toStringStart)
|
||||||
sb.append(", DT: " + if (DT == null) "null" else StringUtil.getStringInLength(DT, 19))
|
sb.append(", DT: " + if (DT == null) "null" else StringUtil.getStringInLength(DT, 19))
|
||||||
sb.append(", length=")
|
sb.append(", length=")
|
||||||
|
@ -208,14 +209,8 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
|
||||||
return ByteUtil.convertUnsignedByteToInt(rawData!![index])
|
return ByteUtil.convertUnsignedByteToInt(rawData!![index])
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setAtechDateTime(dt: Long) {
|
fun addDecodedData(key: String, value: Any) {
|
||||||
atechDateTime = dt
|
decodedData.put(key, value)
|
||||||
DT = DateTimeUtil.toString(atechDateTime!!)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addDecodedData(key: String, value: Any?) {
|
|
||||||
if (decodedData == null) decodedData = HashMap()
|
|
||||||
decodedData!![key] = value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toShortString(): String {
|
fun toShortString(): String {
|
||||||
|
@ -227,7 +222,7 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun containsDecodedData(key: String?): Boolean {
|
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
|
} // if we extend to CGMS this need to be changed back
|
||||||
// public abstract PumpHistoryEntryType getEntryType();
|
// public abstract PumpHistoryEntryType getEntryType();
|
||||||
}
|
}
|
|
@ -50,6 +50,6 @@ class CGMSHistoryEntry : MedtronicHistoryEntry() {
|
||||||
+ StringUtils.leftPad("" + opCode, 3) + ", 0x" + ByteUtil.getCorrectHexValue(opCode!!) + "]")
|
+ StringUtils.leftPad("" + opCode, 3) + ", 0x" + ByteUtil.getCorrectHexValue(opCode!!) + "]")
|
||||||
|
|
||||||
fun setDateTime(timeStamp: LocalDateTime, getIndex: Int) {
|
fun setDateTime(timeStamp: LocalDateTime, getIndex: Int) {
|
||||||
setAtechDateTime(DateTimeUtil.toATechDate(timeStamp.plusMinutes(getIndex * 5)))
|
atechDateTime = (DateTimeUtil.toATechDate(timeStamp.plusMinutes(getIndex * 5)))
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -27,7 +27,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
|
||||||
return try {
|
return try {
|
||||||
decodeRecordInternal(record)
|
decodeRecordInternal(record)
|
||||||
} catch (ex: Exception) {
|
} 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
|
RecordDecodeStatus.Error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
|
||||||
entryType = getByCode(opCode)
|
entryType = getByCode(opCode)
|
||||||
if (entryType === CGMSHistoryEntryType.None) {
|
if (entryType === CGMSHistoryEntryType.None) {
|
||||||
unknownOpCodes!![opCode] = opCode
|
unknownOpCodes!![opCode] = opCode
|
||||||
LOG.warn("GlucoseHistoryEntry with unknown code: $opCode")
|
aapsLogger.warn(LTag.PUMPCOMM, "GlucoseHistoryEntry with unknown code: $opCode")
|
||||||
val pe = CGMSHistoryEntry()
|
val pe = CGMSHistoryEntry()
|
||||||
pe.setEntryType(CGMSHistoryEntryType.None)
|
pe.setEntryType(CGMSHistoryEntryType.None)
|
||||||
pe.opCode = opCode.toByte()
|
pe.opCode = opCode.toByte()
|
||||||
|
@ -112,14 +112,14 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
|
||||||
} while (counter < dataClear.size)
|
} while (counter < dataClear.size)
|
||||||
outList.reverse()
|
outList.reverse()
|
||||||
val reversedOutList = outList // reverseList(outList, CGMSHistoryEntry::class.java)
|
val reversedOutList = outList // reverseList(outList, CGMSHistoryEntry::class.java)
|
||||||
var timeStamp: Long? = null
|
//var timeStamp: Long? = null
|
||||||
var dateTime: LocalDateTime? = null
|
var dateTime: LocalDateTime? = null
|
||||||
var getIndex = 0
|
var getIndex = 0
|
||||||
for (entry in reversedOutList) {
|
for (entry in reversedOutList) {
|
||||||
decodeRecord(entry)
|
decodeRecord(entry)
|
||||||
if (entry.hasTimeStamp()) {
|
if (entry.hasTimeStamp()) {
|
||||||
timeStamp = entry.atechDateTime
|
//timeStamp = entry.atechDateTime
|
||||||
dateTime = DateTimeUtil.toLocalDateTime(timeStamp!!)
|
dateTime = DateTimeUtil.toLocalDateTime(entry.atechDateTime)
|
||||||
getIndex = 0
|
getIndex = 0
|
||||||
} else if (entry.entryType == CGMSHistoryEntryType.GlucoseSensorData) {
|
} else if (entry.entryType == CGMSHistoryEntryType.GlucoseSensorData) {
|
||||||
getIndex++
|
getIndex++
|
||||||
|
@ -127,7 +127,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
|
||||||
} else {
|
} else {
|
||||||
if (dateTime != null) entry.setDateTime(dateTime, getIndex)
|
if (dateTime != null) entry.setDateTime(dateTime, getIndex)
|
||||||
}
|
}
|
||||||
LOG.debug("Record: {}", entry)
|
aapsLogger.debug(LTag.PUMPCOMM,"Record: {}", entry)
|
||||||
}
|
}
|
||||||
return reversedOutList
|
return reversedOutList
|
||||||
}
|
}
|
||||||
|
@ -168,10 +168,10 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
|
||||||
return if (entry.entryType!!.dateType === CGMSHistoryEntryType.DateType.MinuteSpecific) {
|
return if (entry.entryType!!.dateType === CGMSHistoryEntryType.DateType.MinuteSpecific) {
|
||||||
val atechDateTime = DateTimeUtil.toATechDate(parseYear(data!![3].toInt()), parseMonths(data[0].toInt(), data[1].toInt()),
|
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)
|
parseDay(data[2].toInt()), parseHours(data[0].toInt()), parseMinutes(data[1].toInt()), 0)
|
||||||
entry.setAtechDateTime(atechDateTime)
|
entry.atechDateTime = atechDateTime
|
||||||
atechDateTime
|
atechDateTime
|
||||||
} else if (entry.entryType!!.dateType === CGMSHistoryEntryType.DateType.SecondSpecific) {
|
} 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()
|
throw RuntimeException()
|
||||||
// return null;
|
// return null;
|
||||||
} else null
|
} else null
|
||||||
|
@ -268,7 +268,4 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
|
||||||
showStatistics()
|
showStatistics()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val LOG: Logger = getLogger1("MedtronicCGMSHistoryDecoder")
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -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.common.utils.DateTimeUtil
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryDecoder
|
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.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.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.BasalProfile
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BolusDTO
|
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BolusDTO
|
||||||
|
@ -34,22 +33,22 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
medtronicUtil: MedtronicUtil
|
medtronicUtil: MedtronicUtil
|
||||||
) : MedtronicHistoryDecoder<PumpHistoryEntry>() {
|
) : MedtronicHistoryDecoder<PumpHistoryEntry>() {
|
||||||
|
|
||||||
private var tbrPreviousRecord: PumpHistoryEntry? = null
|
//private var tbrPreviousRecord: PumpHistoryEntry? = null
|
||||||
private var changeTimeRecord: PumpHistoryEntry? = null
|
private var changeTimeRecord: PumpHistoryEntry? = null
|
||||||
|
|
||||||
override fun createRecords(dataClear: MutableList<Byte>): MutableList<PumpHistoryEntry> {
|
override fun createRecords(dataClearInput: MutableList<Byte>): MutableList<PumpHistoryEntry> {
|
||||||
prepareStatistics()
|
prepareStatistics()
|
||||||
var counter = 0
|
var counter = 0
|
||||||
var record = 0
|
var record = 0
|
||||||
var incompletePacket: Boolean
|
var incompletePacket: Boolean
|
||||||
val outList: MutableList<PumpHistoryEntry> = mutableListOf()
|
val outList: MutableList<PumpHistoryEntry> = mutableListOf()
|
||||||
var skipped: String? = null
|
var skipped: String? = null
|
||||||
if (dataClear.size == 0) {
|
if (dataClearInput.size == 0) {
|
||||||
aapsLogger.error(LTag.PUMPBTCOMM, "Empty page.")
|
aapsLogger.error(LTag.PUMPBTCOMM, "Empty page.")
|
||||||
return outList
|
return outList
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
val opCode: Int = dataClear[counter].toInt()
|
val opCode: Int = dataClearInput[counter].toInt()
|
||||||
var special = false
|
var special = false
|
||||||
incompletePacket = false
|
incompletePacket = false
|
||||||
var skippedRecords = false
|
var skippedRecords = false
|
||||||
|
@ -79,13 +78,13 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
listRawData.add(opCode.toByte())
|
listRawData.add(opCode.toByte())
|
||||||
if (entryType === PumpHistoryEntryType.UnabsorbedInsulin
|
if (entryType === PumpHistoryEntryType.UnabsorbedInsulin
|
||||||
|| entryType === PumpHistoryEntryType.UnabsorbedInsulin512) {
|
|| entryType === PumpHistoryEntryType.UnabsorbedInsulin512) {
|
||||||
val elements: Int = dataClear[counter].toInt()
|
val elements: Int = dataClearInput[counter].toInt()
|
||||||
listRawData.add(elements.toByte())
|
listRawData.add(elements.toByte())
|
||||||
counter++
|
counter++
|
||||||
val els = getUnsignedInt(elements)
|
val els = getUnsignedInt(elements)
|
||||||
for (k in 0 until els - 2) {
|
for (k in 0 until els - 2) {
|
||||||
if (counter < 1022) {
|
if (counter < 1022) {
|
||||||
listRawData.add(dataClear[counter])
|
listRawData.add(dataClearInput[counter])
|
||||||
counter++
|
counter++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +92,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
} else {
|
} else {
|
||||||
for (j in 0 until entryType.getTotalLength(medtronicUtil.medtronicPumpModel!!) - 1) {
|
for (j in 0 until entryType.getTotalLength(medtronicUtil.medtronicPumpModel!!) - 1) {
|
||||||
try {
|
try {
|
||||||
listRawData.add(dataClear[counter])
|
listRawData.add(dataClearInput[counter])
|
||||||
counter++
|
counter++
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
aapsLogger.error(LTag.PUMPBTCOMM, "OpCode: " + ByteUtil.shortHexString(opCode.toByte()) + ", Invalid package: "
|
aapsLogger.error(LTag.PUMPBTCOMM, "OpCode: " + ByteUtil.shortHexString(opCode.toByte()) + ", Invalid package: "
|
||||||
|
@ -126,7 +125,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
outList.add(pe)
|
outList.add(pe)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (counter < dataClear.size)
|
} while (counter < dataClearInput.size)
|
||||||
return outList
|
return outList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,9 +271,9 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
dto.bolusTotal = ((body[12].toInt() shl 8) + body[13]) / bolusStrokes
|
dto.bolusTotal = ((body[12].toInt() shl 8) + body[13]) / bolusStrokes
|
||||||
} else {
|
} else {
|
||||||
dto.bloodGlucose = (body.get(1) and 0x0F).toInt() shl 8 or entry.head!!.get(0).toInt()
|
dto.bloodGlucose = (body.get(1) and 0x0F).toInt() shl 8 or entry.head!!.get(0).toInt()
|
||||||
dto.carbs = body.get(0).toInt()
|
dto.carbs = body[0].toInt()
|
||||||
dto.carbRatio = body.get(2).toFloat()
|
dto.carbRatio = body[2].toFloat()
|
||||||
dto.insulinSensitivity = body.get(3).toFloat()
|
dto.insulinSensitivity = body[3].toFloat()
|
||||||
dto.bgTargetLow = body.get(4).toInt()
|
dto.bgTargetLow = body.get(4).toInt()
|
||||||
dto.bgTargetHigh = body.get(12).toInt()
|
dto.bgTargetHigh = body.get(12).toInt()
|
||||||
dto.bolusTotal = body.get(11) / bolusStrokes
|
dto.bolusTotal = body.get(11) / bolusStrokes
|
||||||
|
@ -283,10 +282,10 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
dto.bolusTotal = body.get(11) / bolusStrokes
|
dto.bolusTotal = body.get(11) / bolusStrokes
|
||||||
dto.correctionEstimate = (body.get(7) + (body.get(5) and 0x0F)) / 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.bloodGlucose = ByteUtil.convertUnsignedByteToInt(dto.bloodGlucose.toByte())
|
||||||
}
|
}
|
||||||
dto.atechDateTime = entry.atechDateTime!!
|
dto.atechDateTime = entry.atechDateTime
|
||||||
entry.addDecodedData("Object", dto)
|
entry.addDecodedData("Object", dto)
|
||||||
entry.displayableValue = dto.displayableValue
|
entry.displayableValue = dto.displayableValue
|
||||||
return RecordDecodeStatus.OK
|
return RecordDecodeStatus.OK
|
||||||
|
@ -306,10 +305,10 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
dto.unabsorbedInsulin = body.get(9) / bolusStrokes
|
dto.unabsorbedInsulin = body.get(9) / bolusStrokes
|
||||||
dto.bolusTotal = body.get(11) / bolusStrokes
|
dto.bolusTotal = body.get(11) / bolusStrokes
|
||||||
dto.bgTargetHigh = dto.bgTargetLow
|
dto.bgTargetHigh = dto.bgTargetLow
|
||||||
if (dto.bloodGlucose != null && dto.bloodGlucose < 0) {
|
if (dto.bloodGlucose < 0) {
|
||||||
dto.bloodGlucose = ByteUtil.convertUnsignedByteToInt(dto.bloodGlucose.toByte())
|
dto.bloodGlucose = ByteUtil.convertUnsignedByteToInt(dto.bloodGlucose.toByte())
|
||||||
}
|
}
|
||||||
dto.atechDateTime = entry.atechDateTime!!
|
dto.atechDateTime = entry.atechDateTime
|
||||||
entry.addDecodedData("Object", dto)
|
entry.addDecodedData("Object", dto)
|
||||||
entry.displayableValue = dto.displayableValue
|
entry.displayableValue = dto.displayableValue
|
||||||
return RecordDecodeStatus.OK
|
return RecordDecodeStatus.OK
|
||||||
|
@ -371,7 +370,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
bolus.duration = ByteUtil.asUINT8(data.get(2)) * 30
|
bolus.duration = ByteUtil.asUINT8(data.get(2)) * 30
|
||||||
}
|
}
|
||||||
bolus.bolusType = if (bolus.duration != null && bolus.duration!! > 0) PumpBolusType.Extended else PumpBolusType.Normal
|
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.addDecodedData("Object", bolus)
|
||||||
entry.displayableValue = bolus.displayableValue
|
entry.displayableValue = bolus.displayableValue
|
||||||
}
|
}
|
||||||
|
@ -431,9 +430,9 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
val dayOfMonth: Int = (dt.get(3) and 0x1F).toInt()
|
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
|
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.
|
// 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) {
|
} 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 mhigh = ByteUtil.asUINT8(dt.get(0)) and 0xE0 shr 4
|
||||||
val mlow = ByteUtil.asUINT8(dt.get(1)) and 0x80 shr 7
|
val mlow = ByteUtil.asUINT8(dt.get(1)) and 0x80 shr 7
|
||||||
val month = mhigh + mlow
|
val month = mhigh + mlow
|
||||||
|
@ -454,7 +453,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
minutes = 59
|
minutes = 59
|
||||||
seconds = 59
|
seconds = 59
|
||||||
}
|
}
|
||||||
entry.setAtechDateTime(DateTimeUtil.toATechDate(year, month, dayOfMonth, hour, minutes, seconds))
|
entry.atechDateTime = DateTimeUtil.toATechDate(year, month, dayOfMonth, hour, minutes, seconds)
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.warn(LTag.PUMPBTCOMM, "Unknown datetime format: " + entry.dateTimeLength)
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Unknown datetime format: " + entry.dateTimeLength)
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,11 +41,11 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
|
||||||
sizes[0] = entryType.getHeadLength(medtronicDeviceType)
|
sizes[0] = entryType.getHeadLength(medtronicDeviceType)
|
||||||
sizes[1] = entryType.dateLength
|
sizes[1] = entryType.dateLength
|
||||||
sizes[2] = entryType.getBodyLength(medtronicDeviceType)
|
sizes[2] = entryType.getBodyLength(medtronicDeviceType)
|
||||||
if (this.entryType != null && atechDateTime != null) generatePumpId()
|
if (this.entryType != null && atechDateTime != 0L) generatePumpId()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generatePumpId() : Long {
|
private fun generatePumpId() : Long {
|
||||||
return entryType!!.code + atechDateTime!! * 1000L
|
return entryType!!.code + atechDateTime * 1000L
|
||||||
}
|
}
|
||||||
|
|
||||||
override val toStringStart: String
|
override val toStringStart: String
|
||||||
|
@ -91,16 +91,16 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
|
||||||
// return this.dateTime.isAfter(dateTimeIn);
|
// return this.dateTime.isAfter(dateTimeIn);
|
||||||
// }
|
// }
|
||||||
fun isAfter(atechDateTime: Long): Boolean {
|
fun isAfter(atechDateTime: Long): Boolean {
|
||||||
if (this.atechDateTime == null) {
|
if (this.atechDateTime == 0L) {
|
||||||
Log.e("PumpHistoryEntry", "Date is null. Show object: " + toString())
|
// Log.e("PumpHistoryEntry", "Date is null. Show object: " + toString())
|
||||||
return false // FIXME shouldn't happen
|
return false // FIXME shouldn't happen
|
||||||
}
|
}
|
||||||
return atechDateTime < this.atechDateTime!!
|
return atechDateTime < this.atechDateTime
|
||||||
}
|
}
|
||||||
|
|
||||||
class Comparator : java.util.Comparator<PumpHistoryEntry> {
|
class Comparator : java.util.Comparator<PumpHistoryEntry> {
|
||||||
override fun compare(o1: PumpHistoryEntry, o2: PumpHistoryEntry): Int {
|
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
|
return if (data != 0) data else o2.entryType!!.code - o1.entryType!!.code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,17 +116,13 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
|
||||||
|
|
||||||
fun hasBolusChanged(entry: PumpHistoryEntry) : Boolean {
|
fun hasBolusChanged(entry: PumpHistoryEntry) : Boolean {
|
||||||
if (entryType!=null && entryType == PumpHistoryEntryType.Bolus) {
|
if (entryType!=null && entryType == PumpHistoryEntryType.Bolus) {
|
||||||
val thisOne: BolusDTO? = this.decodedData!!["Object"]!! as BolusDTO?
|
val thisOne: BolusDTO = this.decodedData["Object"] as BolusDTO
|
||||||
val otherOne: BolusDTO? = entry.decodedData!!["Object"]!! as BolusDTO?
|
|
||||||
|
|
||||||
if (thisOne==null || otherOne==null) {
|
if (entry.entryType!=null && entry.entryType == PumpHistoryEntryType.Bolus) {
|
||||||
return false;
|
val otherOne: BolusDTO = entry.decodedData["Object"] as BolusDTO
|
||||||
}
|
return (thisOne.value.equals(otherOne.value))
|
||||||
|
} else
|
||||||
|
return false
|
||||||
|
|
||||||
|
|
||||||
return false // TODO needs to be implemented
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -133,7 +133,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
newHistory2.add(pumpHistoryEntry)
|
newHistory2.add(pumpHistoryEntry)
|
||||||
} else {
|
} else {
|
||||||
if (type === PumpHistoryEntryType.EndResultTotals) {
|
if (type === PumpHistoryEntryType.EndResultTotals) {
|
||||||
if (!DateTimeUtil.isSameDay(atechDate, pumpHistoryEntry.atechDateTime!!)) {
|
if (!DateTimeUtil.isSameDay(atechDate, pumpHistoryEntry.atechDateTime)) {
|
||||||
newHistory2.add(pumpHistoryEntry)
|
newHistory2.add(pumpHistoryEntry)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -168,7 +168,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
for (bolusEstimate in bolusEstimates) {
|
for (bolusEstimate in bolusEstimates) {
|
||||||
for (bolus in boluses) {
|
for (bolus in boluses) {
|
||||||
if (bolusEstimate.atechDateTime == bolus.atechDateTime) {
|
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
|
// find last entry
|
||||||
for (pumpHistoryEntry in newHistory) {
|
for (pumpHistoryEntry in newHistory) {
|
||||||
if (pumpHistoryEntry.atechDateTime != null && pumpHistoryEntry.isAfter(pheLast.atechDateTime!!)) {
|
if (pumpHistoryEntry.atechDateTime != 0L && pumpHistoryEntry.isAfter(pheLast.atechDateTime)) {
|
||||||
pheLast = pumpHistoryEntry
|
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
|
var dt: LocalDateTime? = null
|
||||||
try {
|
try {
|
||||||
dt = DateTimeUtil.toLocalDateTime(pheLast.atechDateTime!!)
|
dt = DateTimeUtil.toLocalDateTime(pheLast.atechDateTime)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
aapsLogger.error("Problem decoding date from last record: $pheLast")
|
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
|
// so skip the prime entry if it was not a fixed prime
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (primeRecord.atechDateTime!! > maxAllowedTimeInPast) {
|
if (primeRecord.atechDateTime > maxAllowedTimeInPast) {
|
||||||
if (lastPrimeRecordTime < primeRecord.atechDateTime!!) {
|
if (lastPrimeRecordTime!=0L && lastPrimeRecordTime < primeRecord.atechDateTime) {
|
||||||
lastPrimeRecordTime = primeRecord.atechDateTime!!
|
lastPrimeRecordTime = primeRecord.atechDateTime
|
||||||
lastPrimeRecord = primeRecord
|
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)
|
val maxAllowedTimeInPast = DateTimeUtil.getATDWithAddedMinutes(GregorianCalendar(), -30)
|
||||||
var lastRewindRecordTime = 0L
|
var lastRewindRecordTime = 0L
|
||||||
var lastRewindRecord: PumpHistoryEntry? = null
|
var lastRewindRecord: PumpHistoryEntry? = null
|
||||||
for (rewindRecord in rewindRecords) {
|
for (rewindRecord in rewindRecords) {
|
||||||
if (rewindRecord!!.atechDateTime!! > maxAllowedTimeInPast) {
|
if (rewindRecord.atechDateTime > maxAllowedTimeInPast) {
|
||||||
if (lastRewindRecordTime < rewindRecord.atechDateTime!!) {
|
if (lastRewindRecordTime < rewindRecord.atechDateTime) {
|
||||||
lastRewindRecordTime = rewindRecord.atechDateTime!!
|
lastRewindRecordTime = rewindRecord.atechDateTime
|
||||||
lastRewindRecord = rewindRecord
|
lastRewindRecord = rewindRecord
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -434,17 +434,17 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
val lastPrimeFromAAPS = sp.getLong(eventSP, 0L)
|
val lastPrimeFromAAPS = sp.getLong(eventSP, 0L)
|
||||||
if (historyRecord.atechDateTime != lastPrimeFromAAPS) {
|
if (historyRecord.atechDateTime != lastPrimeFromAAPS) {
|
||||||
var result = pumpSync.insertTherapyEventIfNewWithTimestamp(
|
var result = pumpSync.insertTherapyEventIfNewWithTimestamp(
|
||||||
DateTimeUtil.toMillisFromATD(historyRecord.atechDateTime!!),
|
DateTimeUtil.toMillisFromATD(historyRecord.atechDateTime),
|
||||||
eventType, null,
|
eventType, null,
|
||||||
historyRecord.pumpId,
|
historyRecord.pumpId,
|
||||||
medtronicPumpStatus.pumpType,
|
medtronicPumpStatus.pumpType,
|
||||||
medtronicPumpStatus.serialNumber!!)
|
medtronicPumpStatus.serialNumber!!)
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ROOT, "insertTherapyEventIfNewWithTimestamp [date=%d, eventType=%s, pumpId=%d, pumpSerial=%s] - Result: %b",
|
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))
|
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)))
|
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
|
||||||
|
|
||||||
pumpSync.createOrUpdateTotalDailyDose(
|
pumpSync.createOrUpdateTotalDailyDose(
|
||||||
DateTimeUtil.toMillisFromATD(tdd.atechDateTime!!),
|
DateTimeUtil.toMillisFromATD(tdd.atechDateTime),
|
||||||
totalsDTO.insulinBolus,
|
totalsDTO.insulinBolus,
|
||||||
totalsDTO.insulinBasal!!,
|
totalsDTO.insulinBasal!!,
|
||||||
totalsDTO.insulinTotal,
|
totalsDTO.insulinTotal,
|
||||||
|
@ -484,7 +484,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
|
|
||||||
for (bolus in entryList) {
|
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 type: DetailedBolusInfo.BolusType = DetailedBolusInfo.BolusType.NORMAL
|
||||||
var multiwave = false
|
var multiwave = false
|
||||||
|
|
||||||
|
@ -516,7 +516,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
|
|
||||||
if (temporaryId!=null) {
|
if (temporaryId!=null) {
|
||||||
val result = pumpSync.syncBolusWithTempId(
|
val result = pumpSync.syncBolusWithTempId(
|
||||||
tryToGetByLocalTime(bolus.atechDateTime!!),
|
tryToGetByLocalTime(bolus.atechDateTime),
|
||||||
deliveredAmount,
|
deliveredAmount,
|
||||||
temporaryId,
|
temporaryId,
|
||||||
type,
|
type,
|
||||||
|
@ -525,11 +525,11 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
medtronicPumpStatus.serialNumber!!)
|
medtronicPumpStatus.serialNumber!!)
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncBolusWithTempId [date=%d, temporaryId=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b",
|
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))
|
medtronicPumpStatus.serialNumber!!, result))
|
||||||
} else {
|
} else {
|
||||||
val result = pumpSync.syncBolusWithPumpId(
|
val result = pumpSync.syncBolusWithPumpId(
|
||||||
tryToGetByLocalTime(bolus.atechDateTime!!),
|
tryToGetByLocalTime(bolus.atechDateTime),
|
||||||
deliveredAmount,
|
deliveredAmount,
|
||||||
type,
|
type,
|
||||||
bolus.pumpId!!,
|
bolus.pumpId!!,
|
||||||
|
@ -537,7 +537,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
medtronicPumpStatus.serialNumber!!)
|
medtronicPumpStatus.serialNumber!!)
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncBolusWithPumpId [date=%d, pumpId=%d, insulin=%.2f, pumpSerial=%s] - Result: %b",
|
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))
|
medtronicPumpStatus.serialNumber!!, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -550,7 +550,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
val durationMs : Long = bolusDTO.duration!! * 60L * 1000L
|
val durationMs : Long = bolusDTO.duration!! * 60L * 1000L
|
||||||
|
|
||||||
val result = pumpSync.syncExtendedBolusWithPumpId(
|
val result = pumpSync.syncExtendedBolusWithPumpId(
|
||||||
tryToGetByLocalTime(bolus.atechDateTime!!),
|
tryToGetByLocalTime(bolus.atechDateTime),
|
||||||
bolusDTO.deliveredAmount!!,
|
bolusDTO.deliveredAmount!!,
|
||||||
durationMs,
|
durationMs,
|
||||||
false,
|
false,
|
||||||
|
@ -559,17 +559,17 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
medtronicPumpStatus.serialNumber!!)
|
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",
|
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))
|
medtronicPumpStatus.serialNumber!!, isMultiwave, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun addCarbs(bolus: PumpHistoryEntry) {
|
private fun addCarbs(bolus: PumpHistoryEntry) {
|
||||||
if (bolus.containsDecodedData("Estimate")) {
|
if (bolus.containsDecodedData("Estimate")) {
|
||||||
val bolusWizard = bolus.decodedData!!["Estimate"] as BolusWizardDTO
|
val bolusWizard = bolus.decodedData["Estimate"] as BolusWizardDTO
|
||||||
|
|
||||||
pumpSyncStorage.addCarbs(PumpDbEntryCarbs(
|
pumpSyncStorage.addCarbs(PumpDbEntryCarbs(
|
||||||
tryToGetByLocalTime(bolus.atechDateTime!!),
|
tryToGetByLocalTime(bolus.atechDateTime),
|
||||||
bolusWizard.carbs.toDouble(),
|
bolusWizard.carbs.toDouble(),
|
||||||
medtronicPumpStatus.pumpType,
|
medtronicPumpStatus.pumpType,
|
||||||
medtronicPumpStatus.serialNumber!!,
|
medtronicPumpStatus.serialNumber!!,
|
||||||
|
@ -615,9 +615,9 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
if (processDTO != null) {
|
if (processDTO != null) {
|
||||||
processList.add(processDTO)
|
processList.add(processDTO)
|
||||||
}
|
}
|
||||||
processDTO = TempBasalProcessDTO()
|
processDTO = TempBasalProcessDTO(
|
||||||
processDTO.itemOne = treatment
|
itemOne= treatment,
|
||||||
processDTO.processOperation = TempBasalProcessDTO.Operation.Add
|
processOperation = TempBasalProcessDTO.Operation.Add)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (processDTO != null) {
|
if (processDTO != null) {
|
||||||
|
@ -630,7 +630,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "DD: entryWithTempId: " + (if (entryWithTempId==null) "null" else entryWithTempId.toString()))
|
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)))
|
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
|
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
|
// pumpTime should never be null, but it can theoretically happen if reading of time from pump fails
|
||||||
this.pumpTime?.let { proposedTime += (it.timeDifference * 1000) }
|
this.pumpTime?.let { proposedTime += (it.timeDifference * 1000) }
|
||||||
|
@ -793,18 +793,19 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
for (tempBasalProcess in tempBasalProcessList) {
|
for (tempBasalProcess in tempBasalProcessList) {
|
||||||
|
|
||||||
val result = pumpSync.syncTemporaryBasalWithPumpId(
|
val result = pumpSync.syncTemporaryBasalWithPumpId(
|
||||||
tryToGetByLocalTime(tempBasalProcess.itemOne!!.atechDateTime!!),
|
tryToGetByLocalTime(tempBasalProcess.itemOne.atechDateTime),
|
||||||
0.0,
|
0.0,
|
||||||
tempBasalProcess.duration * 60 * 1000L,
|
tempBasalProcess.duration * 60 * 1000L,
|
||||||
true,
|
true,
|
||||||
PumpSync.TemporaryBasalType.PUMP_SUSPEND,
|
PumpSync.TemporaryBasalType.PUMP_SUSPEND,
|
||||||
tempBasalProcess.itemOne!!.pumpId!!,
|
tempBasalProcess.itemOne.pumpId!!,
|
||||||
medtronicPumpStatus.pumpType,
|
medtronicPumpStatus.pumpType,
|
||||||
medtronicPumpStatus.serialNumber!!)
|
medtronicPumpStatus.serialNumber!!)
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "processSuspends::syncTemporaryBasalWithPumpId [date=%d, rate=%.2f, duration=%d, pumpId=%d, pumpSerial=%s] - Result: %b",
|
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))
|
medtronicPumpStatus.serialNumber!!, result))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -862,11 +863,11 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
Collections.reverse(filtered2Items)
|
Collections.reverse(filtered2Items)
|
||||||
var i = 0
|
var i = 0
|
||||||
while (i < filtered2Items.size) {
|
while (i < filtered2Items.size) {
|
||||||
val dto = TempBasalProcessDTO()
|
outList.add(TempBasalProcessDTO(
|
||||||
dto.itemOne = filtered2Items[i]
|
itemOne= filtered2Items[i],
|
||||||
dto.itemTwo = filtered2Items[i + 1]
|
itemTwo= filtered2Items[i + 1],
|
||||||
dto.processOperation = TempBasalProcessDTO.Operation.Add
|
processOperation = TempBasalProcessDTO.Operation.Add))
|
||||||
outList.add(dto)
|
|
||||||
i += 2
|
i += 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -925,20 +926,20 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
showLogs("NoDeliveryRewindPrimeRecords: Records to evaluate: ", gson.toJson(tempData))
|
showLogs("NoDeliveryRewindPrimeRecords: Records to evaluate: ", gson.toJson(tempData))
|
||||||
var items: MutableList<PumpHistoryEntry> = getFilteredItems(tempData, PumpHistoryEntryType.Prime)
|
var items: MutableList<PumpHistoryEntry> = getFilteredItems(tempData, PumpHistoryEntryType.Prime)
|
||||||
val processDTO = TempBasalProcessDTO()
|
var itemTwo = items[0]
|
||||||
processDTO.itemTwo = items[0]
|
|
||||||
items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm)
|
items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm)
|
||||||
if (items.size > 0) {
|
if (items.size > 0) {
|
||||||
processDTO.itemOne = items[items.size - 1]
|
outList.add(TempBasalProcessDTO(
|
||||||
processDTO.processOperation = TempBasalProcessDTO.Operation.Add
|
itemOne=items[items.size - 1],
|
||||||
outList.add(processDTO)
|
itemTwo= itemTwo,
|
||||||
|
processOperation=TempBasalProcessDTO.Operation.Add))
|
||||||
return outList
|
return outList
|
||||||
}
|
}
|
||||||
items = getFilteredItems(tempData, PumpHistoryEntryType.Rewind)
|
items = getFilteredItems(tempData, PumpHistoryEntryType.Rewind)
|
||||||
if (items.size > 0) {
|
if (items.size > 0) {
|
||||||
processDTO.itemOne = items[0]
|
outList.add(TempBasalProcessDTO(
|
||||||
processDTO.processOperation = TempBasalProcessDTO.Operation.Add
|
itemOne=items[0],
|
||||||
outList.add(processDTO)
|
processOperation=TempBasalProcessDTO.Operation.Add))
|
||||||
return outList
|
return outList
|
||||||
}
|
}
|
||||||
return outList
|
return outList
|
||||||
|
@ -991,8 +992,8 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun processLastBasalProfileChange(pumpType: PumpType?, mdtPumpStatus: MedtronicPumpStatus) {
|
fun processLastBasalProfileChange(pumpType: PumpType, mdtPumpStatus: MedtronicPumpStatus) {
|
||||||
val filteredItems: List<PumpHistoryEntry?> = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile)
|
val filteredItems: List<PumpHistoryEntry> = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile)
|
||||||
aapsLogger.debug(LTag.PUMP, "processLastBasalProfileChange. Items: $filteredItems")
|
aapsLogger.debug(LTag.PUMP, "processLastBasalProfileChange. Items: $filteredItems")
|
||||||
var newProfile: PumpHistoryEntry? = null
|
var newProfile: PumpHistoryEntry? = null
|
||||||
var lastDate: Long? = null
|
var lastDate: Long? = null
|
||||||
|
@ -1000,16 +1001,16 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
newProfile = filteredItems[0]
|
newProfile = filteredItems[0]
|
||||||
} else if (filteredItems.size > 1) {
|
} else if (filteredItems.size > 1) {
|
||||||
for (filteredItem in filteredItems) {
|
for (filteredItem in filteredItems) {
|
||||||
if (lastDate == null || lastDate < filteredItem!!.atechDateTime!!) {
|
if (lastDate == null || lastDate < filteredItem.atechDateTime) {
|
||||||
newProfile = filteredItem
|
newProfile = filteredItem
|
||||||
lastDate = newProfile!!.atechDateTime
|
lastDate = newProfile.atechDateTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newProfile != null) {
|
if (newProfile != null) {
|
||||||
aapsLogger.debug(LTag.PUMP, "processLastBasalProfileChange. item found, setting new basalProfileLocally: $newProfile")
|
aapsLogger.debug(LTag.PUMP, "processLastBasalProfileChange. item found, setting new basalProfileLocally: $newProfile")
|
||||||
val basalProfile = newProfile.decodedData!!["Object"] as BasalProfile?
|
val basalProfile = newProfile.decodedData["Object"] as BasalProfile
|
||||||
mdtPumpStatus.basalsByHour = basalProfile!!.getProfilesByHour(pumpType!!)
|
mdtPumpStatus.basalsByHour = basalProfile.getProfilesByHour(pumpType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.common.utils.DateTimeUtil
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
|
||||||
|
|
||||||
class TempBasalProcessDTO {
|
class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
|
||||||
var itemOne: PumpHistoryEntry? = null
|
var itemTwo: PumpHistoryEntry? = null,
|
||||||
var itemTwo: PumpHistoryEntry? = null
|
var processOperation: Operation = Operation.None) {
|
||||||
var processOperation = Operation.None
|
|
||||||
var cancelPresent: Boolean = false
|
var cancelPresent: Boolean = false
|
||||||
|
|
||||||
val atechDateTime: Long
|
val atechDateTime: Long
|
||||||
get() = if (itemOne==null) 0L else itemOne!!.atechDateTime!!
|
get() = itemOne.atechDateTime
|
||||||
|
|
||||||
val pumpId: Long
|
val pumpId: Long
|
||||||
get() = if (itemOne==null) 0L else itemOne!!.pumpId!!
|
get() = itemOne.pumpId!!
|
||||||
|
|
||||||
val duration: Int
|
val duration: Int
|
||||||
get() = if (itemTwo == null) {
|
get() = if (itemTwo == null) {
|
||||||
val tbr = itemOne!!.getDecodedDataEntry("Object") as TempBasalPair?
|
val tbr = itemOne.getDecodedDataEntry("Object") as TempBasalPair
|
||||||
tbr!!.durationMinutes
|
tbr.durationMinutes
|
||||||
} else {
|
} else {
|
||||||
DateTimeUtil.getATechDateDiferenceAsMinutes(itemOne!!.atechDateTime, itemTwo!!.atechDateTime)
|
DateTimeUtil.getATechDateDiferenceAsMinutes(itemOne.atechDateTime, itemTwo!!.atechDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Operation {
|
enum class Operation {
|
||||||
|
|
Loading…
Reference in a new issue