Added more info to overview
This commit is contained in:
parent
c0138ffad8
commit
082b365520
|
@ -90,6 +90,15 @@ class MedtrumPump @Inject constructor(
|
||||||
_reservoir.value = value
|
_reservoir.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var batteryVoltage_A = 0.0 // Not used in UI
|
||||||
|
private val _batteryVoltage_B = MutableStateFlow(0.0)
|
||||||
|
val batteryVoltage_BFlow: StateFlow<Double> = _batteryVoltage_B
|
||||||
|
var batteryVoltage_B: Double
|
||||||
|
get() = _batteryVoltage_B.value
|
||||||
|
set(value) {
|
||||||
|
_batteryVoltage_B.value = value
|
||||||
|
}
|
||||||
|
|
||||||
/** Stuff stored in SP */
|
/** Stuff stored in SP */
|
||||||
private var _patchSessionToken = 0L
|
private var _patchSessionToken = 0L
|
||||||
var patchSessionToken: Long
|
var patchSessionToken: Long
|
||||||
|
@ -140,19 +149,41 @@ class MedtrumPump @Inject constructor(
|
||||||
sp.putLong(R.string.key_last_connection, value)
|
sp.putLong(R.string.key_last_connection, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var _deviceType: Int = 0 // As reported by pump
|
||||||
|
var deviceType: Int
|
||||||
|
get() = _deviceType
|
||||||
|
set(value) {
|
||||||
|
_deviceType = value
|
||||||
|
sp.putInt(R.string.key_device_type, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var _swVersion: String = "" // As reported by pump
|
||||||
|
var swVersion: String
|
||||||
|
get() = _swVersion
|
||||||
|
set(value) {
|
||||||
|
_swVersion = value
|
||||||
|
sp.putString(R.string.key_sw_version, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var _patchStartTime = 0L // Time in ms!
|
||||||
|
var patchStartTime: Long
|
||||||
|
get() = _patchStartTime
|
||||||
|
set(value) {
|
||||||
|
_patchStartTime = value
|
||||||
|
sp.putLong(R.string.key_patch_start_time, value)
|
||||||
|
}
|
||||||
|
|
||||||
private var _pumpSN = 0L
|
private var _pumpSN = 0L
|
||||||
val pumpSN: Long
|
val pumpSN: Long
|
||||||
get() = _pumpSN
|
get() = _pumpSN
|
||||||
|
|
||||||
val pumpType: PumpType = PumpType.MEDTRUM_NANO // TODO, type based on pumpSN or pump activation/connection
|
val pumpType: PumpType = PumpType.MEDTRUM_NANO // TODO, type based on deviceType from pump
|
||||||
|
|
||||||
var lastTimeReceivedFromPump = 0L // Time in ms! // TODO: Consider removing as is not used?
|
var lastTimeReceivedFromPump = 0L // Time in ms! // TODO: Consider removing as is not used?
|
||||||
var suspendTime = 0L // Time in ms!
|
var suspendTime = 0L // Time in ms!
|
||||||
var patchStartTime = 0L // Time in ms! // TODO: save in SP
|
|
||||||
var patchAge = 0L // Time in seconds?! // TODO: Not used
|
var patchAge = 0L // Time in seconds?! // TODO: Not used
|
||||||
|
|
||||||
var batteryVoltage_A = 0.0
|
|
||||||
var batteryVoltage_B = 0.0
|
|
||||||
|
|
||||||
var alarmFlags = 0
|
var alarmFlags = 0
|
||||||
var alarmParameter = 0
|
var alarmParameter = 0
|
||||||
|
@ -198,6 +229,9 @@ class MedtrumPump @Inject constructor(
|
||||||
_patchId = sp.getLong(R.string.key_patch_id, 0L)
|
_patchId = sp.getLong(R.string.key_patch_id, 0L)
|
||||||
_syncedSequenceNumber = sp.getInt(R.string.key_synced_sequence_number, 0)
|
_syncedSequenceNumber = sp.getInt(R.string.key_synced_sequence_number, 0)
|
||||||
_pumpState.value = MedtrumPumpState.fromByte(sp.getInt(R.string.key_pump_state, MedtrumPumpState.NONE.state.toInt()).toByte())
|
_pumpState.value = MedtrumPumpState.fromByte(sp.getInt(R.string.key_pump_state, MedtrumPumpState.NONE.state.toInt()).toByte())
|
||||||
|
_deviceType = sp.getInt(R.string.key_device_type, 0)
|
||||||
|
_swVersion = sp.getString(R.string.key_sw_version, "")
|
||||||
|
_patchStartTime = sp.getLong(R.string.key_patch_start_time, 0L)
|
||||||
|
|
||||||
val encodedString = sp.getString(R.string.key_actual_basal_profile, "0")
|
val encodedString = sp.getString(R.string.key_actual_basal_profile, "0")
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -6,15 +6,13 @@ import info.nightscout.pump.medtrum.comm.enums.CommandType.AUTH_REQ
|
||||||
import info.nightscout.pump.medtrum.encryption.Crypt
|
import info.nightscout.pump.medtrum.encryption.Crypt
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
import info.nightscout.pump.medtrum.extension.toByteArray
|
||||||
import info.nightscout.pump.medtrum.extension.toInt
|
import info.nightscout.pump.medtrum.extension.toInt
|
||||||
|
import info.nightscout.rx.logging.LTag
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class AuthorizePacket(injector: HasAndroidInjector) : MedtrumPacket(injector) {
|
class AuthorizePacket(injector: HasAndroidInjector) : MedtrumPacket(injector) {
|
||||||
|
|
||||||
@Inject lateinit var medtrumPump: MedtrumPump
|
@Inject lateinit var medtrumPump: MedtrumPump
|
||||||
|
|
||||||
var deviceType: Int = 0
|
|
||||||
var swVersion: String = ""
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val RESP_DEVICE_TYPE_START = 7
|
private const val RESP_DEVICE_TYPE_START = 7
|
||||||
|
@ -41,10 +39,18 @@ class AuthorizePacket(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) {
|
||||||
deviceType = data.copyOfRange(RESP_DEVICE_TYPE_START, RESP_DEVICE_TYPE_END).toInt()
|
val deviceType = data.copyOfRange(RESP_DEVICE_TYPE_START, RESP_DEVICE_TYPE_END).toInt()
|
||||||
swVersion = "" + data.copyOfRange(RESP_VERSION_X_START, RESP_VERSION_X_END).toInt() + "." + data.copyOfRange(RESP_VERSION_Y_START, RESP_VERSION_Y_END).toInt() + "." + data.copyOfRange(
|
val swVersion = "" + data.copyOfRange(RESP_VERSION_X_START, RESP_VERSION_X_END).toInt() + "." + data.copyOfRange(RESP_VERSION_Y_START, RESP_VERSION_Y_END).toInt() + "." + data.copyOfRange(
|
||||||
RESP_VERSION_Z_START, RESP_VERSION_Z_END
|
RESP_VERSION_Z_START, RESP_VERSION_Z_END
|
||||||
).toInt()
|
).toInt()
|
||||||
|
|
||||||
|
if (medtrumPump.deviceType != deviceType) {
|
||||||
|
medtrumPump.deviceType = deviceType
|
||||||
|
}
|
||||||
|
if (medtrumPump.swVersion != swVersion) {
|
||||||
|
medtrumPump.swVersion = swVersion
|
||||||
|
}
|
||||||
|
aapsLogger.debug(LTag.PUMPCOMM, "GetDeviceTypeState: deviceType: ${deviceType}, swVersion: ${swVersion}")
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,8 +188,12 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
||||||
|
|
||||||
if (fieldMask and MASK_START_TIME != 0) {
|
if (fieldMask and MASK_START_TIME != 0) {
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Start time notification received")
|
aapsLogger.debug(LTag.PUMPCOMM, "Start time notification received")
|
||||||
medtrumPump.patchStartTime = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(offset, offset + 4).toLong())
|
val patchStartTime = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(offset, offset + 4).toLong())
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "Patch start time: ${medtrumPump.patchStartTime}")
|
if (medtrumPump.patchStartTime != patchStartTime) {
|
||||||
|
aapsLogger.debug(LTag.PUMPCOMM, "Patch start time changed from ${medtrumPump.patchStartTime} to $patchStartTime")
|
||||||
|
medtrumPump.patchStartTime = patchStartTime
|
||||||
|
}
|
||||||
|
aapsLogger.debug(LTag.PUMPCOMM, "Patch start time: ${patchStartTime}")
|
||||||
offset += 4
|
offset += 4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -587,10 +587,6 @@ class MedtrumService : DaggerService(), BLECommCallback {
|
||||||
// Succes!
|
// Succes!
|
||||||
responseHandled = true
|
responseHandled = true
|
||||||
responseSuccess = true
|
responseSuccess = true
|
||||||
// TODO Get pump version info
|
|
||||||
val deviceType = (mPacket as AuthorizePacket).deviceType
|
|
||||||
val swVersion = (mPacket as AuthorizePacket).swVersion
|
|
||||||
aapsLogger.debug(LTag.PUMPCOMM, "GetDeviceTypeState: deviceType: $deviceType swVersion: $swVersion") // TODO remove me later
|
|
||||||
toState(GetDeviceTypeState())
|
toState(GetDeviceTypeState())
|
||||||
} else if (mPacket?.failed == true) {
|
} else if (mPacket?.failed == true) {
|
||||||
// Failure
|
// Failure
|
||||||
|
|
|
@ -151,9 +151,9 @@ class MedtrumOverviewViewModel @Inject constructor(
|
||||||
|
|
||||||
// TODO: Update these values
|
// TODO: Update these values
|
||||||
// _activeAlarms.postValue(rh.gs(R.string.active_alarms, pump.activeAlarms))
|
// _activeAlarms.postValue(rh.gs(R.string.active_alarms, pump.activeAlarms))
|
||||||
// _pumpType.postValue(rh.gs(R.string.pump_type, pump.pumpType))
|
_pumpType.postValue(medtrumPump.deviceType.toString())
|
||||||
// _fwVersion.postValue(rh.gs(R.string.fw_version, pump.fwVersion))
|
_fwVersion.postValue(medtrumPump.swVersion)
|
||||||
// _patchNo.postValue(rh.gs(R.string.patch_no, pump.patchNo))
|
_patchNo.postValue(medtrumPump.patchId.toString())
|
||||||
|
|
||||||
if (medtrumPump.desiredPatchExpiration) {
|
if (medtrumPump.desiredPatchExpiration) {
|
||||||
val expiry = medtrumPump.patchStartTime + T.hours(84).msecs()
|
val expiry = medtrumPump.patchStartTime + T.hours(84).msecs()
|
||||||
|
|
|
@ -276,6 +276,46 @@
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Battery voltage -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginVertical="3dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1.5"
|
||||||
|
android:gravity="end"
|
||||||
|
android:paddingStart="5dp"
|
||||||
|
android:paddingEnd="5dp"
|
||||||
|
android:text="@string/battery_label"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="5dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingStart="2dp"
|
||||||
|
android:paddingEnd="2dp"
|
||||||
|
android:text=":"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/battery"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="start"
|
||||||
|
android:paddingStart="5dp"
|
||||||
|
android:paddingEnd="5dp"
|
||||||
|
android:text='@{@string/battery_voltage(viewmodel.medtrumPump.batteryVoltage_BFlow)}'
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Active Alarms -->
|
<!-- Active Alarms -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
<string name="key_last_connection" translatable="false">last_connection</string>
|
<string name="key_last_connection" translatable="false">last_connection</string>
|
||||||
<string name="key_session_token" translatable="false">medtrum_session_token</string>
|
<string name="key_session_token" translatable="false">medtrum_session_token</string>
|
||||||
<string name="key_patch_id" translatable="false">patch_id</string>
|
<string name="key_patch_id" translatable="false">patch_id</string>
|
||||||
|
<string name="key_device_type" translatable="false">device_type</string>
|
||||||
|
<string name="key_sw_version" translatable="false">sw_version</string>
|
||||||
|
<string name="key_patch_start_time" translatable="false">patch_start_time</string>
|
||||||
<string name="key_actual_basal_profile" translatable="false">actual_basal_profile</string>
|
<string name="key_actual_basal_profile" translatable="false">actual_basal_profile</string>
|
||||||
<string name="key_current_sequence_number" translatable="false">current_sequence_number</string>
|
<string name="key_current_sequence_number" translatable="false">current_sequence_number</string>
|
||||||
<string name="key_synced_sequence_number" translatable="false">synced_sequence_number</string>
|
<string name="key_synced_sequence_number" translatable="false">synced_sequence_number</string>
|
||||||
|
@ -34,6 +37,8 @@
|
||||||
<string name="active_alarms_label">Active alarms</string>
|
<string name="active_alarms_label">Active alarms</string>
|
||||||
<string name="reservoir_label"> Reservoir</string>
|
<string name="reservoir_label"> Reservoir</string>
|
||||||
<string name="reservoir_level"> %.2f U</string>
|
<string name="reservoir_level"> %.2f U</string>
|
||||||
|
<string name="battery_label">Battery</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>
|
||||||
|
|
|
@ -59,8 +59,8 @@ class AuthorizePacketTest : MedtrumTestBase() {
|
||||||
val swString = "$swVerX.$swVerY.$swVerZ"
|
val swString = "$swVerX.$swVerY.$swVerZ"
|
||||||
assertTrue(result)
|
assertTrue(result)
|
||||||
assertFalse(packet.failed)
|
assertFalse(packet.failed)
|
||||||
assertEquals(deviceType, packet.deviceType)
|
assertEquals(deviceType, medtrumPump.deviceType)
|
||||||
assertEquals(swString, packet.swVersion)
|
assertEquals(swString, medtrumPump.swVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
|
Loading…
Reference in a new issue