From ebe0aeec14820180087274c85190d9f9c6b8b11f Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:04:05 -0500 Subject: [PATCH] Adds support for known 0 hopsAway (#1295) --- .../mesh/database/entity/NodeEntity.kt | 2 +- .../geeksville/mesh/service/MeshService.kt | 14 ++++++++--- .../java/com/geeksville/mesh/ui/SignalInfo.kt | 24 ++++++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/database/entity/NodeEntity.kt b/app/src/main/java/com/geeksville/mesh/database/entity/NodeEntity.kt index ab6f8a21..56b6b127 100644 --- a/app/src/main/java/com/geeksville/mesh/database/entity/NodeEntity.kt +++ b/app/src/main/java/com/geeksville/mesh/database/entity/NodeEntity.kt @@ -48,7 +48,7 @@ data class NodeEntity( var viaMqtt: Boolean = false, @ColumnInfo(name = "hops_away") - var hopsAway: Int = 0, + var hopsAway: Int = -1, @ColumnInfo(name = "is_favorite") var isFavorite: Boolean = false, diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 0ef5fe59..47aa2992 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -1101,8 +1101,10 @@ class MeshService : Service(), Logging { it.rssi = packet.rxRssi // Generate our own hopsAway, comparing hopStart to hopLimit. - if (packet.hopStart != 0 && packet.hopLimit <= packet.hopStart) { - it.hopsAway = packet.hopStart - packet.hopLimit + it.hopsAway = if (packet.hopStart == 0 || packet.hopLimit < packet.hopStart) { + -1 + } else { + packet.hopStart - packet.hopLimit } } handleReceivedData(packet) @@ -1407,7 +1409,13 @@ class MeshService : Service(), Logging { it.channel = info.channel it.viaMqtt = info.viaMqtt - it.hopsAway = info.hopsAway + + // hopsAway should be nullable/optional from the proto, but explicitly checking it's existence first + it.hopsAway = if (info.hasHopsAway()) { + info.hopsAway + } else { + -1 + } it.isFavorite = info.isFavorite } } diff --git a/app/src/main/java/com/geeksville/mesh/ui/SignalInfo.kt b/app/src/main/java/com/geeksville/mesh/ui/SignalInfo.kt index 82e10981..eec6023f 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SignalInfo.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SignalInfo.kt @@ -13,6 +13,9 @@ import com.geeksville.mesh.database.entity.NodeEntity import com.geeksville.mesh.ui.preview.NodeEntityPreviewParameterProvider import com.geeksville.mesh.ui.theme.AppTheme +const val MAX_VALID_SNR = 100F +const val MAX_VALID_RSSI = 0 + @Composable fun signalInfo( modifier: Modifier = Modifier, @@ -26,15 +29,24 @@ fun signalInfo( ) } else { buildList { - if (node.channel > 0) add("ch:${node.channel}") - if (node.hopsAway == 0) { - if (node.snr < 100F && node.rssi < 0) { + val hopsString = "%s: %s".format( + stringResource(R.string.hops_away), + if (node.hopsAway == -1) { + stringResource(R.string.unknown) + } else { + node.hopsAway.toString() + } + ) + if (node.channel > 0) { + add("ch:${node.channel}") + } + if (node.hopsAway <= 0) { + if (node.snr < MAX_VALID_SNR && node.rssi < MAX_VALID_RSSI) { add("RSSI: %d SNR: %.1f".format(node.rssi, node.snr)) } - } else { - add("%s: %d".format(stringResource(R.string.hops_away), node.hopsAway)) } - }.joinToString(" ") + add(hopsString) + }.joinToString(" | ") } return if (text.isNotEmpty()) { Text(