mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-14 11:56:59 -04:00
add EnvironmentMetrics to NodeInfo
This commit is contained in:
@@ -107,6 +107,37 @@ data class DeviceMetrics(
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@Parcelize
|
||||
data class EnvironmentMetrics(
|
||||
val time: Int = currentTime(), // default to current time in secs (NOT MILLISECONDS!)
|
||||
val temperature: Float,
|
||||
val relativeHumidity: Float,
|
||||
val barometricPressure: Float,
|
||||
val gasResistance: Float,
|
||||
val voltage: Float,
|
||||
val current: Float,
|
||||
) : Parcelable {
|
||||
companion object {
|
||||
fun currentTime() = (System.currentTimeMillis() / 1000).toInt()
|
||||
}
|
||||
|
||||
/** Create our model object from a protobuf.
|
||||
*/
|
||||
constructor(t: TelemetryProtos.EnvironmentMetrics, telemetryTime: Int = currentTime()) : this(
|
||||
telemetryTime,
|
||||
t.temperature,
|
||||
t.relativeHumidity,
|
||||
t.barometricPressure,
|
||||
t.gasResistance,
|
||||
t.voltage,
|
||||
t.current
|
||||
)
|
||||
|
||||
override fun toString(): String {
|
||||
return "EnvironmentMetrics(time=${time}, temperature=${temperature}, humidity=${relativeHumidity}, pressure=${barometricPressure}), resistance=${gasResistance}, voltage=${voltage}, current=${current}"
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@Parcelize
|
||||
@@ -117,7 +148,8 @@ 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 deviceMetrics: DeviceMetrics? = null
|
||||
var deviceMetrics: DeviceMetrics? = null,
|
||||
var environmentMetrics: EnvironmentMetrics? = null,
|
||||
) : Parcelable {
|
||||
|
||||
val batteryLevel get() = deviceMetrics?.batteryLevel
|
||||
|
||||
@@ -815,13 +815,17 @@ class MeshService : Service(), Logging {
|
||||
/// Update our DB of users based on someone sending out a Telemetry subpacket
|
||||
private fun handleReceivedTelemetry(
|
||||
fromNum: Int,
|
||||
p: TelemetryProtos.Telemetry,
|
||||
t: TelemetryProtos.Telemetry,
|
||||
defaultTime: Long = System.currentTimeMillis()
|
||||
) {
|
||||
updateNodeInfo(fromNum) {
|
||||
it.deviceMetrics = DeviceMetrics(
|
||||
p.deviceMetrics,
|
||||
if (p.time != 0) p.time else (defaultTime / 1000L).toInt()
|
||||
t.deviceMetrics,
|
||||
if (t.time != 0) t.time else (defaultTime / 1000L).toInt()
|
||||
)
|
||||
it.environmentMetrics = EnvironmentMetrics(
|
||||
t.environmentMetrics,
|
||||
if (t.time != 0) t.time else (defaultTime / 1000L).toInt()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user