connection quality: count connections after retries
This commit is contained in:
parent
7826c41834
commit
59c7955126
4 changed files with 16 additions and 13 deletions
|
@ -243,7 +243,6 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
val stop = CountDownLatch(1)
|
val stop = CountDownLatch(1)
|
||||||
stopConnecting = stop
|
stopConnecting = stop
|
||||||
}
|
}
|
||||||
podStateManager.incrementConnectionAttemptsWithRetries()
|
|
||||||
thread(
|
thread(
|
||||||
start = true,
|
start = true,
|
||||||
name = "ConnectionThread",
|
name = "ConnectionThread",
|
||||||
|
@ -252,6 +251,9 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
stopConnecting?.let {
|
stopConnecting?.let {
|
||||||
val error = omnipodManager.connect(it).ignoreElements().blockingGet()
|
val error = omnipodManager.connect(it).ignoreElements().blockingGet()
|
||||||
aapsLogger.info(LTag.PUMPCOMM, "connect error=$error")
|
aapsLogger.info(LTag.PUMPCOMM, "connect error=$error")
|
||||||
|
if (error == null) {
|
||||||
|
podStateManager.incrementSuccessfulConnectionAttemptsAfterRetries()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ interface OmnipodDashPodStateManager {
|
||||||
var bluetoothConnectionState: BluetoothConnectionState
|
var bluetoothConnectionState: BluetoothConnectionState
|
||||||
var connectionAttempts: Int
|
var connectionAttempts: Int
|
||||||
var successfulConnections: Int
|
var successfulConnections: Int
|
||||||
val connectionAttemptsWithRetries: Int
|
val successfulConnectionAttemptsAfterRetries: Int
|
||||||
val failedConnectionsAfterRetries: Int
|
val failedConnectionsAfterRetries: Int
|
||||||
|
|
||||||
var timeZone: TimeZone
|
var timeZone: TimeZone
|
||||||
|
@ -87,7 +87,7 @@ interface OmnipodDashPodStateManager {
|
||||||
fun updateFromPairing(uniqueId: Id, pairResult: PairResult)
|
fun updateFromPairing(uniqueId: Id, pairResult: PairResult)
|
||||||
fun reset()
|
fun reset()
|
||||||
fun connectionSuccessRatio(): Float
|
fun connectionSuccessRatio(): Float
|
||||||
fun incrementConnectionAttemptsWithRetries()
|
fun incrementSuccessfulConnectionAttemptsAfterRetries()
|
||||||
fun incrementFailedConnectionsAfterRetries()
|
fun incrementFailedConnectionsAfterRetries()
|
||||||
|
|
||||||
fun createActiveCommand(
|
fun createActiveCommand(
|
||||||
|
|
|
@ -114,13 +114,13 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
podState.successfulConnections = value
|
podState.successfulConnections = value
|
||||||
}
|
}
|
||||||
|
|
||||||
override val connectionAttemptsWithRetries: Int
|
override val successfulConnectionAttemptsAfterRetries: Int
|
||||||
@Synchronized
|
@Synchronized
|
||||||
get() = podState.connectionAttemptsWithRetries
|
get() = podState.successfulConnectionAttemptsAfterRetries
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun incrementConnectionAttemptsWithRetries() {
|
override fun incrementSuccessfulConnectionAttemptsAfterRetries() {
|
||||||
podState.connectionAttemptsWithRetries++
|
podState.successfulConnectionAttemptsAfterRetries++
|
||||||
}
|
}
|
||||||
|
|
||||||
override val failedConnectionsAfterRetries: Int
|
override val failedConnectionsAfterRetries: Int
|
||||||
|
@ -646,10 +646,10 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun connectionSuccessRatio(): Float {
|
override fun connectionSuccessRatio(): Float {
|
||||||
if (connectionAttemptsWithRetries == 0) {
|
if (failedConnectionsAfterRetries + successfulConnectionAttemptsAfterRetries == 0) {
|
||||||
return 0.0F
|
return 0.0F
|
||||||
}
|
}
|
||||||
return 1 - (failedConnectionsAfterRetries.toFloat() / connectionAttemptsWithRetries)
|
return successfulConnectionAttemptsAfterRetries.toFloat() / (successfulConnectionAttemptsAfterRetries + failedConnectionsAfterRetries)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun reset() {
|
override fun reset() {
|
||||||
|
@ -691,7 +691,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED
|
OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED
|
||||||
var connectionAttempts = 0
|
var connectionAttempts = 0
|
||||||
var successfulConnections = 0
|
var successfulConnections = 0
|
||||||
var connectionAttemptsWithRetries = 0
|
var successfulConnectionAttemptsAfterRetries = 0
|
||||||
var failedConnectionsAfterRetries = 0
|
var failedConnectionsAfterRetries = 0
|
||||||
var messageSequenceNumber: Short = 0
|
var messageSequenceNumber: Short = 0
|
||||||
var sequenceNumberOfLastProgrammingCommand: Short? = null
|
var sequenceNumberOfLastProgrammingCommand: Short? = null
|
||||||
|
|
|
@ -256,14 +256,15 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
?: PLACEHOLDER
|
?: PLACEHOLDER
|
||||||
|
|
||||||
val connectionSuccessPercentage = podStateManager.connectionSuccessRatio() * 100
|
val connectionSuccessPercentage = podStateManager.connectionSuccessRatio() * 100
|
||||||
|
val connectionAttempts = podStateManager.failedConnectionsAfterRetries + podStateManager.successfulConnectionAttemptsAfterRetries
|
||||||
val successPercentageString = String.format("%.2f %%", connectionSuccessPercentage)
|
val successPercentageString = String.format("%.2f %%", connectionSuccessPercentage)
|
||||||
val quality =
|
val quality =
|
||||||
"${podStateManager.connectionAttemptsWithRetries - podStateManager.failedConnectionsAfterRetries}/${podStateManager.connectionAttemptsWithRetries} :: $successPercentageString"
|
"${podStateManager.successfulConnectionAttemptsAfterRetries}/$connectionAttempts :: $successPercentageString"
|
||||||
bluetoothStatusBinding.omnipodDashBluetoothConnectionQuality.text = quality
|
bluetoothStatusBinding.omnipodDashBluetoothConnectionQuality.text = quality
|
||||||
val connectionStatsColor = when {
|
val connectionStatsColor = when {
|
||||||
connectionSuccessPercentage < 70 && podStateManager.connectionAttemptsWithRetries > 50 ->
|
connectionSuccessPercentage < 70 && podStateManager.successfulConnectionAttemptsAfterRetries > 50 ->
|
||||||
Color.RED
|
Color.RED
|
||||||
connectionSuccessPercentage < 90 && podStateManager.connectionAttemptsWithRetries > 50 ->
|
connectionSuccessPercentage < 90 && podStateManager.successfulConnectionAttemptsAfterRetries > 50 ->
|
||||||
Color.YELLOW
|
Color.YELLOW
|
||||||
else ->
|
else ->
|
||||||
Color.WHITE
|
Color.WHITE
|
||||||
|
|
Loading…
Reference in a new issue