Hops Away implementation (#966)

* Initial Hops Away feature

* Generate our own hopsAway, comparing hopStart to hopLimit

* Remove import of hopsAway from device nodeInfo, as this only shows 0 when hopStart isn't included on packets (with this info, we can't differentiate between a node which is Hops Away but on old firmware, or nodes which are on new firmware but direct. Both are 0)

Check if hopStart is 0 but hopLimit is not 0, if true set hopsAway to -1.

Show nodes with hopsAway with -1 with a (!) appended to the RSSI details, to show this probably isn't true. (eg they are using old firmware)

Change the default of hopsAway to -1, until we know it is direct (0) or hops away (1+)

* tidy up: move from nested if else to when

* Revert Project_Default.xml

* Move hopsAway when block in to updateNodeInfo() block above it.

Move hopsAway var to end of NodeInfo Class.

Schema update due to change above.

* hopsAway now follows firmware implementation.
hopsAway now imported from radio (installNodeInfo)

* reformat

---------

Co-authored-by: andrekir <andrekir@pm.me>
This commit is contained in:
Dayle Drinkwater 2024-04-21 12:14:35 +01:00 committed by GitHub
parent 261af4be62
commit 47b2ecc8aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 459 additions and 9 deletions

View file

@ -2,6 +2,7 @@ package com.geeksville.mesh
import android.graphics.Color
import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Embedded
import androidx.room.Entity
import androidx.room.PrimaryKey
@ -224,6 +225,8 @@ data class NodeInfo(
var channel: Int = 0,
@Embedded(prefix = "envMetrics_")
var environmentMetrics: EnvironmentMetrics? = null,
@ColumnInfo(name = "hopsAway", defaultValue = "0")
var hopsAway: Int = 0
) : Parcelable {
val colors: Pair<Int, Int>

View file

@ -27,8 +27,9 @@ import com.geeksville.mesh.database.entity.QuickChatAction
autoMigrations = [
AutoMigration (from = 3, to = 4),
AutoMigration (from = 4, to = 5),
AutoMigration (from = 5, to = 6),
],
version = 5,
version = 6,
exportSchema = true,
)
@TypeConverters(Converters::class)

View file

@ -1019,8 +1019,12 @@ class MeshService : Service(), Logging {
updateNodeInfoTime(it, rxTime)
it.snr = packet.rxSnr
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
}
}
handleReceivedData(packet)
}
}
@ -1314,6 +1318,7 @@ class MeshService : Service(), Logging {
}
it.channel = info.channel
it.hopsAway = info.hopsAway
}
}

View file

@ -24,9 +24,13 @@ fun signalInfo(
} else {
buildString {
if (nodeInfo.channel > 0) append("ch:${nodeInfo.channel}")
if (nodeInfo.snr < 100F && nodeInfo.rssi < 0) {
if (isNotEmpty()) append(" ")
append("RSSI: %d SNR: %.1f".format(nodeInfo.rssi, nodeInfo.snr))
if (nodeInfo.hopsAway == 0) {
if (nodeInfo.snr < 100F && nodeInfo.rssi < 0) {
if (isNotEmpty()) append(" ")
append("RSSI: %d SNR: %.1f".format(nodeInfo.rssi, nodeInfo.snr))
}
} else {
append("Hops Away: %d".format(nodeInfo.hopsAway))
}
}
}
@ -56,7 +60,8 @@ fun SignalInfoSimplePreview() {
snr = 12.5F,
rssi = -42,
deviceMetrics = null,
user = null
user = null,
hopsAway = 0
),
isThisNode = false
)

View file

@ -35,7 +35,8 @@ class NodeInfoPreviewParameterProvider: PreviewParameterProvider<NodeInfo> {
shortName = "MM",
id = "mickeyMouseId",
hwModel = MeshProtos.HardwareModel.TBEAM
)
),
hopsAway = 0
)
private val minnieMouse = mickeyMouse.copy(
@ -48,7 +49,8 @@ class NodeInfoPreviewParameterProvider: PreviewParameterProvider<NodeInfo> {
),
snr = 12.5F,
rssi = -42,
position = null
position = null,
hopsAway = 1
)
private val donaldDuck = NodeInfo(
@ -81,7 +83,8 @@ class NodeInfoPreviewParameterProvider: PreviewParameterProvider<NodeInfo> {
gasResistance = 0.0F,
voltage = 3.7F,
current = 0.0F
)
),
hopsAway = 2
)
private val unknown = donaldDuck.copy(