- kotlin !! refactorings

This commit is contained in:
Andy Rozman 2021-05-22 16:16:05 +01:00
parent 59a3bf8883
commit 921302bdbf
22 changed files with 337 additions and 261 deletions

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.db
@Deprecated("This class is not needed for new database anymore")
interface DbObjectBase {
fun getDate(): Long

View file

@ -296,13 +296,13 @@ class MedtronicFragment : DaggerFragment() {
val bolus = medtronicPumpStatus.lastBolusAmount
val bolusTime = medtronicPumpStatus.lastBolusTime
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 unit = resourceHelper.gs(R.string.insulin_unit_shortname)
val ago = when {
agoMsc < 60 * 1000 -> resourceHelper.gs(R.string.medtronic_pump_connected_now)
bolusMinAgo < 60 -> dateUtil.minAgo(resourceHelper, medtronicPumpStatus.lastBolusTime!!.time)
else -> dateUtil.hourAgo(medtronicPumpStatus.lastBolusTime!!.time, resourceHelper)
bolusMinAgo < 60 -> dateUtil.minAgo(resourceHelper, bolusTime.time)
else -> dateUtil.hourAgo(bolusTime.time, resourceHelper)
}
binding.lastBolus.text = resourceHelper.gs(R.string.mdt_last_bolus, bolus, unit, ago)
} else {
@ -315,9 +315,9 @@ class MedtronicFragment : DaggerFragment() {
// TBR
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);
}
binding.tempBasal.text = tbrStr

View file

@ -303,7 +303,7 @@ class MedtronicPumpPlugin @Inject constructor(
override fun getPumpStatus(reason: String) {
var needRefresh = true
if (firstRun) {
needRefresh = initializePump(!isRefresh)
needRefresh = initializePump() /*!isRefresh*/
} else {
refreshAnyStatusThatNeedsToBeRefreshed()
}
@ -401,7 +401,7 @@ class MedtronicPumpPlugin @Inject constructor(
rxBus.send(EventRefreshButtonState(enabled))
}
private fun initializePump(realInit: Boolean): Boolean {
private fun initializePump(): Boolean {
if (rileyLinkMedtronicService == null) return false
aapsLogger.info(LTag.PUMP, logPrefix + "initializePump - start")
rileyLinkMedtronicService!!.deviceCommunicationManager.setDoWakeUpBeforeCommand(false)
@ -562,7 +562,7 @@ class MedtronicPumpPlugin @Inject constructor(
if (clock == null) return
val timeDiff = Math.abs(clock.timeDifference)
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))
rileyLinkMedtronicService!!.medtronicUIComm.executeCommand(MedtronicCommandType.SetRealTimeClock)
if (clock.timeDifference == 0) {
@ -570,7 +570,7 @@ class MedtronicPumpPlugin @Inject constructor(
rxBus.send(EventNewNotification(notification))
}
} 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))
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))
medtronicHistoryData.setIsInInit(false)
// 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);

View file

@ -35,7 +35,6 @@ import org.joda.time.LocalDateTime
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.jvm.Throws
/**
* Original file created by geoff on 5/30/16.
@ -54,11 +53,11 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
@Inject lateinit var medtronicConverter: MedtronicConverter
@Inject lateinit var medtronicUtil: MedtronicUtil
@Inject lateinit var medtronicPumpHistoryDecoder: MedtronicPumpHistoryDecoder
private val MAX_COMMAND_TRIES = 3
private val DEFAULT_TIMEOUT = 2000
private val RILEYLINK_TIMEOUT: Long = 15 * 60 * 1000 // 15 min
var errorResponse: String? = null
private set
private val debugSetCommands = false
@ -266,8 +265,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
while (!done) {
// examine current response for problems.
val frameData = currentResponse.frameData
if (frameData != null && frameData.size > 0
&& currentResponse.frameNumber == expectedFrameNum) {
if (frameData.size > 0 && currentResponse.frameNumber == expectedFrameNum) {
// success! got a frame.
if (frameData.size != 64) {
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
}
} else {
if (frameData == null) {
if (frameData.size == 0) {
aapsLogger.error(LTag.PUMPCOMM, "null frame data, retrying")
} else if (currentResponse.frameNumber != 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()
val medtronicHistoryEntries = medtronicPumpHistoryDecoder.processPageAndCreateRecords(rawHistoryPage)
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))
if (pumpTotalResult.isSearchFinished) {
medtronicPumpStatus.pumpDeviceState = PumpDeviceState.Sleeping
@ -350,7 +348,7 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
return when (type) {
RLMessageType.PowerOn -> medtronicUtil.buildCommandPayload(rileyLinkServiceData, MedtronicCommandType.RFPowerOn, byteArrayOf(2, 1, receiverDeviceAwakeForMinutes.toByte()))
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? {
// 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)
// checkResponseRawContent(data, commandType) {
@ -593,26 +589,26 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
}
fun getPumpTime(): ClockDTO? {
val clockDTO = ClockDTO()
clockDTO.localDeviceTime = LocalDateTime()
val localTime = LocalDateTime()
val responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.GetRealTimeClock) { _, _, rawContent ->
medtronicConverter.decodeTime(rawContent)
}
if (responseObject != null) {
clockDTO.pumpTime = responseObject
return clockDTO
return ClockDTO(localDeviceTime = localTime, pumpTime = responseObject)
}
return null
}
fun getTemporaryBasal(): TempBasalPair? {
return sendAndGetResponseWithCheck(MedtronicCommandType.ReadTemporaryBasal) { _, _, rawContent ->
TempBasalPair(aapsLogger, rawContent!!) }
TempBasalPair(aapsLogger, rawContent!!)
}
}
fun getPumpSettings(): Map<String, PumpSettingDTO>? {
return sendAndGetResponseWithCheck(getSettings(medtronicUtil.medtronicPumpModel)) { _, _, rawContent ->
medtronicConverter.decodeSettingsLoop(rawContent) }
medtronicConverter.decodeSettingsLoop(rawContent)
}
}
fun setBolus(units: Double): Boolean {

View file

@ -7,8 +7,6 @@ import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
import org.apache.commons.lang3.StringUtils
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
@ -19,9 +17,17 @@ import kotlin.jvm.Throws
*/
abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?> : MedtronicHistoryDecoderInterface<T> {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var medtronicUtil: MedtronicUtil
@Inject lateinit var bitUtils: ByteUtil
constructor(aapsLogger: AAPSLogger,
medtronicUtil: MedtronicUtil,
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)
protected var statisticsEnabled = true

View file

@ -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.DateTimeUtil
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryType
import java.util.*
/**
@ -42,6 +43,7 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
set(value) {
field = value
DT = DateTimeUtil.toString(value)
if (isEntryTypeSet() && value != 0L) pumpId = generatePumpId()
}
@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)
*/
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
@ -75,6 +77,10 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
// this.linkedObject = linkedObject
// }
abstract fun generatePumpId(): Long
abstract fun isEntryTypeSet(): Boolean
override fun setData(listRawData: List<Byte>, doNotProcess: Boolean) {
rawData = listRawData

View file

@ -30,6 +30,17 @@ class CGMSHistoryEntry : MedtronicHistoryEntry() {
override val entryTypeName: String
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) {
if (entryType!!.schemaSet) {
super.setData(listRawData, doNotProcess)

View file

@ -1,18 +1,17 @@
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.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.medtronic.comm.history.MedtronicHistoryDecoder
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.Companion.getByCode
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
import okhttp3.internal.and
import org.joda.time.LocalDateTime
import org.slf4j.Logger
import org.slf4j.LoggerFactory
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
@ -21,13 +20,17 @@ import org.slf4j.LoggerFactory.getLogger as getLogger1
*
* 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? {
return try {
decodeRecordInternal(record)
} 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
}
}
@ -111,7 +114,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
}
} while (counter < dataClear.size)
outList.reverse()
val reversedOutList = outList // reverseList(outList, CGMSHistoryEntry::class.java)
val reversedOutList = outList // reverseList(outList, CGMSHistoryEntry::class.java)
//var timeStamp: Long? = null
var dateTime: LocalDateTime? = null
var getIndex = 0
@ -127,7 +130,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
} else {
if (dateTime != null) entry.setDateTime(dateTime, getIndex)
}
aapsLogger.debug(LTag.PUMPCOMM,"Record: {}", entry)
aapsLogger.debug(LTag.PUMPCOMM, "Record: {}", entry)
}
return reversedOutList
}
@ -171,7 +174,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
entry.atechDateTime = atechDateTime
atechDateTime
} 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()
// return null;
} else null
@ -246,7 +249,7 @@ class MedtronicCGMSHistoryDecoder : MedtronicHistoryDecoder<CGMSHistoryEntry>()
val packetType: String
packetType = when (entry.getRawDataByIndex(1)) {
0x02.toByte() -> "init"
else -> "unknown"
else -> "unknown"
}
entry.addDecodedData("packetType", packetType)
}

View file

@ -30,8 +30,9 @@ import kotlin.experimental.and
@Singleton
class MedtronicPumpHistoryDecoder @Inject constructor(
aapsLogger: AAPSLogger,
medtronicUtil: MedtronicUtil
) : MedtronicHistoryDecoder<PumpHistoryEntry>() {
medtronicUtil: MedtronicUtil,
bitUtils: ByteUtil
) : MedtronicHistoryDecoder<PumpHistoryEntry>(aapsLogger, medtronicUtil, bitUtils) {
//private var tbrPreviousRecord: PumpHistoryEntry? = null
private var changeTimeRecord: PumpHistoryEntry? = null
@ -133,7 +134,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
return try {
decodeRecordInternal(record)
} 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()
RecordDecodeStatus.Error
}
@ -144,62 +145,125 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
decodeDateTime(entry)
}
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")
RecordDecodeStatus.Ignored
}
PumpHistoryEntryType.UnabsorbedInsulin, PumpHistoryEntryType.UnabsorbedInsulin512 -> RecordDecodeStatus.Ignored
PumpHistoryEntryType.DailyTotals522, PumpHistoryEntryType.DailyTotals523, PumpHistoryEntryType.DailyTotals515, PumpHistoryEntryType.EndResultTotals -> decodeDailyTotals(entry)
PumpHistoryEntryType.ChangeBasalProfile_OldProfile, PumpHistoryEntryType.ChangeBasalProfile_NewProfile -> decodeBasalProfile(entry)
PumpHistoryEntryType.BasalProfileStart -> decodeBasalProfileStart(entry)
PumpHistoryEntryType.UnabsorbedInsulin,
PumpHistoryEntryType.UnabsorbedInsulin512 -> RecordDecodeStatus.Ignored
PumpHistoryEntryType.DailyTotals522,
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
RecordDecodeStatus.OK
}
PumpHistoryEntryType.NewTimeSet -> {
PumpHistoryEntryType.NewTimeSet -> {
decodeChangeTime(entry)
RecordDecodeStatus.OK
}
PumpHistoryEntryType.TempBasalDuration -> // decodeTempBasal(entry);
PumpHistoryEntryType.TempBasalDuration -> // decodeTempBasal(entry);
RecordDecodeStatus.OK
PumpHistoryEntryType.TempBasalRate -> // decodeTempBasal(entry);
PumpHistoryEntryType.TempBasalRate -> // decodeTempBasal(entry);
RecordDecodeStatus.OK
PumpHistoryEntryType.Bolus -> {
PumpHistoryEntryType.Bolus -> {
decodeBolus(entry)
RecordDecodeStatus.OK
}
PumpHistoryEntryType.BatteryChange -> {
PumpHistoryEntryType.BatteryChange -> {
decodeBatteryActivity(entry)
RecordDecodeStatus.OK
}
PumpHistoryEntryType.LowReservoir -> {
PumpHistoryEntryType.LowReservoir -> {
decodeLowReservoir(entry)
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.BolusWizard -> decodeBolusWizard(entry)
PumpHistoryEntryType.BolusWizard512 -> decodeBolusWizard512(entry)
PumpHistoryEntryType.LowBattery,
PumpHistoryEntryType.SuspendPump,
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)
RecordDecodeStatus.OK
}
PumpHistoryEntryType.TempBasalCombined -> RecordDecodeStatus.Ignored
PumpHistoryEntryType.None, PumpHistoryEntryType.UnknownBasePacket -> RecordDecodeStatus.Error
PumpHistoryEntryType.TempBasalCombined -> RecordDecodeStatus.Ignored
PumpHistoryEntryType.None, PumpHistoryEntryType.UnknownBasePacket -> RecordDecodeStatus.Error
else -> {
else -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "Not supported: " + entry.entryType)
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
}
private fun decodeNoDeliveryAlarm(entry: PumpHistoryEntry) {
//rawtype = asUINT8(data[1]);
// not sure if this is actually NoDelivery Alarm?
}
// private fun decodeNoDeliveryAlarm(entry: PumpHistoryEntry) {
// //rawtype = asUINT8(data[1]);
// // not sure if this is actually NoDelivery Alarm?
// }
override fun postProcess() {}
@ -357,34 +421,25 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
}
private fun decodeBolus(entry: PumpHistoryEntry) {
val bolus = BolusDTO()
var bolus: BolusDTO?
val data = entry.head!!
if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel!!, MedtronicDeviceType.Medtronic_523andHigher)) {
bolus.requestedAmount = ByteUtil.toInt(data.get(0), data.get(1)) / 40.0
bolus.deliveredAmount = ByteUtil.toInt(data.get(2), data.get(3)) / 40.0
bolus = BolusDTO(atechDateTime = entry.atechDateTime,
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.duration = data.get(6) * 30
} else {
bolus.requestedAmount = ByteUtil.asUINT8(data.get(0)) / 10.0
bolus.deliveredAmount = ByteUtil.asUINT8(data.get(1)) / 10.0
bolus.duration = ByteUtil.asUINT8(data.get(2)) * 30
bolus = BolusDTO(atechDateTime = entry.atechDateTime,
requestedAmount = ByteUtil.asUINT8(data.get(0)) / 10.0,
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.atechDateTime = entry.atechDateTime
bolus.bolusType = if (bolus.duration > 0) PumpBolusType.Extended else PumpBolusType.Normal
entry.addDecodedData("Object", bolus)
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) {
var tbrRate: PumpHistoryEntry? = null
var tbrDuration: PumpHistoryEntry? = null
@ -399,25 +454,18 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
tbrRate = tbrPreviousRecord
}
// TempBasalPair tbr = new TempBasalPair(
// tbrRate.getHead()[0],
// tbrDuration.getHead()[0],
// (ByteUtil.asUINT8(tbrRate.getDatetime()[4]) >> 3) == 0);
val tbr = TempBasalPair(
tbrRate.head!!.get(0),
tbrRate.body!!.get(0),
tbrDuration!!.head!!.get(0).toInt(),
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.displayableValue = tbr.description
}
private fun decodeDateTime(entry: PumpHistoryEntry) {
if (entry.datetime==null) {
if (entry.datetime == null) {
aapsLogger.warn(LTag.PUMPBTCOMM, "DateTime not set.")
}
val dt = entry.datetime!!
@ -445,7 +493,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
//LOG.debug("DT: {} {} {}", year, month, dayOfMonth);
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))
}
if (isEndResults(entry.entryType)) {
@ -460,7 +508,10 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
}
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 {
@ -474,13 +525,10 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
}
companion object {
private fun getFormattedValue(value: Float, decimals: Int): String {
return String.format(Locale.ENGLISH, "%." + decimals + "f", value)
}
}
init {
super.aapsLogger = aapsLogger
this.medtronicUtil = medtronicUtil
}
}

View file

@ -19,12 +19,12 @@ import java.util.*
class PumpHistoryEntry : MedtronicHistoryEntry() {
@Expose
var entryType: PumpHistoryEntryType? = null
var entryType: PumpHistoryEntryType = PumpHistoryEntryType.None
private set
override var opCode: Byte? = null
// 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) {
field = value
}
@ -41,15 +41,19 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
sizes[0] = entryType.getHeadLength(medtronicDeviceType)
sizes[1] = entryType.dateLength
sizes[2] = entryType.getBodyLength(medtronicDeviceType)
if (this.entryType != null && atechDateTime != 0L) generatePumpId()
if (isEntryTypeSet() && atechDateTime != 0L) pumpId = generatePumpId()
}
private fun generatePumpId() : Long {
return entryType!!.code + atechDateTime * 1000L
override fun generatePumpId() : Long {
return entryType.code + atechDateTime * 1000L
}
override fun isEntryTypeSet(): Boolean {
return this.entryType != PumpHistoryEntryType.None
}
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"
+ ByteUtil.shortHexString(opCode!!) + "]")
@ -65,16 +69,16 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
}
override val entryTypeName: String
get() = entryType!!.name
get() = entryType.name
override val dateLength: Int
get() = entryType!!.dateLength
get() = entryType.dateLength
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is PumpHistoryEntry) return false
val that = other //as PumpHistoryEntry
return this.pumpId === that.pumpId
return this.pumpId == that.pumpId
// return entryType == that.entryType && //
// atechDateTime === that.atechDateTime // && //
// Objects.equals(this.decodedData, that.decodedData);
@ -101,24 +105,26 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
class Comparator : java.util.Comparator<PumpHistoryEntry> {
override fun compare(o1: PumpHistoryEntry, o2: PumpHistoryEntry): Int {
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() {
field = generatePumpId()
if (field==0L) {
field = generatePumpId()
}
return field
}
set(pumpId) {
super.pumpId = pumpId
field = pumpId
}
fun hasBolusChanged(entry: PumpHistoryEntry) : Boolean {
if (entryType!=null && entryType == PumpHistoryEntryType.Bolus) {
if (entryType == PumpHistoryEntryType.Bolus) {
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
return (thisOne.value.equals(otherOne.value))
} else

View file

@ -22,8 +22,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
var unprocessedEntries: List<PumpHistoryEntry> = ArrayList()
var validEntries: MutableList<PumpHistoryEntry> = ArrayList()
fun addHistoryEntries(entries: List<PumpHistoryEntry>, page: Int) {
fun addHistoryEntries(entries: List<PumpHistoryEntry> /*, page: Int*/) {
unprocessedEntries = entries
//aapsLogger.debug(LTag.PUMPCOMM,"PumpHistoryResult. Unprocessed entries: {}", MedtronicUtil.getGsonInstance().toJson(entries));
processEntries()
@ -42,7 +41,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
//Collections.sort(this.unprocessedEntries, new PumpHistoryEntry.Comparator());
aapsLogger.debug(LTag.PUMPCOMM, "PE. PumpHistoryResult. Search entry date: " + searchEntry!!.atechDateTime)
val date = searchEntry.atechDateTime
//val date = searchEntry.atechDateTime
for (unprocessedEntry in unprocessedEntries) {
if (unprocessedEntry.equals(searchEntry)) {
//aapsLogger.debug(LTag.PUMPCOMM,"PE. Item found {}.", unprocessedEntry);
@ -60,7 +59,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
SearchType.Date -> {
aapsLogger.debug(LTag.PUMPCOMM, "PE. Date search: Search date: " + searchDate)
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")
continue
}
@ -83,7 +82,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
}
override fun toString(): String {
return "PumpHistoryResult [unprocessed=" + unprocessedEntries.size + //
return "PumpHistoryResult [unprocessed=" + unprocessedEntries.size + //
", valid=" + validEntries.size + //
", searchEntry=" + searchEntry + //
", searchDate=" + searchDate + //
@ -99,11 +98,9 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
val latestEntry: PumpHistoryEntry?
get() = if (validEntries.size == 0) null else validEntries[0]
// val isSearchRequired: Boolean
// get() = searchType != SearchType.None
internal enum class SearchType {
None, //
LastEntry, //

View file

@ -41,5 +41,11 @@ class GetHistoryPageCarelinkMessageBody : CarelinkLongMessageBody {
}
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)
}
}
}

View file

@ -1,6 +1,5 @@
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.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
@ -38,7 +37,7 @@ class MedtronicUIPostprocessor @Inject constructor(
// where responses won't be directly used
fun postProcessData(uiTask: MedtronicUITask) {
when (uiTask.commandType) {
MedtronicCommandType.SetBasalProfileSTD -> {
MedtronicCommandType.SetBasalProfileSTD -> {
val response = uiTask.result as Boolean?
if (response!!) {
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?
//aapsLogger.debug("D: basal profile on read: " + basalProfile);
try {
// TODO need to refactor
val profilesByHour = basalProfile!!.getProfilesByHour(medtronicPumpPlugin.pumpDescription.pumpType)
if (profilesByHour != null) {
medtronicPumpStatus.basalsByHour = profilesByHour
medtronicPumpStatus.basalProfileStatus = BasalProfileStatus.ProfileOK
//aapsLogger.debug("D: basal profile on read: basalsByHour: " + BasalProfile.getProfilesByHourToString(medtronicPumpStatus.basalsByHour));
} else {
uiTask.responseType = MedtronicUIResponseType.Error
uiTask.errorDescription = "No profile found."
aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Basal Profile was NOT valid. [%s]", basalProfile.basalProfileToStringError()))
if (basalProfile != null) {
val profilesByHour = basalProfile.getProfilesByHour(medtronicPumpPlugin.pumpDescription.pumpType)
if (!BasalProfile.isBasalProfileByHourUndefined(profilesByHour)) {
medtronicPumpStatus.basalsByHour = profilesByHour
medtronicPumpStatus.basalProfileStatus = BasalProfileStatus.ProfileOK
//aapsLogger.debug("D: basal profile on read: basalsByHour: " + BasalProfile.getProfilesByHourToString(medtronicPumpStatus.basalsByHour));
} else {
uiTask.responseType = MedtronicUIResponseType.Error
uiTask.errorDescription = "No profile found."
aapsLogger.error(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "Basal Profile was NOT valid. [%s]", basalProfile.basalProfileToStringError()))
}
}
} catch (ex: Exception) {
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.lastBolusTime = Date()
}
MedtronicCommandType.GetRemainingInsulin -> {
MedtronicCommandType.GetRemainingInsulin -> {
medtronicPumpStatus.reservoirRemainingUnits = uiTask.result as Double
}
MedtronicCommandType.CancelTBR -> {
MedtronicCommandType.CancelTBR -> {
medtronicPumpStatus.tempBasalStart = null
medtronicPumpStatus.tempBasalAmount = null
medtronicPumpStatus.tempBasalLength = null
}
MedtronicCommandType.GetRealTimeClock -> {
MedtronicCommandType.GetRealTimeClock -> {
processTime(uiTask)
}
MedtronicCommandType.SetRealTimeClock -> {
MedtronicCommandType.SetRealTimeClock -> {
val response = uiTask.result as Boolean
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "New time was %s set.", if (response) "" else "NOT"))
if (response) {
@ -100,7 +100,7 @@ class MedtronicUIPostprocessor @Inject constructor(
}
}
MedtronicCommandType.GetBatteryStatus -> {
MedtronicCommandType.GetBatteryStatus -> {
val batteryStatusDTO = uiTask.result as BatteryStatusDTO?
medtronicPumpStatus.batteryRemaining = batteryStatusDTO!!.getCalculatedPercent(medtronicPumpStatus.batteryType)
if (batteryStatusDTO.voltage != null) {
@ -109,7 +109,7 @@ class MedtronicUIPostprocessor @Inject constructor(
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "BatteryStatus: %s", batteryStatusDTO.toString()))
}
MedtronicCommandType.PumpModel -> {
MedtronicCommandType.PumpModel -> {
if (medtronicPumpStatus.medtronicDeviceType !== medtronicUtil.medtronicPumpModel) {
aapsLogger.warn(LTag.PUMP, "Configured pump is different then pump detected !")
medtronicUtil.sendNotification(MedtronicNotificationType.PumpTypeNotSame, resourceHelper, rxBus)
@ -117,23 +117,27 @@ class MedtronicUIPostprocessor @Inject constructor(
}
MedtronicCommandType.Settings_512,
MedtronicCommandType.Settings -> {
MedtronicCommandType.Settings -> {
postProcessSettings(uiTask)
}
else -> {
else -> {
}
}
}
private fun processTime(uiTask: MedtronicUITask) {
val clockDTO = uiTask.result as ClockDTO?
val dur = Duration(clockDTO!!.pumpTime!!.toDateTime(DateTimeZone.UTC),
clockDTO.localDeviceTime!!.toDateTime(DateTimeZone.UTC))
clockDTO.timeDifference = dur.standardSeconds.toInt()
medtronicUtil.pumpTime = clockDTO
aapsLogger.debug(LTag.PUMP, "Pump Time: " + clockDTO.localDeviceTime + ", DeviceTime=" + clockDTO.pumpTime + //
", diff: " + dur.standardSeconds + " s")
if (clockDTO != null) {
val dur = Duration(clockDTO.pumpTime.toDateTime(DateTimeZone.UTC),
clockDTO.localDeviceTime.toDateTime(DateTimeZone.UTC))
clockDTO.timeDifference = dur.standardSeconds.toInt()
medtronicUtil.pumpTime = clockDTO
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) {

View file

@ -66,7 +66,7 @@ class MedtronicUITask {
MedtronicCommandType.GetRealTimeClock -> {
result = communicationManager.getPumpTime()
medtronicUtil.pumpTime = null
//medtronicUtil.pumpTime = null
}
MedtronicCommandType.SetRealTimeClock -> {

View file

@ -68,7 +68,6 @@ class MedtronicHistoryData @Inject constructor(
private var gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
private var gsonCore: Gson = GsonBuilder().create()
/**
* Add New History entries
*
@ -81,12 +80,12 @@ class MedtronicHistoryData @Inject constructor(
if (!allPumpIds.contains(validEntry.pumpId)) {
newEntries.add(validEntry)
} 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)
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? {
val findFirst = this.allHistory.stream()
.filter { f -> f.pumpId!! == pumpId }
.filter { f -> f.pumpId == pumpId }
.findFirst()
return if (findFirst.isPresent()) findFirst.get() else null
@ -192,7 +191,7 @@ class MedtronicHistoryData @Inject constructor(
lastIdUsed++
pumpHistoryEntry.id = lastIdUsed
allHistory.add(pumpHistoryEntry)
allPumpIds.add(pumpHistoryEntry.pumpId!!)
allPumpIds.add(pumpHistoryEntry.pumpId)
}
}
@ -210,7 +209,7 @@ class MedtronicHistoryData @Inject constructor(
for (pumpHistoryEntry in allHistory) {
if (!pumpHistoryEntry.isAfter(dtRemove)) {
removeList.add(pumpHistoryEntry)
allPumpIds.remove(pumpHistoryEntry.pumpId!!)
allPumpIds.remove(pumpHistoryEntry.pumpId)
}
}
allHistory.removeAll(removeList)
@ -241,7 +240,6 @@ class MedtronicHistoryData @Inject constructor(
return col != null && !col.isEmpty()
}
fun isPumpSuspended(): Boolean {
val items = getDataForPumpSuspends()
showLogs("isPumpSuspended: ", gson.toJson(items))
@ -258,7 +256,6 @@ class MedtronicHistoryData @Inject constructor(
} else false
}
private fun getDataForPumpSuspends(): MutableList<PumpHistoryEntry> {
val newAndAll: MutableList<PumpHistoryEntry> = mutableListOf()
if (isCollectionNotEmpty(allHistory)) {
@ -397,7 +394,7 @@ class MedtronicHistoryData @Inject constructor(
continue
}
if (primeRecord.atechDateTime > maxAllowedTimeInPast) {
if (lastPrimeRecordTime!=0L && lastPrimeRecordTime < primeRecord.atechDateTime) {
if (lastPrimeRecordTime != 0L && lastPrimeRecordTime < primeRecord.atechDateTime) {
lastPrimeRecordTime = primeRecord.atechDateTime
lastPrimeRecord = primeRecord
}
@ -429,7 +426,6 @@ class MedtronicHistoryData @Inject constructor(
}
}
private fun uploadCareportalEventIfFoundInHistory(historyRecord: PumpHistoryEntry, eventSP: String, eventType: DetailedBolusInfo.EventType) {
val lastPrimeFromAAPS = sp.getLong(eventSP, 0L)
if (historyRecord.atechDateTime != lastPrimeFromAAPS) {
@ -448,7 +444,6 @@ class MedtronicHistoryData @Inject constructor(
}
}
private fun processTDDs(tddsIn: MutableList<PumpHistoryEntry>) {
val tdds = filterTDDs(tddsIn)
@ -470,14 +465,12 @@ class MedtronicHistoryData @Inject constructor(
}
}
private enum class ProcessHistoryRecord(val description: String) {
Bolus("Bolus"),
TBR("TBR"),
Suspend("Suspend");
}
private fun processBolusEntries(entryList: MutableList<PumpHistoryEntry>) {
val boluses = pumpSyncStorage.getBoluses()
@ -488,16 +481,16 @@ class MedtronicHistoryData @Inject constructor(
var type: DetailedBolusInfo.BolusType = DetailedBolusInfo.BolusType.NORMAL
var multiwave = false
if (bolusDTO.bolusType==PumpBolusType.Extended) {
if (bolusDTO.bolusType == PumpBolusType.Extended) {
addExtendedBolus(bolus, bolusDTO, multiwave)
continue;
} else if (bolusDTO.bolusType==PumpBolusType.Multiwave) {
} else if (bolusDTO.bolusType == PumpBolusType.Multiwave) {
multiwave = true
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "Multiwave bolus from pump, extended bolus and normal bolus will be added."))
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
@ -514,7 +507,7 @@ class MedtronicHistoryData @Inject constructor(
}
}
if (temporaryId!=null) {
if (temporaryId != null) {
val result = pumpSync.syncBolusWithTempId(
tryToGetByLocalTime(bolus.atechDateTime),
deliveredAmount,
@ -532,7 +525,7 @@ class MedtronicHistoryData @Inject constructor(
tryToGetByLocalTime(bolus.atechDateTime),
deliveredAmount,
type,
bolus.pumpId!!,
bolus.pumpId,
medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber!!)
@ -545,25 +538,23 @@ class MedtronicHistoryData @Inject constructor(
}
}
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(
tryToGetByLocalTime(bolus.atechDateTime),
bolusDTO.deliveredAmount!!,
bolusDTO.deliveredAmount,
durationMs,
false,
bolus.pumpId!!,
bolus.pumpId,
medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber!!)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "syncExtendedBolusWithPumpId [date=%d, amount=%.2f, duration=%d, pumpId=%d, pumpSerial=%s, multiwave=%b] - Result: %b",
bolus.atechDateTime, bolusDTO.deliveredAmount!!, bolusDTO.duration, bolus.pumpId,
bolus.atechDateTime, bolusDTO.deliveredAmount, bolusDTO.duration, bolus.pumpId,
medtronicPumpStatus.serialNumber!!, isMultiwave, result))
}
private fun addCarbs(bolus: PumpHistoryEntry) {
if (bolus.containsDecodedData("Estimate")) {
val bolusWizard = bolus.decodedData["Estimate"] as BolusWizardDTO
@ -573,12 +564,11 @@ class MedtronicHistoryData @Inject constructor(
bolusWizard.carbs.toDouble(),
medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber!!,
bolus.pumpId!!
bolus.pumpId
))
}
}
private fun processTBREntries(entryList: MutableList<PumpHistoryEntry>) {
Collections.reverse(entryList)
val tbr = entryList[0].getDecodedDataEntry("Object") as TempBasalPair?
@ -609,14 +599,14 @@ class MedtronicHistoryData @Inject constructor(
readOldItem = false
}
} 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 {
if (processDTO != null) {
processList.add(processDTO)
}
processDTO = TempBasalProcessDTO(
itemOne= treatment,
itemOne = treatment,
processOperation = TempBasalProcessDTO.Operation.Add)
}
}
@ -628,13 +618,13 @@ class MedtronicHistoryData @Inject constructor(
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
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",
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,
medtronicPumpStatus.serialNumber!!, result))
if (medtronicPumpStatus.runningTBR!=null) {
if (medtronicPumpStatus.runningTBR != null) {
if (!isTBRActive(medtronicPumpStatus.runningTBR!!)) {
medtronicPumpStatus.runningTBR = null
}
@ -703,21 +693,16 @@ class MedtronicHistoryData @Inject constructor(
} // collection
}
fun isTBRActive(dbEntry: PumpDbEntry) : Boolean {
fun isTBRActive(dbEntry: PumpDbEntry): Boolean {
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)
return (endDate > System.currentTimeMillis())
}
/**
* 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
@ -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
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()
for (temporaryEntry in temporaryEntries) {
@ -753,7 +738,7 @@ class MedtronicHistoryData @Inject constructor(
if (tempEntriesList.isEmpty()) {
return null
} else if (tempEntriesList.size==1) {
} else if (tempEntriesList.size == 1) {
return tempEntriesList[0]
}
@ -788,7 +773,6 @@ class MedtronicHistoryData @Inject constructor(
return null
}
private fun processSuspends(tempBasalProcessList: List<TempBasalProcessDTO>) {
for (tempBasalProcess in tempBasalProcessList) {
@ -798,21 +782,20 @@ class MedtronicHistoryData @Inject constructor(
tempBasalProcess.duration * 60 * 1000L,
true,
PumpSync.TemporaryBasalType.PUMP_SUSPEND,
tempBasalProcess.itemOne.pumpId!!,
tempBasalProcess.itemOne.pumpId,
medtronicPumpStatus.pumpType,
medtronicPumpStatus.serialNumber!!)
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "processSuspends::syncTemporaryBasalWithPumpId [date=%d, rate=%.2f, duration=%d, pumpId=%d, pumpSerial=%s] - Result: %b",
tempBasalProcess.itemOne.atechDateTime, 0.0, tempBasalProcess.duration, tempBasalProcess.itemOne.pumpId!!,
tempBasalProcess.itemOne.atechDateTime, 0.0, tempBasalProcess.duration, tempBasalProcess.itemOne.pumpId,
medtronicPumpStatus.serialNumber!!, result))
}
}
// suspend/resume
// no_delivery/prime & rewind/prime
private fun getSuspendRecords(): MutableList<TempBasalProcessDTO> {
private fun getSuspendRecords(): MutableList<TempBasalProcessDTO> {
val outList: MutableList<TempBasalProcessDTO> = mutableListOf()
// suspend/resume
@ -822,7 +805,6 @@ class MedtronicHistoryData @Inject constructor(
return outList
}
private fun getSuspendResumeRecordsList(): List<TempBasalProcessDTO> {
val filteredItems = getFilteredItems(newHistory, //
setOf(PumpHistoryEntryType.SuspendPump, PumpHistoryEntryType.ResumePump))
@ -864,8 +846,8 @@ class MedtronicHistoryData @Inject constructor(
var i = 0
while (i < filtered2Items.size) {
outList.add(TempBasalProcessDTO(
itemOne= filtered2Items[i],
itemTwo= filtered2Items[i + 1],
itemOne = filtered2Items[i],
itemTwo = filtered2Items[i + 1],
processOperation = TempBasalProcessDTO.Operation.Add))
i += 2
@ -875,18 +857,17 @@ class MedtronicHistoryData @Inject constructor(
return outList
}
private fun getNoDeliveryRewindPrimeRecordsList(): List<TempBasalProcessDTO> {
private fun getNoDeliveryRewindPrimeRecordsList(): List<TempBasalProcessDTO> {
val primeItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, //
setOf(PumpHistoryEntryType.Prime))
val outList: MutableList<TempBasalProcessDTO> = ArrayList()
if (primeItems.size == 0) return outList
val filteredItems: MutableList<PumpHistoryEntry> = getFilteredItems(newHistory, //
setOf(PumpHistoryEntryType.Prime,
PumpHistoryEntryType.Rewind,
PumpHistoryEntryType.NoDeliveryAlarm,
PumpHistoryEntryType.Bolus,
PumpHistoryEntryType.TempBasalCombined)
PumpHistoryEntryType.Rewind,
PumpHistoryEntryType.NoDeliveryAlarm,
PumpHistoryEntryType.Bolus,
PumpHistoryEntryType.TempBasalCombined)
)
val tempData: MutableList<PumpHistoryEntry> = mutableListOf()
var startedItems = false
@ -930,16 +911,16 @@ class MedtronicHistoryData @Inject constructor(
items = getFilteredItems(tempData, PumpHistoryEntryType.NoDeliveryAlarm)
if (items.size > 0) {
outList.add(TempBasalProcessDTO(
itemOne=items[items.size - 1],
itemTwo= itemTwo,
processOperation=TempBasalProcessDTO.Operation.Add))
itemOne = items[items.size - 1],
itemTwo = itemTwo,
processOperation = TempBasalProcessDTO.Operation.Add))
return outList
}
items = getFilteredItems(tempData, PumpHistoryEntryType.Rewind)
if (items.size > 0) {
outList.add(TempBasalProcessDTO(
itemOne=items[0],
processOperation=TempBasalProcessDTO.Operation.Add))
itemOne = items[0],
processOperation = TempBasalProcessDTO.Operation.Add))
return outList
}
return outList
@ -964,34 +945,31 @@ class MedtronicHistoryData @Inject constructor(
return DateTimeUtil.toMillisFromATD(atechDateTime)
}
private fun getTDDType(): PumpHistoryEntryType {
return if (medtronicUtil.medtronicPumpModel == null) {
PumpHistoryEntryType.EndResultTotals
} else when (medtronicUtil.medtronicPumpModel) {
MedtronicDeviceType.Medtronic_515,
MedtronicDeviceType.Medtronic_715 -> PumpHistoryEntryType.DailyTotals515
MedtronicDeviceType.Medtronic_715 -> PumpHistoryEntryType.DailyTotals515
MedtronicDeviceType.Medtronic_522,
MedtronicDeviceType.Medtronic_722 -> PumpHistoryEntryType.DailyTotals522
MedtronicDeviceType.Medtronic_722 -> PumpHistoryEntryType.DailyTotals522
MedtronicDeviceType.Medtronic_523_Revel,
MedtronicDeviceType.Medtronic_723_Revel,
MedtronicDeviceType.Medtronic_554_Veo,
MedtronicDeviceType.Medtronic_754_Veo -> PumpHistoryEntryType.DailyTotals523
MedtronicDeviceType.Medtronic_754_Veo -> PumpHistoryEntryType.DailyTotals523
else -> {
else -> {
PumpHistoryEntryType.EndResultTotals
}
}
}
fun hasBasalProfileChanged(): Boolean {
val filteredItems: List<PumpHistoryEntry?> = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile)
aapsLogger.debug(LTag.PUMP, "hasBasalProfileChanged. Items: " + gson.toJson(filteredItems))
return filteredItems.size > 0
}
fun processLastBasalProfileChange(pumpType: PumpType, mdtPumpStatus: MedtronicPumpStatus) {
val filteredItems: List<PumpHistoryEntry> = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile)
aapsLogger.debug(LTag.PUMP, "processLastBasalProfileChange. Items: $filteredItems")
@ -1085,12 +1063,11 @@ class MedtronicHistoryData @Inject constructor(
return outList
}
private val logPrefix: String
get() = "MedtronicHistoryData::"
companion object {
/**
* 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,

View file

@ -33,7 +33,7 @@ class BasalProfile {
private val aapsLogger: AAPSLogger
@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 var listEntries: MutableList<BasalProfileEntry>? = null
@ -49,7 +49,7 @@ class BasalProfile {
}
fun init() {
rawData = byteArrayOf(0,0,0x3f)
rawData = byteArrayOf(0, 0, 0x3f)
}
private fun setRawData(data: ByteArray): Boolean {
@ -268,7 +268,7 @@ class BasalProfile {
// if (pumpType == null)
// basalByHour[j] = current.rate
// else
basalByHour[j] = pumpType.determineCorrectBasalSize(current.rate)
basalByHour[j] = pumpType.determineCorrectBasalSize(current.rate)
}
}
return basalByHour
@ -291,9 +291,8 @@ class BasalProfile {
return true
}
companion object {
const val MAX_RAW_DATA_SIZE = 48 * 3 + 1
private const val DEBUG_BASALPROFILE = false
@ -310,5 +309,15 @@ class BasalProfile {
}
return stringBuilder.toString()
}
@JvmStatic
fun isBasalProfileByHourUndefined(basalByHour: DoubleArray): Boolean {
for (i in 0..23) {
if (basalByHour[i] > 0.0) {
return false;
}
}
return true
}
}
}

View file

@ -30,19 +30,24 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpBolusType
*
* 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
var requestedAmount: Double? = null
@Expose
var deliveredAmount: Double? = null
// @Expose
// var requestedAmount: Double? = null
//
// @Expose
// var deliveredAmount: Double? = null
@Expose
var immediateAmount: Double? = null // when Multiwave this is used
@Expose
var duration: Int? = null
// @Expose
// var duration: Int? = null
@Expose
var bolusType: PumpBolusType? = null
@ -51,7 +56,7 @@ class BolusDTO : PumpTimeStampedRecord() {
private val durationString: String
get() {
var minutes = duration!!
var minutes = duration
val h = minutes / 60
minutes -= h * 60
return StringUtil.getLeadingZero(h, 2) + ":" + StringUtil.getLeadingZero(minutes, 2)
@ -59,22 +64,22 @@ class BolusDTO : PumpTimeStampedRecord() {
val value: String
get() = if (bolusType === PumpBolusType.Normal || bolusType === PumpBolusType.Audio) {
getFormattedDecimal(deliveredAmount!!)
getFormattedDecimal(deliveredAmount)
} else if (bolusType === PumpBolusType.Extended) {
String.format("AMOUNT_SQUARE=%s;DURATION=%s", getFormattedDecimal(deliveredAmount!!),
String.format("AMOUNT_SQUARE=%s;DURATION=%s", getFormattedDecimal(deliveredAmount),
durationString)
} else {
String.format("AMOUNT=%s;AMOUNT_SQUARE=%s;DURATION=%s", getFormattedDecimal(immediateAmount!!),
getFormattedDecimal(deliveredAmount!!), durationString)
getFormattedDecimal(deliveredAmount), durationString)
}
val displayableValue: String
get() {
var value = value
value = value!!.replace("AMOUNT_SQUARE=", "Amount Square: ")
value = value.replace("AMOUNT=", "Amount: ")
value = value.replace("DURATION=", "Duration: ")
return value
var valueTemp = value
valueTemp = valueTemp.replace("AMOUNT_SQUARE=", "Amount Square: ")
valueTemp = valueTemp.replace("AMOUNT=", "Amount: ")
valueTemp = valueTemp.replace("DURATION=", "Duration: ")
return valueTemp
}
override fun getFormattedDecimal(value: Double): String {

View file

@ -5,8 +5,9 @@ import org.joda.time.LocalDateTime
/**
* Created by andy on 2/27/19.
*/
class ClockDTO {
var localDeviceTime: LocalDateTime? = null
var pumpTime: LocalDateTime? = null
class ClockDTO constructor(var localDeviceTime: LocalDateTime,
var pumpTime: LocalDateTime) {
// var localDeviceTime: LocalDateTime? = null
// var pumpTime: LocalDateTime? = null
var timeDifference = 0
}

View file

@ -5,10 +5,10 @@ import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
/**
* Created by andy on 6/2/18.
*/
open class PumpTimeStampedRecord {
open class PumpTimeStampedRecord constructor(var atechDateTime: Long = 0) {
var decimalPrecission = 2
var atechDateTime: Long = 0
// var atechDateTime: Long = 0
open fun getFormattedDecimal(value: Double): String? {
return StringUtil.getFormatedValueUS(value, decimalPrecission)

View file

@ -12,7 +12,7 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
get() = itemOne.atechDateTime
val pumpId: Long
get() = itemOne.pumpId!!
get() = itemOne.pumpId
val duration: Int
get() = if (itemTwo == null) {

View file

@ -54,7 +54,7 @@ class MedtronicHistoryActivity : DaggerActivity() {
filteredHistoryList.addAll(list)
} else {
for (pumpHistoryEntry in list) {
if (pumpHistoryEntry.entryType!!.group === group) {
if (pumpHistoryEntry.entryType.group === group) {
filteredHistoryList.add(pumpHistoryEntry)
}
}
@ -159,7 +159,7 @@ class MedtronicHistoryActivity : DaggerActivity() {
val record = historyList[position]
//if (record != null) {
holder.timeView.text = record.dateTimeString
holder.typeView.text = record.entryType!!.description
holder.typeView.text = record.entryType.description
holder.valueView.text = record.displayableValue
//}
}

View file

@ -39,7 +39,7 @@ class RileyLinkMedtronicService // This empty constructor must be kept, otherwi
private val mBinder: IBinder = LocalBinder()
private var serialChanged = false
private var frequencies: Array<String?>? = null
lateinit var frequencies: Array<String>
private var rileyLinkAddress: String? = null
private var rileyLinkAddressChanged = false
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
*/
override fun initRileyLinkServiceData() {
frequencies = arrayOfNulls(2)
frequencies!![0] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_us_ca)
frequencies!![1] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_worldwide)
frequencies = arrayOf()
frequencies[0] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_us_ca)
frequencies[1] = resourceHelper.gs(R.string.key_medtronic_pump_frequency_worldwide)
rileyLinkServiceData.targetDevice = RileyLinkTargetDevice.MedtronicPump
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)
return false
} 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)
return false
} else {
medtronicPumpStatus.pumpFrequency = pumpFrequency
val isFrequencyUS = pumpFrequency == frequencies!![0]
val isFrequencyUS = pumpFrequency == frequencies[0]
val newTargetFrequency = if (isFrequencyUS) //
RileyLinkTargetFrequency.Medtronic_US else RileyLinkTargetFrequency.Medtronic_WorldWide
if (rileyLinkServiceData.rileyLinkTargetFrequency != newTargetFrequency) {