Meshtastic-Android/app/src/main/java/com/geeksville/mesh/model/NodeDB.kt

55 lines
1.7 KiB
Kotlin
Raw Normal View History

2020-02-17 13:34:52 -08:00
package com.geeksville.mesh.model
import androidx.lifecycle.MutableLiveData
2021-03-14 11:42:04 +08:00
import com.geeksville.mesh.MeshProtos
2020-02-17 13:34:52 -08:00
import com.geeksville.mesh.MeshUser
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.Position
/// NodeDB lives inside the UIViewModel, but it needs a backpointer to reach the service
class NodeDB(private val ui: UIViewModel) {
2020-02-17 13:34:52 -08:00
private val testPositions = arrayOf(
2022-03-26 17:44:59 -03:00
Position(32.776665, -96.796989, 35, 123), // dallas
Position(32.960758, -96.733521, 35, 456), // richardson
Position(32.912901, -96.781776, 35, 789) // north dallas
2020-02-17 13:34:52 -08:00
)
val testNodeNoPosition = NodeInfo(
8,
MeshUser(
"+16508765308".format(8),
"Kevin MesterNoLoc",
2021-03-14 11:42:04 +08:00
"KLO",
MeshProtos.HardwareModel.ANDROID_SIM
2020-02-17 13:34:52 -08:00
),
2020-02-19 10:53:36 -08:00
null
2020-02-17 13:34:52 -08:00
)
val testNodes = testPositions.mapIndexed { index, it ->
NodeInfo(
9 + index,
MeshUser(
"+165087653%02d".format(9 + index),
"Kevin Mester$index",
2021-03-14 11:42:04 +08:00
"KM$index",
MeshProtos.HardwareModel.ANDROID_SIM
2020-02-17 13:34:52 -08:00
),
2020-02-19 10:53:36 -08:00
it
2020-02-17 13:34:52 -08:00
)
}
private val seedWithTestNodes = false
2020-02-17 13:34:52 -08:00
/// The unique ID of our node
val myId = object : MutableLiveData<String?>(if (seedWithTestNodes) "+16508765309" else null) {}
2020-02-17 13:34:52 -08:00
/// A map from nodeid to to nodeinfo
val nodes =
object :
MutableLiveData<Map<String, NodeInfo>>(mapOf(*(if (seedWithTestNodes) testNodes else listOf()).map { it.user!!.id to it }
.toTypedArray())) {}
2020-02-17 13:46:13 -08:00
/// Could be null if we haven't received our node DB yet
val ourNodeInfo get() = nodes.value?.get(myId.value)
2020-02-17 13:34:52 -08:00
}