From f3ba084d5b3bb62d906c4ef43970ce6eedc2034e Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:47:48 -0500 Subject: [PATCH] fix #1678: Update MeshService.kt to store the channel for received packets. (#1683) * Update MeshService.kt to store the channel for received packets. The channel for received packets is now stored, allowing for better tracking and management. * Update node info creation to include channel data - Updates `getOrCreateNodeInfo` to accept a channel parameter and to save the channel to the node info during instantiation of a new/unknown node. - Updates `updateNodeInfo` to accept a channel parameter and pass it to the updated function. - Updates call to `updateNodeInfo` in `handleReceivedData` to pass the packet channel data to it. --- .../main/java/com/geeksville/mesh/service/MeshService.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 47b05ffd..6d7f8e3c 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -473,7 +473,7 @@ class MeshService : Service(), Logging { } // given a nodeNum, return a db entry - creating if necessary - private fun getOrCreateNodeInfo(n: Int) = nodeDBbyNodeNum.getOrPut(n) { + private fun getOrCreateNodeInfo(n: Int, channel: Int = 0) = nodeDBbyNodeNum.getOrPut(n) { val userId = DataPacket.nodeNumToDefaultId(n) val defaultUser = user { id = userId @@ -486,6 +486,7 @@ class MeshService : Service(), Logging { num = n, user = defaultUser, longName = defaultUser.longName, + channel = channel, ) } @@ -527,9 +528,10 @@ class MeshService : Service(), Logging { private inline fun updateNodeInfo( nodeNum: Int, withBroadcast: Boolean = true, + channel: Int = 0, crossinline updateFn: (NodeEntity) -> Unit, ) { - val info = getOrCreateNodeInfo(nodeNum) + val info = getOrCreateNodeInfo(nodeNum, channel) updateFn(info) if (info.user.id.isNotEmpty() && haveNodeDB) { @@ -1174,7 +1176,7 @@ class MeshService : Service(), Logging { // Do not generate redundant broadcasts of node change for this bookkeeping updateNodeInfo call // because apps really only care about important updates of node state - which handledReceivedData will give them - updateNodeInfo(fromNum, withBroadcast = false) { + updateNodeInfo(fromNum, withBroadcast = false, channel = packet.channel) { // Update our last seen based on any valid timestamps. If the device didn't provide a timestamp make one it.lastHeard = packet.rxTime it.snr = packet.rxSnr