- kotlin !! refactorings
This commit is contained in:
parent
59a3bf8883
commit
921302bdbf
22 changed files with 337 additions and 261 deletions
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.db
|
package info.nightscout.androidaps.db
|
||||||
|
|
||||||
|
@Deprecated("This class is not needed for new database anymore")
|
||||||
interface DbObjectBase {
|
interface DbObjectBase {
|
||||||
|
|
||||||
fun getDate(): Long
|
fun getDate(): Long
|
||||||
|
|
|
@ -296,13 +296,13 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
val bolus = medtronicPumpStatus.lastBolusAmount
|
val bolus = medtronicPumpStatus.lastBolusAmount
|
||||||
val bolusTime = medtronicPumpStatus.lastBolusTime
|
val bolusTime = medtronicPumpStatus.lastBolusTime
|
||||||
if (bolus != null && bolusTime != null) {
|
if (bolus != null && bolusTime != null) {
|
||||||
val agoMsc = System.currentTimeMillis() - medtronicPumpStatus.lastBolusTime!!.time
|
val agoMsc = System.currentTimeMillis() - bolusTime.time
|
||||||
val bolusMinAgo = agoMsc.toDouble() / 60.0 / 1000.0
|
val bolusMinAgo = agoMsc.toDouble() / 60.0 / 1000.0
|
||||||
val unit = resourceHelper.gs(R.string.insulin_unit_shortname)
|
val unit = resourceHelper.gs(R.string.insulin_unit_shortname)
|
||||||
val ago = when {
|
val ago = when {
|
||||||
agoMsc < 60 * 1000 -> resourceHelper.gs(R.string.medtronic_pump_connected_now)
|
agoMsc < 60 * 1000 -> resourceHelper.gs(R.string.medtronic_pump_connected_now)
|
||||||
bolusMinAgo < 60 -> dateUtil.minAgo(resourceHelper, medtronicPumpStatus.lastBolusTime!!.time)
|
bolusMinAgo < 60 -> dateUtil.minAgo(resourceHelper, bolusTime.time)
|
||||||
else -> dateUtil.hourAgo(medtronicPumpStatus.lastBolusTime!!.time, resourceHelper)
|
else -> dateUtil.hourAgo(bolusTime.time, resourceHelper)
|
||||||
}
|
}
|
||||||
binding.lastBolus.text = resourceHelper.gs(R.string.mdt_last_bolus, bolus, unit, ago)
|
binding.lastBolus.text = resourceHelper.gs(R.string.mdt_last_bolus, bolus, unit, ago)
|
||||||
} else {
|
} else {
|
||||||
|
@ -315,9 +315,9 @@ class MedtronicFragment : DaggerFragment() {
|
||||||
|
|
||||||
// TBR
|
// TBR
|
||||||
var tbrStr = ""
|
var tbrStr = ""
|
||||||
var tbrRemainingTime: Int? = medtronicPumpStatus.tbrRemainingTime
|
val tbrRemainingTime: Int? = medtronicPumpStatus.tbrRemainingTime
|
||||||
|
|
||||||
if (tbrRemainingTime!=null) {
|
if (tbrRemainingTime != null) {
|
||||||
tbrStr = resourceHelper.gs(R.string.mdt_tbr_remaining, medtronicPumpStatus.tempBasalAmount, tbrRemainingTime);
|
tbrStr = resourceHelper.gs(R.string.mdt_tbr_remaining, medtronicPumpStatus.tempBasalAmount, tbrRemainingTime);
|
||||||
}
|
}
|
||||||
binding.tempBasal.text = tbrStr
|
binding.tempBasal.text = tbrStr
|
||||||
|
|
|
@ -303,7 +303,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
override fun getPumpStatus(reason: String) {
|
override fun getPumpStatus(reason: String) {
|
||||||
var needRefresh = true
|
var needRefresh = true
|
||||||
if (firstRun) {
|
if (firstRun) {
|
||||||
needRefresh = initializePump(!isRefresh)
|
needRefresh = initializePump() /*!isRefresh*/
|
||||||
} else {
|
} else {
|
||||||
refreshAnyStatusThatNeedsToBeRefreshed()
|
refreshAnyStatusThatNeedsToBeRefreshed()
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
rxBus.send(EventRefreshButtonState(enabled))
|
rxBus.send(EventRefreshButtonState(enabled))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initializePump(realInit: Boolean): Boolean {
|
private fun initializePump(): Boolean {
|
||||||
if (rileyLinkMedtronicService == null) return false
|
if (rileyLinkMedtronicService == null) return false
|
||||||
aapsLogger.info(LTag.PUMP, logPrefix + "initializePump - start")
|
aapsLogger.info(LTag.PUMP, logPrefix + "initializePump - start")
|
||||||
rileyLinkMedtronicService!!.deviceCommunicationManager.setDoWakeUpBeforeCommand(false)
|
rileyLinkMedtronicService!!.deviceCommunicationManager.setDoWakeUpBeforeCommand(false)
|
||||||
|
@ -562,7 +562,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
if (clock == null) return
|
if (clock == null) return
|
||||||
val timeDiff = Math.abs(clock.timeDifference)
|
val timeDiff = Math.abs(clock.timeDifference)
|
||||||
if (timeDiff > 20) {
|
if (timeDiff > 20) {
|
||||||
if (clock.localDeviceTime!!.year <= 2015 || timeDiff <= 24 * 60 * 60) {
|
if (clock.localDeviceTime.year <= 2015 || timeDiff <= 24 * 60 * 60) {
|
||||||
aapsLogger.info(LTag.PUMP, String.format(Locale.ENGLISH, "MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is %d s. Set time on pump.", timeDiff))
|
aapsLogger.info(LTag.PUMP, String.format(Locale.ENGLISH, "MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference is %d s. Set time on pump.", timeDiff))
|
||||||
rileyLinkMedtronicService!!.medtronicUIComm.executeCommand(MedtronicCommandType.SetRealTimeClock)
|
rileyLinkMedtronicService!!.medtronicUIComm.executeCommand(MedtronicCommandType.SetRealTimeClock)
|
||||||
if (clock.timeDifference == 0) {
|
if (clock.timeDifference == 0) {
|
||||||
|
@ -570,7 +570,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
rxBus.send(EventNewNotification(notification))
|
rxBus.send(EventNewNotification(notification))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (clock.localDeviceTime!!.year > 2015) {
|
if (clock.localDeviceTime.year > 2015) {
|
||||||
aapsLogger.error(String.format(Locale.ENGLISH, "MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference over 24h requested [diff=%d s]. Doing nothing.", timeDiff))
|
aapsLogger.error(String.format(Locale.ENGLISH, "MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference over 24h requested [diff=%d s]. Doing nothing.", timeDiff))
|
||||||
medtronicUtil.sendNotification(MedtronicNotificationType.TimeChangeOver24h, resourceHelper, rxBus)
|
medtronicUtil.sendNotification(MedtronicNotificationType.TimeChangeOver24h, resourceHelper, rxBus)
|
||||||
}
|
}
|
||||||
|
@ -855,7 +855,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
||||||
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntry: not null - " + medtronicUtil.gsonInstance.toJson(lastPumpHistoryEntry))
|
if (debugHistory) aapsLogger.debug(LTag.PUMP, logPrefix + "readPumpHistoryLogic(): lastPumpHistoryEntry: not null - " + medtronicUtil.gsonInstance.toJson(lastPumpHistoryEntry))
|
||||||
medtronicHistoryData.setIsInInit(false)
|
medtronicHistoryData.setIsInInit(false)
|
||||||
// we need to read 35 minutes in the past so that we can repair any TBR or Bolus values if neeeded
|
// we need to read 35 minutes in the past so that we can repair any TBR or Bolus values if neeeded
|
||||||
targetDate = LocalDateTime(DateTimeUtil.getMillisFromATDWithAddedMinutes(lastPumpHistoryEntry!!.atechDateTime!!, -35))
|
targetDate = LocalDateTime(DateTimeUtil.getMillisFromATDWithAddedMinutes(lastPumpHistoryEntry!!.atechDateTime, -35))
|
||||||
}
|
}
|
||||||
|
|
||||||
//aapsLogger.debug(LTag.PUMP, "HST: Target Date: " + targetDate);
|
//aapsLogger.debug(LTag.PUMP, "HST: Target Date: " + targetDate);
|
||||||
|
|
|
@ -35,7 +35,6 @@ import org.joda.time.LocalDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
import kotlin.jvm.Throws
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Original file created by geoff on 5/30/16.
|
* Original file created by geoff on 5/30/16.
|
||||||
|
@ -266,8 +265,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
|
||||||
while (!done) {
|
while (!done) {
|
||||||
// examine current response for problems.
|
// examine current response for problems.
|
||||||
val frameData = currentResponse.frameData
|
val frameData = currentResponse.frameData
|
||||||
if (frameData != null && frameData.size > 0
|
if (frameData.size > 0 && currentResponse.frameNumber == expectedFrameNum) {
|
||||||
&& currentResponse.frameNumber == expectedFrameNum) {
|
|
||||||
// success! got a frame.
|
// success! got a frame.
|
||||||
if (frameData.size != 64) {
|
if (frameData.size != 64) {
|
||||||
aapsLogger.warn(LTag.PUMPCOMM, "Expected frame of length 64, got frame of length " + frameData.size)
|
aapsLogger.warn(LTag.PUMPCOMM, "Expected frame of length 64, got frame of length " + frameData.size)
|
||||||
|
@ -287,7 +285,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
|
||||||
done = true // successful completion
|
done = true // successful completion
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (frameData == null) {
|
if (frameData.size == 0) {
|
||||||
aapsLogger.error(LTag.PUMPCOMM, "null frame data, retrying")
|
aapsLogger.error(LTag.PUMPCOMM, "null frame data, retrying")
|
||||||
} else if (currentResponse.frameNumber != expectedFrameNum) {
|
} else if (currentResponse.frameNumber != expectedFrameNum) {
|
||||||
aapsLogger.warn(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Expected frame number %d, received %d (retrying)", expectedFrameNum,
|
aapsLogger.warn(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Expected frame number %d, received %d (retrying)", expectedFrameNum,
|
||||||
|
@ -335,7 +333,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
|
||||||
rawHistoryPage.dumpToDebug()
|
rawHistoryPage.dumpToDebug()
|
||||||
val medtronicHistoryEntries = medtronicPumpHistoryDecoder.processPageAndCreateRecords(rawHistoryPage)
|
val medtronicHistoryEntries = medtronicPumpHistoryDecoder.processPageAndCreateRecords(rawHistoryPage)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "getPumpHistory: Found %d history entries.", medtronicHistoryEntries.size))
|
aapsLogger.debug(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "getPumpHistory: Found %d history entries.", medtronicHistoryEntries.size))
|
||||||
pumpTotalResult.addHistoryEntries(medtronicHistoryEntries, pageNumber)
|
pumpTotalResult.addHistoryEntries(medtronicHistoryEntries) //, pageNumber)
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "getPumpHistory: Search status: Search finished: %b", pumpTotalResult.isSearchFinished))
|
aapsLogger.debug(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "getPumpHistory: Search status: Search finished: %b", pumpTotalResult.isSearchFinished))
|
||||||
if (pumpTotalResult.isSearchFinished) {
|
if (pumpTotalResult.isSearchFinished) {
|
||||||
medtronicPumpStatus.pumpDeviceState = PumpDeviceState.Sleeping
|
medtronicPumpStatus.pumpDeviceState = PumpDeviceState.Sleeping
|
||||||
|
@ -350,7 +348,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
|
||||||
return when (type) {
|
return when (type) {
|
||||||
RLMessageType.PowerOn -> medtronicUtil.buildCommandPayload(rileyLinkServiceData, MedtronicCommandType.RFPowerOn, byteArrayOf(2, 1, receiverDeviceAwakeForMinutes.toByte()))
|
RLMessageType.PowerOn -> medtronicUtil.buildCommandPayload(rileyLinkServiceData, MedtronicCommandType.RFPowerOn, byteArrayOf(2, 1, receiverDeviceAwakeForMinutes.toByte()))
|
||||||
RLMessageType.ReadSimpleData -> medtronicUtil.buildCommandPayload(rileyLinkServiceData, MedtronicCommandType.PumpModel, null)
|
RLMessageType.ReadSimpleData -> medtronicUtil.buildCommandPayload(rileyLinkServiceData, MedtronicCommandType.PumpModel, null)
|
||||||
else -> ByteArray(0)
|
else -> ByteArray(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,8 +505,6 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun getBasalProfile(): BasalProfile? {
|
fun getBasalProfile(): BasalProfile? {
|
||||||
|
|
||||||
// wakeUp
|
// wakeUp
|
||||||
|
@ -552,7 +548,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMPCOMM,"End Response: {}", ByteUtil.getHex(data))
|
aapsLogger.debug(LTag.PUMPCOMM, "End Response: {}", ByteUtil.getHex(data))
|
||||||
|
|
||||||
var basalProfile: BasalProfile? = medtronicConverter.decodeBasalProfile(medtronicPumpPlugin.pumpDescription.pumpType, data)
|
var basalProfile: BasalProfile? = medtronicConverter.decodeBasalProfile(medtronicPumpPlugin.pumpDescription.pumpType, data)
|
||||||
// checkResponseRawContent(data, commandType) {
|
// checkResponseRawContent(data, commandType) {
|
||||||
|
@ -593,26 +589,26 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPumpTime(): ClockDTO? {
|
fun getPumpTime(): ClockDTO? {
|
||||||
val clockDTO = ClockDTO()
|
val localTime = LocalDateTime()
|
||||||
clockDTO.localDeviceTime = LocalDateTime()
|
|
||||||
val responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.GetRealTimeClock) { _, _, rawContent ->
|
val responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.GetRealTimeClock) { _, _, rawContent ->
|
||||||
medtronicConverter.decodeTime(rawContent)
|
medtronicConverter.decodeTime(rawContent)
|
||||||
}
|
}
|
||||||
if (responseObject != null) {
|
if (responseObject != null) {
|
||||||
clockDTO.pumpTime = responseObject
|
return ClockDTO(localDeviceTime = localTime, pumpTime = responseObject)
|
||||||
return clockDTO
|
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTemporaryBasal(): TempBasalPair? {
|
fun getTemporaryBasal(): TempBasalPair? {
|
||||||
return sendAndGetResponseWithCheck(MedtronicCommandType.ReadTemporaryBasal) { _, _, rawContent ->
|
return sendAndGetResponseWithCheck(MedtronicCommandType.ReadTemporaryBasal) { _, _, rawContent ->
|
||||||
TempBasalPair(aapsLogger, rawContent!!) }
|
TempBasalPair(aapsLogger, rawContent!!)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPumpSettings(): Map<String, PumpSettingDTO>? {
|
fun getPumpSettings(): Map<String, PumpSettingDTO>? {
|
||||||
return sendAndGetResponseWithCheck(getSettings(medtronicUtil.medtronicPumpModel)) { _, _, rawContent ->
|
return sendAndGetResponseWithCheck(getSettings(medtronicUtil.medtronicPumpModel)) { _, _, rawContent ->
|
||||||
medtronicConverter.decodeSettingsLoop(rawContent) }
|
medtronicConverter.decodeSettingsLoop(rawContent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setBolus(units: Double): Boolean {
|
fun setBolus(units: Double): Boolean {
|
||||||
|
|
|
@ -7,8 +7,6 @@ import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.jvm.Throws
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file was taken from GGC - GNU Gluco Control (ggc.sourceforge.net), application for diabetes
|
* This file was taken from GGC - GNU Gluco Control (ggc.sourceforge.net), application for diabetes
|
||||||
|
@ -19,9 +17,17 @@ import kotlin.jvm.Throws
|
||||||
*/
|
*/
|
||||||
abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?> : MedtronicHistoryDecoderInterface<T> {
|
abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?> : MedtronicHistoryDecoderInterface<T> {
|
||||||
|
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
constructor(aapsLogger: AAPSLogger,
|
||||||
@Inject lateinit var medtronicUtil: MedtronicUtil
|
medtronicUtil: MedtronicUtil,
|
||||||
@Inject lateinit var bitUtils: ByteUtil
|
bitUtils: ByteUtil) {
|
||||||
|
this.aapsLogger = aapsLogger
|
||||||
|
this.medtronicUtil = medtronicUtil
|
||||||
|
this.bitUtils = bitUtils
|
||||||
|
}
|
||||||
|
|
||||||
|
var aapsLogger: AAPSLogger
|
||||||
|
var medtronicUtil: MedtronicUtil
|
||||||
|
var bitUtils: ByteUtil
|
||||||
|
|
||||||
// STATISTICS (remove at later time or not)
|
// STATISTICS (remove at later time or not)
|
||||||
protected var statisticsEnabled = true
|
protected var statisticsEnabled = true
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.google.gson.annotations.Expose
|
||||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil
|
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.common.utils.StringUtil
|
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,6 +43,7 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
DT = DateTimeUtil.toString(value)
|
DT = DateTimeUtil.toString(value)
|
||||||
|
if (isEntryTypeSet() && value != 0L) pumpId = generatePumpId()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
|
@ -51,7 +53,7 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
|
||||||
/**
|
/**
|
||||||
* Pump id that will be used with AAPS object (time * 1000 + historyType (max is FF = 255)
|
* Pump id that will be used with AAPS object (time * 1000 + historyType (max is FF = 255)
|
||||||
*/
|
*/
|
||||||
open var pumpId: Long? = null
|
open var pumpId: Long = 0L
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if history object is already linked to AAPS object (either Treatment, TempBasal or TDD (tdd's
|
* if history object is already linked to AAPS object (either Treatment, TempBasal or TDD (tdd's
|
||||||
|
@ -75,6 +77,10 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
|
||||||
// this.linkedObject = linkedObject
|
// this.linkedObject = linkedObject
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
abstract fun generatePumpId(): Long
|
||||||
|
|
||||||
|
abstract fun isEntryTypeSet(): Boolean
|
||||||
|
|
||||||
override fun setData(listRawData: List<Byte>, doNotProcess: Boolean) {
|
override fun setData(listRawData: List<Byte>, doNotProcess: Boolean) {
|
||||||
rawData = listRawData
|
rawData = listRawData
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,17 @@ class CGMSHistoryEntry : MedtronicHistoryEntry() {
|
||||||
override val entryTypeName: String
|
override val entryTypeName: String
|
||||||
get() = entryType!!.name
|
get() = entryType!!.name
|
||||||
|
|
||||||
|
override fun generatePumpId(): Long {
|
||||||
|
return if (entryType==null)
|
||||||
|
atechDateTime * 1000L
|
||||||
|
else
|
||||||
|
entryType!!.code + atechDateTime * 1000L
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isEntryTypeSet(): Boolean {
|
||||||
|
return entryType!=null
|
||||||
|
}
|
||||||
|
|
||||||
override fun setData(listRawData: List<Byte>, doNotProcess: Boolean) {
|
override fun setData(listRawData: List<Byte>, doNotProcess: Boolean) {
|
||||||
if (entryType!!.schemaSet) {
|
if (entryType!!.schemaSet) {
|
||||||
super.setData(listRawData, doNotProcess)
|
super.setData(listRawData, doNotProcess)
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.cgms
|
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.cgms
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper.Companion.getLogger
|
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.cgms.CGMSHistoryEntryType
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.cgms.CGMSHistoryEntryType
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.cgms.CGMSHistoryEntryType.Companion.getByCode
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.cgms.CGMSHistoryEntryType.Companion.getByCode
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
|
||||||
import okhttp3.internal.and
|
import okhttp3.internal.and
|
||||||
import org.joda.time.LocalDateTime
|
import org.joda.time.LocalDateTime
|
||||||
import org.slf4j.Logger
|
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import org.slf4j.LoggerFactory.getLogger as getLogger1
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file was taken from GGC - GNU Gluco Control (ggc.sourceforge.net), application for diabetes
|
* This file was taken from GGC - GNU Gluco Control (ggc.sourceforge.net), application for diabetes
|
||||||
|
@ -21,13 +20,17 @@ import org.slf4j.LoggerFactory.getLogger as getLogger1
|
||||||
*
|
*
|
||||||
* Author: Andy {andy.rozman@gmail.com}
|
* Author: Andy {andy.rozman@gmail.com}
|
||||||
*/
|
*/
|
||||||
class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>() {
|
class MedtronicCGMSHistoryDecoder constructor(
|
||||||
|
aapsLogger: AAPSLogger,
|
||||||
|
medtronicUtil: MedtronicUtil,
|
||||||
|
bitUtils: ByteUtil
|
||||||
|
) : MedtronicHistoryDecoder<CGMSHistoryEntry>(aapsLogger, medtronicUtil, bitUtils) {
|
||||||
|
|
||||||
override fun decodeRecord(record: CGMSHistoryEntry): RecordDecodeStatus? {
|
override fun decodeRecord(record: CGMSHistoryEntry): RecordDecodeStatus? {
|
||||||
return try {
|
return try {
|
||||||
decodeRecordInternal(record)
|
decodeRecordInternal(record)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
aapsLogger.error(LTag.PUMPCOMM," 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +114,7 @@ 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
|
||||||
|
@ -127,7 +130,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
|
||||||
} else {
|
} else {
|
||||||
if (dateTime != null) entry.setDateTime(dateTime, getIndex)
|
if (dateTime != null) entry.setDateTime(dateTime, getIndex)
|
||||||
}
|
}
|
||||||
aapsLogger.debug(LTag.PUMPCOMM,"Record: {}", entry)
|
aapsLogger.debug(LTag.PUMPCOMM, "Record: {}", entry)
|
||||||
}
|
}
|
||||||
return reversedOutList
|
return reversedOutList
|
||||||
}
|
}
|
||||||
|
@ -171,7 +174,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
|
||||||
entry.atechDateTime = atechDateTime
|
entry.atechDateTime = atechDateTime
|
||||||
atechDateTime
|
atechDateTime
|
||||||
} else if (entry.entryType!!.dateType === CGMSHistoryEntryType.DateType.SecondSpecific) {
|
} else if (entry.entryType!!.dateType === CGMSHistoryEntryType.DateType.SecondSpecific) {
|
||||||
aapsLogger.warn(LTag.PUMPCOMM,"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
|
||||||
|
@ -246,7 +249,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
|
||||||
val packetType: String
|
val packetType: String
|
||||||
packetType = when (entry.getRawDataByIndex(1)) {
|
packetType = when (entry.getRawDataByIndex(1)) {
|
||||||
0x02.toByte() -> "init"
|
0x02.toByte() -> "init"
|
||||||
else -> "unknown"
|
else -> "unknown"
|
||||||
}
|
}
|
||||||
entry.addDecodedData("packetType", packetType)
|
entry.addDecodedData("packetType", packetType)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,9 @@ import kotlin.experimental.and
|
||||||
@Singleton
|
@Singleton
|
||||||
class MedtronicPumpHistoryDecoder @Inject constructor(
|
class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
aapsLogger: AAPSLogger,
|
aapsLogger: AAPSLogger,
|
||||||
medtronicUtil: MedtronicUtil
|
medtronicUtil: MedtronicUtil,
|
||||||
) : MedtronicHistoryDecoder<PumpHistoryEntry>() {
|
bitUtils: ByteUtil
|
||||||
|
) : MedtronicHistoryDecoder<PumpHistoryEntry>(aapsLogger, medtronicUtil, bitUtils) {
|
||||||
|
|
||||||
//private var tbrPreviousRecord: PumpHistoryEntry? = null
|
//private var tbrPreviousRecord: PumpHistoryEntry? = null
|
||||||
private var changeTimeRecord: PumpHistoryEntry? = null
|
private var changeTimeRecord: PumpHistoryEntry? = null
|
||||||
|
@ -133,7 +134,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
return try {
|
return try {
|
||||||
decodeRecordInternal(record)
|
decodeRecordInternal(record)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
aapsLogger.error(LTag.PUMPBTCOMM, String.format(Locale.ENGLISH, " Error decoding: type=%s, ex=%s", record.entryType!!.name, ex.message, ex))
|
aapsLogger.error(LTag.PUMPBTCOMM, String.format(Locale.ENGLISH, " Error decoding: type=%s, ex=%s", record.entryType.name, ex.message, ex))
|
||||||
//ex.printStackTrace()
|
//ex.printStackTrace()
|
||||||
RecordDecodeStatus.Error
|
RecordDecodeStatus.Error
|
||||||
}
|
}
|
||||||
|
@ -144,62 +145,125 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
decodeDateTime(entry)
|
decodeDateTime(entry)
|
||||||
}
|
}
|
||||||
return when (entry.entryType) {
|
return when (entry.entryType) {
|
||||||
PumpHistoryEntryType.ChangeBasalPattern, PumpHistoryEntryType.CalBGForPH, PumpHistoryEntryType.ChangeRemoteId, PumpHistoryEntryType.ClearAlarm, PumpHistoryEntryType.ChangeAlarmNotifyMode, PumpHistoryEntryType.EnableDisableRemote, PumpHistoryEntryType.BGReceived, PumpHistoryEntryType.SensorAlert, PumpHistoryEntryType.ChangeTimeFormat, PumpHistoryEntryType.ChangeReservoirWarningTime, PumpHistoryEntryType.ChangeBolusReminderEnable, PumpHistoryEntryType.SetBolusReminderTime, PumpHistoryEntryType.ChangeChildBlockEnable, PumpHistoryEntryType.BolusWizardEnabled, PumpHistoryEntryType.ChangeBGReminderOffset, PumpHistoryEntryType.ChangeAlarmClockTime, PumpHistoryEntryType.ChangeMeterId, PumpHistoryEntryType.ChangeParadigmID, PumpHistoryEntryType.JournalEntryMealMarker, PumpHistoryEntryType.JournalEntryExerciseMarker, PumpHistoryEntryType.DeleteBolusReminderTime, PumpHistoryEntryType.SetAutoOff, PumpHistoryEntryType.SelfTest, PumpHistoryEntryType.JournalEntryInsulinMarker, PumpHistoryEntryType.JournalEntryOtherMarker, PumpHistoryEntryType.BolusWizardSetup512, PumpHistoryEntryType.ChangeSensorSetup2, PumpHistoryEntryType.ChangeSensorAlarmSilenceConfig, PumpHistoryEntryType.ChangeSensorRateOfChangeAlertSetup, PumpHistoryEntryType.ChangeBolusScrollStepSize, PumpHistoryEntryType.BolusWizardSetup, PumpHistoryEntryType.ChangeVariableBolus, PumpHistoryEntryType.ChangeAudioBolus, PumpHistoryEntryType.ChangeBGReminderEnable, PumpHistoryEntryType.ChangeAlarmClockEnable, PumpHistoryEntryType.BolusReminder, PumpHistoryEntryType.DeleteAlarmClockTime, PumpHistoryEntryType.ChangeCarbUnits, PumpHistoryEntryType.ChangeWatchdogEnable, PumpHistoryEntryType.ChangeOtherDeviceID, PumpHistoryEntryType.ReadOtherDevicesIDs, PumpHistoryEntryType.BGReceived512, PumpHistoryEntryType.SensorStatus, PumpHistoryEntryType.ReadCaptureEventEnabled, PumpHistoryEntryType.ChangeCaptureEventEnable, PumpHistoryEntryType.ReadOtherDevicesStatus -> RecordDecodeStatus.OK
|
PumpHistoryEntryType.ChangeBasalPattern,
|
||||||
|
PumpHistoryEntryType.CalBGForPH,
|
||||||
|
PumpHistoryEntryType.ChangeRemoteId,
|
||||||
|
PumpHistoryEntryType.ClearAlarm,
|
||||||
|
PumpHistoryEntryType.ChangeAlarmNotifyMode,
|
||||||
|
PumpHistoryEntryType.EnableDisableRemote,
|
||||||
|
PumpHistoryEntryType.BGReceived,
|
||||||
|
PumpHistoryEntryType.SensorAlert,
|
||||||
|
PumpHistoryEntryType.ChangeTimeFormat,
|
||||||
|
PumpHistoryEntryType.ChangeReservoirWarningTime,
|
||||||
|
PumpHistoryEntryType.ChangeBolusReminderEnable,
|
||||||
|
PumpHistoryEntryType.SetBolusReminderTime,
|
||||||
|
PumpHistoryEntryType.ChangeChildBlockEnable,
|
||||||
|
PumpHistoryEntryType.BolusWizardEnabled,
|
||||||
|
PumpHistoryEntryType.ChangeBGReminderOffset,
|
||||||
|
PumpHistoryEntryType.ChangeAlarmClockTime,
|
||||||
|
PumpHistoryEntryType.ChangeMeterId,
|
||||||
|
PumpHistoryEntryType.ChangeParadigmID,
|
||||||
|
PumpHistoryEntryType.JournalEntryMealMarker,
|
||||||
|
PumpHistoryEntryType.JournalEntryExerciseMarker,
|
||||||
|
PumpHistoryEntryType.DeleteBolusReminderTime,
|
||||||
|
PumpHistoryEntryType.SetAutoOff,
|
||||||
|
PumpHistoryEntryType.SelfTest,
|
||||||
|
PumpHistoryEntryType.JournalEntryInsulinMarker,
|
||||||
|
PumpHistoryEntryType.JournalEntryOtherMarker,
|
||||||
|
PumpHistoryEntryType.BolusWizardSetup512,
|
||||||
|
PumpHistoryEntryType.ChangeSensorSetup2,
|
||||||
|
PumpHistoryEntryType.ChangeSensorAlarmSilenceConfig,
|
||||||
|
PumpHistoryEntryType.ChangeSensorRateOfChangeAlertSetup,
|
||||||
|
PumpHistoryEntryType.ChangeBolusScrollStepSize,
|
||||||
|
PumpHistoryEntryType.BolusWizardSetup,
|
||||||
|
PumpHistoryEntryType.ChangeVariableBolus,
|
||||||
|
PumpHistoryEntryType.ChangeAudioBolus,
|
||||||
|
PumpHistoryEntryType.ChangeBGReminderEnable,
|
||||||
|
PumpHistoryEntryType.ChangeAlarmClockEnable,
|
||||||
|
PumpHistoryEntryType.BolusReminder,
|
||||||
|
PumpHistoryEntryType.DeleteAlarmClockTime,
|
||||||
|
PumpHistoryEntryType.ChangeCarbUnits,
|
||||||
|
PumpHistoryEntryType.ChangeWatchdogEnable,
|
||||||
|
PumpHistoryEntryType.ChangeOtherDeviceID,
|
||||||
|
PumpHistoryEntryType.ReadOtherDevicesIDs,
|
||||||
|
PumpHistoryEntryType.BGReceived512,
|
||||||
|
PumpHistoryEntryType.SensorStatus,
|
||||||
|
PumpHistoryEntryType.ReadCaptureEventEnabled,
|
||||||
|
PumpHistoryEntryType.ChangeCaptureEventEnable,
|
||||||
|
PumpHistoryEntryType.ReadOtherDevicesStatus -> RecordDecodeStatus.OK
|
||||||
|
|
||||||
PumpHistoryEntryType.Sensor_0x54, PumpHistoryEntryType.Sensor_0x55, PumpHistoryEntryType.Sensor_0x51, PumpHistoryEntryType.Sensor_0x52, PumpHistoryEntryType.EventUnknown_MM512_0x2e -> {
|
PumpHistoryEntryType.Sensor_0x54,
|
||||||
|
PumpHistoryEntryType.Sensor_0x55,
|
||||||
|
PumpHistoryEntryType.Sensor_0x51,
|
||||||
|
PumpHistoryEntryType.Sensor_0x52,
|
||||||
|
PumpHistoryEntryType.EventUnknown_MM512_0x2e -> {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, " -- ignored Unknown Pump Entry: $entry")
|
aapsLogger.debug(LTag.PUMPBTCOMM, " -- ignored Unknown Pump Entry: $entry")
|
||||||
RecordDecodeStatus.Ignored
|
RecordDecodeStatus.Ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
PumpHistoryEntryType.UnabsorbedInsulin, PumpHistoryEntryType.UnabsorbedInsulin512 -> RecordDecodeStatus.Ignored
|
PumpHistoryEntryType.UnabsorbedInsulin,
|
||||||
PumpHistoryEntryType.DailyTotals522, PumpHistoryEntryType.DailyTotals523, PumpHistoryEntryType.DailyTotals515, PumpHistoryEntryType.EndResultTotals -> decodeDailyTotals(entry)
|
PumpHistoryEntryType.UnabsorbedInsulin512 -> RecordDecodeStatus.Ignored
|
||||||
PumpHistoryEntryType.ChangeBasalProfile_OldProfile, PumpHistoryEntryType.ChangeBasalProfile_NewProfile -> decodeBasalProfile(entry)
|
PumpHistoryEntryType.DailyTotals522,
|
||||||
PumpHistoryEntryType.BasalProfileStart -> decodeBasalProfileStart(entry)
|
PumpHistoryEntryType.DailyTotals523,
|
||||||
|
PumpHistoryEntryType.DailyTotals515,
|
||||||
|
PumpHistoryEntryType.EndResultTotals -> decodeDailyTotals(entry)
|
||||||
|
PumpHistoryEntryType.ChangeBasalProfile_OldProfile,
|
||||||
|
PumpHistoryEntryType.ChangeBasalProfile_NewProfile -> decodeBasalProfile(entry)
|
||||||
|
PumpHistoryEntryType.BasalProfileStart -> decodeBasalProfileStart(entry)
|
||||||
|
|
||||||
PumpHistoryEntryType.ChangeTime -> {
|
PumpHistoryEntryType.ChangeTime -> {
|
||||||
changeTimeRecord = entry
|
changeTimeRecord = entry
|
||||||
RecordDecodeStatus.OK
|
RecordDecodeStatus.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
PumpHistoryEntryType.NewTimeSet -> {
|
PumpHistoryEntryType.NewTimeSet -> {
|
||||||
decodeChangeTime(entry)
|
decodeChangeTime(entry)
|
||||||
RecordDecodeStatus.OK
|
RecordDecodeStatus.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
PumpHistoryEntryType.TempBasalDuration -> // decodeTempBasal(entry);
|
PumpHistoryEntryType.TempBasalDuration -> // decodeTempBasal(entry);
|
||||||
RecordDecodeStatus.OK
|
RecordDecodeStatus.OK
|
||||||
|
|
||||||
PumpHistoryEntryType.TempBasalRate -> // decodeTempBasal(entry);
|
PumpHistoryEntryType.TempBasalRate -> // decodeTempBasal(entry);
|
||||||
RecordDecodeStatus.OK
|
RecordDecodeStatus.OK
|
||||||
|
|
||||||
PumpHistoryEntryType.Bolus -> {
|
PumpHistoryEntryType.Bolus -> {
|
||||||
decodeBolus(entry)
|
decodeBolus(entry)
|
||||||
RecordDecodeStatus.OK
|
RecordDecodeStatus.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
PumpHistoryEntryType.BatteryChange -> {
|
PumpHistoryEntryType.BatteryChange -> {
|
||||||
decodeBatteryActivity(entry)
|
decodeBatteryActivity(entry)
|
||||||
RecordDecodeStatus.OK
|
RecordDecodeStatus.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
PumpHistoryEntryType.LowReservoir -> {
|
PumpHistoryEntryType.LowReservoir -> {
|
||||||
decodeLowReservoir(entry)
|
decodeLowReservoir(entry)
|
||||||
RecordDecodeStatus.OK
|
RecordDecodeStatus.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
PumpHistoryEntryType.LowBattery, PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump, PumpHistoryEntryType.Rewind, PumpHistoryEntryType.NoDeliveryAlarm, PumpHistoryEntryType.ChangeTempBasalType, PumpHistoryEntryType.ChangeMaxBolus, PumpHistoryEntryType.ChangeMaxBasal, PumpHistoryEntryType.ClearSettings, PumpHistoryEntryType.SaveSettings -> RecordDecodeStatus.OK
|
PumpHistoryEntryType.LowBattery,
|
||||||
PumpHistoryEntryType.BolusWizard -> decodeBolusWizard(entry)
|
PumpHistoryEntryType.SuspendPump,
|
||||||
PumpHistoryEntryType.BolusWizard512 -> decodeBolusWizard512(entry)
|
PumpHistoryEntryType.ResumePump,
|
||||||
|
PumpHistoryEntryType.Rewind,
|
||||||
|
PumpHistoryEntryType.NoDeliveryAlarm,
|
||||||
|
PumpHistoryEntryType.ChangeTempBasalType,
|
||||||
|
PumpHistoryEntryType.ChangeMaxBolus,
|
||||||
|
PumpHistoryEntryType.ChangeMaxBasal,
|
||||||
|
PumpHistoryEntryType.ClearSettings,
|
||||||
|
PumpHistoryEntryType.SaveSettings -> RecordDecodeStatus.OK
|
||||||
|
PumpHistoryEntryType.BolusWizard -> decodeBolusWizard(entry)
|
||||||
|
PumpHistoryEntryType.BolusWizard512 -> decodeBolusWizard512(entry)
|
||||||
|
|
||||||
PumpHistoryEntryType.Prime -> {
|
PumpHistoryEntryType.Prime -> {
|
||||||
decodePrime(entry)
|
decodePrime(entry)
|
||||||
RecordDecodeStatus.OK
|
RecordDecodeStatus.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
PumpHistoryEntryType.TempBasalCombined -> RecordDecodeStatus.Ignored
|
PumpHistoryEntryType.TempBasalCombined -> RecordDecodeStatus.Ignored
|
||||||
PumpHistoryEntryType.None, PumpHistoryEntryType.UnknownBasePacket -> RecordDecodeStatus.Error
|
PumpHistoryEntryType.None, PumpHistoryEntryType.UnknownBasePacket -> RecordDecodeStatus.Error
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Not supported: " + entry.entryType)
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Not supported: " + entry.entryType)
|
||||||
RecordDecodeStatus.NotSupported
|
RecordDecodeStatus.NotSupported
|
||||||
}
|
}
|
||||||
|
@ -345,10 +409,10 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
entry.addDecodedData("amount", (ByteUtil.asUINT8(entry.getRawDataByIndex(5)) and 0x80 shl 1) + ByteUtil.asUINT8(entry.getRawDataByIndex(0))) // index moved from 1 -> 0
|
entry.addDecodedData("amount", (ByteUtil.asUINT8(entry.getRawDataByIndex(5)) and 0x80 shl 1) + ByteUtil.asUINT8(entry.getRawDataByIndex(0))) // index moved from 1 -> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun decodeNoDeliveryAlarm(entry: PumpHistoryEntry) {
|
// private fun decodeNoDeliveryAlarm(entry: PumpHistoryEntry) {
|
||||||
//rawtype = asUINT8(data[1]);
|
// //rawtype = asUINT8(data[1]);
|
||||||
// not sure if this is actually NoDelivery Alarm?
|
// // not sure if this is actually NoDelivery Alarm?
|
||||||
}
|
// }
|
||||||
|
|
||||||
override fun postProcess() {}
|
override fun postProcess() {}
|
||||||
|
|
||||||
|
@ -357,34 +421,25 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun decodeBolus(entry: PumpHistoryEntry) {
|
private fun decodeBolus(entry: PumpHistoryEntry) {
|
||||||
val bolus = BolusDTO()
|
var bolus: BolusDTO?
|
||||||
val data = entry.head!!
|
val data = entry.head!!
|
||||||
if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel!!, MedtronicDeviceType.Medtronic_523andHigher)) {
|
if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel!!, MedtronicDeviceType.Medtronic_523andHigher)) {
|
||||||
bolus.requestedAmount = ByteUtil.toInt(data.get(0), data.get(1)) / 40.0
|
bolus = BolusDTO(atechDateTime = entry.atechDateTime,
|
||||||
bolus.deliveredAmount = ByteUtil.toInt(data.get(2), data.get(3)) / 40.0
|
requestedAmount = ByteUtil.toInt(data.get(0), data.get(1)) / 40.0,
|
||||||
|
deliveredAmount = ByteUtil.toInt(data.get(2), data.get(3)) / 40.0,
|
||||||
|
duration = data.get(6) * 30)
|
||||||
bolus.insulinOnBoard = ByteUtil.toInt(data.get(4), data.get(5)) / 40.0
|
bolus.insulinOnBoard = ByteUtil.toInt(data.get(4), data.get(5)) / 40.0
|
||||||
bolus.duration = data.get(6) * 30
|
|
||||||
} else {
|
} else {
|
||||||
bolus.requestedAmount = ByteUtil.asUINT8(data.get(0)) / 10.0
|
bolus = BolusDTO(atechDateTime = entry.atechDateTime,
|
||||||
bolus.deliveredAmount = ByteUtil.asUINT8(data.get(1)) / 10.0
|
requestedAmount = ByteUtil.asUINT8(data.get(0)) / 10.0,
|
||||||
bolus.duration = ByteUtil.asUINT8(data.get(2)) * 30
|
deliveredAmount = ByteUtil.asUINT8(data.get(1)) / 10.0,
|
||||||
|
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 > 0) PumpBolusType.Extended else PumpBolusType.Normal
|
||||||
bolus.atechDateTime = entry.atechDateTime
|
|
||||||
entry.addDecodedData("Object", bolus)
|
entry.addDecodedData("Object", bolus)
|
||||||
entry.displayableValue = bolus.displayableValue
|
entry.displayableValue = bolus.displayableValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// private fun decodeTempBasal(entry: PumpHistoryEntry) {
|
|
||||||
// if (tbrPreviousRecord == null) {
|
|
||||||
// // LOG.debug(this.tbrPreviousRecord.toString());
|
|
||||||
// tbrPreviousRecord = entry
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// decodeTempBasal(tbrPreviousRecord, entry)
|
|
||||||
// tbrPreviousRecord = null
|
|
||||||
// }
|
|
||||||
|
|
||||||
fun decodeTempBasal(tbrPreviousRecord: PumpHistoryEntry, entry: PumpHistoryEntry) {
|
fun decodeTempBasal(tbrPreviousRecord: PumpHistoryEntry, entry: PumpHistoryEntry) {
|
||||||
var tbrRate: PumpHistoryEntry? = null
|
var tbrRate: PumpHistoryEntry? = null
|
||||||
var tbrDuration: PumpHistoryEntry? = null
|
var tbrDuration: PumpHistoryEntry? = null
|
||||||
|
@ -399,25 +454,18 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
tbrRate = tbrPreviousRecord
|
tbrRate = tbrPreviousRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
// TempBasalPair tbr = new TempBasalPair(
|
|
||||||
// tbrRate.getHead()[0],
|
|
||||||
// tbrDuration.getHead()[0],
|
|
||||||
// (ByteUtil.asUINT8(tbrRate.getDatetime()[4]) >> 3) == 0);
|
|
||||||
val tbr = TempBasalPair(
|
val tbr = TempBasalPair(
|
||||||
tbrRate.head!!.get(0),
|
tbrRate.head!!.get(0),
|
||||||
tbrRate.body!!.get(0),
|
tbrRate.body!!.get(0),
|
||||||
tbrDuration!!.head!!.get(0).toInt(),
|
tbrDuration!!.head!!.get(0).toInt(),
|
||||||
ByteUtil.asUINT8(tbrRate.datetime!!.get(4)) shr 3 == 0)
|
ByteUtil.asUINT8(tbrRate.datetime!!.get(4)) shr 3 == 0)
|
||||||
|
|
||||||
// System.out.println("TBR: amount=" + tbr.getInsulinRate() + ", duration=" + tbr.getDurationMinutes()
|
|
||||||
// // + " min. Packed: " + tbr.getValue()
|
|
||||||
// );
|
|
||||||
entry.addDecodedData("Object", tbr)
|
entry.addDecodedData("Object", tbr)
|
||||||
entry.displayableValue = tbr.description
|
entry.displayableValue = tbr.description
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun decodeDateTime(entry: PumpHistoryEntry) {
|
private fun decodeDateTime(entry: PumpHistoryEntry) {
|
||||||
if (entry.datetime==null) {
|
if (entry.datetime == null) {
|
||||||
aapsLogger.warn(LTag.PUMPBTCOMM, "DateTime not set.")
|
aapsLogger.warn(LTag.PUMPBTCOMM, "DateTime not set.")
|
||||||
}
|
}
|
||||||
val dt = entry.datetime!!
|
val dt = entry.datetime!!
|
||||||
|
@ -445,7 +493,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
|
|
||||||
//LOG.debug("DT: {} {} {}", year, month, dayOfMonth);
|
//LOG.debug("DT: {} {} {}", year, month, dayOfMonth);
|
||||||
if (dayOfMonth == 32) {
|
if (dayOfMonth == 32) {
|
||||||
aapsLogger.warn(LTag.PUMPBTCOMM, String.format(Locale.ENGLISH, "Entry: Day 32 %s = [%s] %s", entry.entryType!!.name,
|
aapsLogger.warn(LTag.PUMPBTCOMM, String.format(Locale.ENGLISH, "Entry: Day 32 %s = [%s] %s", entry.entryType.name,
|
||||||
ByteUtil.getHex(entry.rawData), entry))
|
ByteUtil.getHex(entry.rawData), entry))
|
||||||
}
|
}
|
||||||
if (isEndResults(entry.entryType)) {
|
if (isEndResults(entry.entryType)) {
|
||||||
|
@ -460,7 +508,10 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isEndResults(entryType: PumpHistoryEntryType?): Boolean {
|
private fun isEndResults(entryType: PumpHistoryEntryType?): Boolean {
|
||||||
return entryType === PumpHistoryEntryType.EndResultTotals || entryType === PumpHistoryEntryType.DailyTotals515 || entryType === PumpHistoryEntryType.DailyTotals522 || entryType === PumpHistoryEntryType.DailyTotals523
|
return entryType === PumpHistoryEntryType.EndResultTotals ||
|
||||||
|
entryType === PumpHistoryEntryType.DailyTotals515 ||
|
||||||
|
entryType === PumpHistoryEntryType.DailyTotals522 ||
|
||||||
|
entryType === PumpHistoryEntryType.DailyTotals523
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fix2DigitYear(year: Int): Int {
|
private fun fix2DigitYear(year: Int): Int {
|
||||||
|
@ -474,13 +525,10 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private fun getFormattedValue(value: Float, decimals: Int): String {
|
private fun getFormattedValue(value: Float, decimals: Int): String {
|
||||||
return String.format(Locale.ENGLISH, "%." + decimals + "f", value)
|
return String.format(Locale.ENGLISH, "%." + decimals + "f", value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
|
||||||
super.aapsLogger = aapsLogger
|
|
||||||
this.medtronicUtil = medtronicUtil
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -19,12 +19,12 @@ import java.util.*
|
||||||
class PumpHistoryEntry : MedtronicHistoryEntry() {
|
class PumpHistoryEntry : MedtronicHistoryEntry() {
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
var entryType: PumpHistoryEntryType? = null
|
var entryType: PumpHistoryEntryType = PumpHistoryEntryType.None
|
||||||
private set
|
private set
|
||||||
|
|
||||||
override var opCode: Byte? = null
|
override var opCode: Byte? = null
|
||||||
// this is set only when we have unknown entry...
|
// this is set only when we have unknown entry...
|
||||||
get() = if (field == null) entryType!!.code else field
|
get() = if (field == null) entryType.code else field
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
@ -41,15 +41,19 @@ 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 != 0L) generatePumpId()
|
if (isEntryTypeSet() && atechDateTime != 0L) pumpId = generatePumpId()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generatePumpId() : Long {
|
override fun generatePumpId() : Long {
|
||||||
return entryType!!.code + atechDateTime * 1000L
|
return entryType.code + atechDateTime * 1000L
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isEntryTypeSet(): Boolean {
|
||||||
|
return this.entryType != PumpHistoryEntryType.None
|
||||||
}
|
}
|
||||||
|
|
||||||
override val toStringStart: String
|
override val toStringStart: String
|
||||||
get() = ("PumpHistoryEntry [type=" + StringUtil.getStringInLength(entryType!!.name, 20) + " ["
|
get() = ("PumpHistoryEntry [type=" + StringUtil.getStringInLength(entryType.name, 20) + " ["
|
||||||
+ StringUtil.getStringInLength("" + opCode, 3) + ", 0x"
|
+ StringUtil.getStringInLength("" + opCode, 3) + ", 0x"
|
||||||
+ ByteUtil.shortHexString(opCode!!) + "]")
|
+ ByteUtil.shortHexString(opCode!!) + "]")
|
||||||
|
|
||||||
|
@ -65,16 +69,16 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override val entryTypeName: String
|
override val entryTypeName: String
|
||||||
get() = entryType!!.name
|
get() = entryType.name
|
||||||
|
|
||||||
override val dateLength: Int
|
override val dateLength: Int
|
||||||
get() = entryType!!.dateLength
|
get() = entryType.dateLength
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other !is PumpHistoryEntry) return false
|
if (other !is PumpHistoryEntry) return false
|
||||||
val that = other //as PumpHistoryEntry
|
val that = other //as PumpHistoryEntry
|
||||||
return this.pumpId === that.pumpId
|
return this.pumpId == that.pumpId
|
||||||
// return entryType == that.entryType && //
|
// return entryType == that.entryType && //
|
||||||
// atechDateTime === that.atechDateTime // && //
|
// atechDateTime === that.atechDateTime // && //
|
||||||
// Objects.equals(this.decodedData, that.decodedData);
|
// Objects.equals(this.decodedData, that.decodedData);
|
||||||
|
@ -101,24 +105,26 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override var pumpId: Long? = null
|
override var pumpId: Long = 0L
|
||||||
get() {
|
get() {
|
||||||
field = generatePumpId()
|
if (field==0L) {
|
||||||
|
field = generatePumpId()
|
||||||
|
}
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
set(pumpId) {
|
set(pumpId) {
|
||||||
super.pumpId = pumpId
|
field = pumpId
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasBolusChanged(entry: PumpHistoryEntry) : Boolean {
|
fun hasBolusChanged(entry: PumpHistoryEntry) : Boolean {
|
||||||
if (entryType!=null && entryType == PumpHistoryEntryType.Bolus) {
|
if (entryType == PumpHistoryEntryType.Bolus) {
|
||||||
val thisOne: BolusDTO = this.decodedData["Object"] as BolusDTO
|
val thisOne: BolusDTO = this.decodedData["Object"] as BolusDTO
|
||||||
|
|
||||||
if (entry.entryType!=null && entry.entryType == PumpHistoryEntryType.Bolus) {
|
if (entry.entryType == PumpHistoryEntryType.Bolus) {
|
||||||
val otherOne: BolusDTO = entry.decodedData["Object"] as BolusDTO
|
val otherOne: BolusDTO = entry.decodedData["Object"] as BolusDTO
|
||||||
return (thisOne.value.equals(otherOne.value))
|
return (thisOne.value.equals(otherOne.value))
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -22,8 +22,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
|
||||||
var unprocessedEntries: List<PumpHistoryEntry> = ArrayList()
|
var unprocessedEntries: List<PumpHistoryEntry> = ArrayList()
|
||||||
var validEntries: MutableList<PumpHistoryEntry> = ArrayList()
|
var validEntries: MutableList<PumpHistoryEntry> = ArrayList()
|
||||||
|
|
||||||
|
fun addHistoryEntries(entries: List<PumpHistoryEntry> /*, page: Int*/) {
|
||||||
fun addHistoryEntries(entries: List<PumpHistoryEntry>, page: Int) {
|
|
||||||
unprocessedEntries = entries
|
unprocessedEntries = entries
|
||||||
//aapsLogger.debug(LTag.PUMPCOMM,"PumpHistoryResult. Unprocessed entries: {}", MedtronicUtil.getGsonInstance().toJson(entries));
|
//aapsLogger.debug(LTag.PUMPCOMM,"PumpHistoryResult. Unprocessed entries: {}", MedtronicUtil.getGsonInstance().toJson(entries));
|
||||||
processEntries()
|
processEntries()
|
||||||
|
@ -42,7 +41,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
|
||||||
|
|
||||||
//Collections.sort(this.unprocessedEntries, new PumpHistoryEntry.Comparator());
|
//Collections.sort(this.unprocessedEntries, new PumpHistoryEntry.Comparator());
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "PE. PumpHistoryResult. Search entry date: " + searchEntry!!.atechDateTime)
|
aapsLogger.debug(LTag.PUMPCOMM, "PE. PumpHistoryResult. Search entry date: " + searchEntry!!.atechDateTime)
|
||||||
val date = searchEntry.atechDateTime
|
//val date = searchEntry.atechDateTime
|
||||||
for (unprocessedEntry in unprocessedEntries) {
|
for (unprocessedEntry in unprocessedEntries) {
|
||||||
if (unprocessedEntry.equals(searchEntry)) {
|
if (unprocessedEntry.equals(searchEntry)) {
|
||||||
//aapsLogger.debug(LTag.PUMPCOMM,"PE. Item found {}.", unprocessedEntry);
|
//aapsLogger.debug(LTag.PUMPCOMM,"PE. Item found {}.", unprocessedEntry);
|
||||||
|
@ -60,7 +59,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
|
||||||
SearchType.Date -> {
|
SearchType.Date -> {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "PE. Date search: Search date: " + searchDate)
|
aapsLogger.debug(LTag.PUMPCOMM, "PE. Date search: Search date: " + searchDate)
|
||||||
for (unprocessedEntry in unprocessedEntries) {
|
for (unprocessedEntry in unprocessedEntries) {
|
||||||
if (unprocessedEntry.atechDateTime == null || unprocessedEntry.atechDateTime == 0L) {
|
if (unprocessedEntry.atechDateTime == 0L) {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "PE. PumpHistoryResult. Search entry date: Entry with no date: $unprocessedEntry")
|
aapsLogger.debug(LTag.PUMPCOMM, "PE. PumpHistoryResult. Search entry date: Entry with no date: $unprocessedEntry")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -83,7 +82,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "PumpHistoryResult [unprocessed=" + unprocessedEntries.size + //
|
return "PumpHistoryResult [unprocessed=" + unprocessedEntries.size + //
|
||||||
", valid=" + validEntries.size + //
|
", valid=" + validEntries.size + //
|
||||||
", searchEntry=" + searchEntry + //
|
", searchEntry=" + searchEntry + //
|
||||||
", searchDate=" + searchDate + //
|
", searchDate=" + searchDate + //
|
||||||
|
@ -99,11 +98,9 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
|
||||||
val latestEntry: PumpHistoryEntry?
|
val latestEntry: PumpHistoryEntry?
|
||||||
get() = if (validEntries.size == 0) null else validEntries[0]
|
get() = if (validEntries.size == 0) null else validEntries[0]
|
||||||
|
|
||||||
|
|
||||||
// val isSearchRequired: Boolean
|
// val isSearchRequired: Boolean
|
||||||
// get() = searchType != SearchType.None
|
// get() = searchType != SearchType.None
|
||||||
|
|
||||||
|
|
||||||
internal enum class SearchType {
|
internal enum class SearchType {
|
||||||
None, //
|
None, //
|
||||||
LastEntry, //
|
LastEntry, //
|
||||||
|
|
|
@ -41,5 +41,11 @@ class GetHistoryPageCarelinkMessageBody : CarelinkLongMessageBody {
|
||||||
}
|
}
|
||||||
|
|
||||||
val frameData: ByteArray
|
val frameData: ByteArray
|
||||||
get() = ByteUtil.substring(data!!, 1, data!!.size - 1)
|
get() {
|
||||||
|
return if (data == null) {
|
||||||
|
byteArrayOf()
|
||||||
|
} else {
|
||||||
|
ByteUtil.substring(data!!, 1, data!!.size - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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.androidaps.interfaces.PumpDescription
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
@ -38,7 +37,7 @@ class MedtronicUIPostprocessor @Inject constructor(
|
||||||
// where responses won't be directly used
|
// where responses won't be directly used
|
||||||
fun postProcessData(uiTask: MedtronicUITask) {
|
fun postProcessData(uiTask: MedtronicUITask) {
|
||||||
when (uiTask.commandType) {
|
when (uiTask.commandType) {
|
||||||
MedtronicCommandType.SetBasalProfileSTD -> {
|
MedtronicCommandType.SetBasalProfileSTD -> {
|
||||||
val response = uiTask.result as Boolean?
|
val response = uiTask.result as Boolean?
|
||||||
if (response!!) {
|
if (response!!) {
|
||||||
val basalProfile = uiTask.getParameter(0) as BasalProfile
|
val basalProfile = uiTask.getParameter(0) as BasalProfile
|
||||||
|
@ -50,21 +49,22 @@ class MedtronicUIPostprocessor @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicCommandType.GetBasalProfileSTD -> {
|
MedtronicCommandType.GetBasalProfileSTD -> {
|
||||||
val basalProfile = uiTask.result as BasalProfile?
|
val basalProfile = uiTask.result as BasalProfile?
|
||||||
|
|
||||||
//aapsLogger.debug("D: basal profile on read: " + basalProfile);
|
//aapsLogger.debug("D: basal profile on read: " + basalProfile);
|
||||||
try {
|
try {
|
||||||
// TODO need to refactor
|
if (basalProfile != null) {
|
||||||
val profilesByHour = basalProfile!!.getProfilesByHour(medtronicPumpPlugin.pumpDescription.pumpType)
|
val profilesByHour = basalProfile.getProfilesByHour(medtronicPumpPlugin.pumpDescription.pumpType)
|
||||||
if (profilesByHour != null) {
|
if (!BasalProfile.isBasalProfileByHourUndefined(profilesByHour)) {
|
||||||
medtronicPumpStatus.basalsByHour = profilesByHour
|
medtronicPumpStatus.basalsByHour = profilesByHour
|
||||||
medtronicPumpStatus.basalProfileStatus = BasalProfileStatus.ProfileOK
|
medtronicPumpStatus.basalProfileStatus = BasalProfileStatus.ProfileOK
|
||||||
//aapsLogger.debug("D: basal profile on read: basalsByHour: " + BasalProfile.getProfilesByHourToString(medtronicPumpStatus.basalsByHour));
|
//aapsLogger.debug("D: basal profile on read: basalsByHour: " + BasalProfile.getProfilesByHourToString(medtronicPumpStatus.basalsByHour));
|
||||||
} else {
|
} else {
|
||||||
uiTask.responseType = MedtronicUIResponseType.Error
|
uiTask.responseType = MedtronicUIResponseType.Error
|
||||||
uiTask.errorDescription = "No profile found."
|
uiTask.errorDescription = "No profile found."
|
||||||
aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Basal Profile was NOT valid. [%s]", basalProfile.basalProfileToStringError()))
|
aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Basal Profile was NOT valid. [%s]", basalProfile.basalProfileToStringError()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} 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()))
|
||||||
|
@ -73,26 +73,26 @@ class MedtronicUIPostprocessor @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicCommandType.SetBolus -> {
|
MedtronicCommandType.SetBolus -> {
|
||||||
medtronicPumpStatus.lastBolusAmount = uiTask.getDoubleFromParameters(0)
|
medtronicPumpStatus.lastBolusAmount = uiTask.getDoubleFromParameters(0)
|
||||||
medtronicPumpStatus.lastBolusTime = Date()
|
medtronicPumpStatus.lastBolusTime = Date()
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicCommandType.GetRemainingInsulin -> {
|
MedtronicCommandType.GetRemainingInsulin -> {
|
||||||
medtronicPumpStatus.reservoirRemainingUnits = uiTask.result as Double
|
medtronicPumpStatus.reservoirRemainingUnits = uiTask.result as Double
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicCommandType.CancelTBR -> {
|
MedtronicCommandType.CancelTBR -> {
|
||||||
medtronicPumpStatus.tempBasalStart = null
|
medtronicPumpStatus.tempBasalStart = null
|
||||||
medtronicPumpStatus.tempBasalAmount = null
|
medtronicPumpStatus.tempBasalAmount = null
|
||||||
medtronicPumpStatus.tempBasalLength = null
|
medtronicPumpStatus.tempBasalLength = null
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicCommandType.GetRealTimeClock -> {
|
MedtronicCommandType.GetRealTimeClock -> {
|
||||||
processTime(uiTask)
|
processTime(uiTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicCommandType.SetRealTimeClock -> {
|
MedtronicCommandType.SetRealTimeClock -> {
|
||||||
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) {
|
||||||
|
@ -100,7 +100,7 @@ class MedtronicUIPostprocessor @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicCommandType.GetBatteryStatus -> {
|
MedtronicCommandType.GetBatteryStatus -> {
|
||||||
val batteryStatusDTO = uiTask.result as BatteryStatusDTO?
|
val batteryStatusDTO = uiTask.result as BatteryStatusDTO?
|
||||||
medtronicPumpStatus.batteryRemaining = batteryStatusDTO!!.getCalculatedPercent(medtronicPumpStatus.batteryType)
|
medtronicPumpStatus.batteryRemaining = batteryStatusDTO!!.getCalculatedPercent(medtronicPumpStatus.batteryType)
|
||||||
if (batteryStatusDTO.voltage != null) {
|
if (batteryStatusDTO.voltage != null) {
|
||||||
|
@ -109,7 +109,7 @@ class MedtronicUIPostprocessor @Inject constructor(
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "BatteryStatus: %s", batteryStatusDTO.toString()))
|
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "BatteryStatus: %s", batteryStatusDTO.toString()))
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicCommandType.PumpModel -> {
|
MedtronicCommandType.PumpModel -> {
|
||||||
if (medtronicPumpStatus.medtronicDeviceType !== medtronicUtil.medtronicPumpModel) {
|
if (medtronicPumpStatus.medtronicDeviceType !== medtronicUtil.medtronicPumpModel) {
|
||||||
aapsLogger.warn(LTag.PUMP, "Configured pump is different then pump detected !")
|
aapsLogger.warn(LTag.PUMP, "Configured pump is different then pump detected !")
|
||||||
medtronicUtil.sendNotification(MedtronicNotificationType.PumpTypeNotSame, resourceHelper, rxBus)
|
medtronicUtil.sendNotification(MedtronicNotificationType.PumpTypeNotSame, resourceHelper, rxBus)
|
||||||
|
@ -117,23 +117,27 @@ class MedtronicUIPostprocessor @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicCommandType.Settings_512,
|
MedtronicCommandType.Settings_512,
|
||||||
MedtronicCommandType.Settings -> {
|
MedtronicCommandType.Settings -> {
|
||||||
postProcessSettings(uiTask)
|
postProcessSettings(uiTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processTime(uiTask: MedtronicUITask) {
|
private fun processTime(uiTask: MedtronicUITask) {
|
||||||
val clockDTO = uiTask.result as ClockDTO?
|
val clockDTO = uiTask.result as ClockDTO?
|
||||||
val dur = Duration(clockDTO!!.pumpTime!!.toDateTime(DateTimeZone.UTC),
|
if (clockDTO != null) {
|
||||||
clockDTO.localDeviceTime!!.toDateTime(DateTimeZone.UTC))
|
val dur = Duration(clockDTO.pumpTime.toDateTime(DateTimeZone.UTC),
|
||||||
clockDTO.timeDifference = dur.standardSeconds.toInt()
|
clockDTO.localDeviceTime.toDateTime(DateTimeZone.UTC))
|
||||||
medtronicUtil.pumpTime = clockDTO
|
clockDTO.timeDifference = dur.standardSeconds.toInt()
|
||||||
aapsLogger.debug(LTag.PUMP, "Pump Time: " + clockDTO.localDeviceTime + ", DeviceTime=" + clockDTO.pumpTime + //
|
medtronicUtil.pumpTime = clockDTO
|
||||||
", diff: " + dur.standardSeconds + " s")
|
aapsLogger.debug(LTag.PUMP, "Pump Time: " + clockDTO.localDeviceTime + ", DeviceTime=" + clockDTO.pumpTime + //
|
||||||
|
", diff: " + dur.standardSeconds + " s")
|
||||||
|
} else {
|
||||||
|
aapsLogger.debug(LTag.PUMP, "Problem with returned data: " + medtronicUtil.gsonInstance.toJson(uiTask.result))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun postProcessSettings(uiTask: MedtronicUITask) {
|
private fun postProcessSettings(uiTask: MedtronicUITask) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ class MedtronicUITask {
|
||||||
|
|
||||||
MedtronicCommandType.GetRealTimeClock -> {
|
MedtronicCommandType.GetRealTimeClock -> {
|
||||||
result = communicationManager.getPumpTime()
|
result = communicationManager.getPumpTime()
|
||||||
medtronicUtil.pumpTime = null
|
//medtronicUtil.pumpTime = null
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtronicCommandType.SetRealTimeClock -> {
|
MedtronicCommandType.SetRealTimeClock -> {
|
||||||
|
|
|
@ -68,7 +68,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
private var gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
|
private var gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
|
||||||
private var gsonCore: Gson = GsonBuilder().create()
|
private var gsonCore: Gson = GsonBuilder().create()
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add New History entries
|
* Add New History entries
|
||||||
*
|
*
|
||||||
|
@ -81,12 +80,12 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
if (!allPumpIds.contains(validEntry.pumpId)) {
|
if (!allPumpIds.contains(validEntry.pumpId)) {
|
||||||
newEntries.add(validEntry)
|
newEntries.add(validEntry)
|
||||||
} else {
|
} else {
|
||||||
val entryByPumpId = getEntryByPumpId(validEntry.pumpId!!)
|
val entryByPumpId = getEntryByPumpId(validEntry.pumpId)
|
||||||
|
|
||||||
if (entryByPumpId!=null && entryByPumpId.hasBolusChanged(validEntry)) {
|
if (entryByPumpId != null && entryByPumpId.hasBolusChanged(validEntry)) {
|
||||||
newEntries.add(validEntry)
|
newEntries.add(validEntry)
|
||||||
allHistory.remove(entryByPumpId)
|
allHistory.remove(entryByPumpId)
|
||||||
allPumpIds.remove(validEntry.pumpId!!);
|
allPumpIds.remove(validEntry.pumpId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +95,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
|
|
||||||
private fun getEntryByPumpId(pumpId: Long): PumpHistoryEntry? {
|
private fun getEntryByPumpId(pumpId: Long): PumpHistoryEntry? {
|
||||||
val findFirst = this.allHistory.stream()
|
val findFirst = this.allHistory.stream()
|
||||||
.filter { f -> f.pumpId!! == pumpId }
|
.filter { f -> f.pumpId == pumpId }
|
||||||
.findFirst()
|
.findFirst()
|
||||||
|
|
||||||
return if (findFirst.isPresent()) findFirst.get() else null
|
return if (findFirst.isPresent()) findFirst.get() else null
|
||||||
|
@ -192,7 +191,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
lastIdUsed++
|
lastIdUsed++
|
||||||
pumpHistoryEntry.id = lastIdUsed
|
pumpHistoryEntry.id = lastIdUsed
|
||||||
allHistory.add(pumpHistoryEntry)
|
allHistory.add(pumpHistoryEntry)
|
||||||
allPumpIds.add(pumpHistoryEntry.pumpId!!)
|
allPumpIds.add(pumpHistoryEntry.pumpId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +209,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
for (pumpHistoryEntry in allHistory) {
|
for (pumpHistoryEntry in allHistory) {
|
||||||
if (!pumpHistoryEntry.isAfter(dtRemove)) {
|
if (!pumpHistoryEntry.isAfter(dtRemove)) {
|
||||||
removeList.add(pumpHistoryEntry)
|
removeList.add(pumpHistoryEntry)
|
||||||
allPumpIds.remove(pumpHistoryEntry.pumpId!!)
|
allPumpIds.remove(pumpHistoryEntry.pumpId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allHistory.removeAll(removeList)
|
allHistory.removeAll(removeList)
|
||||||
|
@ -241,7 +240,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
return col != null && !col.isEmpty()
|
return col != null && !col.isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun isPumpSuspended(): Boolean {
|
fun isPumpSuspended(): Boolean {
|
||||||
val items = getDataForPumpSuspends()
|
val items = getDataForPumpSuspends()
|
||||||
showLogs("isPumpSuspended: ", gson.toJson(items))
|
showLogs("isPumpSuspended: ", gson.toJson(items))
|
||||||
|
@ -258,7 +256,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
} else false
|
} else false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getDataForPumpSuspends(): MutableList<PumpHistoryEntry> {
|
private fun getDataForPumpSuspends(): MutableList<PumpHistoryEntry> {
|
||||||
val newAndAll: MutableList<PumpHistoryEntry> = mutableListOf()
|
val newAndAll: MutableList<PumpHistoryEntry> = mutableListOf()
|
||||||
if (isCollectionNotEmpty(allHistory)) {
|
if (isCollectionNotEmpty(allHistory)) {
|
||||||
|
@ -397,7 +394,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (primeRecord.atechDateTime > maxAllowedTimeInPast) {
|
if (primeRecord.atechDateTime > maxAllowedTimeInPast) {
|
||||||
if (lastPrimeRecordTime!=0L && lastPrimeRecordTime < primeRecord.atechDateTime) {
|
if (lastPrimeRecordTime != 0L && lastPrimeRecordTime < primeRecord.atechDateTime) {
|
||||||
lastPrimeRecordTime = primeRecord.atechDateTime
|
lastPrimeRecordTime = primeRecord.atechDateTime
|
||||||
lastPrimeRecord = primeRecord
|
lastPrimeRecord = primeRecord
|
||||||
}
|
}
|
||||||
|
@ -429,7 +426,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun uploadCareportalEventIfFoundInHistory(historyRecord: PumpHistoryEntry, eventSP: String, eventType: DetailedBolusInfo.EventType) {
|
private fun uploadCareportalEventIfFoundInHistory(historyRecord: PumpHistoryEntry, eventSP: String, eventType: DetailedBolusInfo.EventType) {
|
||||||
val lastPrimeFromAAPS = sp.getLong(eventSP, 0L)
|
val lastPrimeFromAAPS = sp.getLong(eventSP, 0L)
|
||||||
if (historyRecord.atechDateTime != lastPrimeFromAAPS) {
|
if (historyRecord.atechDateTime != lastPrimeFromAAPS) {
|
||||||
|
@ -448,7 +444,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun processTDDs(tddsIn: MutableList<PumpHistoryEntry>) {
|
private fun processTDDs(tddsIn: MutableList<PumpHistoryEntry>) {
|
||||||
val tdds = filterTDDs(tddsIn)
|
val tdds = filterTDDs(tddsIn)
|
||||||
|
|
||||||
|
@ -470,14 +465,12 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun processBolusEntries(entryList: MutableList<PumpHistoryEntry>) {
|
private fun processBolusEntries(entryList: MutableList<PumpHistoryEntry>) {
|
||||||
|
|
||||||
val boluses = pumpSyncStorage.getBoluses()
|
val boluses = pumpSyncStorage.getBoluses()
|
||||||
|
@ -488,16 +481,16 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
var type: DetailedBolusInfo.BolusType = DetailedBolusInfo.BolusType.NORMAL
|
var type: DetailedBolusInfo.BolusType = DetailedBolusInfo.BolusType.NORMAL
|
||||||
var multiwave = false
|
var multiwave = false
|
||||||
|
|
||||||
if (bolusDTO.bolusType==PumpBolusType.Extended) {
|
if (bolusDTO.bolusType == PumpBolusType.Extended) {
|
||||||
addExtendedBolus(bolus, bolusDTO, multiwave)
|
addExtendedBolus(bolus, bolusDTO, multiwave)
|
||||||
continue;
|
continue;
|
||||||
} else if (bolusDTO.bolusType==PumpBolusType.Multiwave) {
|
} else if (bolusDTO.bolusType == PumpBolusType.Multiwave) {
|
||||||
multiwave = true
|
multiwave = true
|
||||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "Multiwave bolus from pump, extended bolus and normal bolus will be added."))
|
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "Multiwave bolus from pump, extended bolus and normal bolus will be added."))
|
||||||
addExtendedBolus(bolus, bolusDTO, multiwave);
|
addExtendedBolus(bolus, bolusDTO, multiwave);
|
||||||
}
|
}
|
||||||
|
|
||||||
val deliveredAmount: Double = if (multiwave) bolusDTO.immediateAmount!! else bolusDTO.deliveredAmount!!
|
val deliveredAmount: Double = if (multiwave) bolusDTO.immediateAmount!! else bolusDTO.deliveredAmount
|
||||||
|
|
||||||
var temporaryId: Long? = null
|
var temporaryId: Long? = null
|
||||||
|
|
||||||
|
@ -514,7 +507,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,
|
||||||
|
@ -532,7 +525,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
tryToGetByLocalTime(bolus.atechDateTime),
|
tryToGetByLocalTime(bolus.atechDateTime),
|
||||||
deliveredAmount,
|
deliveredAmount,
|
||||||
type,
|
type,
|
||||||
bolus.pumpId!!,
|
bolus.pumpId,
|
||||||
medtronicPumpStatus.pumpType,
|
medtronicPumpStatus.pumpType,
|
||||||
medtronicPumpStatus.serialNumber!!)
|
medtronicPumpStatus.serialNumber!!)
|
||||||
|
|
||||||
|
@ -545,25 +538,23 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun addExtendedBolus(bolus: PumpHistoryEntry, bolusDTO: BolusDTO, isMultiwave: Boolean) {
|
private fun addExtendedBolus(bolus: PumpHistoryEntry, bolusDTO: BolusDTO, isMultiwave: Boolean) {
|
||||||
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,
|
||||||
bolus.pumpId!!,
|
bolus.pumpId,
|
||||||
medtronicPumpStatus.pumpType,
|
medtronicPumpStatus.pumpType,
|
||||||
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
|
||||||
|
@ -573,12 +564,11 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
bolusWizard.carbs.toDouble(),
|
bolusWizard.carbs.toDouble(),
|
||||||
medtronicPumpStatus.pumpType,
|
medtronicPumpStatus.pumpType,
|
||||||
medtronicPumpStatus.serialNumber!!,
|
medtronicPumpStatus.serialNumber!!,
|
||||||
bolus.pumpId!!
|
bolus.pumpId
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun processTBREntries(entryList: MutableList<PumpHistoryEntry>) {
|
private fun processTBREntries(entryList: MutableList<PumpHistoryEntry>) {
|
||||||
Collections.reverse(entryList)
|
Collections.reverse(entryList)
|
||||||
val tbr = entryList[0].getDecodedDataEntry("Object") as TempBasalPair?
|
val tbr = entryList[0].getDecodedDataEntry("Object") as TempBasalPair?
|
||||||
|
@ -609,14 +599,14 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
readOldItem = false
|
readOldItem = false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.warn(LTag.PUMP,"processDTO was null - shouldn't happen, ignoring item. ItemTwo=$treatment")
|
aapsLogger.warn(LTag.PUMP, "processDTO was null - shouldn't happen, ignoring item. ItemTwo=$treatment")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (processDTO != null) {
|
if (processDTO != null) {
|
||||||
processList.add(processDTO)
|
processList.add(processDTO)
|
||||||
}
|
}
|
||||||
processDTO = TempBasalProcessDTO(
|
processDTO = TempBasalProcessDTO(
|
||||||
itemOne= treatment,
|
itemOne = treatment,
|
||||||
processOperation = TempBasalProcessDTO.Operation.Add)
|
processOperation = TempBasalProcessDTO.Operation.Add)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -628,13 +618,13 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
|
|
||||||
val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords)
|
val entryWithTempId = findDbEntry(tempBasalProcessDTO.itemOne, tbrRecords)
|
||||||
|
|
||||||
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)))
|
||||||
|
|
||||||
if (entryWithTempId!=null) {
|
if (entryWithTempId != null) {
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, String.format("DD: tempIdEntry=%s, tbrEntry=%s, tempBasalProcessDTO=%s, pumpType=%s, serial=%s",
|
aapsLogger.debug(LTag.PUMP, String.format("DD: tempIdEntry=%s, tbrEntry=%s, tempBasalProcessDTO=%s, pumpType=%s, serial=%s",
|
||||||
gson.toJson(entryWithTempId), gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO), medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber!!))
|
gson.toJson(entryWithTempId), gson.toJson(tbrEntry), gson.toJson(tempBasalProcessDTO), medtronicPumpStatus.pumpType, medtronicPumpStatus.serialNumber!!))
|
||||||
|
@ -681,7 +671,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration,
|
tbrEntry.insulinRate, (if (tbrEntry.isPercent) "%" else "U"), tempBasalProcessDTO.duration,
|
||||||
medtronicPumpStatus.serialNumber!!, result))
|
medtronicPumpStatus.serialNumber!!, result))
|
||||||
|
|
||||||
if (medtronicPumpStatus.runningTBR!=null) {
|
if (medtronicPumpStatus.runningTBR != null) {
|
||||||
if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) {
|
if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) {
|
||||||
medtronicPumpStatus.runningTBR = null
|
medtronicPumpStatus.runningTBR = null
|
||||||
}
|
}
|
||||||
|
@ -703,21 +693,16 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
} // collection
|
} // collection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isTBRActive(dbEntry: PumpDbEntry): Boolean {
|
||||||
fun isTBRActive(dbEntry: PumpDbEntry) : Boolean {
|
|
||||||
return isTBRActive(dbEntry.date, dbEntry.tbrData!!.durationInMinutes)
|
return isTBRActive(dbEntry.date, dbEntry.tbrData!!.durationInMinutes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isTBRActive(startTimestamp: Long, durationMin: Int): Boolean {
|
||||||
fun isTBRActive(startTimestamp: Long, durationMin: Int) : Boolean {
|
|
||||||
val endDate = startTimestamp + (durationMin * 60 * 1000)
|
val endDate = startTimestamp + (durationMin * 60 * 1000)
|
||||||
|
|
||||||
return (endDate > System.currentTimeMillis())
|
return (endDate > System.currentTimeMillis())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* findDbEntry - finds Db entries in database, while theoretically this should have same dateTime they
|
* findDbEntry - finds Db entries in database, while theoretically this should have same dateTime they
|
||||||
* don't. Entry on pump is few seconds before treatment in AAPS, and on manual boluses on pump there
|
* don't. Entry on pump is few seconds before treatment in AAPS, and on manual boluses on pump there
|
||||||
|
@ -742,7 +727,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
// 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) }
|
||||||
|
|
||||||
val proposedTimeDiff : LongArray = longArrayOf(proposedTime-(2*60*1000), proposedTime+(2L*60L*1000L))
|
val proposedTimeDiff: LongArray = longArrayOf(proposedTime - (2 * 60 * 1000), proposedTime + (2L * 60L * 1000L))
|
||||||
val tempEntriesList: MutableList<PumpDbEntry> = mutableListOf()
|
val tempEntriesList: MutableList<PumpDbEntry> = mutableListOf()
|
||||||
|
|
||||||
for (temporaryEntry in temporaryEntries) {
|
for (temporaryEntry in temporaryEntries) {
|
||||||
|
@ -753,7 +738,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
|
|
||||||
if (tempEntriesList.isEmpty()) {
|
if (tempEntriesList.isEmpty()) {
|
||||||
return null
|
return null
|
||||||
} else if (tempEntriesList.size==1) {
|
} else if (tempEntriesList.size == 1) {
|
||||||
return tempEntriesList[0]
|
return tempEntriesList[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,7 +773,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun processSuspends(tempBasalProcessList: List<TempBasalProcessDTO>) {
|
private fun processSuspends(tempBasalProcessList: List<TempBasalProcessDTO>) {
|
||||||
for (tempBasalProcess in tempBasalProcessList) {
|
for (tempBasalProcess in tempBasalProcessList) {
|
||||||
|
|
||||||
|
@ -798,21 +782,20 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
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))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// suspend/resume
|
// suspend/resume
|
||||||
// no_delivery/prime & rewind/prime
|
// no_delivery/prime & rewind/prime
|
||||||
private fun getSuspendRecords(): MutableList<TempBasalProcessDTO> {
|
private fun getSuspendRecords(): MutableList<TempBasalProcessDTO> {
|
||||||
val outList: MutableList<TempBasalProcessDTO> = mutableListOf()
|
val outList: MutableList<TempBasalProcessDTO> = mutableListOf()
|
||||||
|
|
||||||
// suspend/resume
|
// suspend/resume
|
||||||
|
@ -822,7 +805,6 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
return outList
|
return outList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getSuspendResumeRecordsList(): List<TempBasalProcessDTO> {
|
private fun getSuspendResumeRecordsList(): List<TempBasalProcessDTO> {
|
||||||
val filteredItems = getFilteredItems(newHistory, //
|
val filteredItems = getFilteredItems(newHistory, //
|
||||||
setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump))
|
setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump))
|
||||||
|
@ -864,8 +846,8 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
var i = 0
|
var i = 0
|
||||||
while (i < filtered2Items.size) {
|
while (i < filtered2Items.size) {
|
||||||
outList.add(TempBasalProcessDTO(
|
outList.add(TempBasalProcessDTO(
|
||||||
itemOne= filtered2Items[i],
|
itemOne = filtered2Items[i],
|
||||||
itemTwo= filtered2Items[i + 1],
|
itemTwo = filtered2Items[i + 1],
|
||||||
processOperation = TempBasalProcessDTO.Operation.Add))
|
processOperation = TempBasalProcessDTO.Operation.Add))
|
||||||
|
|
||||||
i += 2
|
i += 2
|
||||||
|
@ -875,18 +857,17 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
return outList
|
return outList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getNoDeliveryRewindPrimeRecordsList(): List<TempBasalProcessDTO> {
|
||||||
private fun getNoDeliveryRewindPrimeRecordsList(): List<TempBasalProcessDTO> {
|
|
||||||
val primeItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, //
|
val primeItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, //
|
||||||
setOf(PumpHistoryEntryType.Prime))
|
setOf(PumpHistoryEntryType.Prime))
|
||||||
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(newHistory, //
|
||||||
setOf(PumpHistoryEntryType.Prime,
|
setOf(PumpHistoryEntryType.Prime,
|
||||||
PumpHistoryEntryType.Rewind,
|
PumpHistoryEntryType.Rewind,
|
||||||
PumpHistoryEntryType.NoDeliveryAlarm,
|
PumpHistoryEntryType.NoDeliveryAlarm,
|
||||||
PumpHistoryEntryType.Bolus,
|
PumpHistoryEntryType.Bolus,
|
||||||
PumpHistoryEntryType.TempBasalCombined)
|
PumpHistoryEntryType.TempBasalCombined)
|
||||||
)
|
)
|
||||||
val tempData: MutableList<PumpHistoryEntry> = mutableListOf()
|
val tempData: MutableList<PumpHistoryEntry> = mutableListOf()
|
||||||
var startedItems = false
|
var startedItems = false
|
||||||
|
@ -930,16 +911,16 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm)
|
items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm)
|
||||||
if (items.size > 0) {
|
if (items.size > 0) {
|
||||||
outList.add(TempBasalProcessDTO(
|
outList.add(TempBasalProcessDTO(
|
||||||
itemOne=items[items.size - 1],
|
itemOne = items[items.size - 1],
|
||||||
itemTwo= itemTwo,
|
itemTwo = itemTwo,
|
||||||
processOperation=TempBasalProcessDTO.Operation.Add))
|
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) {
|
||||||
outList.add(TempBasalProcessDTO(
|
outList.add(TempBasalProcessDTO(
|
||||||
itemOne=items[0],
|
itemOne = items[0],
|
||||||
processOperation=TempBasalProcessDTO.Operation.Add))
|
processOperation = TempBasalProcessDTO.Operation.Add))
|
||||||
return outList
|
return outList
|
||||||
}
|
}
|
||||||
return outList
|
return outList
|
||||||
|
@ -964,34 +945,31 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
return DateTimeUtil.toMillisFromATD(atechDateTime)
|
return DateTimeUtil.toMillisFromATD(atechDateTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getTDDType(): PumpHistoryEntryType {
|
private fun getTDDType(): PumpHistoryEntryType {
|
||||||
return if (medtronicUtil.medtronicPumpModel == null) {
|
return if (medtronicUtil.medtronicPumpModel == null) {
|
||||||
PumpHistoryEntryType.EndResultTotals
|
PumpHistoryEntryType.EndResultTotals
|
||||||
} 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,
|
||||||
MedtronicDeviceType.Medtronic_754_Veo -> PumpHistoryEntryType.DailyTotals523
|
MedtronicDeviceType.Medtronic_754_Veo -> PumpHistoryEntryType.DailyTotals523
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
PumpHistoryEntryType.EndResultTotals
|
PumpHistoryEntryType.EndResultTotals
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun hasBasalProfileChanged(): Boolean {
|
fun hasBasalProfileChanged(): Boolean {
|
||||||
val filteredItems: List<PumpHistoryEntry?> = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile)
|
val filteredItems: List<PumpHistoryEntry?> = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile)
|
||||||
aapsLogger.debug(LTag.PUMP, "hasBasalProfileChanged. Items: " + gson.toJson(filteredItems))
|
aapsLogger.debug(LTag.PUMP, "hasBasalProfileChanged. Items: " + gson.toJson(filteredItems))
|
||||||
return filteredItems.size > 0
|
return filteredItems.size > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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")
|
||||||
|
@ -1085,12 +1063,11 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
return outList
|
return outList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private val logPrefix: String
|
private val logPrefix: String
|
||||||
get() = "MedtronicHistoryData::"
|
get() = "MedtronicHistoryData::"
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Double bolus debug. We seem to have small problem with double Boluses (or sometimes also missing boluses
|
* Double bolus debug. We seem to have small problem with double Boluses (or sometimes also missing boluses
|
||||||
* from history. This flag turns on debugging for that (default is off=false)... Debugging is pretty detailed,
|
* from history. This flag turns on debugging for that (default is off=false)... Debugging is pretty detailed,
|
||||||
|
|
|
@ -33,7 +33,7 @@ class BasalProfile {
|
||||||
private val aapsLogger: AAPSLogger
|
private val aapsLogger: AAPSLogger
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
lateinit var rawData : ByteArray // store as byte array to make transport (via parcel) easier
|
lateinit var rawData: ByteArray // store as byte array to make transport (via parcel) easier
|
||||||
private set
|
private set
|
||||||
|
|
||||||
private var listEntries: MutableList<BasalProfileEntry>? = null
|
private var listEntries: MutableList<BasalProfileEntry>? = null
|
||||||
|
@ -49,7 +49,7 @@ class BasalProfile {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
rawData = byteArrayOf(0,0,0x3f)
|
rawData = byteArrayOf(0, 0, 0x3f)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setRawData(data: ByteArray): Boolean {
|
private fun setRawData(data: ByteArray): Boolean {
|
||||||
|
@ -268,7 +268,7 @@ class BasalProfile {
|
||||||
// if (pumpType == null)
|
// if (pumpType == null)
|
||||||
// basalByHour[j] = current.rate
|
// basalByHour[j] = current.rate
|
||||||
// else
|
// else
|
||||||
basalByHour[j] = pumpType.determineCorrectBasalSize(current.rate)
|
basalByHour[j] = pumpType.determineCorrectBasalSize(current.rate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return basalByHour
|
return basalByHour
|
||||||
|
@ -291,9 +291,8 @@ class BasalProfile {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val MAX_RAW_DATA_SIZE = 48 * 3 + 1
|
const val MAX_RAW_DATA_SIZE = 48 * 3 + 1
|
||||||
private const val DEBUG_BASALPROFILE = false
|
private const val DEBUG_BASALPROFILE = false
|
||||||
|
|
||||||
|
@ -310,5 +309,15 @@ class BasalProfile {
|
||||||
}
|
}
|
||||||
return stringBuilder.toString()
|
return stringBuilder.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun isBasalProfileByHourUndefined(basalByHour: DoubleArray): Boolean {
|
||||||
|
for (i in 0..23) {
|
||||||
|
if (basalByHour[i] > 0.0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -30,19 +30,24 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpBolusType
|
||||||
*
|
*
|
||||||
* Author: Andy {andy@atech-software.com}
|
* Author: Andy {andy@atech-software.com}
|
||||||
*/
|
*/
|
||||||
class BolusDTO : PumpTimeStampedRecord() {
|
class BolusDTO constructor(atechDateTime: Long,
|
||||||
|
@Expose var requestedAmount: Double,
|
||||||
|
@Expose var deliveredAmount: Double,
|
||||||
|
@Expose var duration: Int = 0
|
||||||
|
)
|
||||||
|
: PumpTimeStampedRecord(atechDateTime) {
|
||||||
|
|
||||||
@Expose
|
// @Expose
|
||||||
var requestedAmount: Double? = null
|
// var requestedAmount: Double? = null
|
||||||
|
//
|
||||||
@Expose
|
// @Expose
|
||||||
var deliveredAmount: Double? = null
|
// var deliveredAmount: Double? = null
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
var immediateAmount: Double? = null // when Multiwave this is used
|
var immediateAmount: Double? = null // when Multiwave this is used
|
||||||
|
|
||||||
@Expose
|
// @Expose
|
||||||
var duration: Int? = null
|
// var duration: Int? = null
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
var bolusType: PumpBolusType? = null
|
var bolusType: PumpBolusType? = null
|
||||||
|
@ -51,7 +56,7 @@ class BolusDTO : PumpTimeStampedRecord() {
|
||||||
|
|
||||||
private val durationString: String
|
private val durationString: String
|
||||||
get() {
|
get() {
|
||||||
var minutes = duration!!
|
var minutes = duration
|
||||||
val h = minutes / 60
|
val h = minutes / 60
|
||||||
minutes -= h * 60
|
minutes -= h * 60
|
||||||
return StringUtil.getLeadingZero(h, 2) + ":" + StringUtil.getLeadingZero(minutes, 2)
|
return StringUtil.getLeadingZero(h, 2) + ":" + StringUtil.getLeadingZero(minutes, 2)
|
||||||
|
@ -59,22 +64,22 @@ class BolusDTO : PumpTimeStampedRecord() {
|
||||||
|
|
||||||
val value: String
|
val value: String
|
||||||
get() = if (bolusType === PumpBolusType.Normal || bolusType === PumpBolusType.Audio) {
|
get() = if (bolusType === PumpBolusType.Normal || bolusType === PumpBolusType.Audio) {
|
||||||
getFormattedDecimal(deliveredAmount!!)
|
getFormattedDecimal(deliveredAmount)
|
||||||
} else if (bolusType === PumpBolusType.Extended) {
|
} else if (bolusType === PumpBolusType.Extended) {
|
||||||
String.format("AMOUNT_SQUARE=%s;DURATION=%s", getFormattedDecimal(deliveredAmount!!),
|
String.format("AMOUNT_SQUARE=%s;DURATION=%s", getFormattedDecimal(deliveredAmount),
|
||||||
durationString)
|
durationString)
|
||||||
} else {
|
} else {
|
||||||
String.format("AMOUNT=%s;AMOUNT_SQUARE=%s;DURATION=%s", getFormattedDecimal(immediateAmount!!),
|
String.format("AMOUNT=%s;AMOUNT_SQUARE=%s;DURATION=%s", getFormattedDecimal(immediateAmount!!),
|
||||||
getFormattedDecimal(deliveredAmount!!), durationString)
|
getFormattedDecimal(deliveredAmount), durationString)
|
||||||
}
|
}
|
||||||
|
|
||||||
val displayableValue: String
|
val displayableValue: String
|
||||||
get() {
|
get() {
|
||||||
var value = value
|
var valueTemp = value
|
||||||
value = value!!.replace("AMOUNT_SQUARE=", "Amount Square: ")
|
valueTemp = valueTemp.replace("AMOUNT_SQUARE=", "Amount Square: ")
|
||||||
value = value.replace("AMOUNT=", "Amount: ")
|
valueTemp = valueTemp.replace("AMOUNT=", "Amount: ")
|
||||||
value = value.replace("DURATION=", "Duration: ")
|
valueTemp = valueTemp.replace("DURATION=", "Duration: ")
|
||||||
return value
|
return valueTemp
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getFormattedDecimal(value: Double): String {
|
override fun getFormattedDecimal(value: Double): String {
|
||||||
|
|
|
@ -5,8 +5,9 @@ import org.joda.time.LocalDateTime
|
||||||
/**
|
/**
|
||||||
* Created by andy on 2/27/19.
|
* Created by andy on 2/27/19.
|
||||||
*/
|
*/
|
||||||
class ClockDTO {
|
class ClockDTO constructor(var localDeviceTime: LocalDateTime,
|
||||||
var localDeviceTime: LocalDateTime? = null
|
var pumpTime: LocalDateTime) {
|
||||||
var pumpTime: LocalDateTime? = null
|
// var localDeviceTime: LocalDateTime? = null
|
||||||
|
// var pumpTime: LocalDateTime? = null
|
||||||
var timeDifference = 0
|
var timeDifference = 0
|
||||||
}
|
}
|
|
@ -5,10 +5,10 @@ import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
|
||||||
/**
|
/**
|
||||||
* Created by andy on 6/2/18.
|
* Created by andy on 6/2/18.
|
||||||
*/
|
*/
|
||||||
open class PumpTimeStampedRecord {
|
open class PumpTimeStampedRecord constructor(var atechDateTime: Long = 0) {
|
||||||
|
|
||||||
var decimalPrecission = 2
|
var decimalPrecission = 2
|
||||||
var atechDateTime: Long = 0
|
// var atechDateTime: Long = 0
|
||||||
|
|
||||||
open fun getFormattedDecimal(value: Double): String? {
|
open fun getFormattedDecimal(value: Double): String? {
|
||||||
return StringUtil.getFormatedValueUS(value, decimalPrecission)
|
return StringUtil.getFormatedValueUS(value, decimalPrecission)
|
||||||
|
|
|
@ -12,7 +12,7 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
|
||||||
get() = itemOne.atechDateTime
|
get() = itemOne.atechDateTime
|
||||||
|
|
||||||
val pumpId: Long
|
val pumpId: Long
|
||||||
get() = itemOne.pumpId!!
|
get() = itemOne.pumpId
|
||||||
|
|
||||||
val duration: Int
|
val duration: Int
|
||||||
get() = if (itemTwo == null) {
|
get() = if (itemTwo == null) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ class MedtronicHistoryActivity : DaggerActivity() {
|
||||||
filteredHistoryList.addAll(list)
|
filteredHistoryList.addAll(list)
|
||||||
} else {
|
} else {
|
||||||
for (pumpHistoryEntry in list) {
|
for (pumpHistoryEntry in list) {
|
||||||
if (pumpHistoryEntry.entryType!!.group === group) {
|
if (pumpHistoryEntry.entryType.group === group) {
|
||||||
filteredHistoryList.add(pumpHistoryEntry)
|
filteredHistoryList.add(pumpHistoryEntry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ class MedtronicHistoryActivity : DaggerActivity() {
|
||||||
val record = historyList[position]
|
val record = historyList[position]
|
||||||
//if (record != null) {
|
//if (record != null) {
|
||||||
holder.timeView.text = record.dateTimeString
|
holder.timeView.text = record.dateTimeString
|
||||||
holder.typeView.text = record.entryType!!.description
|
holder.typeView.text = record.entryType.description
|
||||||
holder.valueView.text = record.displayableValue
|
holder.valueView.text = record.displayableValue
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ class RileyLinkMedtronicService // This empty constructor must be kept, otherwi
|
||||||
|
|
||||||
private val mBinder: IBinder = LocalBinder()
|
private val mBinder: IBinder = LocalBinder()
|
||||||
private var serialChanged = false
|
private var serialChanged = false
|
||||||
private var frequencies: Array<String?>? = null
|
lateinit var frequencies: Array<String>
|
||||||
private var rileyLinkAddress: String? = null
|
private var rileyLinkAddress: String? = null
|
||||||
private var rileyLinkAddressChanged = false
|
private var rileyLinkAddressChanged = false
|
||||||
private var encodingType: RileyLinkEncodingType? = null
|
private var encodingType: RileyLinkEncodingType? = null
|
||||||
|
@ -68,9 +68,9 @@ class RileyLinkMedtronicService // This empty constructor must be kept, otherwi
|
||||||
* If you have customized RileyLinkServiceData you need to override this
|
* If you have customized RileyLinkServiceData you need to override this
|
||||||
*/
|
*/
|
||||||
override fun initRileyLinkServiceData() {
|
override fun initRileyLinkServiceData() {
|
||||||
frequencies = arrayOfNulls(2)
|
frequencies = arrayOf()
|
||||||
frequencies!![0] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_us_ca)
|
frequencies[0] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_us_ca)
|
||||||
frequencies!![1] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_worldwide)
|
frequencies[1] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_worldwide)
|
||||||
rileyLinkServiceData.targetDevice = RileyLinkTargetDevice.MedtronicPump
|
rileyLinkServiceData.targetDevice = RileyLinkTargetDevice.MedtronicPump
|
||||||
setPumpIDString(sp.getString(MedtronicConst.Prefs.PumpSerial, "000000"))
|
setPumpIDString(sp.getString(MedtronicConst.Prefs.PumpSerial, "000000"))
|
||||||
|
|
||||||
|
@ -169,12 +169,12 @@ class RileyLinkMedtronicService // This empty constructor must be kept, otherwi
|
||||||
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_frequency_not_set)
|
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_frequency_not_set)
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
if (pumpFrequency != frequencies!![0] && pumpFrequency != frequencies!![1]) {
|
if (pumpFrequency != frequencies[0] && pumpFrequency != frequencies[1]) {
|
||||||
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_frequency_invalid)
|
medtronicPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_pump_frequency_invalid)
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
medtronicPumpStatus.pumpFrequency = pumpFrequency
|
medtronicPumpStatus.pumpFrequency = pumpFrequency
|
||||||
val isFrequencyUS = pumpFrequency == frequencies!![0]
|
val isFrequencyUS = pumpFrequency == frequencies[0]
|
||||||
val newTargetFrequency = if (isFrequencyUS) //
|
val newTargetFrequency = if (isFrequencyUS) //
|
||||||
RileyLinkTargetFrequency.Medtronic_US else RileyLinkTargetFrequency.Medtronic_WorldWide
|
RileyLinkTargetFrequency.Medtronic_US else RileyLinkTargetFrequency.Medtronic_WorldWide
|
||||||
if (rileyLinkServiceData.rileyLinkTargetFrequency != newTargetFrequency) {
|
if (rileyLinkServiceData.rileyLinkTargetFrequency != newTargetFrequency) {
|
||||||
|
|
Loading…
Reference in a new issue