From fa24dd43b8eb6b6062843e38276aec7b720a0741 Mon Sep 17 00:00:00 2001 From: andrekir Date: Wed, 23 Oct 2024 17:49:47 -0300 Subject: [PATCH] refactor: update `signalMetrics` filter for 0 hop packets --- .../main/java/com/geeksville/mesh/model/MetricsViewModel.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/geeksville/mesh/model/MetricsViewModel.kt b/app/src/main/java/com/geeksville/mesh/model/MetricsViewModel.kt index 5087e0ddb..00c1130aa 100644 --- a/app/src/main/java/com/geeksville/mesh/model/MetricsViewModel.kt +++ b/app/src/main/java/com/geeksville/mesh/model/MetricsViewModel.kt @@ -37,6 +37,9 @@ class MetricsViewModel @Inject constructor( ) : ViewModel() { private val destNum = MutableStateFlow(0) + private fun MeshPacket.hasValidSignal(): Boolean = + rxTime > 0 && (rxSnr != 0f && rxRssi != 0) && (hopStart > 0 && hopStart - hopLimit == 0) + @OptIn(ExperimentalCoroutinesApi::class) val state = destNum.flatMapLatest { destNum -> combine( @@ -49,7 +52,7 @@ class MetricsViewModel @Inject constructor( environmentMetrics = telemetry.filter { it.hasEnvironmentMetrics() && it.environmentMetrics.relativeHumidity >= 0f }, - signalMetrics = meshPackets.filter { it.rxTime > 0 }, + signalMetrics = meshPackets.filter { it.hasValidSignal() }, environmentDisplayFahrenheit = config.telemetry.environmentDisplayFahrenheit, ) }