- kotlin refactorings - MedtronicDeviceType

This commit is contained in:
Andy Rozman 2021-05-22 16:55:07 +01:00
parent 921302bdbf
commit d0f46d6745
13 changed files with 72 additions and 56 deletions

View file

@ -209,13 +209,16 @@ class MedtronicFragment : DaggerFragment() {
} ?: "-" } ?: "-"
when (medtronicPumpStatus.pumpDeviceState) { when (medtronicPumpStatus.pumpDeviceState) {
PumpDeviceState.Sleeping -> binding.pumpStatusIcon.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name()); PumpDeviceState.Sleeping ->
binding.pumpStatusIcon.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name());
PumpDeviceState.NeverContacted, PumpDeviceState.NeverContacted,
PumpDeviceState.WakingUp, PumpDeviceState.WakingUp,
PumpDeviceState.PumpUnreachable, PumpDeviceState.PumpUnreachable,
PumpDeviceState.ErrorWhenCommunicating, PumpDeviceState.ErrorWhenCommunicating,
PumpDeviceState.TimeoutWhenCommunicating, PumpDeviceState.TimeoutWhenCommunicating,
PumpDeviceState.InvalidConfiguration -> binding.pumpStatusIcon.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId) PumpDeviceState.InvalidConfiguration ->
binding.pumpStatusIcon.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId)
PumpDeviceState.Active -> { PumpDeviceState.Active -> {
val cmd = medtronicUtil.getCurrentCommand() val cmd = medtronicUtil.getCurrentCommand()
@ -223,10 +226,10 @@ class MedtronicFragment : DaggerFragment() {
binding.pumpStatusIcon.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId) binding.pumpStatusIcon.text = " " + resourceHelper.gs(medtronicPumpStatus.pumpDeviceState.resourceId)
else { else {
aapsLogger.debug(LTag.PUMP, "Command: $cmd") aapsLogger.debug(LTag.PUMP, "Command: $cmd")
val cmdResourceId = cmd.resourceId!! val cmdResourceId = cmd.resourceId //!!
if (cmd == MedtronicCommandType.GetHistoryData) { if (cmd == MedtronicCommandType.GetHistoryData) {
binding.pumpStatusIcon.text = medtronicUtil.frameNumber?.let { binding.pumpStatusIcon.text = medtronicUtil.frameNumber?.let {
resourceHelper.gs(cmdResourceId, medtronicUtil.pageNumber, medtronicUtil.frameNumber) resourceHelper.gs(cmdResourceId!!, medtronicUtil.pageNumber, medtronicUtil.frameNumber)
} }
?: resourceHelper.gs(R.string.medtronic_cmd_desc_get_history_request, medtronicUtil.pageNumber) ?: resourceHelper.gs(R.string.medtronic_cmd_desc_get_history_request, medtronicUtil.pageNumber)
} else { } else {
@ -236,7 +239,8 @@ class MedtronicFragment : DaggerFragment() {
} }
} }
else -> aapsLogger.warn(LTag.PUMP, "Unknown pump state: " + medtronicPumpStatus.pumpDeviceState) else ->
aapsLogger.warn(LTag.PUMP, "Unknown pump state: " + medtronicPumpStatus.pumpDeviceState)
} }
val status = commandQueue.spannedStatus() val status = commandQueue.spannedStatus()

View file

@ -36,8 +36,8 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask
import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR import info.nightscout.androidaps.plugins.pump.common.sync.PumpDbEntryTBR
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncEntriesCreator import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncEntriesCreator
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage import info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryResult import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryResult
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData
@ -236,7 +236,7 @@ class MedtronicPumpPlugin @Inject constructor(
override fun getPumpInfo(): RileyLinkPumpInfo { override fun getPumpInfo(): RileyLinkPumpInfo {
val frequency = resourceHelper.gs(if (medtronicPumpStatus.pumpFrequency == "medtronic_pump_frequency_us_ca") R.string.medtronic_pump_frequency_us_ca else R.string.medtronic_pump_frequency_worldwide) val frequency = resourceHelper.gs(if (medtronicPumpStatus.pumpFrequency == "medtronic_pump_frequency_us_ca") R.string.medtronic_pump_frequency_us_ca else R.string.medtronic_pump_frequency_worldwide)
val model = if (medtronicPumpStatus.medtronicDeviceType == null) "???" else "Medtronic " + medtronicPumpStatus.medtronicDeviceType!!.pumpModel val model = if (!medtronicUtil.isModelSet) "???" else "Medtronic " + medtronicPumpStatus.medtronicDeviceType.pumpModel
val serialNumber = medtronicPumpStatus.serialNumber val serialNumber = medtronicPumpStatus.serialNumber
return RileyLinkPumpInfo(frequency, model, serialNumber) return RileyLinkPumpInfo(frequency, model, serialNumber)
} }
@ -417,7 +417,7 @@ class MedtronicPumpPlugin @Inject constructor(
} }
// model (once) // model (once)
if (medtronicUtil.medtronicPumpModel == null) { if (!medtronicUtil.isModelSet) {
rileyLinkMedtronicService!!.medtronicUIComm.executeCommand(MedtronicCommandType.PumpModel) rileyLinkMedtronicService!!.medtronicUIComm.executeCommand(MedtronicCommandType.PumpModel)
} else { } else {
if (medtronicPumpStatus.medtronicDeviceType !== medtronicUtil.medtronicPumpModel) { if (medtronicPumpStatus.medtronicDeviceType !== medtronicUtil.medtronicPumpModel) {
@ -534,7 +534,6 @@ class MedtronicPumpPlugin @Inject constructor(
return DateTimeUtil.toATechDate(timestamp) return DateTimeUtil.toATechDate(timestamp)
} }
private var bolusDeliveryType = BolusDeliveryType.Idle private var bolusDeliveryType = BolusDeliveryType.Idle
private enum class BolusDeliveryType { private enum class BolusDeliveryType {
@ -1175,6 +1174,7 @@ class MedtronicPumpPlugin @Inject constructor(
} }
companion object { companion object {
var isBusy = false var isBusy = false
} }

View file

@ -136,8 +136,9 @@ class MedtronicCommunicationManager // This empty constructor must be kept, oth
val dataResponse = medtronicConverter.decodeModel(pumpResponse.rawContent) val dataResponse = medtronicConverter.decodeModel(pumpResponse.rawContent)
val pumpModel = dataResponse as MedtronicDeviceType? val pumpModel = dataResponse as MedtronicDeviceType?
val valid = pumpModel !== MedtronicDeviceType.Unknown_Device val valid = pumpModel !== MedtronicDeviceType.Unknown_Device
if (medtronicUtil.medtronicPumpModel == null && valid) { if (!medtronicUtil.isModelSet && valid) {
medtronicUtil.medtronicPumpModel = pumpModel medtronicUtil.medtronicPumpModel = pumpModel!!
medtronicUtil.isModelSet = true
} }
aapsLogger.debug(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "isDeviceReachable. PumpModel is %s - Valid: %b (rssi=%d)", pumpModel!!.name, valid, aapsLogger.debug(LTag.PUMPCOMM, String.format(Locale.ENGLISH, "isDeviceReachable. PumpModel is %s - Valid: %b (rssi=%d)", pumpModel!!.name, valid,
radioResponse.rssi)) radioResponse.rssi))

View file

@ -8,8 +8,6 @@ import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BatteryStatusDTO import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BatteryStatusDTO
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.PumpSettingDTO import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.PumpSettingDTO
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpConfigurationGroup import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpConfigurationGroup
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
@ -95,6 +93,7 @@ class MedtronicConverter @Inject constructor(
if (pumpModel != MedtronicDeviceType.Unknown_Device) { if (pumpModel != MedtronicDeviceType.Unknown_Device) {
if (!medtronicUtil.isModelSet) { if (!medtronicUtil.isModelSet) {
medtronicUtil.medtronicPumpModel = pumpModel medtronicUtil.medtronicPumpModel = pumpModel
medtronicUtil.isModelSet = true
} }
} }
return pumpModel return pumpModel
@ -129,7 +128,7 @@ class MedtronicConverter @Inject constructor(
public fun decodeRemainingInsulin(rawData: ByteArray?): Double { public fun decodeRemainingInsulin(rawData: ByteArray?): Double {
var startIdx = 0 var startIdx = 0
val pumpModel = medtronicUtil.medtronicPumpModel val pumpModel = medtronicUtil.medtronicPumpModel
val strokes = pumpModel?.bolusStrokes ?: 10 val strokes = pumpModel.bolusStrokes //?: 10
if (strokes == 40) { if (strokes == 40) {
startIdx = 2 startIdx = 2
} }
@ -208,7 +207,7 @@ class MedtronicConverter @Inject constructor(
rd[settingIndexMaxBasal + 1].toInt())), PumpConfigurationGroup.Basal, map) rd[settingIndexMaxBasal + 1].toInt())), PumpConfigurationGroup.Basal, map)
addSettingToMap("CFG_BASE_CLOCK_MODE", if (rd[settingIndexTimeDisplayFormat].toInt() == 0) "12h" else "24h", addSettingToMap("CFG_BASE_CLOCK_MODE", if (rd[settingIndexTimeDisplayFormat].toInt() == 0) "12h" else "24h",
PumpConfigurationGroup.General, map) PumpConfigurationGroup.General, map)
if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel!!, MedtronicDeviceType.Medtronic_523andHigher)) { if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel, MedtronicDeviceType.Medtronic_523andHigher)) {
addSettingToMap("PCFG_INSULIN_CONCENTRATION", "" + if (rd[9].toInt() == 0) 50 else 100, PumpConfigurationGroup.Insulin, addSettingToMap("PCFG_INSULIN_CONCENTRATION", "" + if (rd[9].toInt() == 0) 50 else 100, PumpConfigurationGroup.Insulin,
map) map)
// LOG.debug("Insulin concentration: " + rd[9]); // LOG.debug("Insulin concentration: " + rd[9]);
@ -249,7 +248,7 @@ class MedtronicConverter @Inject constructor(
addSettingToMap("PCFG_MM_SRESERVOIR_WARNING_POINT", "" + ByteUtil.asUINT8(rd[19]), addSettingToMap("PCFG_MM_SRESERVOIR_WARNING_POINT", "" + ByteUtil.asUINT8(rd[19]),
PumpConfigurationGroup.Other, map) PumpConfigurationGroup.Other, map)
addSettingToMap("CFG_MM_KEYPAD_LOCKED", parseResultEnable(rd[20].toInt()), PumpConfigurationGroup.Other, map) addSettingToMap("CFG_MM_KEYPAD_LOCKED", parseResultEnable(rd[20].toInt()), PumpConfigurationGroup.Other, map)
if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel!!, MedtronicDeviceType.Medtronic_523andHigher)) { if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel, MedtronicDeviceType.Medtronic_523andHigher)) {
addSettingToMap("PCFG_BOLUS_SCROLL_STEP_SIZE", "" + rd[21], PumpConfigurationGroup.Bolus, map) addSettingToMap("PCFG_BOLUS_SCROLL_STEP_SIZE", "" + rd[21], PumpConfigurationGroup.Bolus, map)
addSettingToMap("PCFG_CAPTURE_EVENT_ENABLE", parseResultEnable(rd[22].toInt()), PumpConfigurationGroup.Other, map) addSettingToMap("PCFG_CAPTURE_EVENT_ENABLE", parseResultEnable(rd[22].toInt()), PumpConfigurationGroup.Other, map)
addSettingToMap("PCFG_OTHER_DEVICE_ENABLE", parseResultEnable(rd[23].toInt()), PumpConfigurationGroup.Other, map) addSettingToMap("PCFG_OTHER_DEVICE_ENABLE", parseResultEnable(rd[23].toInt()), PumpConfigurationGroup.Other, map)
@ -273,7 +272,7 @@ class MedtronicConverter @Inject constructor(
// 512 // 512
private fun decodeInsulinActionSetting(ai: ByteArray, map: MutableMap<String, PumpSettingDTO>) { private fun decodeInsulinActionSetting(ai: ByteArray, map: MutableMap<String, PumpSettingDTO>) {
if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel!!, MedtronicDeviceType.Medtronic_512_712)) { if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel, MedtronicDeviceType.Medtronic_512_712)) {
addSettingToMap("PCFG_INSULIN_ACTION_TYPE", if (ai[17].toInt() != 0) "Regular" else "Fast", addSettingToMap("PCFG_INSULIN_ACTION_TYPE", if (ai[17].toInt() != 0) "Regular" else "Fast",
PumpConfigurationGroup.Insulin, map) PumpConfigurationGroup.Insulin, map)
} else { } else {
@ -308,7 +307,7 @@ class MedtronicConverter @Inject constructor(
} }
private fun is523orHigher(): Boolean { private fun is523orHigher(): Boolean {
return MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel!!, MedtronicDeviceType.Medtronic_523andHigher) return MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel, MedtronicDeviceType.Medtronic_523andHigher)
} }
} }

View file

@ -44,7 +44,7 @@ abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?> : MedtronicHi
private fun checkPage(page: RawHistoryPage): MutableList<Byte> { private fun checkPage(page: RawHistoryPage): MutableList<Byte> {
//val byteList: MutableList<Byte> = mutableListOf() //val byteList: MutableList<Byte> = mutableListOf()
if (medtronicUtil.medtronicPumpModel == null) { if (!medtronicUtil.isModelSet) {
aapsLogger.error(LTag.PUMPCOMM, "Device Type is not defined.") aapsLogger.error(LTag.PUMPCOMM, "Device Type is not defined.")
return mutableListOf() return mutableListOf()
} }

View file

@ -69,7 +69,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
} }
val entryType = getByCode(opCode.toByte()) val entryType = getByCode(opCode.toByte())
val pe = PumpHistoryEntry() val pe = PumpHistoryEntry()
pe.setEntryType(medtronicUtil.medtronicPumpModel!!, entryType!!) pe.setEntryType(medtronicUtil.medtronicPumpModel, entryType, if (entryType == PumpHistoryEntryType.UnknownBasePacket) opCode.toByte() else null)
pe.offset = counter pe.offset = counter
counter++ counter++
if (counter >= 1022) { if (counter >= 1022) {
@ -91,7 +91,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
} }
special = true special = true
} else { } else {
for (j in 0 until entryType.getTotalLength(medtronicUtil.medtronicPumpModel!!) - 1) { for (j in 0 until entryType.getTotalLength(medtronicUtil.medtronicPumpModel) - 1) {
try { try {
listRawData.add(dataClearInput[counter]) listRawData.add(dataClearInput[counter])
counter++ counter++
@ -111,7 +111,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
if (pe.entryType === PumpHistoryEntryType.UnknownBasePacket) { if (pe.entryType === PumpHistoryEntryType.UnknownBasePacket) {
pe.opCode = opCode.toByte() pe.opCode = opCode.toByte()
} }
if (entryType.getHeadLength(medtronicUtil.medtronicPumpModel!!) == 0) special = true if (entryType.getHeadLength(medtronicUtil.medtronicPumpModel) == 0) special = true
pe.setData(listRawData as List<Byte>, special) pe.setData(listRawData as List<Byte>, special)
val decoded = decodeRecord(pe) val decoded = decodeRecord(pe)
if (decoded === RecordDecodeStatus.OK || decoded === RecordDecodeStatus.Ignored) { if (decoded === RecordDecodeStatus.OK || decoded === RecordDecodeStatus.Ignored) {
@ -299,7 +299,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
val offset = body!![0] * 1000 * 30 * 60 val offset = body!![0] * 1000 * 30 * 60
var rate: Float? = null var rate: Float? = null
val index = entry.head!![0].toInt() val index = entry.head!![0].toInt()
if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel!!, MedtronicDeviceType.Medtronic_523andHigher)) { if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel, MedtronicDeviceType.Medtronic_523andHigher)) {
rate = body[1] * 0.025f rate = body[1] * 0.025f
} }
@ -318,7 +318,7 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
val body = entry.body!! val body = entry.body!!
val dto = BolusWizardDTO() val dto = BolusWizardDTO()
var bolusStrokes = 10.0f var bolusStrokes = 10.0f
if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel!!, MedtronicDeviceType.Medtronic_523andHigher)) { if (MedtronicDeviceType.isSameDevice(medtronicUtil.medtronicPumpModel, MedtronicDeviceType.Medtronic_523andHigher)) {
// https://github.com/ps2/minimed_rf/blob/master/lib/minimed_rf/log_entries/bolus_wizard.rb#L102 // https://github.com/ps2/minimed_rf/blob/master/lib/minimed_rf/log_entries/bolus_wizard.rb#L102
bolusStrokes = 40.0f bolusStrokes = 40.0f
dto.carbs = ((body[1] and 0x0c.toByte()).toInt() shl 6) + body[0] dto.carbs = ((body[1] and 0x0c.toByte()).toInt() shl 6) + body[0]
@ -421,9 +421,9 @@ class MedtronicPumpHistoryDecoder @Inject constructor(
} }
private fun decodeBolus(entry: PumpHistoryEntry) { private fun decodeBolus(entry: PumpHistoryEntry) {
var bolus: BolusDTO? val 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 = BolusDTO(atechDateTime = entry.atechDateTime, bolus = BolusDTO(atechDateTime = entry.atechDateTime,
requestedAmount = ByteUtil.toInt(data.get(0), data.get(1)) / 40.0, requestedAmount = ByteUtil.toInt(data.get(0), data.get(1)) / 40.0,
deliveredAmount = ByteUtil.toInt(data.get(2), data.get(3)) / 40.0, deliveredAmount = ByteUtil.toInt(data.get(2), data.get(3)) / 40.0,

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump
import android.util.Log
import com.google.gson.annotations.Expose 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.StringUtil import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil
@ -36,12 +35,13 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
field = value field = value
} }
fun setEntryType(medtronicDeviceType: MedtronicDeviceType, entryType: PumpHistoryEntryType) { fun setEntryType(medtronicDeviceType: MedtronicDeviceType, entryType: PumpHistoryEntryType, opCode: Byte? = null) {
this.entryType = entryType this.entryType = entryType
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 (isEntryTypeSet() && atechDateTime != 0L) pumpId = generatePumpId() if (isEntryTypeSet() && atechDateTime != 0L) pumpId = generatePumpId()
this.opCode = opCode
} }
override fun generatePumpId(): Long { override fun generatePumpId(): Long {
@ -103,6 +103,7 @@ 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

View file

@ -15,7 +15,8 @@ enum class PumpHistoryEntryType // implements CodeEnum
constructor(opCode: Byte, name: String?, group: PumpHistoryEntryGroup, head: Int = 2, date: Int = 5, body: Int = 0) { constructor(opCode: Byte, name: String?, group: PumpHistoryEntryGroup, head: Int = 2, date: Int = 5, body: Int = 0) {
// all commented out are probably not the real items // all commented out are probably not the real items
None(0, "None", PumpHistoryEntryGroup.Unknown, 1, 0, 0), Bolus(0x01, "Bolus", PumpHistoryEntryGroup.Bolus, 4, 5, 0), // 523+[H=8] 9/13 None(0, "None", PumpHistoryEntryGroup.Unknown, 1, 0, 0),
Bolus(0x01, "Bolus", PumpHistoryEntryGroup.Bolus, 4, 5, 0), // 523+[H=8] 9/13
Prime(0x03, "Prime", PumpHistoryEntryGroup.Prime, 5, 5, 0), // Prime(0x03, "Prime", PumpHistoryEntryGroup.Prime, 5, 5, 0), //
// /**/EventUnknown_MM522_0x05((byte) 0x05, "Unknown Event 0x05", PumpHistoryEntryGroup.Unknown, 2, 5, 28), // // /**/EventUnknown_MM522_0x05((byte) 0x05, "Unknown Event 0x05", PumpHistoryEntryGroup.Unknown, 2, 5, 28), //
@ -40,6 +41,7 @@ enum class PumpHistoryEntryType // implements CodeEnum
ClearSettings(0x22, "Clear Settings", PumpHistoryEntryGroup.Configuration), // ClearSettings(0x22, "Clear Settings", PumpHistoryEntryGroup.Configuration), //
ChangeChildBlockEnable(0x23, "Change Child Block Enable", PumpHistoryEntryGroup.Configuration), // ChangeChildBlockEnable(0x23, "Change Child Block Enable", PumpHistoryEntryGroup.Configuration), //
ChangeMaxBolus(0x24, "Change Max Bolus", PumpHistoryEntryGroup.Configuration), // ChangeMaxBolus(0x24, "Change Max Bolus", PumpHistoryEntryGroup.Configuration), //
// /**/EventUnknown_MM522_0x25(0x25, "Unknown Event 0x25", PumpHistoryEntryGroup.Unknown), // 8? // /**/EventUnknown_MM522_0x25(0x25, "Unknown Event 0x25", PumpHistoryEntryGroup.Unknown), // 8?
EnableDisableRemote(0x26, "Enable/Disable Remote", PumpHistoryEntryGroup.Configuration, 2, 5, 14), // 2, 5, 14 V6:2,5,14 EnableDisableRemote(0x26, "Enable/Disable Remote", PumpHistoryEntryGroup.Configuration, 2, 5, 14), // 2, 5, 14 V6:2,5,14
ChangeRemoteId(0x27, "Change Remote ID", PumpHistoryEntryGroup.Configuration), // ?? ChangeRemoteId(0x27, "Change Remote ID", PumpHistoryEntryGroup.Configuration), // ??
@ -54,6 +56,7 @@ enum class PumpHistoryEntryType // implements CodeEnum
LowReservoir(0x34, "Low Reservoir", PumpHistoryEntryGroup.Notification), // LowReservoir(0x34, "Low Reservoir", PumpHistoryEntryGroup.Notification), //
ChangeAlarmClock(0x35, "Change Alarm Clock", PumpHistoryEntryGroup.Configuration), // ChangeAlarmClock(0x35, "Change Alarm Clock", PumpHistoryEntryGroup.Configuration), //
ChangeMeterId(0x36, "Change Meter ID", PumpHistoryEntryGroup.Configuration), // ChangeMeterId(0x36, "Change Meter ID", PumpHistoryEntryGroup.Configuration), //
// /**/EventUnknown_MM512_0x37(0x37, "Unknown Event 0x37", PumpHistoryEntryGroup.Unknown), // V:MM512 // /**/EventUnknown_MM512_0x37(0x37, "Unknown Event 0x37", PumpHistoryEntryGroup.Unknown), // V:MM512
// /**/EventUnknown_MM512_0x38(0x38, "Unknown Event 0x38", PumpHistoryEntryGroup.Unknown), // // /**/EventUnknown_MM512_0x38(0x38, "Unknown Event 0x38", PumpHistoryEntryGroup.Unknown), //
BGReceived512(0x39, "BG Received (512)", PumpHistoryEntryGroup.Glucose, 2, 5, 3), // BGReceived512(0x39, "BG Received (512)", PumpHistoryEntryGroup.Glucose, 2, 5, 3), //
@ -69,6 +72,7 @@ enum class PumpHistoryEntryType // implements CodeEnum
JournalEntryInsulinMarker(0x42, "Insulin Marker", PumpHistoryEntryGroup.Bolus, 2, 5, 0), // V6 = body(0)/was=1 JournalEntryInsulinMarker(0x42, "Insulin Marker", PumpHistoryEntryGroup.Bolus, 2, 5, 0), // V6 = body(0)/was=1
JournalEntryOtherMarker(0x43, "Other Marker", PumpHistoryEntryGroup.Bolus, 2, 5, 1), // V6 = body(1) was=0 JournalEntryOtherMarker(0x43, "Other Marker", PumpHistoryEntryGroup.Bolus, 2, 5, 1), // V6 = body(1) was=0
EnableSensorAutoCal(0x44, "Enable Sensor AutoCal", PumpHistoryEntryGroup.Glucose), // EnableSensorAutoCal(0x44, "Enable Sensor AutoCal", PumpHistoryEntryGroup.Glucose), //
// /**/EventUnknown_MM522_0x45(0x45, "Unknown Event 0x45", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // // /**/EventUnknown_MM522_0x45(0x45, "Unknown Event 0x45", PumpHistoryEntryGroup.Unknown, 2, 5, 1), //
// /**/EventUnknown_MM522_0x46(0x46, "Unknown Event 0x46", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // // /**/EventUnknown_MM522_0x46(0x46, "Unknown Event 0x46", PumpHistoryEntryGroup.Unknown, 2, 5, 1), //
// /**/EventUnknown_MM522_0x47(0x47, "Unknown Event 0x47", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // // /**/EventUnknown_MM522_0x47(0x47, "Unknown Event 0x47", PumpHistoryEntryGroup.Unknown, 2, 5, 1), //
@ -110,6 +114,7 @@ enum class PumpHistoryEntryType // implements CodeEnum
DailyTotals522(0x6d, "Daily Totals (522)", PumpHistoryEntryGroup.Statistic, 1, 2, 41), // DailyTotals522(0x6d, "Daily Totals (522)", PumpHistoryEntryGroup.Statistic, 1, 2, 41), //
DailyTotals523(0x6e, "Daily Totals (523)", PumpHistoryEntryGroup.Statistic, 1, 2, 49), // 1102014-03-17T00:00:00 DailyTotals523(0x6e, "Daily Totals (523)", PumpHistoryEntryGroup.Statistic, 1, 2, 49), // 1102014-03-17T00:00:00
ChangeCarbUnits(0x6f.toByte(), "Change Carb Units", PumpHistoryEntryGroup.Configuration), // ChangeCarbUnits(0x6f.toByte(), "Change Carb Units", PumpHistoryEntryGroup.Configuration), //
// /**/EventUnknown_MM522_0x70((byte) 0x70, "Unknown Event 0x70", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // // /**/EventUnknown_MM522_0x70((byte) 0x70, "Unknown Event 0x70", PumpHistoryEntryGroup.Unknown, 2, 5, 1), //
BasalProfileStart(0x7b, "Basal Profile Start", PumpHistoryEntryGroup.Basal, 2, 5, 3), // // 722 BasalProfileStart(0x7b, "Basal Profile Start", PumpHistoryEntryGroup.Basal, 2, 5, 3), // // 722
ChangeWatchdogEnable(0x7c, "Change Watchdog Enable", PumpHistoryEntryGroup.Configuration), // ChangeWatchdogEnable(0x7c, "Change Watchdog Enable", PumpHistoryEntryGroup.Configuration), //
@ -133,6 +138,7 @@ enum class PumpHistoryEntryType // implements CodeEnum
UnknownBasePacket(0xff.toByte(), "Unknown Base Packet", PumpHistoryEntryGroup.Unknown); UnknownBasePacket(0xff.toByte(), "Unknown Base Packet", PumpHistoryEntryGroup.Unknown);
companion object { companion object {
private val opCodeMap: MutableMap<Byte, PumpHistoryEntryType?> = HashMap() private val opCodeMap: MutableMap<Byte, PumpHistoryEntryType?> = HashMap()
fun setSpecialRulesForEntryTypes() { fun setSpecialRulesForEntryTypes() {
EndResultTotals.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 3)) EndResultTotals.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 3))
@ -143,9 +149,9 @@ enum class PumpHistoryEntryType // implements CodeEnum
ChangeSensorSetup2.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 34)) ChangeSensorSetup2.addSpecialRuleBody(SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 34))
} }
fun getByCode(opCode: Byte): PumpHistoryEntryType? { fun getByCode(opCode: Byte): PumpHistoryEntryType {
return if (opCodeMap.containsKey(opCode)) { return if (opCodeMap.containsKey(opCode)) {
opCodeMap[opCode] opCodeMap[opCode]!!
} else { } else {
UnknownBasePacket UnknownBasePacket
} }

View file

@ -102,11 +102,15 @@ 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) if (batteryStatusDTO != null) {
medtronicPumpStatus.batteryRemaining = batteryStatusDTO.getCalculatedPercent(medtronicPumpStatus.batteryType)
if (batteryStatusDTO.voltage != null) { if (batteryStatusDTO.voltage != null) {
medtronicPumpStatus.batteryVoltage = batteryStatusDTO.voltage medtronicPumpStatus.batteryVoltage = batteryStatusDTO.voltage
} }
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "BatteryStatus: %s", batteryStatusDTO.toString())) aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "BatteryStatus: %s", batteryStatusDTO.toString()))
} else {
medtronicPumpStatus.batteryVoltage = null
}
} }
MedtronicCommandType.PumpModel -> { MedtronicCommandType.PumpModel -> {

View file

@ -946,7 +946,7 @@ class MedtronicHistoryData @Inject constructor(
} }
private fun getTDDType(): PumpHistoryEntryType { private fun getTDDType(): PumpHistoryEntryType {
return if (medtronicUtil.medtronicPumpModel == null) { return if (!medtronicUtil.isModelSet) {
PumpHistoryEntryType.EndResultTotals PumpHistoryEntryType.EndResultTotals
} else when (medtronicUtil.medtronicPumpModel) { } else when (medtronicUtil.medtronicPumpModel) {
MedtronicDeviceType.Medtronic_515, MedtronicDeviceType.Medtronic_515,
@ -1015,7 +1015,7 @@ class MedtronicHistoryData @Inject constructor(
for (pumpHistoryEntry in TBRs_Input) { for (pumpHistoryEntry in TBRs_Input) {
if (map.containsKey(pumpHistoryEntry.DT)) { if (map.containsKey(pumpHistoryEntry.DT)) {
medtronicPumpHistoryDecoder.decodeTempBasal(map[pumpHistoryEntry.DT]!!, pumpHistoryEntry) medtronicPumpHistoryDecoder.decodeTempBasal(map[pumpHistoryEntry.DT]!!, pumpHistoryEntry)
pumpHistoryEntry.setEntryType(medtronicUtil.medtronicPumpModel!!, PumpHistoryEntryType.TempBasalCombined) pumpHistoryEntry.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.TempBasalCombined)
TBRs.add(pumpHistoryEntry) TBRs.add(pumpHistoryEntry)
map.remove(pumpHistoryEntry.DT) map.remove(pumpHistoryEntry.DT)
} else { } else {

View file

@ -44,7 +44,7 @@ class MedtronicPumpStatus @Inject constructor(private val resourceHelper: Resour
rxBus.send(EventRileyLinkDeviceStatusChange(pumpDeviceState)) rxBus.send(EventRileyLinkDeviceStatusChange(pumpDeviceState))
} }
var medtronicDeviceType: MedtronicDeviceType? = null var medtronicDeviceType: MedtronicDeviceType = MedtronicDeviceType.Medtronic_522
var medtronicPumpMap: MutableMap<String, PumpType> = mutableMapOf() var medtronicPumpMap: MutableMap<String, PumpType> = mutableMapOf()
var medtronicDeviceTypeMap: MutableMap<String, MedtronicDeviceType> = mutableMapOf() var medtronicDeviceTypeMap: MutableMap<String, MedtronicDeviceType> = mutableMapOf()
var basalProfileStatus = BasalProfileStatus.NotInitialized var basalProfileStatus = BasalProfileStatus.NotInitialized
@ -87,7 +87,6 @@ class MedtronicPumpStatus @Inject constructor(private val resourceHelper: Resour
medtronicPumpMap["754"] = PumpType.MEDTRONIC_554_754_VEO medtronicPumpMap["754"] = PumpType.MEDTRONIC_554_754_VEO
} }
val basalProfileForHour: Double val basalProfileForHour: Double
get() { get() {
if (basalsByHour != null) { if (basalsByHour != null) {
@ -115,7 +114,6 @@ class MedtronicPumpStatus @Inject constructor(private val resourceHelper: Resour
override val errorInfo: String override val errorInfo: String
get() = if (errorDescription == null) "-" else errorDescription!! get() = if (errorDescription == null) "-" else errorDescription!!
val tbrRemainingTime: Int? val tbrRemainingTime: Int?
get() { get() {
if (tempBasalStart == null) return null if (tempBasalStart == null) return null

View file

@ -17,6 +17,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin
import info.nightscout.androidaps.plugins.pump.medtronic.R import info.nightscout.androidaps.plugins.pump.medtronic.R
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUIComm import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUIComm
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
@ -109,7 +110,8 @@ class RileyLinkMedtronicService // This empty constructor must be kept, otherwi
val oldId = rileyLinkServiceData.pumpID val oldId = rileyLinkServiceData.pumpID
rileyLinkServiceData.setPumpID(pumpID, pumpIDBytes) rileyLinkServiceData.setPumpID(pumpID, pumpIDBytes)
if (oldId != null && oldId != pumpID) { if (oldId != null && oldId != pumpID) {
medtronicUtil.medtronicPumpModel = null // if we change pumpId, model probably changed too medtronicUtil.medtronicPumpModel = MedtronicDeviceType.Medtronic_522 // if we change pumpId, model probably changed too
medtronicUtil.isModelSet = false
} }
return return
} }
@ -119,6 +121,7 @@ class RileyLinkMedtronicService // This empty constructor must be kept, otherwi
} }
inner class LocalBinder : Binder() { inner class LocalBinder : Binder() {
val serviceInstance: RileyLinkMedtronicService val serviceInstance: RileyLinkMedtronicService
get() = this@RileyLinkMedtronicService get() = this@RileyLinkMedtronicService
} }
@ -158,7 +161,7 @@ class RileyLinkMedtronicService // This empty constructor must be kept, otherwi
return false return false
} else { } else {
val pumpType = medtronicPumpStatus.medtronicPumpMap[pumpTypePart] val pumpType = medtronicPumpStatus.medtronicPumpMap[pumpTypePart]
medtronicPumpStatus.medtronicDeviceType = medtronicPumpStatus.medtronicDeviceTypeMap[pumpTypePart] medtronicPumpStatus.medtronicDeviceType = medtronicPumpStatus.medtronicDeviceTypeMap[pumpTypePart]!!
medtronicPumpStatus.pumpType = pumpType!! medtronicPumpStatus.pumpType = pumpType!!
medtronicPumpPlugin.pumpType = pumpType medtronicPumpPlugin.pumpType = pumpType
if (pumpTypePart.startsWith("7")) medtronicPumpStatus.reservoirFullUnits = 300 else medtronicPumpStatus.reservoirFullUnits = 176 if (pumpTypePart.startsWith("7")) medtronicPumpStatus.reservoirFullUnits = 300 else medtronicPumpStatus.reservoirFullUnits = 176

View file

@ -48,7 +48,6 @@ class MedtronicUtil @Inject constructor(
var pumpTime: ClockDTO? = null var pumpTime: ClockDTO? = null
var gsonInstance = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create() var gsonInstance = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
fun getTimeFrom30MinInterval(interval: Int): LocalTime { fun getTimeFrom30MinInterval(interval: Int): LocalTime {
return if (interval % 2 == 0) { return if (interval % 2 == 0) {
LocalTime(interval / 2, 0) LocalTime(interval / 2, 0)
@ -74,7 +73,7 @@ class MedtronicUtil @Inject constructor(
} }
fun getBolusStrokes(amount: Double): ByteArray { fun getBolusStrokes(amount: Double): ByteArray {
val strokesPerUnit = medtronicPumpStatus.medtronicDeviceType!!.bolusStrokes val strokesPerUnit = medtronicPumpStatus.medtronicDeviceType.bolusStrokes
val length: Int val length: Int
val scrollRate: Int val scrollRate: Int
if (strokesPerUnit >= 40) { if (strokesPerUnit >= 40) {
@ -217,10 +216,10 @@ class MedtronicUtil @Inject constructor(
return true return true
} }
val isModelSet: Boolean var isModelSet: Boolean = false
get() = medtronicPumpStatus.medtronicDeviceType != null // get() = medtronicPumpStatus.medtronicDeviceType != null
var medtronicPumpModel: MedtronicDeviceType? var medtronicPumpModel: MedtronicDeviceType
get() = medtronicPumpStatus.medtronicDeviceType get() = medtronicPumpStatus.medtronicDeviceType
set(medtronicPumpModel) { set(medtronicPumpModel) {
medtronicPumpStatus.medtronicDeviceType = medtronicPumpModel medtronicPumpStatus.medtronicDeviceType = medtronicPumpModel
@ -248,6 +247,7 @@ class MedtronicUtil @Inject constructor(
} }
companion object { companion object {
const val isLowLevelDebug = true const val isLowLevelDebug = true
fun getIntervalFromMinutes(minutes: Int): Int { fun getIntervalFromMinutes(minutes: Int): Int {
return minutes / 30 return minutes / 30