kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
commit
bcadeada25
|
@ -81,7 +81,7 @@ data class Position(
|
|||
|
||||
@Serializable
|
||||
@Parcelize
|
||||
data class Telemetry(
|
||||
data class DeviceMetrics(
|
||||
val time: Int = currentTime(), // default to current time in secs (NOT MILLISECONDS!)
|
||||
val batteryLevel: Int = 0,
|
||||
val voltage: Float,
|
||||
|
@ -94,16 +94,16 @@ data class Telemetry(
|
|||
|
||||
/** Create our model object from a protobuf.
|
||||
*/
|
||||
constructor(p: TelemetryProtos.Telemetry, defaultTime: Int = currentTime()) : this(
|
||||
if (p.time != 0) p.time else defaultTime,
|
||||
p.deviceMetrics.batteryLevel,
|
||||
p.deviceMetrics.voltage,
|
||||
p.deviceMetrics.channelUtilization,
|
||||
p.deviceMetrics.airUtilTx
|
||||
constructor(p: TelemetryProtos.DeviceMetrics, telemetryTime: Int = currentTime()) : this(
|
||||
telemetryTime,
|
||||
p.batteryLevel,
|
||||
p.voltage,
|
||||
p.channelUtilization,
|
||||
p.airUtilTx
|
||||
)
|
||||
|
||||
override fun toString(): String {
|
||||
return "Telemetry(time=${time}, batteryLevel=${batteryLevel}, voltage=${voltage}, channelUtilization=${channelUtilization}, airUtilTx=${airUtilTx})"
|
||||
return "DeviceMetrics(time=${time}, batteryLevel=${batteryLevel}, voltage=${voltage}, channelUtilization=${channelUtilization}, airUtilTx=${airUtilTx})"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,10 +117,10 @@ data class NodeInfo(
|
|||
var snr: Float = Float.MAX_VALUE,
|
||||
var rssi: Int = Int.MAX_VALUE,
|
||||
var lastHeard: Int = 0, // the last time we've seen this node in secs since 1970
|
||||
var telemetry: Telemetry? = null
|
||||
var deviceMetrics: DeviceMetrics? = null
|
||||
) : Parcelable {
|
||||
|
||||
val batteryPctLevel get() = telemetry?.batteryLevel
|
||||
val batteryPctLevel get() = deviceMetrics?.batteryLevel
|
||||
|
||||
/**
|
||||
* true if the device was heard from recently
|
||||
|
|
|
@ -902,14 +902,17 @@ class MeshService : Service(), Logging {
|
|||
}
|
||||
}
|
||||
|
||||
/// Update our DB of users based on someone sending out a User subpacket
|
||||
/// Update our DB of users based on someone sending out a Telemetry subpacket
|
||||
private fun handleReceivedTelemetry(
|
||||
fromNum: Int,
|
||||
p: TelemetryProtos.Telemetry,
|
||||
defaultTime: Long = System.currentTimeMillis()
|
||||
) {
|
||||
updateNodeInfo(fromNum) {
|
||||
it.telemetry = Telemetry(p, (defaultTime / 1000L).toInt())
|
||||
it.deviceMetrics = DeviceMetrics(
|
||||
p.deviceMetrics,
|
||||
if (p.time != 0) p.time else (defaultTime / 1000L).toInt()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1300,10 +1303,8 @@ class MeshService : Service(), Logging {
|
|||
it.position = Position(info.position)
|
||||
}
|
||||
|
||||
if (info.hasTelemetry()) {
|
||||
// For the local node, it might not be able to update its times because it doesn't have a valid GPS reading yet
|
||||
// so if the info is for _our_ node we always assume time is current
|
||||
it.telemetry = Telemetry(info.telemetry)
|
||||
if (info.hasDeviceMetrics()) {
|
||||
it.deviceMetrics = DeviceMetrics(info.deviceMetrics)
|
||||
}
|
||||
|
||||
it.lastHeard = info.lastHeard
|
||||
|
@ -1311,7 +1312,7 @@ class MeshService : Service(), Logging {
|
|||
}
|
||||
|
||||
private fun handleNodeInfo(info: MeshProtos.NodeInfo) {
|
||||
debug("Received nodeinfo num=${info.num}, hasUser=${info.hasUser()}, hasPosition=${info.hasPosition()}, hasTelemetry=${info.hasTelemetry()}")
|
||||
debug("Received nodeinfo num=${info.num}, hasUser=${info.hasUser()}, hasPosition=${info.hasPosition()}, hasDeviceMetrics=${info.hasDeviceMetrics()}")
|
||||
|
||||
val packetToSave = Packet(
|
||||
UUID.randomUUID().toString(),
|
||||
|
|
|
@ -136,7 +136,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
} else {
|
||||
holder.distanceView.visibility = View.INVISIBLE
|
||||
}
|
||||
renderBattery(n.batteryPctLevel, n.telemetry?.voltage, holder)
|
||||
renderBattery(n.batteryPctLevel, n.deviceMetrics?.voltage, holder)
|
||||
|
||||
holder.lastTime.text = formatAgo(n.lastHeard)
|
||||
|
||||
|
@ -146,8 +146,8 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
val text =
|
||||
String.format(
|
||||
"ChUtil %.1f%% AirUtilTX %.1f%%",
|
||||
n.telemetry?.channelUtilization ?: info.channelUtilization,
|
||||
n.telemetry?.airUtilTx ?: info.airUtilTx
|
||||
n.deviceMetrics?.channelUtilization ?: info.channelUtilization,
|
||||
n.deviceMetrics?.airUtilTx ?: info.airUtilTx
|
||||
)
|
||||
holder.signalView.text = text
|
||||
holder.signalView.visibility = View.VISIBLE
|
||||
|
|
Ładowanie…
Reference in New Issue