Medtrum: Remove unused, typo's and other lints
This commit is contained in:
parent
b2d9f1c39b
commit
275a7e39d8
|
@ -295,7 +295,7 @@ import kotlin.math.abs
|
||||||
val connectionOK = medtrumService?.setTempBasal(pumpRate, durationInMinutes) ?: false
|
val connectionOK = medtrumService?.setTempBasal(pumpRate, durationInMinutes) ?: false
|
||||||
if (connectionOK
|
if (connectionOK
|
||||||
&& medtrumPump.tempBasalInProgress
|
&& medtrumPump.tempBasalInProgress
|
||||||
&& Math.abs(medtrumPump.tempBasalAbsoluteRate - pumpRate) <= 0.05
|
&& abs(medtrumPump.tempBasalAbsoluteRate - pumpRate) <= 0.05
|
||||||
) {
|
) {
|
||||||
|
|
||||||
return PumpEnactResult(injector).success(true).enacted(true).duration(durationInMinutes).absolute(medtrumPump.tempBasalAbsoluteRate)
|
return PumpEnactResult(injector).success(true).enacted(true).duration(durationInMinutes).absolute(medtrumPump.tempBasalAbsoluteRate)
|
||||||
|
@ -436,7 +436,7 @@ import kotlin.math.abs
|
||||||
if (isInitialized()) {
|
if (isInitialized()) {
|
||||||
commandQueue.updateTime(object : Callback() {
|
commandQueue.updateTime(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (this.result.success == false) {
|
if (!this.result.success) {
|
||||||
aapsLogger.error(LTag.PUMP, "Medtrum time update failed")
|
aapsLogger.error(LTag.PUMP, "Medtrum time update failed")
|
||||||
// Only notify here on failure (connection may be failed), service will handle success
|
// Only notify here on failure (connection may be failed), service will handle success
|
||||||
medtrumService?.timeUpdateNotification(false)
|
medtrumService?.timeUpdateNotification(false)
|
||||||
|
|
|
@ -291,11 +291,11 @@ class MedtrumPump @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadUserSettingsFromSP() {
|
fun loadUserSettingsFromSP() {
|
||||||
desiredPatchExpiration = sp.getBoolean(info.nightscout.pump.medtrum.R.string.key_patch_expiration, false)
|
desiredPatchExpiration = sp.getBoolean(R.string.key_patch_expiration, false)
|
||||||
val alarmSettingCode = sp.getString(info.nightscout.pump.medtrum.R.string.key_alarm_setting, AlarmSetting.LIGHT_VIBRATE_AND_BEEP.code.toString()).toByte()
|
val alarmSettingCode = sp.getString(R.string.key_alarm_setting, AlarmSetting.LIGHT_VIBRATE_AND_BEEP.code.toString()).toByte()
|
||||||
desiredAlarmSetting = AlarmSetting.values().firstOrNull { it.code == alarmSettingCode } ?: AlarmSetting.LIGHT_VIBRATE_AND_BEEP
|
desiredAlarmSetting = AlarmSetting.values().firstOrNull { it.code == alarmSettingCode } ?: AlarmSetting.LIGHT_VIBRATE_AND_BEEP
|
||||||
desiredHourlyMaxInsulin = sp.getInt(info.nightscout.pump.medtrum.R.string.key_hourly_max_insulin, 40)
|
desiredHourlyMaxInsulin = sp.getInt(R.string.key_hourly_max_insulin, 40)
|
||||||
desiredDailyMaxInsulin = sp.getInt(info.nightscout.pump.medtrum.R.string.key_daily_max_insulin, 180)
|
desiredDailyMaxInsulin = sp.getInt(R.string.key_daily_max_insulin, 180)
|
||||||
_pumpSN = pumpSNFromSP
|
_pumpSN = pumpSNFromSP
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -502,12 +502,12 @@ class MedtrumPump @Inject constructor(
|
||||||
AlarmState.PUMP_LOW_BATTERY -> R.string.alarm_pump_low_battery
|
AlarmState.PUMP_LOW_BATTERY -> R.string.alarm_pump_low_battery
|
||||||
AlarmState.PUMP_LOW_RESERVOIR -> R.string.alarm_pump_low_reservoir
|
AlarmState.PUMP_LOW_RESERVOIR -> R.string.alarm_pump_low_reservoir
|
||||||
AlarmState.PUMP_EXPIRES_SOON -> R.string.alarm_pump_expires_soon
|
AlarmState.PUMP_EXPIRES_SOON -> R.string.alarm_pump_expires_soon
|
||||||
AlarmState.LOWBG_SUSPENDED -> R.string.alarm_lowbg_suspended
|
AlarmState.LOW_BG_SUSPENDED -> R.string.alarm_low_bg_suspended
|
||||||
AlarmState.LOWBG_SUSPENDED2 -> R.string.alarm_lowbg_suspended2
|
AlarmState.LOW_BG_SUSPENDED2 -> R.string.alarm_low_bg_suspended2
|
||||||
AlarmState.AUTO_SUSPENDED -> R.string.alarm_auto_suspended
|
AlarmState.AUTO_SUSPENDED -> R.string.alarm_auto_suspended
|
||||||
AlarmState.HMAX_SUSPENDED -> R.string.alarm_hmax_suspended
|
AlarmState.HOURLY_MAX_SUSPENDED -> R.string.alarm_hourly_max_suspended
|
||||||
AlarmState.DMAX_SUSPENDED -> R.string.alarm_dmax_suspended
|
AlarmState.DAILY_MAX_SUSPENDED -> R.string.alarm_daily_max_suspended
|
||||||
AlarmState.SUSPENDED -> R.string.alarm_suspended
|
AlarmState.SUSPENDED -> R.string.alarm_suspended
|
||||||
AlarmState.PAUSED -> R.string.alarm_paused
|
AlarmState.PAUSED -> R.string.alarm_paused
|
||||||
AlarmState.OCCLUSION -> R.string.alarm_occlusion
|
AlarmState.OCCLUSION -> R.string.alarm_occlusion
|
||||||
AlarmState.EXPIRED -> R.string.alarm_expired
|
AlarmState.EXPIRED -> R.string.alarm_expired
|
||||||
|
@ -528,10 +528,10 @@ class MedtrumPump @Inject constructor(
|
||||||
|
|
||||||
private fun loadActiveAlarms() {
|
private fun loadActiveAlarms() {
|
||||||
val alarmsStr = sp.getString(R.string.key_active_alarms, "")
|
val alarmsStr = sp.getString(R.string.key_active_alarms, "")
|
||||||
if (alarmsStr.isNullOrEmpty()) {
|
activeAlarms = if (alarmsStr.isEmpty()) {
|
||||||
activeAlarms = EnumSet.noneOf(AlarmState::class.java)
|
EnumSet.noneOf(AlarmState::class.java)
|
||||||
} else {
|
} else {
|
||||||
activeAlarms = alarmsStr.split(",")
|
alarmsStr.split(",")
|
||||||
.mapNotNull { AlarmState.values().find { alarm -> alarm.name == it } }
|
.mapNotNull { AlarmState.values().find { alarm -> alarm.name == it } }
|
||||||
.let { EnumSet.copyOf(it) }
|
.let { EnumSet.copyOf(it) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,7 @@
|
||||||
package info.nightscout.pump.medtrum.bindingadapters
|
package info.nightscout.pump.medtrum.bindingadapters
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.annotation.ColorRes
|
|
||||||
import androidx.databinding.BindingAdapter
|
import androidx.databinding.BindingAdapter
|
||||||
import info.nightscout.pump.medtrum.extension.setVisibleOrGone
|
|
||||||
|
|
||||||
@BindingAdapter("android:visibility")
|
|
||||||
fun setVisibility(view: View, visible: Boolean) {
|
|
||||||
view.setVisibleOrGone(visible)
|
|
||||||
}
|
|
||||||
|
|
||||||
@BindingAdapter("visibleOrGone")
|
|
||||||
fun setVisibleOrGone(view: View, visibleOrGone: Boolean) {
|
|
||||||
view.setVisibleOrGone(visibleOrGone)
|
|
||||||
}
|
|
||||||
|
|
||||||
@BindingAdapter("onSafeClick")
|
@BindingAdapter("onSafeClick")
|
||||||
fun View.setOnSafeClickListener(clickListener: View.OnClickListener?) {
|
fun View.setOnSafeClickListener(clickListener: View.OnClickListener?) {
|
||||||
|
@ -22,8 +9,3 @@ fun View.setOnSafeClickListener(clickListener: View.OnClickListener?) {
|
||||||
setOnClickListener(OnSafeClickListener(it))
|
setOnClickListener(OnSafeClickListener(it))
|
||||||
} ?: setOnClickListener(null)
|
} ?: setOnClickListener(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
@BindingAdapter("textColor")
|
|
||||||
fun setTextColor(view: TextView, @ColorRes colorResId: Int) {
|
|
||||||
view.setTextColor(view.context.getColor(colorResId))
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package info.nightscout.pump.medtrum.comm
|
||||||
import kotlin.experimental.and
|
import kotlin.experimental.and
|
||||||
import info.nightscout.pump.medtrum.extension.toLong
|
import info.nightscout.pump.medtrum.extension.toLong
|
||||||
|
|
||||||
class ManufacturerData(private val manufacturerDataBytes: ByteArray) {
|
class ManufacturerData(manufacturerDataBytes: ByteArray) {
|
||||||
private var deviceID: Long = 0
|
private var deviceID: Long = 0
|
||||||
private var deviceType = 0
|
private var deviceType = 0
|
||||||
private var version = 0
|
private var version = 0
|
||||||
|
@ -12,7 +12,7 @@ class ManufacturerData(private val manufacturerDataBytes: ByteArray) {
|
||||||
setData(manufacturerDataBytes)
|
setData(manufacturerDataBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setData(inputData: ByteArray) {
|
private fun setData(inputData: ByteArray) {
|
||||||
var index = 0
|
var index = 0
|
||||||
val deviceIDBytes: ByteArray = inputData.copyOfRange(index, index + 4)
|
val deviceIDBytes: ByteArray = inputData.copyOfRange(index, index + 4)
|
||||||
deviceID = deviceIDBytes.toLong()
|
deviceID = deviceIDBytes.toLong()
|
||||||
|
|
|
@ -9,21 +9,20 @@ class WriteCommandPackets(data: ByteArray, sequenceNumber: Int) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// PackageIndex: 0 initially, if there are multiple packets, for the first packet it is set to 0 (not included in CRC calculation but sent in actual header)
|
// PackageIndex: 0 initially, if there are multiple packets, for the first packet it is set to 0 (not included in CRC calculation but sent in actual header)
|
||||||
var pkgIndex = 0
|
val header = byteArrayOf(
|
||||||
var header = byteArrayOf(
|
|
||||||
(data.size + 4).toByte(),
|
(data.size + 4).toByte(),
|
||||||
data[0],
|
data[0],
|
||||||
sequenceNumber.toByte(),
|
sequenceNumber.toByte(),
|
||||||
pkgIndex.toByte()
|
0.toByte() // pkgIndex
|
||||||
)
|
)
|
||||||
|
|
||||||
var tmp: ByteArray = header + data.copyOfRange(1, data.size)
|
var tmp: ByteArray = header + data.copyOfRange(1, data.size)
|
||||||
var totalCommand: ByteArray = tmp + calcCrc8(tmp, tmp.size).toByte()
|
val totalCommand: ByteArray = tmp + calcCrc8(tmp, tmp.size).toByte()
|
||||||
|
|
||||||
if ((totalCommand.size - header.size) <= 15) {
|
if ((totalCommand.size - header.size) <= 15) {
|
||||||
packages.add(totalCommand + 0.toByte())
|
packages.add(totalCommand + 0.toByte())
|
||||||
} else {
|
} else {
|
||||||
pkgIndex = 1
|
var pkgIndex = 1
|
||||||
var remainingCommand = totalCommand.copyOfRange(4, totalCommand.size)
|
var remainingCommand = totalCommand.copyOfRange(4, totalCommand.size)
|
||||||
|
|
||||||
while (remainingCommand.size > 15) {
|
while (remainingCommand.size > 15) {
|
||||||
|
@ -52,13 +51,13 @@ class WriteCommandPackets(data: ByteArray, sequenceNumber: Int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun allPacketsConsumed(): Boolean {
|
fun allPacketsConsumed(): Boolean {
|
||||||
return !(index < packages.size)
|
return index >= packages.size
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calcCrc8(value: ByteArray, size: Int): Int {
|
private fun calcCrc8(value: ByteArray, size: Int): Int {
|
||||||
var crc8 = 0
|
var crc8 = 0
|
||||||
for (i in 0 until size) {
|
for (i in 0 until size) {
|
||||||
crc8 = CRC_8_TABLE[(value[i].toInt() and 255) xor (crc8 and 255)].toInt() and 255
|
crc8 = CRC_8_TABLE[(value[i].toInt() and 255) xor (crc8 and 255)] and 255
|
||||||
}
|
}
|
||||||
return crc8
|
return crc8
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ enum class AlarmState {
|
||||||
PUMP_LOW_BATTERY, // Mapped from error flag 1
|
PUMP_LOW_BATTERY, // Mapped from error flag 1
|
||||||
PUMP_LOW_RESERVOIR, // Mapped from error flag 2
|
PUMP_LOW_RESERVOIR, // Mapped from error flag 2
|
||||||
PUMP_EXPIRES_SOON, // Mapped from error flag 3
|
PUMP_EXPIRES_SOON, // Mapped from error flag 3
|
||||||
LOWBG_SUSPENDED, // Mapped from pump status 64
|
LOW_BG_SUSPENDED, // Mapped from pump status 64
|
||||||
LOWBG_SUSPENDED2, // Mapped from pump status 65
|
LOW_BG_SUSPENDED2, // Mapped from pump status 65
|
||||||
AUTO_SUSPENDED, // Mapped from pump status 66
|
AUTO_SUSPENDED, // Mapped from pump status 66
|
||||||
HMAX_SUSPENDED, // Mapped from pump status 67
|
HOURLY_MAX_SUSPENDED, // Mapped from pump status 67
|
||||||
DMAX_SUSPENDED, // Mapped from pump status 68
|
DAILY_MAX_SUSPENDED, // Mapped from pump status 68
|
||||||
SUSPENDED, // Mapped from pump status 69
|
SUSPENDED, // Mapped from pump status 69
|
||||||
PAUSED, // Mapped from pump status 70
|
PAUSED, // Mapped from pump status 70
|
||||||
OCCLUSION, // Mapped from pump status 96
|
OCCLUSION, // Mapped from pump status 96
|
||||||
|
|
|
@ -10,11 +10,11 @@ enum class MedtrumPumpState(val state: Byte) {
|
||||||
EJECTED(6),
|
EJECTED(6),
|
||||||
ACTIVE(32),
|
ACTIVE(32),
|
||||||
ACTIVE_ALT(33),
|
ACTIVE_ALT(33),
|
||||||
LOWBG_SUSPENDED(64),
|
LOW_BG_SUSPENDED(64),
|
||||||
LOWBG_SUSPENDED2(65),
|
LOW_BG_SUSPENDED2(65),
|
||||||
AUTO_SUSPENDED(66),
|
AUTO_SUSPENDED(66),
|
||||||
HMAX_SUSPENDED(67),
|
HOURLY_MAX_SUSPENDED(67),
|
||||||
DMAX_SUSPENDED(68),
|
DAILY_MAX_SUSPENDED(68),
|
||||||
SUSPENDED(69),
|
SUSPENDED(69),
|
||||||
PAUSED(70),
|
PAUSED(70),
|
||||||
OCCLUSION(96),
|
OCCLUSION(96),
|
||||||
|
@ -28,6 +28,7 @@ enum class MedtrumPumpState(val state: Byte) {
|
||||||
STOPPED(128.toByte());
|
STOPPED(128.toByte());
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun fromByte(state: Byte) = values().find { it.state == state }
|
fun fromByte(state: Byte) = values().find { it.state == state }
|
||||||
?: throw IllegalAccessException("")
|
?: throw IllegalAccessException("")
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ class ActivatePacket(injector: HasAndroidInjector, private val basalProfile: Byt
|
||||||
* byte 6: predictiveLowSuspend // Value for auto mode, not used for AAPS
|
* byte 6: predictiveLowSuspend // Value for auto mode, not used for AAPS
|
||||||
* byte 7: predictiveLowSuspendRange // Value for auto mode, not used for AAPS
|
* byte 7: predictiveLowSuspendRange // Value for auto mode, not used for AAPS
|
||||||
* byte 8-9: hourlyMaxInsulin // Max hourly dose of insulin, divided by 0.05
|
* byte 8-9: hourlyMaxInsulin // Max hourly dose of insulin, divided by 0.05
|
||||||
* byte 10-11: daylyMaxSet // Max daily dose of insulin, divided by 0.05
|
* byte 10-11: dailyMaxSet // Max daily dose of insulin, divided by 0.05
|
||||||
* byte 12-13: tddToday // Current TDD (of present day), divided by 0.05
|
* byte 12-13: tddToday // Current TDD (of present day), divided by 0.05
|
||||||
* byte 14: 1 // Always 1
|
* byte 14: 1 // Always 1
|
||||||
* bytes 15 - end // Basal profile > see MedtrumPump
|
* bytes 15 - end // Basal profile > see MedtrumPump
|
||||||
|
@ -98,7 +98,7 @@ class ActivatePacket(injector: HasAndroidInjector, private val basalProfile: Byt
|
||||||
medtrumPump.currentSequenceNumber = basalSequence // We are activated, set the new seq nr
|
medtrumPump.currentSequenceNumber = basalSequence // We are activated, set the new seq nr
|
||||||
medtrumPump.syncedSequenceNumber = basalSequence // We are activated, reset the synced seq nr ()
|
medtrumPump.syncedSequenceNumber = basalSequence // We are activated, reset the synced seq nr ()
|
||||||
|
|
||||||
// Sync canula change
|
// Sync cannula change
|
||||||
pumpSync.insertTherapyEventIfNewWithTimestamp(
|
pumpSync.insertTherapyEventIfNewWithTimestamp(
|
||||||
timestamp = System.currentTimeMillis(),
|
timestamp = System.currentTimeMillis(),
|
||||||
type = DetailedBolusInfo.EventType.CANNULA_CHANGE,
|
type = DetailedBolusInfo.EventType.CANNULA_CHANGE,
|
||||||
|
|
|
@ -7,7 +7,6 @@ import info.nightscout.pump.medtrum.comm.enums.BasalType
|
||||||
import info.nightscout.pump.medtrum.extension.toInt
|
import info.nightscout.pump.medtrum.extension.toInt
|
||||||
import info.nightscout.pump.medtrum.extension.toLong
|
import info.nightscout.pump.medtrum.extension.toLong
|
||||||
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
||||||
import info.nightscout.rx.logging.LTag
|
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.comm.enums.CommandType.CLEAR_ALARM
|
import info.nightscout.pump.medtrum.comm.enums.CommandType.CLEAR_ALARM
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
import info.nightscout.pump.medtrum.extension.toByteArray
|
||||||
|
|
||||||
class ClearPumpAlarmPacket(injector: HasAndroidInjector, val clearType: Int) : MedtrumPacket(injector) {
|
class ClearPumpAlarmPacket(injector: HasAndroidInjector, private val clearType: Int) : MedtrumPacket(injector) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
opCode = CLEAR_ALARM.code
|
opCode = CLEAR_ALARM.code
|
||||||
|
|
|
@ -15,7 +15,6 @@ import info.nightscout.pump.medtrum.extension.toLong
|
||||||
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int) : MedtrumPacket(injector) {
|
class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int) : MedtrumPacket(injector) {
|
||||||
|
@ -38,9 +37,9 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
||||||
private const val RESP_RECORD_UNKNOWN1_END = RESP_RECORD_UNKNOWN1_START + 1
|
private const val RESP_RECORD_UNKNOWN1_END = RESP_RECORD_UNKNOWN1_START + 1
|
||||||
private const val RESP_RECORD_SERIAL_START = RESP_RECORD_UNKNOWN1_END
|
private const val RESP_RECORD_SERIAL_START = RESP_RECORD_UNKNOWN1_END
|
||||||
private const val RESP_RECORD_SERIAL_END = RESP_RECORD_SERIAL_START + 4
|
private const val RESP_RECORD_SERIAL_END = RESP_RECORD_SERIAL_START + 4
|
||||||
private const val RESP_RECORD_PATCHID_START = RESP_RECORD_SERIAL_END
|
private const val RESP_RECORD_PATCH_ID_START = RESP_RECORD_SERIAL_END
|
||||||
private const val RESP_RECORD_PATCHID_END = RESP_RECORD_PATCHID_START + 2
|
private const val RESP_RECORD_PATCH_ID_END = RESP_RECORD_PATCH_ID_START + 2
|
||||||
private const val RESP_RECORD_SEQUENCE_START = RESP_RECORD_PATCHID_END
|
private const val RESP_RECORD_SEQUENCE_START = RESP_RECORD_PATCH_ID_END
|
||||||
private const val RESP_RECORD_SEQUENCE_END = RESP_RECORD_SEQUENCE_START + 2
|
private const val RESP_RECORD_SEQUENCE_END = RESP_RECORD_SEQUENCE_START + 2
|
||||||
private const val RESP_RECORD_DATA_START = RESP_RECORD_SEQUENCE_END
|
private const val RESP_RECORD_DATA_START = RESP_RECORD_SEQUENCE_END
|
||||||
|
|
||||||
|
@ -75,7 +74,7 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
||||||
val recordUnknown = data.copyOfRange(RESP_RECORD_UNKNOWN_START, RESP_RECORD_UNKNOWN_END).toInt()
|
val recordUnknown = data.copyOfRange(RESP_RECORD_UNKNOWN_START, RESP_RECORD_UNKNOWN_END).toInt()
|
||||||
val recordType = data.copyOfRange(RESP_RECORD_TYPE_START, RESP_RECORD_TYPE_END).toInt()
|
val recordType = data.copyOfRange(RESP_RECORD_TYPE_START, RESP_RECORD_TYPE_END).toInt()
|
||||||
val recordSerial = data.copyOfRange(RESP_RECORD_SERIAL_START, RESP_RECORD_SERIAL_END).toLong()
|
val recordSerial = data.copyOfRange(RESP_RECORD_SERIAL_START, RESP_RECORD_SERIAL_END).toLong()
|
||||||
val recordPatchId = data.copyOfRange(RESP_RECORD_PATCHID_START, RESP_RECORD_PATCHID_END).toInt()
|
val recordPatchId = data.copyOfRange(RESP_RECORD_PATCH_ID_START, RESP_RECORD_PATCH_ID_END).toInt()
|
||||||
val recordSequence = data.copyOfRange(RESP_RECORD_SEQUENCE_START, RESP_RECORD_SEQUENCE_END).toInt()
|
val recordSequence = data.copyOfRange(RESP_RECORD_SEQUENCE_START, RESP_RECORD_SEQUENCE_END).toInt()
|
||||||
|
|
||||||
aapsLogger.debug(
|
aapsLogger.debug(
|
||||||
|
@ -101,13 +100,15 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
||||||
val bolusCarb = data.copyOfRange(RESP_RECORD_DATA_START + 18, RESP_RECORD_DATA_START + 20).toInt()
|
val bolusCarb = data.copyOfRange(RESP_RECORD_DATA_START + 18, RESP_RECORD_DATA_START + 20).toInt()
|
||||||
val bolusGlucose = data.copyOfRange(RESP_RECORD_DATA_START + 20, RESP_RECORD_DATA_START + 22).toInt()
|
val bolusGlucose = data.copyOfRange(RESP_RECORD_DATA_START + 20, RESP_RECORD_DATA_START + 22).toInt()
|
||||||
val bolusIOB = data.copyOfRange(RESP_RECORD_DATA_START + 22, RESP_RECORD_DATA_START + 24).toInt()
|
val bolusIOB = data.copyOfRange(RESP_RECORD_DATA_START + 22, RESP_RECORD_DATA_START + 24).toInt()
|
||||||
val unkown1 = data.copyOfRange(RESP_RECORD_DATA_START + 24, RESP_RECORD_DATA_START + 26).toInt()
|
val unknown1 = data.copyOfRange(RESP_RECORD_DATA_START + 24, RESP_RECORD_DATA_START + 26).toInt()
|
||||||
val unkown2 = data.copyOfRange(RESP_RECORD_DATA_START + 26, RESP_RECORD_DATA_START + 28).toInt()
|
val unknown2 = data.copyOfRange(RESP_RECORD_DATA_START + 26, RESP_RECORD_DATA_START + 28).toInt()
|
||||||
val bolusType = enumValues<BolusType>()[typeAndWizard and 0x0F]
|
val bolusType = enumValues<BolusType>()[typeAndWizard and 0x0F]
|
||||||
val bolusWizard = (typeAndWizard and 0xF0) != 0
|
val bolusWizard = (typeAndWizard and 0xF0) != 0
|
||||||
aapsLogger.debug(
|
aapsLogger.debug(
|
||||||
LTag.PUMPCOMM,
|
LTag.PUMPCOMM,
|
||||||
"GetRecordPacket HandleResponse: BOLUS_RECORD: typeAndWizard: $typeAndWizard, bolusCause: $bolusCause, unknown: $unknown, bolusStartTime: $bolusStartTime, " + "bolusNormalAmount: $bolusNormalAmount, bolusNormalDelivered: $bolusNormalDelivered, bolusExtendedAmount: $bolusExtendedAmount, bolusExtendedDuration: $bolusExtendedDuration, " + "bolusExtendedDelivered: $bolusExtendedDelivered, bolusCarb: $bolusCarb, bolusGlucose: $bolusGlucose, bolusIOB: $bolusIOB, unkown1: $unkown1, unkown2: $unkown2, " + "bolusType: $bolusType, bolusWizard: $bolusWizard"
|
"GetRecordPacket HandleResponse: BOLUS_RECORD: typeAndWizard: $typeAndWizard, bolusCause: $bolusCause, unknown: $unknown, bolusStartTime: $bolusStartTime, " +
|
||||||
|
"bolusNormalAmount: $bolusNormalAmount, bolusNormalDelivered: $bolusNormalDelivered, bolusExtendedAmount: $bolusExtendedAmount, bolusExtendedDuration: " +
|
||||||
|
"$bolusExtendedDuration, " + "bolusExtendedDelivered: $bolusExtendedDelivered, bolusCarb: $bolusCarb, bolusGlucose: $bolusGlucose, bolusIOB: $bolusIOB, unknown1: $unknown1, unknown2: $unknown2, " + "bolusType: $bolusType, bolusWizard: $bolusWizard"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (bolusType == BolusType.NORMAL) {
|
if (bolusType == BolusType.NORMAL) {
|
||||||
|
@ -123,7 +124,7 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
||||||
pumpType = medtrumPump.pumpType(),
|
pumpType = medtrumPump.pumpType(),
|
||||||
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
|
pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
|
||||||
)
|
)
|
||||||
if (syncOk == false) {
|
if (!syncOk) {
|
||||||
aapsLogger.warn(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: BOLUS_RECORD: Failed to sync bolus with tempId: ${detailedBolusInfo.timestamp}")
|
aapsLogger.warn(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: BOLUS_RECORD: Failed to sync bolus with tempId: ${detailedBolusInfo.timestamp}")
|
||||||
// detailedInfo can be from another similar record. Reinsert
|
// detailedInfo can be from another similar record. Reinsert
|
||||||
detailedBolusInfoStorage.add(detailedBolusInfo)
|
detailedBolusInfoStorage.add(detailedBolusInfo)
|
||||||
|
@ -298,7 +299,7 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: TDD_RECORD")
|
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: TDD_RECORD")
|
||||||
val timestamp = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(RESP_RECORD_DATA_START, RESP_RECORD_DATA_START + 4).toLong())
|
val timestamp = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(RESP_RECORD_DATA_START, RESP_RECORD_DATA_START + 4).toLong())
|
||||||
val timeZoneOffset = data.copyOfRange(RESP_RECORD_DATA_START + 4, RESP_RECORD_DATA_START + 6).toInt()
|
val timeZoneOffset = data.copyOfRange(RESP_RECORD_DATA_START + 4, RESP_RECORD_DATA_START + 6).toInt()
|
||||||
val tddMins = data.copyOfRange(RESP_RECORD_DATA_START + 6, RESP_RECORD_DATA_START + 8).toInt()
|
val tddMinutes = data.copyOfRange(RESP_RECORD_DATA_START + 6, RESP_RECORD_DATA_START + 8).toInt()
|
||||||
val glucoseRecordTime = data.copyOfRange(RESP_RECORD_DATA_START + 8, RESP_RECORD_DATA_START + 12).toLong()
|
val glucoseRecordTime = data.copyOfRange(RESP_RECORD_DATA_START + 8, RESP_RECORD_DATA_START + 12).toLong()
|
||||||
val tdd = data.copyOfRange(RESP_RECORD_DATA_START + 12, RESP_RECORD_DATA_START + 16).toFloat()
|
val tdd = data.copyOfRange(RESP_RECORD_DATA_START + 12, RESP_RECORD_DATA_START + 16).toFloat()
|
||||||
val basalTdd = data.copyOfRange(RESP_RECORD_DATA_START + 16, RESP_RECORD_DATA_START + 20).toFloat()
|
val basalTdd = data.copyOfRange(RESP_RECORD_DATA_START + 16, RESP_RECORD_DATA_START + 20).toFloat()
|
||||||
|
@ -315,7 +316,7 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
||||||
val newUMax = data.copyOfRange(RESP_RECORD_DATA_START + 60, RESP_RECORD_DATA_START + 64).toFloat()
|
val newUMax = data.copyOfRange(RESP_RECORD_DATA_START + 60, RESP_RECORD_DATA_START + 64).toFloat()
|
||||||
|
|
||||||
aapsLogger.debug(
|
aapsLogger.debug(
|
||||||
LTag.PUMPCOMM, "TDD_RECORD: timestamp: $timestamp, timeZoneOffset: $timeZoneOffset, tddMins: $tddMins, glucoseRecordTime: $glucoseRecordTime, tdd: " +
|
LTag.PUMPCOMM, "TDD_RECORD: timestamp: $timestamp, timeZoneOffset: $timeZoneOffset, tddMinutes: $tddMinutes, glucoseRecordTime: $glucoseRecordTime, tdd: " +
|
||||||
"$tdd, basalTdd: $basalTdd, glucose: $glucose, unknown: $unknown, meanSomething: $meanSomething, usedTdd: $usedTdd, usedIBasal: $usedIBasal, usedSgBasal: " +
|
"$tdd, basalTdd: $basalTdd, glucose: $glucose, unknown: $unknown, meanSomething: $meanSomething, usedTdd: $usedTdd, usedIBasal: $usedIBasal, usedSgBasal: " +
|
||||||
"$usedSgBasal, usedUMax: $usedUMax, newTdd: $newTdd, newIBasal: $newIBasal, newSgBasal: $newSgBasal, newUMax: $newUMax"
|
"$usedSgBasal, usedUMax: $usedUMax, newTdd: $newTdd, newIBasal: $newIBasal, newSgBasal: $newSgBasal, newUMax: $newUMax"
|
||||||
)
|
)
|
||||||
|
|
|
@ -25,7 +25,7 @@ open class MedtrumPacket(protected var injector: HasAndroidInjector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// @Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
injector.androidInjector().inject(this)
|
injector.androidInjector().inject(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ open class MedtrumPacket(protected var injector: HasAndroidInjector) {
|
||||||
return byteArrayOf(opCode)
|
return byteArrayOf(opCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** handles a response from the Medtrum pump, returns true if command was successfull, returns false if command failed or waiting for response */
|
/** handles a response from the Medtrum pump, returns true if command was successful, returns false if command failed or waiting for response */
|
||||||
open fun handleResponse(data: ByteArray): Boolean {
|
open fun handleResponse(data: ByteArray): Boolean {
|
||||||
// Check for broken packets
|
// Check for broken packets
|
||||||
if (RESP_RESULT_END > data.size) {
|
if (RESP_RESULT_END > data.size) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
||||||
* but a notification packet. It is sent by the pump to the phone
|
* but a notification packet. It is sent by the pump to the phone
|
||||||
* when the pump has a notification to send.
|
* when the pump has a notification to send.
|
||||||
*
|
*
|
||||||
* Notifications are sent regualary, regardless of the pump state.
|
* Notifications are sent regularly, regardless of the pump state.
|
||||||
*
|
*
|
||||||
* There can be multiple messages in one packet, this is noted by the fieldMask.
|
* There can be multiple messages in one packet, this is noted by the fieldMask.
|
||||||
*
|
*
|
||||||
|
@ -97,10 +97,10 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
||||||
|
|
||||||
if (fieldMask and MASK_NORMAL_BOLUS != 0) {
|
if (fieldMask and MASK_NORMAL_BOLUS != 0) {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Normal bolus notification received")
|
aapsLogger.debug(LTag.PUMPCOMM, "Normal bolus notification received")
|
||||||
var bolusData = data.copyOfRange(offset, offset + 1).toInt()
|
val bolusData = data.copyOfRange(offset, offset + 1).toInt()
|
||||||
var bolusType = bolusData and 0x7F
|
val bolusType = bolusData and 0x7F
|
||||||
val bolusCompleted: Boolean = ((bolusData shr 7) and 0x01) != 0
|
val bolusCompleted: Boolean = ((bolusData shr 7) and 0x01) != 0
|
||||||
var bolusDelivered = data.copyOfRange(offset + 1, offset + 3).toInt() * 0.05
|
val bolusDelivered = data.copyOfRange(offset + 1, offset + 3).toInt() * 0.05
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Bolus type: $bolusType, bolusData: $bolusData bolus completed: $bolusCompleted, bolus delivered: $bolusDelivered")
|
aapsLogger.debug(LTag.PUMPCOMM, "Bolus type: $bolusType, bolusData: $bolusData bolus completed: $bolusCompleted, bolus delivered: $bolusDelivered")
|
||||||
medtrumPump.handleBolusStatusUpdate(bolusType, bolusCompleted, bolusDelivered)
|
medtrumPump.handleBolusStatusUpdate(bolusType, bolusCompleted, bolusDelivered)
|
||||||
offset += 3
|
offset += 3
|
||||||
|
@ -115,12 +115,12 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
||||||
if (fieldMask and MASK_BASAL != 0) {
|
if (fieldMask and MASK_BASAL != 0) {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Basal notification received")
|
aapsLogger.debug(LTag.PUMPCOMM, "Basal notification received")
|
||||||
val basalType = enumValues<BasalType>()[data.copyOfRange(offset, offset + 1).toInt()]
|
val basalType = enumValues<BasalType>()[data.copyOfRange(offset, offset + 1).toInt()]
|
||||||
var basalSequence = data.copyOfRange(offset + 1, offset + 3).toInt()
|
val basalSequence = data.copyOfRange(offset + 1, offset + 3).toInt()
|
||||||
var basalPatchId = data.copyOfRange(offset + 3, offset + 5).toLong()
|
val basalPatchId = data.copyOfRange(offset + 3, offset + 5).toLong()
|
||||||
var basalStartTime = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(offset + 5, offset + 9).toLong())
|
val basalStartTime = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(offset + 5, offset + 9).toLong())
|
||||||
var basalRateAndDelivery = data.copyOfRange(offset + 9, offset + 12).toInt()
|
val basalRateAndDelivery = data.copyOfRange(offset + 9, offset + 12).toInt()
|
||||||
var basalRate = (basalRateAndDelivery and 0xFFF) * 0.05
|
val basalRate = (basalRateAndDelivery and 0xFFF) * 0.05
|
||||||
var basalDelivery = (basalRateAndDelivery shr 12) * 0.05
|
val basalDelivery = (basalRateAndDelivery shr 12) * 0.05
|
||||||
aapsLogger.debug(
|
aapsLogger.debug(
|
||||||
LTag.PUMPCOMM,
|
LTag.PUMPCOMM,
|
||||||
"Basal type: $basalType, basal sequence: $basalSequence, basal patch id: $basalPatchId, basal time: $basalStartTime, basal rate: $basalRate, basal delivery: $basalDelivery"
|
"Basal type: $basalType, basal sequence: $basalSequence, basal patch id: $basalPatchId, basal time: $basalStartTime, basal rate: $basalRate, basal delivery: $basalDelivery"
|
||||||
|
@ -159,7 +159,7 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
||||||
|
|
||||||
if (fieldMask and MASK_BATTERY != 0) {
|
if (fieldMask and MASK_BATTERY != 0) {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Battery notification received")
|
aapsLogger.debug(LTag.PUMPCOMM, "Battery notification received")
|
||||||
var parameter = data.copyOfRange(offset, offset + 3).toInt()
|
val parameter = data.copyOfRange(offset, offset + 3).toInt()
|
||||||
// Precision for voltage A is a guess, voltage B is the important one, threshold: < 2.64
|
// Precision for voltage A is a guess, voltage B is the important one, threshold: < 2.64
|
||||||
medtrumPump.batteryVoltage_A = (parameter and 0xFFF) / 512.0
|
medtrumPump.batteryVoltage_A = (parameter and 0xFFF) / 512.0
|
||||||
medtrumPump.batteryVoltage_B = (parameter shr 12) / 512.0
|
medtrumPump.batteryVoltage_B = (parameter shr 12) / 512.0
|
||||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.pump.medtrum.comm.packets
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.comm.enums.CommandType.RESUME_PUMP
|
import info.nightscout.pump.medtrum.comm.enums.CommandType.RESUME_PUMP
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
|
||||||
|
|
||||||
class ResumePumpPacket(injector: HasAndroidInjector) : MedtrumPacket(injector) {
|
class ResumePumpPacket(injector: HasAndroidInjector) : MedtrumPacket(injector) {
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class SetTimeZonePacket(injector: HasAndroidInjector) : MedtrumPacket(injector)
|
||||||
@Inject lateinit var dateUtil: DateUtil
|
@Inject lateinit var dateUtil: DateUtil
|
||||||
@Inject lateinit var medtrumPump: MedtrumPump
|
@Inject lateinit var medtrumPump: MedtrumPump
|
||||||
|
|
||||||
var offsetMins: Int = 0
|
private var offsetMinutes: Int = 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
opCode = SET_TIME_ZONE.code
|
opCode = SET_TIME_ZONE.code
|
||||||
|
@ -21,15 +21,15 @@ class SetTimeZonePacket(injector: HasAndroidInjector) : MedtrumPacket(injector)
|
||||||
|
|
||||||
override fun getRequest(): ByteArray {
|
override fun getRequest(): ByteArray {
|
||||||
val time = MedtrumTimeUtil().getCurrentTimePumpSeconds()
|
val time = MedtrumTimeUtil().getCurrentTimePumpSeconds()
|
||||||
offsetMins = dateUtil.getTimeZoneOffsetMinutes(dateUtil.now())
|
offsetMinutes = dateUtil.getTimeZoneOffsetMinutes(dateUtil.now())
|
||||||
if (offsetMins < 0) offsetMins += 65536
|
if (offsetMinutes < 0) offsetMinutes += 65536
|
||||||
return byteArrayOf(opCode) + offsetMins.toByteArray(2) + time.toByteArray(4)
|
return byteArrayOf(opCode) + offsetMinutes.toByteArray(2) + time.toByteArray(4)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleResponse(data: ByteArray): Boolean {
|
override fun handleResponse(data: ByteArray): Boolean {
|
||||||
val success = super.handleResponse(data)
|
val success = super.handleResponse(data)
|
||||||
if (success) {
|
if (success) {
|
||||||
medtrumPump.pumpTimeZoneOffset = offsetMins
|
medtrumPump.pumpTimeZoneOffset = offsetMinutes
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ class SynchronizePacket(injector: HasAndroidInjector) : MedtrumPacket(injector)
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val RESP_STATE_START = 6
|
private const val RESP_STATE_START = 6
|
||||||
private const val RESP_STATE_END = RESP_STATE_START + 1
|
|
||||||
private const val RESP_FIELDS_START = 7
|
private const val RESP_FIELDS_START = 7
|
||||||
private const val RESP_FIELDS_END = RESP_FIELDS_START + 2
|
private const val RESP_FIELDS_END = RESP_FIELDS_START + 2
|
||||||
private const val RESP_SYNC_DATA_START = 9
|
private const val RESP_SYNC_DATA_START = 9
|
||||||
|
@ -34,7 +33,7 @@ class SynchronizePacket(injector: HasAndroidInjector) : MedtrumPacket(injector)
|
||||||
override fun handleResponse(data: ByteArray): Boolean {
|
override fun handleResponse(data: ByteArray): Boolean {
|
||||||
val success = super.handleResponse(data)
|
val success = super.handleResponse(data)
|
||||||
if (success) {
|
if (success) {
|
||||||
var state = MedtrumPumpState.fromByte(data[RESP_STATE_START])
|
val state = MedtrumPumpState.fromByte(data[RESP_STATE_START])
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "SynchronizePacket: state: $state")
|
aapsLogger.debug(LTag.PUMPCOMM, "SynchronizePacket: state: $state")
|
||||||
if (state != medtrumPump.pumpState) {
|
if (state != medtrumPump.pumpState) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Crypt {
|
||||||
private val RIJNDEAL_S_BOX: IntArray = intArrayOf(99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192, 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, 216, 49, 21, 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, 235, 39, 178, 117, 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, 179, 41, 227, 47, 132, 83, 209, 0, 237, 32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88, 207, 208, 239, 170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159, 168, 81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 255, 243, 210, 205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61, 100, 93, 25, 115, 96, 129, 79, 220, 34, 42, 144, 136, 70, 238, 184, 20, 222, 94, 11, 219, 224, 50, 58, 10, 73, 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121, 231, 200, 55, 109, 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8, 186, 120, 37, 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, 112, 62, 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158, 225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223, 140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, 22)
|
private val RIJNDEAL_S_BOX: IntArray = intArrayOf(99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192, 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, 216, 49, 21, 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, 235, 39, 178, 117, 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, 179, 41, 227, 47, 132, 83, 209, 0, 237, 32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88, 207, 208, 239, 170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159, 168, 81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 255, 243, 210, 205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61, 100, 93, 25, 115, 96, 129, 79, 220, 34, 42, 144, 136, 70, 238, 184, 20, 222, 94, 11, 219, 224, 50, 58, 10, 73, 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121, 231, 200, 55, 109, 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8, 186, 120, 37, 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, 112, 62, 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158, 225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223, 140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, 22)
|
||||||
private val RIJNDEAL_INVERSE_S_BOX: IntArray = intArrayOf(82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215, 251, 124, 227, 57, 130, 155, 47, 255, 135, 52, 142, 67, 68, 196, 222, 233, 203, 84, 123, 148, 50, 166, 194, 35, 61, 238, 76, 149, 11, 66, 250, 195, 78, 8, 46, 161, 102, 40, 217, 36, 178, 118, 91, 162, 73, 109, 139, 209, 37, 114, 248, 246, 100, 134, 104, 152, 22, 212, 164, 92, 204, 93, 101, 182, 146, 108, 112, 72, 80, 253, 237, 185, 218, 94, 21, 70, 87, 167, 141, 157, 132, 144, 216, 171, 0, 140, 188, 211, 10, 247, 228, 88, 5, 184, 179, 69, 6, 208, 44, 30, 143, 202, 63, 15, 2, 193, 175, 189, 3, 1, 19, 138, 107, 58, 145, 17, 65, 79, 103, 220, 234, 151, 242, 207, 206, 240, 180, 230, 115, 150, 172, 116, 34, 231, 173, 53, 133, 226, 249, 55, 232, 28, 117, 223, 110, 71, 241, 26, 113, 29, 41, 197, 137, 111, 183, 98, 14, 170, 24, 190, 27, 252, 86, 62, 75, 198, 210, 121, 32, 154, 219, 192, 254, 120, 205, 90, 244, 31, 221, 168, 51, 136, 7, 199, 49, 177, 18, 16, 89, 39, 128, 236, 95, 96, 81, 127, 169, 25, 181, 74, 13, 45, 229, 122, 159, 147, 201, 156, 239, 160, 224, 59, 77, 174, 42, 245, 176, 200, 235, 187, 60, 131, 83, 153, 97, 23, 43, 4, 126, 186, 119, 214, 38, 225, 105, 20, 99, 85, 33, 12, 125)
|
private val RIJNDEAL_INVERSE_S_BOX: IntArray = intArrayOf(82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215, 251, 124, 227, 57, 130, 155, 47, 255, 135, 52, 142, 67, 68, 196, 222, 233, 203, 84, 123, 148, 50, 166, 194, 35, 61, 238, 76, 149, 11, 66, 250, 195, 78, 8, 46, 161, 102, 40, 217, 36, 178, 118, 91, 162, 73, 109, 139, 209, 37, 114, 248, 246, 100, 134, 104, 152, 22, 212, 164, 92, 204, 93, 101, 182, 146, 108, 112, 72, 80, 253, 237, 185, 218, 94, 21, 70, 87, 167, 141, 157, 132, 144, 216, 171, 0, 140, 188, 211, 10, 247, 228, 88, 5, 184, 179, 69, 6, 208, 44, 30, 143, 202, 63, 15, 2, 193, 175, 189, 3, 1, 19, 138, 107, 58, 145, 17, 65, 79, 103, 220, 234, 151, 242, 207, 206, 240, 180, 230, 115, 150, 172, 116, 34, 231, 173, 53, 133, 226, 249, 55, 232, 28, 117, 223, 110, 71, 241, 26, 113, 29, 41, 197, 137, 111, 183, 98, 14, 170, 24, 190, 27, 252, 86, 62, 75, 198, 210, 121, 32, 154, 219, 192, 254, 120, 205, 90, 244, 31, 221, 168, 51, 136, 7, 199, 49, 177, 18, 16, 89, 39, 128, 236, 95, 96, 81, 127, 169, 25, 181, 74, 13, 45, 229, 122, 159, 147, 201, 156, 239, 160, 224, 59, 77, 174, 42, 245, 176, 200, 235, 187, 60, 131, 83, 153, 97, 23, 43, 4, 126, 186, 119, 214, 38, 225, 105, 20, 99, 85, 33, 12, 125)
|
||||||
|
|
||||||
val MED_CIPHER: Long = 1344751489
|
private val MED_CIPHER: Long = 1344751489
|
||||||
|
|
||||||
fun keyGen(input: Long): Long {
|
fun keyGen(input: Long): Long {
|
||||||
val key = randomGen(randomGen(MED_CIPHER xor input))
|
val key = randomGen(randomGen(MED_CIPHER xor input))
|
||||||
|
@ -25,7 +25,7 @@ class Crypt {
|
||||||
private fun simpleCrypt(inputData: Long): Long {
|
private fun simpleCrypt(inputData: Long): Long {
|
||||||
var temp = inputData xor MED_CIPHER
|
var temp = inputData xor MED_CIPHER
|
||||||
for (i in 0 until 32) {
|
for (i in 0 until 32) {
|
||||||
temp = changeByTable(rotatoLeft(temp, 32, 1), RIJNDEAL_S_BOX).toLong()
|
temp = changeByTable(rotatoLeft(temp, 32, 1), RIJNDEAL_S_BOX)
|
||||||
}
|
}
|
||||||
return temp
|
return temp
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ fun ByteArray.toInt(): Int {
|
||||||
var result = 0
|
var result = 0
|
||||||
for (i in this.indices) {
|
for (i in this.indices) {
|
||||||
val byte = this[i]
|
val byte = this[i]
|
||||||
val shifted = (byte.toInt() and 0xFF).toInt() shl 8 * i
|
val shifted = (byte.toInt() and 0xFF) shl 8 * i
|
||||||
result = result or shifted
|
result = result or shifted
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -9,26 +9,3 @@ fun View?.visible(vararg views: View?) {
|
||||||
for (view in views)
|
for (view in views)
|
||||||
view.visible()
|
view.visible()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun View?.invisible() = this?.run { visibility = View.INVISIBLE }
|
|
||||||
|
|
||||||
fun View?.invisible(vararg views: View?) {
|
|
||||||
invisible()
|
|
||||||
for (view in views)
|
|
||||||
view.invisible()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun View?.gone() = this?.run { visibility = View.GONE }
|
|
||||||
|
|
||||||
fun View?.gone(vararg views: View?) {
|
|
||||||
gone()
|
|
||||||
for (view in views)
|
|
||||||
view.gone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun View?.setVisibleOrGone(visibleOrGone: Boolean, vararg views: View?) {
|
|
||||||
for (view in views)
|
|
||||||
if (visibleOrGone) view.visible() else view.gone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun View?.setVisibleOrGone(visibleOrGone: Boolean) = setVisibleOrGone(visibleOrGone, this)
|
|
||||||
|
|
|
@ -241,16 +241,16 @@ class BLEComm @Inject internal constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCharacteristicRead(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) {
|
override fun onCharacteristicRead(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicRead data: " + characteristic.value.contentToString() + " UUID: " + characteristic.getUuid().toString() + " status: " + status)
|
aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicRead data: " + characteristic.value.contentToString() + " UUID: " + characteristic.uuid.toString() + " status: " + status)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) {
|
override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicChanged data: " + characteristic.value.contentToString() + " UUID: " + characteristic.getUuid().toString())
|
aapsLogger.debug(LTag.PUMPBTCOMM, "onCharacteristicChanged data: " + characteristic.value.contentToString() + " UUID: " + characteristic.uuid.toString())
|
||||||
|
|
||||||
val value = characteristic.getValue()
|
val value = characteristic.value
|
||||||
if (characteristic.getUuid() == UUID.fromString(READ_UUID)) {
|
if (characteristic.uuid == UUID.fromString(READ_UUID)) {
|
||||||
mCallback?.onNotification(value)
|
mCallback?.onNotification(value)
|
||||||
} else if (characteristic.getUuid() == UUID.fromString(WRITE_UUID)) {
|
} else if (characteristic.uuid == UUID.fromString(WRITE_UUID)) {
|
||||||
synchronized(readLock) {
|
synchronized(readLock) {
|
||||||
if (mReadPacket == null) {
|
if (mReadPacket == null) {
|
||||||
mReadPacket = ReadDataPacket(value)
|
mReadPacket = ReadDataPacket(value)
|
||||||
|
@ -398,7 +398,7 @@ class BLEComm @Inject internal constructor(
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun sendMessage(message: ByteArray) {
|
fun sendMessage(message: ByteArray) {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "sendMessage message = " + Arrays.toString(message))
|
aapsLogger.debug(LTag.PUMPBTCOMM, "sendMessage message = " + message.contentToString())
|
||||||
if (mWritePackets?.allPacketsConsumed() == false) {
|
if (mWritePackets?.allPacketsConsumed() == false) {
|
||||||
aapsLogger.error(LTag.PUMPBTCOMM, "sendMessage not all packets consumed!! unable to sent message!")
|
aapsLogger.error(LTag.PUMPBTCOMM, "sendMessage not all packets consumed!! unable to sent message!")
|
||||||
return
|
return
|
||||||
|
@ -455,7 +455,7 @@ class BLEComm @Inject internal constructor(
|
||||||
val gattService = getGattService() ?: return
|
val gattService = getGattService() ?: return
|
||||||
var uuid: String
|
var uuid: String
|
||||||
val gattCharacteristics = gattService.characteristics
|
val gattCharacteristics = gattService.characteristics
|
||||||
for (i in 0..gattCharacteristics.size - 1) {
|
for (i in 0 until gattCharacteristics.size) {
|
||||||
val gattCharacteristic = gattCharacteristics.get(i)
|
val gattCharacteristic = gattCharacteristics.get(i)
|
||||||
// Check whether read or write properties is set, the pump needs us to enable notifications on all characteristics that have these properties
|
// Check whether read or write properties is set, the pump needs us to enable notifications on all characteristics that have these properties
|
||||||
if (gattCharacteristic.properties and NEEDS_ENABLE > 0) {
|
if (gattCharacteristic.properties and NEEDS_ENABLE > 0) {
|
||||||
|
|
|
@ -29,7 +29,6 @@ import info.nightscout.pump.medtrum.code.ConnectionState
|
||||||
import info.nightscout.pump.medtrum.comm.enums.AlarmState
|
import info.nightscout.pump.medtrum.comm.enums.AlarmState
|
||||||
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
||||||
import info.nightscout.pump.medtrum.comm.packets.*
|
import info.nightscout.pump.medtrum.comm.packets.*
|
||||||
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
|
||||||
import info.nightscout.rx.AapsSchedulers
|
import info.nightscout.rx.AapsSchedulers
|
||||||
import info.nightscout.rx.bus.RxBus
|
import info.nightscout.rx.bus.RxBus
|
||||||
import info.nightscout.rx.events.EventAppExit
|
import info.nightscout.rx.events.EventAppExit
|
||||||
|
@ -84,8 +83,6 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
private const val ALARM_DAILY_MAX_CLEAR_CODE = 5
|
private const val ALARM_DAILY_MAX_CLEAR_CODE = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
val timeUtil = MedtrumTimeUtil()
|
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
private val mBinder: IBinder = LocalBinder()
|
private val mBinder: IBinder = LocalBinder()
|
||||||
|
|
||||||
|
@ -124,7 +121,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
medtrumPump.loadUserSettingsFromSP()
|
medtrumPump.loadUserSettingsFromSP()
|
||||||
commandQueue.setUserOptions(object : Callback() {
|
commandQueue.setUserOptions(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (medtrumPlugin.isInitialized() && this.result.success == false) {
|
if (medtrumPlugin.isInitialized() && !this.result.success) {
|
||||||
uiInteraction.addNotification(
|
uiInteraction.addNotification(
|
||||||
Notification.PUMP_SETTINGS_FAILED,
|
Notification.PUMP_SETTINGS_FAILED,
|
||||||
rh.gs(R.string.pump_setting_failed),
|
rh.gs(R.string.pump_setting_failed),
|
||||||
|
@ -204,7 +201,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readPumpStatus() {
|
fun readPumpStatus() {
|
||||||
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.gettingpumpstatus)))
|
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.getting_pump_status)))
|
||||||
updateTimeIfNeeded(false)
|
updateTimeIfNeeded(false)
|
||||||
loadEvents()
|
loadEvents()
|
||||||
}
|
}
|
||||||
|
@ -229,7 +226,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
fun updateTimeIfNeeded(needLoadHistory: Boolean = true): Boolean {
|
fun updateTimeIfNeeded(needLoadHistory: Boolean = true): Boolean {
|
||||||
// Note we only check timeZone here, time is updated each connection attempt if needed, because the pump requires it to be checked
|
// Note we only check timeZone here, time is updated each connection attempt if needed, because the pump requires it to be checked
|
||||||
// But we dont check timeZone each time, therefore we do it here (if needed)
|
// But we don't check timeZone each time, therefore we do it here (if needed)
|
||||||
var result = true
|
var result = true
|
||||||
if (medtrumPump.pumpTimeZoneOffset != dateUtil.getTimeZoneOffsetMinutes(dateUtil.now())) {
|
if (medtrumPump.pumpTimeZoneOffset != dateUtil.getTimeZoneOffsetMinutes(dateUtil.now())) {
|
||||||
result = sendPacketAndGetResponse(SetTimePacket(injector))
|
result = sendPacketAndGetResponse(SetTimePacket(injector))
|
||||||
|
@ -245,7 +242,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadEvents(): Boolean {
|
fun loadEvents(): Boolean {
|
||||||
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.gettingpumpstatus)))
|
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.getting_pump_status)))
|
||||||
// Sync records
|
// Sync records
|
||||||
val result = syncRecords()
|
val result = syncRecords()
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -261,16 +258,16 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
var result = true
|
var result = true
|
||||||
if (medtrumPump.pumpState in listOf(
|
if (medtrumPump.pumpState in listOf(
|
||||||
MedtrumPumpState.PAUSED,
|
MedtrumPumpState.PAUSED,
|
||||||
MedtrumPumpState.HMAX_SUSPENDED,
|
MedtrumPumpState.HOURLY_MAX_SUSPENDED,
|
||||||
MedtrumPumpState.DMAX_SUSPENDED
|
MedtrumPumpState.DAILY_MAX_SUSPENDED
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
when (medtrumPump.pumpState) {
|
when (medtrumPump.pumpState) {
|
||||||
MedtrumPumpState.HMAX_SUSPENDED -> {
|
MedtrumPumpState.HOURLY_MAX_SUSPENDED -> {
|
||||||
result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, ALARM_HOURLY_MAX_CLEAR_CODE))
|
result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, ALARM_HOURLY_MAX_CLEAR_CODE))
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtrumPumpState.DMAX_SUSPENDED -> {
|
MedtrumPumpState.DAILY_MAX_SUSPENDED -> {
|
||||||
result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, ALARM_DAILY_MAX_CLEAR_CODE))
|
result = sendPacketAndGetResponse(ClearPumpAlarmPacket(injector, ALARM_DAILY_MAX_CLEAR_CODE))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +282,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setUserSettings(): Boolean {
|
fun setUserSettings(): Boolean {
|
||||||
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.settingpumpsettings)))
|
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.setting_pump_settings)))
|
||||||
return sendPacketAndGetResponse(SetPatchPacket(injector))
|
return sendPacketAndGetResponse(SetPatchPacket(injector))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,16 +298,16 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
medtrumPump.bolusStopped = false
|
medtrumPump.bolusStopped = false
|
||||||
medtrumPump.bolusProgressLastTimeStamp = bolusStart
|
medtrumPump.bolusProgressLastTimeStamp = bolusStart
|
||||||
|
|
||||||
if (insulin > 0 && !medtrumPump.bolusStopped) {
|
if (insulin > 0) {
|
||||||
val result = sendPacketAndGetResponse(SetBolusPacket(injector, insulin))
|
val result = sendPacketAndGetResponse(SetBolusPacket(injector, insulin))
|
||||||
if (result == false) {
|
if (!result) {
|
||||||
aapsLogger.error(LTag.PUMPCOMM, "Failed to set bolus")
|
aapsLogger.error(LTag.PUMPCOMM, "Failed to set bolus")
|
||||||
commandQueue.loadEvents(null) // make sure if anything is delivered (which is highly unlikely at this point) we get it
|
commandQueue.loadEvents(null) // make sure if anything is delivered (which is highly unlikely at this point) we get it
|
||||||
t.insulin = 0.0
|
t.insulin = 0.0
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Bolus not set, insulin: $insulin, bolusStopped: ${medtrumPump.bolusStopped}")
|
aapsLogger.debug(LTag.PUMPCOMM, "Bolus not set, insulin: $insulin")
|
||||||
t.insulin = 0.0
|
t.insulin = 0.0
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -384,7 +381,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
// Do not call update status directly, reconnection may be needed
|
// Do not call update status directly, reconnection may be needed
|
||||||
commandQueue.loadEvents(object : Callback() {
|
commandQueue.loadEvents(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.gettingbolusstatus)))
|
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.getting_bolus_status)))
|
||||||
bolusingEvent.percent = 100
|
bolusingEvent.percent = 100
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -395,7 +392,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "bolusStop >>>>> @ " + if (medtrumPump.bolusingTreatment == null) "" else medtrumPump.bolusingTreatment?.insulin)
|
aapsLogger.debug(LTag.PUMPCOMM, "bolusStop >>>>> @ " + if (medtrumPump.bolusingTreatment == null) "" else medtrumPump.bolusingTreatment?.insulin)
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
var success = sendPacketAndGetResponse(CancelBolusPacket(injector))
|
var success = sendPacketAndGetResponse(CancelBolusPacket(injector))
|
||||||
var timeout = System.currentTimeMillis() + T.secs(30).msecs()
|
val timeout = System.currentTimeMillis() + T.secs(30).msecs()
|
||||||
while (!success && System.currentTimeMillis() < timeout) {
|
while (!success && System.currentTimeMillis() < timeout) {
|
||||||
success = sendPacketAndGetResponse(CancelBolusPacket(injector))
|
success = sendPacketAndGetResponse(CancelBolusPacket(injector))
|
||||||
SystemClock.sleep(200)
|
SystemClock.sleep(200)
|
||||||
|
@ -414,11 +411,11 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
}
|
}
|
||||||
if (result) result = sendPacketAndGetResponse(SetTempBasalPacket(injector, absoluteRate, durationInMinutes))
|
if (result) result = sendPacketAndGetResponse(SetTempBasalPacket(injector, absoluteRate, durationInMinutes))
|
||||||
|
|
||||||
// Get history records, this will update the prevoius basals
|
// Get history records, this will update the previous basals
|
||||||
// Do not call update status directly, reconnection may be needed
|
// Do not call update status directly, reconnection may be needed
|
||||||
commandQueue.loadEvents(object : Callback() {
|
commandQueue.loadEvents(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.gettingtempbasalstatus)))
|
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.getting_temp_basal_status)))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -426,13 +423,13 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cancelTempBasal(): Boolean {
|
fun cancelTempBasal(): Boolean {
|
||||||
var result = sendPacketAndGetResponse(CancelTempBasalPacket(injector))
|
val result = sendPacketAndGetResponse(CancelTempBasalPacket(injector))
|
||||||
|
|
||||||
// Get history records, this will update the prevoius basals
|
// Get history records, this will update the previous basals
|
||||||
// Do not call update status directly, reconnection may be needed
|
// Do not call update status directly, reconnection may be needed
|
||||||
commandQueue.loadEvents(object : Callback() {
|
commandQueue.loadEvents(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.gettingtempbasalstatus)))
|
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.getting_temp_basal_status)))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -462,7 +459,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
if (medtrumPump.syncedSequenceNumber < medtrumPump.currentSequenceNumber) {
|
if (medtrumPump.syncedSequenceNumber < medtrumPump.currentSequenceNumber) {
|
||||||
for (sequence in (medtrumPump.syncedSequenceNumber + 1)..medtrumPump.currentSequenceNumber) {
|
for (sequence in (medtrumPump.syncedSequenceNumber + 1)..medtrumPump.currentSequenceNumber) {
|
||||||
result = sendPacketAndGetResponse(GetRecordPacket(injector, sequence), COMMAND_SYNC_TIMEOUT_SEC)
|
result = sendPacketAndGetResponse(GetRecordPacket(injector, sequence), COMMAND_SYNC_TIMEOUT_SEC)
|
||||||
if (result == false) break
|
if (!result) break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -471,23 +468,23 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
private fun handlePumpStateUpdate(state: MedtrumPumpState) {
|
private fun handlePumpStateUpdate(state: MedtrumPumpState) {
|
||||||
// Map the pump state to an alarm state and add it to the active alarms
|
// Map the pump state to an alarm state and add it to the active alarms
|
||||||
val alarmState = when (state) {
|
val alarmState = when (state) {
|
||||||
MedtrumPumpState.NONE -> AlarmState.NONE
|
MedtrumPumpState.NONE -> AlarmState.NONE
|
||||||
MedtrumPumpState.LOWBG_SUSPENDED -> AlarmState.LOWBG_SUSPENDED
|
MedtrumPumpState.LOW_BG_SUSPENDED -> AlarmState.LOW_BG_SUSPENDED
|
||||||
MedtrumPumpState.LOWBG_SUSPENDED2 -> AlarmState.LOWBG_SUSPENDED2
|
MedtrumPumpState.LOW_BG_SUSPENDED2 -> AlarmState.LOW_BG_SUSPENDED2
|
||||||
MedtrumPumpState.AUTO_SUSPENDED -> AlarmState.AUTO_SUSPENDED
|
MedtrumPumpState.AUTO_SUSPENDED -> AlarmState.AUTO_SUSPENDED
|
||||||
MedtrumPumpState.HMAX_SUSPENDED -> AlarmState.HMAX_SUSPENDED
|
MedtrumPumpState.HOURLY_MAX_SUSPENDED -> AlarmState.HOURLY_MAX_SUSPENDED
|
||||||
MedtrumPumpState.DMAX_SUSPENDED -> AlarmState.DMAX_SUSPENDED
|
MedtrumPumpState.DAILY_MAX_SUSPENDED -> AlarmState.DAILY_MAX_SUSPENDED
|
||||||
MedtrumPumpState.SUSPENDED -> AlarmState.SUSPENDED
|
MedtrumPumpState.SUSPENDED -> AlarmState.SUSPENDED
|
||||||
MedtrumPumpState.PAUSED -> AlarmState.PAUSED
|
MedtrumPumpState.PAUSED -> AlarmState.PAUSED
|
||||||
MedtrumPumpState.OCCLUSION -> AlarmState.OCCLUSION
|
MedtrumPumpState.OCCLUSION -> AlarmState.OCCLUSION
|
||||||
MedtrumPumpState.EXPIRED -> AlarmState.EXPIRED
|
MedtrumPumpState.EXPIRED -> AlarmState.EXPIRED
|
||||||
MedtrumPumpState.RESERVOIR_EMPTY -> AlarmState.RESERVOIR_EMPTY
|
MedtrumPumpState.RESERVOIR_EMPTY -> AlarmState.RESERVOIR_EMPTY
|
||||||
MedtrumPumpState.PATCH_FAULT -> AlarmState.PATCH_FAULT
|
MedtrumPumpState.PATCH_FAULT -> AlarmState.PATCH_FAULT
|
||||||
MedtrumPumpState.PATCH_FAULT2 -> AlarmState.PATCH_FAULT2
|
MedtrumPumpState.PATCH_FAULT2 -> AlarmState.PATCH_FAULT2
|
||||||
MedtrumPumpState.BASE_FAULT -> AlarmState.BASE_FAULT
|
MedtrumPumpState.BASE_FAULT -> AlarmState.BASE_FAULT
|
||||||
MedtrumPumpState.BATTERY_OUT -> AlarmState.BATTERY_OUT
|
MedtrumPumpState.BATTERY_OUT -> AlarmState.BATTERY_OUT
|
||||||
MedtrumPumpState.NO_CALIBRATION -> AlarmState.NO_CALIBRATION
|
MedtrumPumpState.NO_CALIBRATION -> AlarmState.NO_CALIBRATION
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
if (alarmState != null && alarmState != AlarmState.NONE) {
|
if (alarmState != null && alarmState != AlarmState.NONE) {
|
||||||
medtrumPump.addAlarm(alarmState)
|
medtrumPump.addAlarm(alarmState)
|
||||||
|
@ -533,8 +530,8 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
medtrumPump.clearAlarmState()
|
medtrumPump.clearAlarmState()
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtrumPumpState.LOWBG_SUSPENDED,
|
MedtrumPumpState.LOW_BG_SUSPENDED,
|
||||||
MedtrumPumpState.LOWBG_SUSPENDED2,
|
MedtrumPumpState.LOW_BG_SUSPENDED2,
|
||||||
MedtrumPumpState.AUTO_SUSPENDED,
|
MedtrumPumpState.AUTO_SUSPENDED,
|
||||||
MedtrumPumpState.SUSPENDED,
|
MedtrumPumpState.SUSPENDED,
|
||||||
MedtrumPumpState.PAUSED -> {
|
MedtrumPumpState.PAUSED -> {
|
||||||
|
@ -546,7 +543,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
// Pump will report proper TBR for this
|
// Pump will report proper TBR for this
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtrumPumpState.HMAX_SUSPENDED -> {
|
MedtrumPumpState.HOURLY_MAX_SUSPENDED -> {
|
||||||
uiInteraction.addNotification(
|
uiInteraction.addNotification(
|
||||||
Notification.PUMP_SUSPENDED,
|
Notification.PUMP_SUSPENDED,
|
||||||
rh.gs(R.string.pump_is_suspended_hour_max),
|
rh.gs(R.string.pump_is_suspended_hour_max),
|
||||||
|
@ -555,7 +552,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
// Pump will report proper TBR for this
|
// Pump will report proper TBR for this
|
||||||
}
|
}
|
||||||
|
|
||||||
MedtrumPumpState.DMAX_SUSPENDED -> {
|
MedtrumPumpState.DAILY_MAX_SUSPENDED -> {
|
||||||
uiInteraction.addNotification(
|
uiInteraction.addNotification(
|
||||||
Notification.PUMP_SUSPENDED,
|
Notification.PUMP_SUSPENDED,
|
||||||
rh.gs(R.string.pump_is_suspended_day_max),
|
rh.gs(R.string.pump_is_suspended_day_max),
|
||||||
|
@ -721,8 +718,6 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
// State for connect flow
|
// State for connect flow
|
||||||
private inner class AuthState : State() {
|
private inner class AuthState : State() {
|
||||||
|
|
||||||
val retryCounter = 0
|
|
||||||
|
|
||||||
override fun onEnter() {
|
override fun onEnter() {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Medtrum Service reached AuthState")
|
aapsLogger.debug(LTag.PUMPCOMM, "Medtrum Service reached AuthState")
|
||||||
mPacket = AuthorizePacket(injector)
|
mPacket = AuthorizePacket(injector)
|
||||||
|
@ -734,7 +729,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
override fun onIndication(data: ByteArray) {
|
override fun onIndication(data: ByteArray) {
|
||||||
if (mPacket?.handleResponse(data) == true) {
|
if (mPacket?.handleResponse(data) == true) {
|
||||||
// Succes!
|
// Success!
|
||||||
responseHandled = true
|
responseHandled = true
|
||||||
responseSuccess = true
|
responseSuccess = true
|
||||||
// Check if we have a supported pump
|
// Check if we have a supported pump
|
||||||
|
@ -776,7 +771,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
override fun onIndication(data: ByteArray) {
|
override fun onIndication(data: ByteArray) {
|
||||||
if (mPacket?.handleResponse(data) == true) {
|
if (mPacket?.handleResponse(data) == true) {
|
||||||
// Succes!
|
// Success!
|
||||||
responseHandled = true
|
responseHandled = true
|
||||||
responseSuccess = true
|
responseSuccess = true
|
||||||
// Place holder, not really used (yet)
|
// Place holder, not really used (yet)
|
||||||
|
@ -808,7 +803,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
override fun onIndication(data: ByteArray) {
|
override fun onIndication(data: ByteArray) {
|
||||||
if (mPacket?.handleResponse(data) == true) {
|
if (mPacket?.handleResponse(data) == true) {
|
||||||
// Succes!
|
// Success!
|
||||||
responseHandled = true
|
responseHandled = true
|
||||||
responseSuccess = true
|
responseSuccess = true
|
||||||
val currTime = dateUtil.now()
|
val currTime = dateUtil.now()
|
||||||
|
@ -843,7 +838,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
override fun onIndication(data: ByteArray) {
|
override fun onIndication(data: ByteArray) {
|
||||||
if (mPacket?.handleResponse(data) == true) {
|
if (mPacket?.handleResponse(data) == true) {
|
||||||
// Succes!
|
// Success!
|
||||||
responseHandled = true
|
responseHandled = true
|
||||||
responseSuccess = true
|
responseSuccess = true
|
||||||
toState(SetTimeZoneState())
|
toState(SetTimeZoneState())
|
||||||
|
@ -871,7 +866,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
override fun onIndication(data: ByteArray) {
|
override fun onIndication(data: ByteArray) {
|
||||||
if (mPacket?.handleResponse(data) == true) {
|
if (mPacket?.handleResponse(data) == true) {
|
||||||
// Succes!
|
// Success!
|
||||||
responseHandled = true
|
responseHandled = true
|
||||||
responseSuccess = true
|
responseSuccess = true
|
||||||
medtrumPump.needCheckTimeUpdate = false
|
medtrumPump.needCheckTimeUpdate = false
|
||||||
|
@ -901,7 +896,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
override fun onIndication(data: ByteArray) {
|
override fun onIndication(data: ByteArray) {
|
||||||
if (mPacket?.handleResponse(data) == true) {
|
if (mPacket?.handleResponse(data) == true) {
|
||||||
// Succes!
|
// Success!
|
||||||
responseHandled = true
|
responseHandled = true
|
||||||
responseSuccess = true
|
responseSuccess = true
|
||||||
toState(SubscribeState())
|
toState(SubscribeState())
|
||||||
|
@ -929,7 +924,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
override fun onIndication(data: ByteArray) {
|
override fun onIndication(data: ByteArray) {
|
||||||
if (mPacket?.handleResponse(data) == true) {
|
if (mPacket?.handleResponse(data) == true) {
|
||||||
// Succes!
|
// Success!
|
||||||
responseHandled = true
|
responseHandled = true
|
||||||
responseSuccess = true
|
responseSuccess = true
|
||||||
toState(ReadyState())
|
toState(ReadyState())
|
||||||
|
@ -949,7 +944,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
override fun onEnter() {
|
override fun onEnter() {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Medtrum Service reached ReadyState!")
|
aapsLogger.debug(LTag.PUMPCOMM, "Medtrum Service reached ReadyState!")
|
||||||
// Now we are fully connected and authenticated and we can start sending commands. Let AAPS know
|
// Now we are fully connected and authenticated and we can start sending commands. Let AAPS know
|
||||||
if (isConnected == false) {
|
if (!isConnected) {
|
||||||
medtrumPump.connectionState = ConnectionState.CONNECTED
|
medtrumPump.connectionState = ConnectionState.CONNECTED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -964,7 +959,7 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
|
|
||||||
override fun onIndication(data: ByteArray) {
|
override fun onIndication(data: ByteArray) {
|
||||||
if (mPacket?.handleResponse(data) == true) {
|
if (mPacket?.handleResponse(data) == true) {
|
||||||
// Succes!
|
// Success!
|
||||||
responseHandled = true
|
responseHandled = true
|
||||||
responseSuccess = true
|
responseSuccess = true
|
||||||
toState(ReadyState())
|
toState(ReadyState())
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.view.View
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import info.nightscout.pump.medtrum.R
|
import info.nightscout.pump.medtrum.R
|
||||||
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPreparePatchBinding
|
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPreparePatchBinding
|
||||||
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
|
|
||||||
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
|
|
|
@ -8,7 +8,6 @@ import info.nightscout.core.ui.toast.ToastUtils
|
||||||
import info.nightscout.pump.medtrum.R
|
import info.nightscout.pump.medtrum.R
|
||||||
import info.nightscout.pump.medtrum.code.PatchStep
|
import info.nightscout.pump.medtrum.code.PatchStep
|
||||||
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPrimeCompleteBinding
|
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPrimeCompleteBinding
|
||||||
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
|
|
||||||
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
|
|
|
@ -8,7 +8,6 @@ import info.nightscout.core.ui.toast.ToastUtils
|
||||||
import info.nightscout.pump.medtrum.R
|
import info.nightscout.pump.medtrum.R
|
||||||
import info.nightscout.pump.medtrum.code.PatchStep
|
import info.nightscout.pump.medtrum.code.PatchStep
|
||||||
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPrimeBinding
|
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPrimeBinding
|
||||||
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
|
|
||||||
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
|
|
|
@ -8,7 +8,6 @@ import info.nightscout.core.ui.toast.ToastUtils
|
||||||
import info.nightscout.pump.medtrum.R
|
import info.nightscout.pump.medtrum.R
|
||||||
import info.nightscout.pump.medtrum.code.PatchStep
|
import info.nightscout.pump.medtrum.code.PatchStep
|
||||||
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPrimingBinding
|
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPrimingBinding
|
||||||
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
|
|
||||||
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
|
|
|
@ -7,7 +7,6 @@ import info.nightscout.core.ui.dialogs.OKDialog
|
||||||
import info.nightscout.pump.medtrum.R
|
import info.nightscout.pump.medtrum.R
|
||||||
import info.nightscout.pump.medtrum.code.PatchStep
|
import info.nightscout.pump.medtrum.code.PatchStep
|
||||||
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumRetryActivationConnectBinding
|
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumRetryActivationConnectBinding
|
||||||
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
|
|
||||||
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
|
|
|
@ -7,7 +7,6 @@ import info.nightscout.core.ui.dialogs.OKDialog
|
||||||
import info.nightscout.pump.medtrum.R
|
import info.nightscout.pump.medtrum.R
|
||||||
import info.nightscout.pump.medtrum.code.PatchStep
|
import info.nightscout.pump.medtrum.code.PatchStep
|
||||||
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumRetryActivationBinding
|
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumRetryActivationBinding
|
||||||
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
|
|
||||||
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
|
@ -32,7 +31,7 @@ class MedtrumRetryActivationFragment : MedtrumBaseFragment<FragmentMedtrumRetryA
|
||||||
binding.apply {
|
binding.apply {
|
||||||
viewModel = ViewModelProvider(requireActivity(), viewModelFactory)[MedtrumViewModel::class.java]
|
viewModel = ViewModelProvider(requireActivity(), viewModelFactory)[MedtrumViewModel::class.java]
|
||||||
viewModel?.apply {
|
viewModel?.apply {
|
||||||
preparePatch() // Use this to make sure we are disconnceted at this stage
|
preparePatch() // Use this to make sure we are disconnected at this stage
|
||||||
}
|
}
|
||||||
btnNegative.setOnClickListener {
|
btnNegative.setOnClickListener {
|
||||||
OKDialog.showConfirmation(requireActivity(), rh.gs(R.string.medtrum_deactivate_pump_confirm)) {
|
OKDialog.showConfirmation(requireActivity(), rh.gs(R.string.medtrum_deactivate_pump_confirm)) {
|
||||||
|
|
|
@ -7,7 +7,6 @@ import info.nightscout.core.ui.dialogs.OKDialog
|
||||||
import info.nightscout.pump.medtrum.R
|
import info.nightscout.pump.medtrum.R
|
||||||
import info.nightscout.pump.medtrum.code.PatchStep
|
import info.nightscout.pump.medtrum.code.PatchStep
|
||||||
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumStartDeactivationBinding
|
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumStartDeactivationBinding
|
||||||
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
|
|
||||||
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.lang.ref.WeakReference
|
||||||
abstract class BaseViewModel<N : MedtrumBaseNavigator> : ViewModel() {
|
abstract class BaseViewModel<N : MedtrumBaseNavigator> : ViewModel() {
|
||||||
|
|
||||||
private var _navigator: WeakReference<N?>? = null
|
private var _navigator: WeakReference<N?>? = null
|
||||||
var navigator: N?
|
private var navigator: N?
|
||||||
set(value) {
|
set(value) {
|
||||||
_navigator = WeakReference(value)
|
_navigator = WeakReference(value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ class MedtrumOverviewViewModel @Inject constructor(
|
||||||
aapsLogger.debug(LTag.PUMP, "MedtrumViewModel pumpStateFlow: $state")
|
aapsLogger.debug(LTag.PUMP, "MedtrumViewModel pumpStateFlow: $state")
|
||||||
_canDoResetAlarms.postValue(
|
_canDoResetAlarms.postValue(
|
||||||
medtrumPump.pumpState in listOf(
|
medtrumPump.pumpState in listOf(
|
||||||
MedtrumPumpState.PAUSED, MedtrumPumpState.HMAX_SUSPENDED, MedtrumPumpState.DMAX_SUSPENDED
|
MedtrumPumpState.PAUSED, MedtrumPumpState.HOURLY_MAX_SUSPENDED, MedtrumPumpState.DAILY_MAX_SUSPENDED
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ class MedtrumOverviewViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateGUI() {
|
private fun updateGUI() {
|
||||||
// Update less dynamic values
|
// Update less dynamic values
|
||||||
if (medtrumPump.lastConnection != 0L) {
|
if (medtrumPump.lastConnection != 0L) {
|
||||||
val agoMilliseconds = System.currentTimeMillis() - medtrumPump.lastConnection
|
val agoMilliseconds = System.currentTimeMillis() - medtrumPump.lastConnection
|
||||||
|
|
|
@ -10,13 +10,10 @@ import info.nightscout.pump.medtrum.MedtrumPump
|
||||||
import info.nightscout.pump.medtrum.R
|
import info.nightscout.pump.medtrum.R
|
||||||
import info.nightscout.pump.medtrum.code.ConnectionState
|
import info.nightscout.pump.medtrum.code.ConnectionState
|
||||||
import info.nightscout.pump.medtrum.services.MedtrumService
|
import info.nightscout.pump.medtrum.services.MedtrumService
|
||||||
import info.nightscout.pump.medtrum.code.EventType
|
|
||||||
import info.nightscout.pump.medtrum.code.PatchStep
|
import info.nightscout.pump.medtrum.code.PatchStep
|
||||||
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
||||||
import info.nightscout.pump.medtrum.encryption.Crypt
|
import info.nightscout.pump.medtrum.encryption.Crypt
|
||||||
import info.nightscout.pump.medtrum.ui.MedtrumBaseNavigator
|
import info.nightscout.pump.medtrum.ui.MedtrumBaseNavigator
|
||||||
import info.nightscout.pump.medtrum.ui.event.SingleLiveEvent
|
|
||||||
import info.nightscout.pump.medtrum.ui.event.UIEvent
|
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
@ -43,10 +40,6 @@ class MedtrumViewModel @Inject constructor(
|
||||||
val title: LiveData<Int>
|
val title: LiveData<Int>
|
||||||
get() = _title
|
get() = _title
|
||||||
|
|
||||||
private val _eventHandler = SingleLiveEvent<UIEvent<EventType>>()
|
|
||||||
val eventHandler: LiveData<UIEvent<EventType>>
|
|
||||||
get() = _eventHandler
|
|
||||||
|
|
||||||
private var oldPatchStep: PatchStep? = null
|
private var oldPatchStep: PatchStep? = null
|
||||||
private var mInitPatchStep: PatchStep? = null
|
private var mInitPatchStep: PatchStep? = null
|
||||||
private var connectRetryCounter = 0
|
private var connectRetryCounter = 0
|
||||||
|
@ -155,7 +148,7 @@ class MedtrumViewModel @Inject constructor(
|
||||||
|
|
||||||
PatchStep.RETRY_ACTIVATION_CONNECT,
|
PatchStep.RETRY_ACTIVATION_CONNECT,
|
||||||
PatchStep.PREPARE_PATCH_CONNECT -> {
|
PatchStep.PREPARE_PATCH_CONNECT -> {
|
||||||
// Make sure we are disconnected, else dont move step
|
// Make sure we are disconnected, else don't move step
|
||||||
if (medtrumService?.isConnected == true) {
|
if (medtrumService?.isConnected == true) {
|
||||||
aapsLogger.info(LTag.PUMP, "moveStep: connected, not moving step")
|
aapsLogger.info(LTag.PUMP, "moveStep: connected, not moving step")
|
||||||
return
|
return
|
||||||
|
@ -167,7 +160,7 @@ class MedtrumViewModel @Inject constructor(
|
||||||
PatchStep.PRIME_COMPLETE,
|
PatchStep.PRIME_COMPLETE,
|
||||||
PatchStep.ATTACH_PATCH,
|
PatchStep.ATTACH_PATCH,
|
||||||
PatchStep.ACTIVATE -> {
|
PatchStep.ACTIVATE -> {
|
||||||
// Make sure we are connected, else dont move step
|
// Make sure we are connected, else don't move step
|
||||||
if (medtrumService?.isConnected == false) {
|
if (medtrumService?.isConnected == false) {
|
||||||
aapsLogger.info(LTag.PUMP, "moveStep: not connected, not moving step")
|
aapsLogger.info(LTag.PUMP, "moveStep: not connected, not moving step")
|
||||||
return
|
return
|
||||||
|
@ -321,7 +314,7 @@ class MedtrumViewModel @Inject constructor(
|
||||||
aapsLogger.info(LTag.PUMP, "prepareStep: title before cond: $stringResId")
|
aapsLogger.info(LTag.PUMP, "prepareStep: title before cond: $stringResId")
|
||||||
if (currentTitle != stringResId) {
|
if (currentTitle != stringResId) {
|
||||||
aapsLogger.info(LTag.PUMP, "prepareStep: title: $stringResId")
|
aapsLogger.info(LTag.PUMP, "prepareStep: title: $stringResId")
|
||||||
_title.postValue(stringResId)
|
stringResId?.let { _title.postValue(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
patchStep.postValue(newStep)
|
patchStep.postValue(newStep)
|
||||||
|
|
|
@ -5,19 +5,13 @@ import java.time.Instant
|
||||||
|
|
||||||
class MedtrumTimeUtil {
|
class MedtrumTimeUtil {
|
||||||
|
|
||||||
fun getCurrentTimePumpSeconds() : Long {
|
fun getCurrentTimePumpSeconds(): Long {
|
||||||
val startInstant = Instant.parse("2014-01-01T00:00:00Z")
|
val startInstant = Instant.parse("2014-01-01T00:00:00Z")
|
||||||
val currentInstant = Instant.now()
|
val currentInstant = Instant.now()
|
||||||
return Duration.between(startInstant, currentInstant).seconds
|
return Duration.between(startInstant, currentInstant).seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCurrentTimePumpMillis() : Long {
|
fun convertPumpTimeToSystemTimeMillis(pumpTime: Long): Long {
|
||||||
val startInstant = Instant.parse("2014-01-01T00:00:00Z")
|
|
||||||
val currentInstant = Instant.now()
|
|
||||||
return Duration.between(startInstant, currentInstant).seconds * 1000
|
|
||||||
}
|
|
||||||
|
|
||||||
fun convertPumpTimeToSystemTimeMillis(pumpTime: Long) : Long {
|
|
||||||
val startInstant = Instant.parse("2014-01-01T00:00:00Z")
|
val startInstant = Instant.parse("2014-01-01T00:00:00Z")
|
||||||
val pumpInstant = startInstant.plusSeconds(pumpTime)
|
val pumpInstant = startInstant.plusSeconds(pumpTime)
|
||||||
val epochInstant = Instant.EPOCH
|
val epochInstant = Instant.EPOCH
|
||||||
|
|
|
@ -34,8 +34,7 @@
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
tools:text="@string/string_change_patch" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
|
|
@ -26,19 +26,33 @@
|
||||||
tools:context=".ui.MedtrumActivity">
|
tools:context=".ui.MedtrumActivity">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_remove_base_discard_patch"
|
android:id="@+id/text_retract_needle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="5dp"
|
android:layout_marginStart="5dp"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="20dp"
|
||||||
android:layout_marginEnd="5dp"
|
android:layout_marginEnd="5dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="@string/remove_base_discard_patch"
|
android:text="@string/retract_needle"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_remove_base_discard_patch"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/remove_base_discard_patch"
|
||||||
|
android:textSize="16sp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/text_retract_needle" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_press_next_or_OK"
|
android:id="@+id/text_press_next_or_OK"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
|
||||||
|
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<string name="key_patch_expiration" translatable="false">patch_expiration</string>
|
<string name="key_patch_expiration" translatable="false">patch_expiration</string>
|
||||||
<string name="key_hourly_max_insulin" translatable="false">hourly_max_insulin</string>
|
<string name="key_hourly_max_insulin" translatable="false">hourly_max_insulin</string>
|
||||||
<string name="key_daily_max_insulin" translatable="false">daily_max_insulin</string>
|
<string name="key_daily_max_insulin" translatable="false">daily_max_insulin</string>
|
||||||
|
|
||||||
<string name="key_medtrumpump_settings" translatable="false">medtrumpump_settings</string>
|
<string name="key_medtrum_pump_settings" translatable="false">medtrum_pump_setting</string>
|
||||||
<string name="key_pump_state" translatable="false">pump_state</string>
|
<string name="key_pump_state" translatable="false">pump_state</string>
|
||||||
<string name="key_active_alarms" translatable="false">active_alarms</string>
|
<string name="key_active_alarms" translatable="false">active_alarms</string>
|
||||||
<string name="key_last_connection" translatable="false">last_connection</string>
|
<string name="key_last_connection" translatable="false">last_connection</string>
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
<string name="medtrum">Medtrum</string>
|
<string name="medtrum">Medtrum</string>
|
||||||
<string name="medtrum_pump_shortname">MT</string>
|
<string name="medtrum_pump_shortname">MT</string>
|
||||||
<string name="medtrum_pump_description">Pump integration for Medtrum Nano</string>
|
<string name="medtrum_pump_description">Pump integration for Medtrum Nano</string>
|
||||||
<string name="medtrumpump_settings">Medtrum pump settings</string>
|
<string name="medtrum_pump_setting">Medtrum pump settings</string>
|
||||||
<string name="pump_error">Pump error: %1$s !! </string>
|
<string name="pump_error">Pump error: %1$s !! </string>
|
||||||
<string name="pump_unsupported">Pump untested: %1$d! Please contact us at discord or github for support</string>
|
<string name="pump_unsupported">Pump untested: %1$d! Please contact us at discord or github for support</string>
|
||||||
<string name="pump_is_suspended">Pump is suspended</string>
|
<string name="pump_is_suspended">Pump is suspended</string>
|
||||||
|
@ -34,14 +34,14 @@
|
||||||
<string name="pump_is_suspended_day_max">Pump is suspended due to daily max insulin exceeded</string>
|
<string name="pump_is_suspended_day_max">Pump is suspended due to daily max insulin exceeded</string>
|
||||||
<string name="patch_not_active">Patch not activated</string>
|
<string name="patch_not_active">Patch not activated</string>
|
||||||
<string name="pump_setting_failed">Setting user settings to pump failed!</string>
|
<string name="pump_setting_failed">Setting user settings to pump failed!</string>
|
||||||
|
|
||||||
<!-- overview fragment -->
|
<!-- overview fragment -->
|
||||||
<string name="ble_status_label">BLE Status</string>
|
<string name="ble_status_label">BLE Status</string>
|
||||||
<string name="last_connection_label">Last connected</string>
|
<string name="last_connection_label">Last connected</string>
|
||||||
<string name="pump_state_label">Pump state</string>
|
<string name="pump_state_label">Pump state</string>
|
||||||
<string name="active_alarms_label">Active alarms</string>
|
<string name="active_alarms_label">Active alarms</string>
|
||||||
<string name="reservoir_level"> %.2f U</string>
|
<string name="reservoir_level"> %.2f U</string>
|
||||||
<string name="battery_voltage"> %.2f V</string>
|
<string name="battery_voltage"> %.2f V</string>
|
||||||
<string name="basal_type_label">Basal type</string>
|
<string name="basal_type_label">Basal type</string>
|
||||||
<string name="basal_rate_label">Basal rate</string>
|
<string name="basal_rate_label">Basal rate</string>
|
||||||
<string name="current_basal_rate"> %.2f U/h</string>
|
<string name="current_basal_rate"> %.2f U/h</string>
|
||||||
|
@ -60,11 +60,11 @@
|
||||||
<string name="alarm_pump_low_battery">Pump low battery</string>
|
<string name="alarm_pump_low_battery">Pump low battery</string>
|
||||||
<string name="alarm_pump_low_reservoir">Pump low reservoir</string>
|
<string name="alarm_pump_low_reservoir">Pump low reservoir</string>
|
||||||
<string name="alarm_pump_expires_soon">Pump expires soon</string>
|
<string name="alarm_pump_expires_soon">Pump expires soon</string>
|
||||||
<string name="alarm_lowbg_suspended">Low BG suspended</string>
|
<string name="alarm_low_bg_suspended">Low BG suspended</string>
|
||||||
<string name="alarm_lowbg_suspended2">Low BG suspended 2</string>
|
<string name="alarm_low_bg_suspended2">Low BG suspended 2</string>
|
||||||
<string name="alarm_auto_suspended">Auto suspended</string>
|
<string name="alarm_auto_suspended">Auto suspended</string>
|
||||||
<string name="alarm_hmax_suspended">hourly max suspended</string>
|
<string name="alarm_hourly_max_suspended">hourly max suspended</string>
|
||||||
<string name="alarm_dmax_suspended">daily max suspended</string>
|
<string name="alarm_daily_max_suspended">daily max suspended</string>
|
||||||
<string name="alarm_suspended">Suspended</string>
|
<string name="alarm_suspended">Suspended</string>
|
||||||
<string name="alarm_paused">Paused</string>
|
<string name="alarm_paused">Paused</string>
|
||||||
<string name="alarm_occlusion">Occlusion</string>
|
<string name="alarm_occlusion">Occlusion</string>
|
||||||
|
@ -101,16 +101,15 @@
|
||||||
<string name="patch_begin_activation">No active patch. Press <b>Next</b> to begin the activation process.</string>
|
<string name="patch_begin_activation">No active patch. Press <b>Next</b> to begin the activation process.</string>
|
||||||
<string name="patch_not_active_note">Pump base should not be connected to the patch until the next step!</string>
|
<string name="patch_not_active_note">Pump base should not be connected to the patch until the next step!</string>
|
||||||
<string name="connect_pump_base">Connect pump base to a new patch, remove the residual air and fill with insulin, then press <b>Next</b>.</string>
|
<string name="connect_pump_base">Connect pump base to a new patch, remove the residual air and fill with insulin, then press <b>Next</b>.</string>
|
||||||
<string name="note_min_70_units">Note: A minimum of 70 units is required for actvation.</string>
|
<string name="note_min_70_units">Note: A minimum of 70 units is required for activation.</string>
|
||||||
<string name="do_not_attach_to_body">Do not attach the patch to the body yet.</string>
|
<string name="do_not_attach_to_body">Do not attach the patch to the body yet.</string>
|
||||||
<string name="half_press_needle">Half-press needle button. Then tap <b>Next</b> to start prime.</string>
|
<string name="half_press_needle">Half-press needle button. Then tap <b>Next</b> to start prime.</string>
|
||||||
<string name="wait_for_priming">Please wait for the priming to complete.</string>
|
<string name="wait_for_priming">Please wait for the priming to complete.</string>
|
||||||
<string name="priming_error">Failed to prime, press <b>Retry</b> to try again.</string>
|
<string name="priming_error">Failed to prime, press <b>Retry</b> to try again.</string>
|
||||||
<string name="press_next">Press <b>Next</b> to continue.</string>
|
<string name="press_next">Press <b>Next</b> to continue.</string>
|
||||||
<string name="press_next_to_start_activation">Press <b>Next</b> to start activation.</string>
|
<string name="press_next_to_start_activation">Press <b>Next</b> to start activation.</string>
|
||||||
<string name='attach_patch_to_body'>Remove the safety lock. Attach the pump to the body. Press the needle button.</string>
|
|
||||||
<string name="remove_safety_lock">Remove the safety lock. Attach the pump to the body. Press the needle button.</string>
|
<string name="remove_safety_lock">Remove the safety lock. Attach the pump to the body. Press the needle button.</string>
|
||||||
<string name="activating_pump">Activating pump and settng initial basal rate. Please Wait.</string>
|
<string name="activating_pump">Activating pump and setting initial basal rate. Please Wait.</string>
|
||||||
<string name="activating_error">Failed to activate, press <b>Retry</b> to try again.</string>
|
<string name="activating_error">Failed to activate, press <b>Retry</b> to try again.</string>
|
||||||
<string name="activating_complete">New patch activated. %.2f Units remaining.</string>
|
<string name="activating_complete">New patch activated. %.2f Units remaining.</string>
|
||||||
<string name="press_OK_to_return">Press <b>OK</b> to return to main screen.</string>
|
<string name="press_OK_to_return">Press <b>OK</b> to return to main screen.</string>
|
||||||
|
@ -142,10 +141,9 @@
|
||||||
<string name="daily_max_insulin_summary">Specify the maximum units of insulin allowed per day. If exceeded, the pump will suspend.</string>
|
<string name="daily_max_insulin_summary">Specify the maximum units of insulin allowed per day. If exceeded, the pump will suspend.</string>
|
||||||
|
|
||||||
<!-- treatment state-->
|
<!-- treatment state-->
|
||||||
<string name="waitingforestimatedbolusend">Waiting for bolus end. Remaining %1$d sec.</string>
|
<string name="getting_pump_status">Getting pump status</string>
|
||||||
<string name="gettingpumpstatus">Getting pump status</string>
|
<string name="getting_bolus_status">Getting bolus status</string>
|
||||||
<string name="gettingbolusstatus">Getting bolus status</string>
|
<string name="getting_temp_basal_status">Getting temporary basal status</string>
|
||||||
<string name="gettingtempbasalstatus">Getting temporary basal status</string>
|
<string name="setting_pump_settings">Setting user options</string>
|
||||||
<string name="settingpumpsettings">Setting user options</string>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
xmlns:validate="http://schemas.android.com/apk/res-auto">
|
xmlns:validate="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="@string/key_medtrumpump_settings"
|
android:key="@string/key_medtrum_pump_settings"
|
||||||
android:title="@string/medtrumpump_settings"
|
android:title="@string/medtrum_pump_setting"
|
||||||
app:initialExpandedChildrenCount="0">
|
app:initialExpandedChildrenCount="0">
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore {
|
class ProfileStoreObject(injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore {
|
||||||
|
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
@Inject lateinit var activePlugin: ActivePlugin
|
@Inject lateinit var activePlugin: ActivePlugin
|
||||||
|
|
|
@ -84,21 +84,21 @@ class MedtrumPumpTest : MedtrumTestBase() {
|
||||||
val localTime2230 = LocalTime.of(22, 30)
|
val localTime2230 = LocalTime.of(22, 30)
|
||||||
val zonedDateTime2230 = localDate.atTime(localTime2230).atZone(ZoneId.systemDefault())
|
val zonedDateTime2230 = localDate.atTime(localTime2230).atZone(ZoneId.systemDefault())
|
||||||
val time2230 = zonedDateTime2230.toInstant().toEpochMilli()
|
val time2230 = zonedDateTime2230.toInstant().toEpochMilli()
|
||||||
val result1 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray!!, time2230)
|
val result1 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2230)
|
||||||
assertEquals(1.7, result1, 0.01)
|
assertEquals(1.7, result1, 0.01)
|
||||||
|
|
||||||
// For 23:59
|
// For 23:59
|
||||||
val localTime2359 = LocalTime.of(23, 59)
|
val localTime2359 = LocalTime.of(23, 59)
|
||||||
val zonedDateTime2359 = localDate.atTime(localTime2359).atZone(ZoneId.systemDefault())
|
val zonedDateTime2359 = localDate.atTime(localTime2359).atZone(ZoneId.systemDefault())
|
||||||
val time2359 = zonedDateTime2359.toInstant().toEpochMilli()
|
val time2359 = zonedDateTime2359.toInstant().toEpochMilli()
|
||||||
val result2 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray!!, time2359)
|
val result2 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2359)
|
||||||
assertEquals(2.0, result2, 0.01)
|
assertEquals(2.0, result2, 0.01)
|
||||||
|
|
||||||
// For 00:00
|
// For 00:00
|
||||||
val localTime0000 = LocalTime.of(0, 0)
|
val localTime0000 = LocalTime.of(0, 0)
|
||||||
val zonedDateTime0000 = localDate.atTime(localTime0000).atZone(ZoneId.systemDefault())
|
val zonedDateTime0000 = localDate.atTime(localTime0000).atZone(ZoneId.systemDefault())
|
||||||
val time0000 = zonedDateTime0000.toInstant().toEpochMilli()
|
val time0000 = zonedDateTime0000.toInstant().toEpochMilli()
|
||||||
val result3 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray!!, time0000)
|
val result3 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time0000)
|
||||||
assertEquals(2.1, result3, 0.01)
|
assertEquals(2.1, result3, 0.01)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,15 @@ package info.nightscout.pump.medtrum
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
import info.nightscout.androidaps.TestBaseWithProfile
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.interfaces.profile.Instantiator
|
|
||||||
import info.nightscout.interfaces.pump.PumpSync
|
import info.nightscout.interfaces.pump.PumpSync
|
||||||
import info.nightscout.interfaces.pump.TemporaryBasalStorage
|
import info.nightscout.interfaces.pump.TemporaryBasalStorage
|
||||||
import info.nightscout.interfaces.stats.TddCalculator
|
import info.nightscout.interfaces.stats.TddCalculator
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
|
||||||
open class MedtrumTestBase: TestBaseWithProfile() {
|
open class MedtrumTestBase : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var instantiator: Instantiator
|
|
||||||
@Mock lateinit var tddCalculator: TddCalculator
|
@Mock lateinit var tddCalculator: TddCalculator
|
||||||
@Mock lateinit var pumpSync: PumpSync
|
@Mock lateinit var pumpSync: PumpSync
|
||||||
@Mock lateinit var temporaryBasalStorage: TemporaryBasalStorage
|
@Mock lateinit var temporaryBasalStorage: TemporaryBasalStorage
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.junit.Assert.*
|
||||||
class WriteCommandPacketsTest {
|
class WriteCommandPacketsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun Given14LongCommandExpectOnePacket() {
|
fun given14LongCommandExpectOnePacket() {
|
||||||
val input = byteArrayOf(5, 2, 0, 0, 0, 0, -21, 57, -122, -56)
|
val input = byteArrayOf(5, 2, 0, 0, 0, 0, -21, 57, -122, -56)
|
||||||
val expect = byteArrayOf(14, 5, 0, 0, 2, 0, 0, 0, 0, -21, 57, -122, -56, -93, 0)
|
val expect = byteArrayOf(14, 5, 0, 0, 2, 0, 0, 0, 0, -21, 57, -122, -56, -93, 0)
|
||||||
val sequence = 0
|
val sequence = 0
|
||||||
|
@ -17,7 +17,7 @@ class WriteCommandPacketsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun Given41LongCommandExpectThreePackets() {
|
fun given41LongCommandExpectThreePackets() {
|
||||||
val input = byteArrayOf(18, 0, 12, 0, 3, 0, 1, 30, 32, 3, 16, 14, 0, 0, 1, 7, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -20, 36, 2, 100, -123, 2)
|
val input = byteArrayOf(18, 0, 12, 0, 3, 0, 1, 30, 32, 3, 16, 14, 0, 0, 1, 7, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -20, 36, 2, 100, -123, 2)
|
||||||
val expect1 = byteArrayOf(41, 18, 0, 1, 0, 12, 0, 3, 0, 1, 30, 32, 3, 16, 14, 0, 0, 1, 7, -121)
|
val expect1 = byteArrayOf(41, 18, 0, 1, 0, 12, 0, 3, 0, 1, 30, 32, 3, 16, 14, 0, 0, 1, 7, -121)
|
||||||
val expect2 = byteArrayOf(41, 18, 0, 2, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -3)
|
val expect2 = byteArrayOf(41, 18, 0, 2, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -3)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class ActivatePacketTest : MedtrumTestBase() {
|
class ActivatePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
@ -58,7 +58,7 @@ class ActivatePacketTest : MedtrumTestBase() {
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedPatchId = 41L
|
val expectedPatchId = 41L
|
||||||
val expectedTime = 1675605528000L
|
val expectedTime = 1675605528000L
|
||||||
val exptectedBasalType = BasalType.STANDARD
|
val expectedBasalType = BasalType.STANDARD
|
||||||
val expectedBasalRate = 1.5
|
val expectedBasalRate = 1.5
|
||||||
val expectedBasalSequence = 1
|
val expectedBasalSequence = 1
|
||||||
val expectedBasalPatchId = 41L
|
val expectedBasalPatchId = 41L
|
||||||
|
@ -67,7 +67,7 @@ class ActivatePacketTest : MedtrumTestBase() {
|
||||||
assertEquals(true, result)
|
assertEquals(true, result)
|
||||||
assertEquals(expectedPatchId, medtrumPump.patchId)
|
assertEquals(expectedPatchId, medtrumPump.patchId)
|
||||||
assertEquals(expectedTime, medtrumPump.lastTimeReceivedFromPump)
|
assertEquals(expectedTime, medtrumPump.lastTimeReceivedFromPump)
|
||||||
assertEquals(exptectedBasalType, medtrumPump.lastBasalType)
|
assertEquals(expectedBasalType, medtrumPump.lastBasalType)
|
||||||
assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
|
assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
|
||||||
assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
|
assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
|
||||||
assertEquals(expectedBasalPatchId, medtrumPump.lastBasalPatchId)
|
assertEquals(expectedBasalPatchId, medtrumPump.lastBasalPatchId)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class AuthorizePacketTest : MedtrumTestBase() {
|
class AuthorizePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class CancelBolusPacketTest : MedtrumTestBase() {
|
class CancelBolusPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class CancelTempBasalPacketTest : MedtrumTestBase() {
|
class CancelTempBasalPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
@ -36,11 +36,11 @@ class CancelTempBasalPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
||||||
// Inputs
|
// Inputs
|
||||||
val repsonse = byteArrayOf(18, 25, 16, 0, 0, 0, 1, 22, 0, 3, 0, -110, 0, -32, -18, 88, 17)
|
val response = byteArrayOf(18, 25, 16, 0, 0, 0, 1, 22, 0, 3, 0, -110, 0, -32, -18, 88, 17)
|
||||||
|
|
||||||
// Call
|
// Call
|
||||||
val packet = CancelTempBasalPacket(packetInjector)
|
val packet = CancelTempBasalPacket(packetInjector)
|
||||||
val result = packet.handleResponse(repsonse)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedBasalType = BasalType.STANDARD
|
val expectedBasalType = BasalType.STANDARD
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class ClearPumpAlarmPacketTest : MedtrumTestBase() {
|
class ClearPumpAlarmPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class GetDeviceTypePacketTest : MedtrumTestBase() {
|
class GetDeviceTypePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -3,13 +3,12 @@ package info.nightscout.pump.medtrum.comm.packets
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
|
|
||||||
class GetRecordPacketTest : MedtrumTestBase() {
|
class GetRecordPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class GetTimePacketTest : MedtrumTestBase() {
|
class GetTimePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class MedtrumPacketTest : MedtrumTestBase() {
|
class MedtrumPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test base behavoir of the medtrum packet */
|
/** Test base behavior of the medtrum packet */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
@ -49,7 +49,7 @@ class MedtrumPacketTest : MedtrumTestBase() {
|
||||||
assertEquals(packet.failed, false)
|
assertEquals(packet.failed, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenRepsonseWhenOpcodeIsIncorrectThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenOpcodeIsIncorrectThenResultFalse() {
|
||||||
// Inputs
|
// Inputs
|
||||||
val opCode = 1
|
val opCode = 1
|
||||||
val responseCode = 0
|
val responseCode = 0
|
||||||
|
@ -81,7 +81,7 @@ class MedtrumPacketTest : MedtrumTestBase() {
|
||||||
assertEquals(packet.failed, false)
|
assertEquals(packet.failed, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenRepsonseCodeIsErrorThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenResponseCodeIsErrorThenResultFalse() {
|
||||||
// Inputs
|
// Inputs
|
||||||
val opCode = 1
|
val opCode = 1
|
||||||
val responseCode = 1
|
val responseCode = 1
|
||||||
|
@ -100,7 +100,6 @@ class MedtrumPacketTest : MedtrumTestBase() {
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
// Inputs
|
// Inputs
|
||||||
val opCode = 1
|
val opCode = 1
|
||||||
val responseCode = 0
|
|
||||||
val response = byteArrayOf(0) + opCode.toByte() + 0x0 + 0x0
|
val response = byteArrayOf(0) + opCode.toByte() + 0x0 + 0x0
|
||||||
|
|
||||||
// Call
|
// Call
|
||||||
|
|
|
@ -5,14 +5,13 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
||||||
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
|
||||||
import info.nightscout.rx.events.EventOverviewBolusProgress
|
import info.nightscout.rx.events.EventOverviewBolusProgress
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
|
|
||||||
class NotificationPacketTest : MedtrumTestBase() {
|
class NotificationPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test base behavoir of the Notification packet */
|
/** Test base behavior of the Notification packet */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
@ -75,7 +74,7 @@ class NotificationPacketTest : MedtrumTestBase() {
|
||||||
assertEquals(163.5, medtrumPump.reservoir, 0.01)
|
assertEquals(163.5, medtrumPump.reservoir, 0.01)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleNotificationGivenBolusFinnishedThenDataSaved() {
|
@Test fun handleNotificationGivenBolusFinishedThenDataSaved() {
|
||||||
// Inputs
|
// Inputs
|
||||||
val data = byteArrayOf(32, 34, 17, -128, 33, 0, -89, 12, -80, 0, 14, 0, 0, 0, 0, 0, 0)
|
val data = byteArrayOf(32, 34, 17, -128, 33, 0, -89, 12, -80, 0, 14, 0, 0, 0, 0, 0, 0)
|
||||||
medtrumPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, false, 1)
|
medtrumPump.bolusingTreatment = EventOverviewBolusProgress.Treatment(0.0, 0, false, 1)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class PollPatchPacketTest : MedtrumTestBase() {
|
class PollPatchPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class PrimePacketTest : MedtrumTestBase() {
|
class PrimePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class ReadBolusStatePacketTest : MedtrumTestBase() {
|
class ReadBolusStatePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class ResumePumpPacketTest : MedtrumTestBase() {
|
class ResumePumpPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class SetBasalProfilePacketTest : MedtrumTestBase() {
|
class SetBasalProfilePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
@ -36,12 +36,12 @@ class SetBasalProfilePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
||||||
// Inputs
|
// Inputs
|
||||||
val repsonse = byteArrayOf(18, 21, 16, 0, 0, 0, 1, 22, 0, 3, 0, -110, 0, -32, -18, 88, 17)
|
val response = byteArrayOf(18, 21, 16, 0, 0, 0, 1, 22, 0, 3, 0, -110, 0, -32, -18, 88, 17)
|
||||||
val basalProfile = byteArrayOf(8, 2, 3, 4, -1, 0, 0, 0, 0)
|
val basalProfile = byteArrayOf(8, 2, 3, 4, -1, 0, 0, 0, 0)
|
||||||
|
|
||||||
// Call
|
// Call
|
||||||
val packet = SetBasalProfilePacket(packetInjector, basalProfile)
|
val packet = SetBasalProfilePacket(packetInjector, basalProfile)
|
||||||
val result = packet.handleResponse(repsonse)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedBasalType = BasalType.STANDARD
|
val expectedBasalType = BasalType.STANDARD
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class SetBolusMotorPacketTest : MedtrumTestBase() {
|
class SetBolusMotorPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class SetBolusPacketTest : MedtrumTestBase() {
|
class SetBolusPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class SetPatchPacketTest : MedtrumTestBase() {
|
class SetPatchPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class SetTempBasalPacketTest : MedtrumTestBase() {
|
class SetTempBasalPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class SetTimePacketTest : MedtrumTestBase() {
|
class SetTimePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class SetTimeZonePacketTest : MedtrumTestBase() {
|
class SetTimeZonePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
@ -28,14 +28,14 @@ class SetTimeZonePacketTest : MedtrumTestBase() {
|
||||||
// Inputs
|
// Inputs
|
||||||
val opCode = 12
|
val opCode = 12
|
||||||
val time = MedtrumTimeUtil().getCurrentTimePumpSeconds()
|
val time = MedtrumTimeUtil().getCurrentTimePumpSeconds()
|
||||||
val offsetMins = dateUtil.getTimeZoneOffsetMinutes(dateUtil.now())
|
val offsetMinutes = dateUtil.getTimeZoneOffsetMinutes(dateUtil.now())
|
||||||
|
|
||||||
// Call
|
// Call
|
||||||
val packet = SetTimeZonePacket(packetInjector)
|
val packet = SetTimeZonePacket(packetInjector)
|
||||||
val result = packet.getRequest()
|
val result = packet.getRequest()
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedByteArray = byteArrayOf(opCode.toByte()) + offsetMins.toByteArray(2) + time.toByteArray(4)
|
val expectedByteArray = byteArrayOf(opCode.toByte()) + offsetMinutes.toByteArray(2) + time.toByteArray(4)
|
||||||
assertEquals(7, result.size)
|
assertEquals(7, result.size)
|
||||||
assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,9 @@ class SetTimeZonePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedOffsetMins = 0
|
val expectedOffsetMinutes = 0
|
||||||
|
|
||||||
assertTrue(result)
|
assertTrue(result)
|
||||||
assertEquals(expectedOffsetMins, medtrumPump.pumpTimeZoneOffset)
|
assertEquals(expectedOffsetMinutes, medtrumPump.pumpTimeZoneOffset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class StopPatchPacketTest : MedtrumTestBase() {
|
class StopPatchPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
@ -43,6 +43,7 @@ class StopPatchPacketTest : MedtrumTestBase() {
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedPatchId = 146L
|
val expectedPatchId = 146L
|
||||||
val expectedStopSequence = 23
|
val expectedStopSequence = 23
|
||||||
|
assertTrue(result)
|
||||||
assertEquals(expectedPatchId, medtrumPump.lastStopPatchId)
|
assertEquals(expectedPatchId, medtrumPump.lastStopPatchId)
|
||||||
assertEquals(expectedStopSequence, medtrumPump.lastStopSequence)
|
assertEquals(expectedStopSequence, medtrumPump.lastStopSequence)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class SubscribePacketTest : MedtrumTestBase() {
|
class SubscribePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.pump.medtrum.comm.packets
|
||||||
|
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.interfaces.pump.PumpSync
|
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
||||||
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
||||||
|
@ -12,7 +11,7 @@ import org.junit.Assert.*
|
||||||
|
|
||||||
class SynchronizePacketTest : MedtrumTestBase() {
|
class SynchronizePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
/** Test packet specific behavoir */
|
/** Test packet specific behavior */
|
||||||
|
|
||||||
private val packetInjector = HasAndroidInjector {
|
private val packetInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.junit.Assert.*
|
||||||
class CryptTest {
|
class CryptTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun GivenSNExpectKey() {
|
fun givenSNExpectKey() {
|
||||||
val crypt = Crypt()
|
val crypt = Crypt()
|
||||||
|
|
||||||
val input: Long = 2859923929
|
val input: Long = 2859923929
|
||||||
|
@ -16,7 +16,7 @@ class CryptTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun GivenSNExpectReal() {
|
fun givenSNExpectReal() {
|
||||||
val crypt = Crypt()
|
val crypt = Crypt()
|
||||||
|
|
||||||
val input: Long = 2859923929
|
val input: Long = 2859923929
|
||||||
|
|
Loading…
Reference in a new issue