mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Merge pull request #405 from meshtastic/refactor-protos
promote device metrics
This commit is contained in:
commit
bcadeada25
3 changed files with 21 additions and 20 deletions
|
|
@ -81,7 +81,7 @@ data class Position(
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class Telemetry(
|
data class DeviceMetrics(
|
||||||
val time: Int = currentTime(), // default to current time in secs (NOT MILLISECONDS!)
|
val time: Int = currentTime(), // default to current time in secs (NOT MILLISECONDS!)
|
||||||
val batteryLevel: Int = 0,
|
val batteryLevel: Int = 0,
|
||||||
val voltage: Float,
|
val voltage: Float,
|
||||||
|
|
@ -94,16 +94,16 @@ data class Telemetry(
|
||||||
|
|
||||||
/** Create our model object from a protobuf.
|
/** Create our model object from a protobuf.
|
||||||
*/
|
*/
|
||||||
constructor(p: TelemetryProtos.Telemetry, defaultTime: Int = currentTime()) : this(
|
constructor(p: TelemetryProtos.DeviceMetrics, telemetryTime: Int = currentTime()) : this(
|
||||||
if (p.time != 0) p.time else defaultTime,
|
telemetryTime,
|
||||||
p.deviceMetrics.batteryLevel,
|
p.batteryLevel,
|
||||||
p.deviceMetrics.voltage,
|
p.voltage,
|
||||||
p.deviceMetrics.channelUtilization,
|
p.channelUtilization,
|
||||||
p.deviceMetrics.airUtilTx
|
p.airUtilTx
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun toString(): String {
|
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 snr: Float = Float.MAX_VALUE,
|
||||||
var rssi: Int = Int.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 lastHeard: Int = 0, // the last time we've seen this node in secs since 1970
|
||||||
var telemetry: Telemetry? = null
|
var deviceMetrics: DeviceMetrics? = null
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
|
|
||||||
val batteryPctLevel get() = telemetry?.batteryLevel
|
val batteryPctLevel get() = deviceMetrics?.batteryLevel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true if the device was heard from recently
|
* 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(
|
private fun handleReceivedTelemetry(
|
||||||
fromNum: Int,
|
fromNum: Int,
|
||||||
p: TelemetryProtos.Telemetry,
|
p: TelemetryProtos.Telemetry,
|
||||||
defaultTime: Long = System.currentTimeMillis()
|
defaultTime: Long = System.currentTimeMillis()
|
||||||
) {
|
) {
|
||||||
updateNodeInfo(fromNum) {
|
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)
|
it.position = Position(info.position)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.hasTelemetry()) {
|
if (info.hasDeviceMetrics()) {
|
||||||
// For the local node, it might not be able to update its times because it doesn't have a valid GPS reading yet
|
it.deviceMetrics = DeviceMetrics(info.deviceMetrics)
|
||||||
// so if the info is for _our_ node we always assume time is current
|
|
||||||
it.telemetry = Telemetry(info.telemetry)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
it.lastHeard = info.lastHeard
|
it.lastHeard = info.lastHeard
|
||||||
|
|
@ -1311,7 +1312,7 @@ class MeshService : Service(), Logging {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleNodeInfo(info: MeshProtos.NodeInfo) {
|
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(
|
val packetToSave = Packet(
|
||||||
UUID.randomUUID().toString(),
|
UUID.randomUUID().toString(),
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
||||||
} else {
|
} else {
|
||||||
holder.distanceView.visibility = View.INVISIBLE
|
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)
|
holder.lastTime.text = formatAgo(n.lastHeard)
|
||||||
|
|
||||||
|
|
@ -146,8 +146,8 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
||||||
val text =
|
val text =
|
||||||
String.format(
|
String.format(
|
||||||
"ChUtil %.1f%% AirUtilTX %.1f%%",
|
"ChUtil %.1f%% AirUtilTX %.1f%%",
|
||||||
n.telemetry?.channelUtilization ?: info.channelUtilization,
|
n.deviceMetrics?.channelUtilization ?: info.channelUtilization,
|
||||||
n.telemetry?.airUtilTx ?: info.airUtilTx
|
n.deviceMetrics?.airUtilTx ?: info.airUtilTx
|
||||||
)
|
)
|
||||||
holder.signalView.text = text
|
holder.signalView.text = text
|
||||||
holder.signalView.visibility = View.VISIBLE
|
holder.signalView.visibility = View.VISIBLE
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue