add connection quality and delivery status

This commit is contained in:
Andrei Vereha 2021-07-31 12:49:44 +02:00
parent ea5ec8e2c1
commit 8743ae208c
7 changed files with 142 additions and 21 deletions

View file

@ -166,7 +166,7 @@ class OmnipodDashBleManagerImpl @Inject constructor(
throw SessionEstablishmentException("Received resynchronization SQN for the second time") throw SessionEstablishmentException("Received resynchronization SQN for the second time")
} }
} }
podState.successfulConnections++
podState.commitEapAkaSequenceNumber() podState.commitEapAkaSequenceNumber()
} }
@ -223,6 +223,7 @@ class OmnipodDashBleManagerImpl @Inject constructor(
} }
emitter.onNext(PodEvent.EstablishingSession) emitter.onNext(PodEvent.EstablishingSession)
establishSession(pairResult.msgSeq) establishSession(pairResult.msgSeq)
podState.successfulConnections++
emitter.onNext(PodEvent.Connected) emitter.onNext(PodEvent.Connected)
emitter.onComplete() emitter.onComplete()
} catch (ex: Exception) { } catch (ex: Exception) {

View file

@ -64,7 +64,7 @@ class Connection(
fun connect(connectionWaitCond: ConnectionWaitCondition) { fun connect(connectionWaitCond: ConnectionWaitCondition) {
aapsLogger.debug("Connecting connectionWaitCond=$connectionWaitCond") aapsLogger.debug("Connecting connectionWaitCond=$connectionWaitCond")
podState.connectionAttempts++
podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING
val autoConnect = false val autoConnect = false
val gatt = gattConnection val gatt = gattConnection

View file

@ -31,6 +31,8 @@ interface OmnipodDashPodStateManager {
val isPodRunning: Boolean val isPodRunning: Boolean
val isPodKaput: Boolean val isPodKaput: Boolean
var bluetoothConnectionState: BluetoothConnectionState var bluetoothConnectionState: BluetoothConnectionState
var connectionAttempts: Int
var successfulConnections: Int
var timeZone: TimeZone var timeZone: TimeZone
val sameTimeZone: Boolean // The TimeZone is the same on the phone and on the pod val sameTimeZone: Boolean // The TimeZone is the same on the phone and on the pod
@ -81,6 +83,7 @@ interface OmnipodDashPodStateManager {
fun updateFromAlarmStatusResponse(response: AlarmStatusResponse) fun updateFromAlarmStatusResponse(response: AlarmStatusResponse)
fun updateFromPairing(uniqueId: Id, pairResult: PairResult) fun updateFromPairing(uniqueId: Id, pairResult: PairResult)
fun reset() fun reset()
fun connectionSuccessRatio(): Float
fun createActiveCommand( fun createActiveCommand(
historyId: String, historyId: String,

View file

@ -98,6 +98,22 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
} }
} }
override var connectionAttempts: Int
@Synchronized
get() = podState.connectionAttempts
@Synchronized
set(value) {
podState.connectionAttempts = value
}
override var successfulConnections: Int
@Synchronized
get() = podState.successfulConnections
@Synchronized
set(value) {
podState.successfulConnections = value
}
override var timeZone: TimeZone override var timeZone: TimeZone
get() = TimeZone.getTimeZone(podState.timeZone) get() = TimeZone.getTimeZone(podState.timeZone)
set(tz) { set(tz) {
@ -588,6 +604,14 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
podState.uniqueId = uniqueId.toLong() podState.uniqueId = uniqueId.toLong()
} }
override fun connectionSuccessRatio(): Float {
val attempts = connectionAttempts
if (attempts == 0) {
return 1.0F
}
return successfulConnections.toFloat() * 100 / attempts.toFloat()
}
override fun reset() { override fun reset() {
podState = PodState() podState = PodState()
store() store()
@ -625,6 +649,8 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
var lastStatusResponseReceived: Long = 0 var lastStatusResponseReceived: Long = 0
var bluetoothConnectionState: OmnipodDashPodStateManager.BluetoothConnectionState = var bluetoothConnectionState: OmnipodDashPodStateManager.BluetoothConnectionState =
OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED
var connectionAttempts = 0
var successfulConnections = 0
var messageSequenceNumber: Short = 0 var messageSequenceNumber: Short = 0
var sequenceNumberOfLastProgrammingCommand: Short? = null var sequenceNumberOfLastProgrammingCommand: Short? = null
var activationTime: Long? = null var activationTime: Long? = null

View file

@ -24,7 +24,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.Comm
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandResumeDelivery import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandResumeDelivery
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandSilenceAlerts import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandSilenceAlerts
import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandSuspendDelivery import info.nightscout.androidaps.plugins.pump.omnipod.common.queue.command.CommandSuspendDelivery
import info.nightscout.androidaps.plugins.pump.omnipod.dash.BuildConfig
import info.nightscout.androidaps.plugins.pump.omnipod.dash.EventOmnipodDashPumpValuesChanged import info.nightscout.androidaps.plugins.pump.omnipod.dash.EventOmnipodDashPumpValuesChanged
import info.nightscout.androidaps.plugins.pump.omnipod.dash.OmnipodDashPumpPlugin import info.nightscout.androidaps.plugins.pump.omnipod.dash.OmnipodDashPumpPlugin
import info.nightscout.androidaps.plugins.pump.omnipod.dash.R import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
@ -83,17 +82,17 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
} }
} }
var _binding: OmnipodDashOverviewBinding? = null private var _binding: OmnipodDashOverviewBinding? = null
var _bluetoothStatusBinding: OmnipodDashOverviewBluetoothStatusBinding? = null private var _bluetoothStatusBinding: OmnipodDashOverviewBluetoothStatusBinding? = null
var _podInfoBinding: OmnipodCommonOverviewPodInfoBinding? = null private var _podInfoBinding: OmnipodCommonOverviewPodInfoBinding? = null
var _buttonBinding: OmnipodCommonOverviewButtonsBinding? = null private var _buttonBinding: OmnipodCommonOverviewButtonsBinding? = null
// These properties are only valid between onCreateView and // These properties are only valid between onCreateView and
// onDestroyView. // onDestroyView.
val binding get() = _binding!! val binding get() = _binding!!
val bluetoothStatusBinding get() = _bluetoothStatusBinding!! val bluetoothStatusBinding get() = _bluetoothStatusBinding!!
val podInfoBinding get() = _podInfoBinding!! private val podInfoBinding get() = _podInfoBinding!!
val buttonBinding get() = _buttonBinding!! private val buttonBinding get() = _buttonBinding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
OmnipodDashOverviewBinding.inflate(inflater, container, false).also { OmnipodDashOverviewBinding.inflate(inflater, container, false).also {
@ -234,6 +233,23 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING -> OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING ->
"{fa-bluetooth-b spin}" "{fa-bluetooth-b spin}"
} }
val connectionSuccessPercentage = podStateManager.connectionSuccessRatio() * 100
val successPercentageString = String.format("%.2f %", podStateManager.connectionSuccessRatio())
val connectionQuality = "${podStateManager.successfulConnections}/${podStateManager.connectionAttempts} :: $successPercentageString"
bluetoothStatusBinding.omnipodDashBluetoothConnectionQuality.text = connectionQuality
val connectionStatsColor = when {
connectionSuccessPercentage > 90 ->
Color.WHITE
connectionSuccessPercentage > 60 ->
Color.YELLOW
else ->
Color.RED
}
bluetoothStatusBinding.omnipodDashBluetoothConnectionQuality.setTextColor(connectionStatsColor)
bluetoothStatusBinding.omnipodDashDeliveryStatus.text = podStateManager.deliveryStatus?.let {
podStateManager.deliveryStatus.toString()
} ?: PLACEHOLDER
} }
private fun updateOmnipodStatus() { private fun updateOmnipodStatus() {
@ -361,8 +377,8 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
) )
} }
podInfoBinding.podActiveAlerts.text = podStateManager.activeAlerts?.let { podInfoBinding.podActiveAlerts.text = podStateManager.activeAlerts?.let { it ->
it.map { it.toString() }.joinToString(",") it.joinToString(",") { it.toString() }
} ?: PLACEHOLDER } ?: PLACEHOLDER
} }
@ -415,12 +431,8 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
if (podStateManager.isSuspended) { if (podStateManager.isSuspended) {
resourceHelper.gs(R.string.omnipod_common_pod_status_suspended) resourceHelper.gs(R.string.omnipod_common_pod_status_suspended)
} else { } else {
resourceHelper.gs(R.string.omnipod_common_pod_status_running) + resourceHelper.gs(R.string.omnipod_common_pod_status_running)
if (BuildConfig.DEBUG)
podStateManager.deliveryStatus?.let { " " + podStateManager.deliveryStatus.toString() }
else ""
} }
// TODO
/* /*
} else if (podStateManager.podStatus == PodProgressStatus.FAULT_EVENT_OCCURRED) { } else if (podStateManager.podStatus == PodProgressStatus.FAULT_EVENT_OCCURRED) {
resourceHelper.gs(R.string.omnipod_common_pod_status_pod_fault) resourceHelper.gs(R.string.omnipod_common_pod_status_pod_fault)
@ -466,10 +478,10 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
podInfoBinding.lastBolus.setTextColor(textColor) podInfoBinding.lastBolus.setTextColor(textColor)
podStateManager.lastBolus?.let { podStateManager.lastBolus?.let {
// display requested units if delivery is in progress // display requested units if delivery is in progress
var bolusSize = it.deliveredUnits() val bolusSize = it.deliveredUnits()
?: it.requestedUnits ?: it.requestedUnits
var text = resourceHelper.gs( val text = resourceHelper.gs(
R.string.omnipod_common_overview_last_bolus_value, R.string.omnipod_common_overview_last_bolus_value,
omnipodDashPumpPlugin.model().determineCorrectBolusSize(bolusSize), omnipodDashPumpPlugin.model().determineCorrectBolusSize(bolusSize),
resourceHelper.gs(R.string.insulin_unit_shortname), resourceHelper.gs(R.string.insulin_unit_shortname),

View file

@ -13,7 +13,7 @@
android:gravity="end" android:gravity="end"
android:paddingStart="5dp" android:paddingStart="5dp"
android:paddingEnd="5dp" android:paddingEnd="5dp"
android:text="@string/omnipod_dash_overview_bluetooth_status" android:text="@string/omnipod_dash_overview_bluetooth_address"
android:textSize="14sp" /> android:textSize="14sp" />
<TextView <TextView
@ -51,7 +51,7 @@
android:gravity="end" android:gravity="end"
android:paddingStart="5dp" android:paddingStart="5dp"
android:paddingEnd="5dp" android:paddingEnd="5dp"
android:text="@string/omnipod_dash_overview_bluetooth_address" android:text="@string/omnipod_dash_overview_bluetooth_status"
android:textSize="14sp" /> android:textSize="14sp" />
<TextView <TextView
@ -78,6 +78,83 @@
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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/omnipod_dash_overview_bluetooth_connection_quality"
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"
tools:ignore="HardcodedText" />
<com.joanzapata.iconify.widget.IconTextView
android:id="@+id/omnipod_dash_bluetooth_connection_quality"
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="{fa-bluetooth-b} "
android:textSize="14sp"
tools:ignore="HardcodedText" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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/omnipod_dash_overview_delivery_status"
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"
tools:ignore="HardcodedText" />
<com.joanzapata.iconify.widget.IconTextView
android:id="@+id/omnipod_dash_delivery_status"
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="{fa-bluetooth-b} "
android:textSize="14sp"
tools:ignore="HardcodedText" />
</LinearLayout>
<View <View
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="2dip" android:layout_height="2dip"

View file

@ -12,6 +12,8 @@
<string name="omnipod_dash_overview_bluetooth_status">Bluetooth Status</string> <string name="omnipod_dash_overview_bluetooth_status">Bluetooth Status</string>
<string name="omnipod_dash_overview_bluetooth_address">Bluetooth Address</string> <string name="omnipod_dash_overview_bluetooth_address">Bluetooth Address</string>
<string name="omnipod_dash_overview_firmware_version_value">Firmware %1$s / Bluetooth %2$s</string> <string name="omnipod_dash_overview_firmware_version_value">Firmware %1$s / Bluetooth %2$s</string>
<string name="omnipod_dash_overview_bluetooth_connection_quality">Connection quality</string>
<string name="omnipod_dash_overview_delivery_status">Delivery Status</string>
<!-- Omnipod Dash - Pod Activation Wizard --> <!-- Omnipod Dash - Pod Activation Wizard -->
<string name="omnipod_dash_pod_activation_wizard_start_pod_activation_text">Fill a new Pod with enough insulin for 3 days.\n\nListen for two beeps from the Pod during the filling process. These indicate that the minimum amount of 85U has been inserted. Be sure to completely empty the fill syringe, even after hearing the two beeps.\n\nAfter filling the Pod, please press <b>Next</b>.\n\n<b>Note:</b> do not remove the Pod\'s needle cap at this time.</string> <string name="omnipod_dash_pod_activation_wizard_start_pod_activation_text">Fill a new Pod with enough insulin for 3 days.\n\nListen for two beeps from the Pod during the filling process. These indicate that the minimum amount of 85U has been inserted. Be sure to completely empty the fill syringe, even after hearing the two beeps.\n\nAfter filling the Pod, please press <b>Next</b>.\n\n<b>Note:</b> do not remove the Pod\'s needle cap at this time.</string>