mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-05-15 10:17:20 -04:00
feat: add client-side NodeInfo channel routing
This commit is contained in:
@@ -186,7 +186,7 @@ data class NodeInfo(
|
||||
var lastHeard: Int = 0, // the last time we've seen this node in secs since 1970
|
||||
@Embedded(prefix = "devMetrics_")
|
||||
var deviceMetrics: DeviceMetrics? = null,
|
||||
val channel: Int = 0,
|
||||
var channel: Int = 0,
|
||||
@Embedded(prefix = "envMetrics_")
|
||||
var environmentMetrics: EnvironmentMetrics? = null,
|
||||
) : Parcelable {
|
||||
|
||||
@@ -432,10 +432,10 @@ class MeshService : Service(), Logging {
|
||||
}
|
||||
|
||||
/// A helper function that makes it easy to update node info objects
|
||||
private fun updateNodeInfo(
|
||||
private inline fun updateNodeInfo(
|
||||
nodeNum: Int,
|
||||
withBroadcast: Boolean = true,
|
||||
updateFn: (NodeInfo) -> Unit
|
||||
crossinline updateFn: (NodeInfo) -> Unit,
|
||||
) {
|
||||
val info = getOrCreateNodeInfo(nodeNum)
|
||||
updateFn(info)
|
||||
@@ -647,7 +647,7 @@ class MeshService : Service(), Logging {
|
||||
Portnums.PortNum.NODEINFO_APP_VALUE ->
|
||||
if (!fromUs) {
|
||||
val u = MeshProtos.User.parseFrom(data.payload)
|
||||
handleReceivedUser(packet.from, u)
|
||||
handleReceivedUser(packet.from, u, packet.channel)
|
||||
}
|
||||
|
||||
// Handle new telemetry info
|
||||
@@ -741,7 +741,7 @@ class MeshService : Service(), Logging {
|
||||
}
|
||||
|
||||
/// Update our DB of users based on someone sending out a User subpacket
|
||||
private fun handleReceivedUser(fromNum: Int, p: MeshProtos.User) {
|
||||
private fun handleReceivedUser(fromNum: Int, p: MeshProtos.User, channel: Int = 0) {
|
||||
updateNodeInfo(fromNum) {
|
||||
val oldId = it.user?.id.orEmpty()
|
||||
it.user = MeshUser(
|
||||
@@ -751,6 +751,7 @@ class MeshService : Service(), Logging {
|
||||
p.hwModel,
|
||||
p.isLicensed
|
||||
)
|
||||
it.channel = channel
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1244,11 +1245,13 @@ class MeshService : Service(), Logging {
|
||||
it.position = Position(info.position)
|
||||
}
|
||||
|
||||
it.lastHeard = info.lastHeard
|
||||
|
||||
if (info.hasDeviceMetrics()) {
|
||||
it.deviceMetrics = DeviceMetrics(info.deviceMetrics)
|
||||
}
|
||||
|
||||
it.lastHeard = info.lastHeard
|
||||
it.channel = info.channel
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1513,16 +1516,17 @@ class MeshService : Service(), Logging {
|
||||
it.time = time
|
||||
}.build()
|
||||
|
||||
// Also update our own map for our nodenum, by handling the packet just like packets from other users
|
||||
// Also update our own map for our nodeNum, by handling the packet just like packets from other users
|
||||
handleReceivedPosition(mi.myNodeNum, position)
|
||||
|
||||
val fullPacket =
|
||||
newMeshPacketTo(idNum).buildMeshPacket(priority = MeshPacket.Priority.BACKGROUND) {
|
||||
// Use the new position as data format
|
||||
portnumValue = Portnums.PortNum.POSITION_APP_VALUE
|
||||
payload = position.toByteString()
|
||||
this.wantResponse = wantResponse
|
||||
}
|
||||
val fullPacket = newMeshPacketTo(idNum).buildMeshPacket(
|
||||
channel = if (destNum == null) 0 else nodeDBbyNodeNum[destNum]?.channel ?: 0,
|
||||
priority = MeshPacket.Priority.BACKGROUND,
|
||||
) {
|
||||
portnumValue = Portnums.PortNum.POSITION_APP_VALUE
|
||||
payload = position.toByteString()
|
||||
this.wantResponse = wantResponse
|
||||
}
|
||||
|
||||
// send the packet into the mesh
|
||||
sendToRadio(fullPacket)
|
||||
@@ -1831,7 +1835,11 @@ class MeshService : Service(), Logging {
|
||||
}
|
||||
|
||||
override fun requestTraceroute(requestId: Int, destNum: Int) = toRemoteExceptions {
|
||||
sendToRadio(newMeshPacketTo(destNum).buildMeshPacket(wantAck = true, id = requestId) {
|
||||
sendToRadio(newMeshPacketTo(destNum).buildMeshPacket(
|
||||
wantAck = true,
|
||||
id = requestId,
|
||||
channel = nodeDBbyNodeNum[destNum]?.channel ?: 0,
|
||||
) {
|
||||
portnumValue = Portnums.PortNum.TRACEROUTE_APP_VALUE
|
||||
payload = routeDiscovery {}.toByteString()
|
||||
wantResponse = true
|
||||
|
||||
@@ -86,11 +86,11 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
||||
popup.setOnMenuItemClickListener { item: MenuItem ->
|
||||
when (item.itemId) {
|
||||
R.id.direct_message -> {
|
||||
debug("calling MessagesFragment filter: 0${user.id}")
|
||||
debug("calling MessagesFragment filter: ${node.channel}${user.id}")
|
||||
setFragmentResult(
|
||||
"requestKey",
|
||||
bundleOf(
|
||||
"contactKey" to "0${user.id}",
|
||||
"contactKey" to "${node.channel}${user.id}",
|
||||
"contactName" to user.longName
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user