deliver full node db when client app asks for it

pull/8/head
geeksville 2020-02-10 17:05:51 -08:00
rodzic 9a0da9ef67
commit 10b4d2395c
6 zmienionych plików z 117 dodań i 116 usunięć

Wyświetl plik

@ -3,6 +3,8 @@ package com.geeksville.mesh;
// Declare any non-default types here with import statements
parcelable NodeInfo;
/**
* Note - these calls might throw RemoteException to indicate mesh error states
*/
@ -28,7 +30,7 @@ interface IMeshService {
/**
Get the IDs of everyone on the mesh. You should also subscribe for NODE_CHANGE broadcasts.
*/
String[] getOnline();
NodeInfo[] getNodes();
/**
Is the packet radio currently connected to the phone?

Wyświetl plik

@ -151,8 +151,8 @@ class MainActivity : AppCompatActivity(), Logging {
when (intent.action) {
MeshService.ACTION_NODE_CHANGE -> {
warn("TODO nodechange")
val info: NodeInfo = intent.getParcelableExtra(EXTRA_NODEINFO)!!
debug("UI nodechange $info")
// We only care about nodes that have user info
info.user?.id?.let {
@ -163,7 +163,7 @@ class MainActivity : AppCompatActivity(), Logging {
}
MeshService.ACTION_RECEIVED_DATA -> {
warn("TODO rxdata")
debug("TODO rxdata")
val sender = intent.getStringExtra(EXTRA_SENDER)!!
val payload = intent.getByteArrayExtra(EXTRA_PAYLOAD)!!
val typ = intent.getIntExtra(EXTRA_TYP, -1)
@ -201,11 +201,8 @@ class MainActivity : AppCompatActivity(), Logging {
// make some placeholder nodeinfos
UIState.nodes.value =
m.online.toList().map {
it to NodeInfo(
0,
MeshUser(it, "unknown", "unk")
)
m.nodes.toList().map {
it.user?.id!! to it
}.toMap()
}

Wyświetl plik

@ -0,0 +1,103 @@
package com.geeksville.mesh
import android.os.Parcel
import android.os.Parcelable
// model objects that directly map to the corresponding protobufs
data class MeshUser(val id: String, val longName: String, val shortName: String) :
Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString()!!,
parcel.readString()!!,
parcel.readString()!!
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(id)
parcel.writeString(longName)
parcel.writeString(shortName)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<MeshUser> {
override fun createFromParcel(parcel: Parcel): MeshUser {
return MeshUser(parcel)
}
override fun newArray(size: Int): Array<MeshUser?> {
return arrayOfNulls(size)
}
}
}
data class Position(val latitude: Double, val longitude: Double, val altitude: Int) :
Parcelable {
constructor(parcel: Parcel) : this(
parcel.readDouble(),
parcel.readDouble(),
parcel.readInt()
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeDouble(latitude)
parcel.writeDouble(longitude)
parcel.writeInt(altitude)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Position> {
override fun createFromParcel(parcel: Parcel): Position {
return Position(parcel)
}
override fun newArray(size: Int): Array<Position?> {
return arrayOfNulls(size)
}
}
}
data class NodeInfo(
val num: Int, // This is immutable, and used as a key
var user: MeshUser? = null,
var position: Position? = null,
var lastSeen: Long? = null
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readParcelable(MeshUser::class.java.classLoader),
parcel.readParcelable(Position::class.java.classLoader),
parcel.readValue(Long::class.java.classLoader) as? Long
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(num)
parcel.writeParcelable(user, flags)
parcel.writeParcelable(position, flags)
parcel.writeValue(lastSeen)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<NodeInfo> {
override fun createFromParcel(parcel: Parcel): NodeInfo {
return NodeInfo(parcel)
}
override fun newArray(size: Int): Array<NodeInfo?> {
return arrayOfNulls(size)
}
}
}

Wyświetl plik

@ -8,15 +8,11 @@ import android.content.*
import android.graphics.Color
import android.os.Build
import android.os.IBinder
import android.os.Parcel
import android.os.Parcelable
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationCompat.PRIORITY_MIN
import com.geeksville.android.Logging
import com.geeksville.mesh.IMeshService
import com.geeksville.mesh.IRadioInterfaceService
import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.*
import com.geeksville.mesh.MeshProtos.MeshPacket
import com.geeksville.mesh.MeshProtos.ToRadio
import com.geeksville.util.exceptionReporter
@ -28,103 +24,6 @@ import java.nio.charset.Charset
class RadioNotConnectedException() : Exception("Can't find radio")
// model objects that directly map to the corresponding protobufs
data class MeshUser(val id: String, val longName: String, val shortName: String) :
Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString()!!,
parcel.readString()!!,
parcel.readString()!!
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(id)
parcel.writeString(longName)
parcel.writeString(shortName)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<MeshUser> {
override fun createFromParcel(parcel: Parcel): MeshUser {
return MeshUser(parcel)
}
override fun newArray(size: Int): Array<MeshUser?> {
return arrayOfNulls(size)
}
}
}
data class Position(val latitude: Double, val longitude: Double, val altitude: Int) :
Parcelable {
constructor(parcel: Parcel) : this(
parcel.readDouble(),
parcel.readDouble(),
parcel.readInt()
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeDouble(latitude)
parcel.writeDouble(longitude)
parcel.writeInt(altitude)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Position> {
override fun createFromParcel(parcel: Parcel): Position {
return Position(parcel)
}
override fun newArray(size: Int): Array<Position?> {
return arrayOfNulls(size)
}
}
}
data class NodeInfo(
val num: Int, // This is immutable, and used as a key
var user: MeshUser? = null,
var position: Position? = null,
var lastSeen: Long? = null
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readParcelable(MeshUser::class.java.classLoader),
parcel.readParcelable(Position::class.java.classLoader),
parcel.readValue(Long::class.java.classLoader) as? Long
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(num)
parcel.writeParcelable(user, flags)
parcel.writeParcelable(position, flags)
parcel.writeValue(lastSeen)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<NodeInfo> {
override fun createFromParcel(parcel: Parcel): NodeInfo {
return NodeInfo(parcel)
}
override fun newArray(size: Int): Array<NodeInfo?> {
return arrayOfNulls(size)
}
}
}
/**
* Handles all the communication with android apps. Also keeps an internal model
@ -642,8 +541,8 @@ class MeshService : Service(), Logging {
})
}
override fun getOnline(): Array<String> = toRemoteExceptions {
val r = nodeDBbyID.keys.toTypedArray()
override fun getNodes(): Array<NodeInfo> = toRemoteExceptions {
val r = nodeDBbyID.values.toTypedArray()
info("in getOnline, count=${r.size}")
// return arrayOf("+16508675309")
r

Wyświetl plik

@ -9,8 +9,8 @@ import androidx.ui.material.MaterialTheme
import androidx.ui.material.ProvideEmphasis
import androidx.ui.tooling.preview.Preview
import androidx.ui.unit.dp
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.R
import com.geeksville.mesh.service.NodeInfo
@Composable

Wyświetl plik

@ -2,9 +2,9 @@ package com.geeksville.mesh.ui
import androidx.compose.Model
import androidx.compose.mutableStateOf
import com.geeksville.mesh.service.MeshUser
import com.geeksville.mesh.service.NodeInfo
import com.geeksville.mesh.service.Position
import com.geeksville.mesh.MeshUser
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.Position
import java.util.*
// defines the screens we have in the app