mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Fix/2523 redundant soil metrics (#2556)
Signed-off-by: DaneEvans <dane@goneepic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
edcf0f11eb
commit
1ba70ca547
16 changed files with 823 additions and 449 deletions
|
|
@ -76,7 +76,7 @@ class Converters : Logging {
|
|||
TelemetryProtos.Telemetry.parseFrom(bytes)
|
||||
} catch (ex: InvalidProtocolBufferException) {
|
||||
errormsg("bytesToTelemetry TypeConverter error:", ex)
|
||||
TelemetryProtos.Telemetry.getDefaultInstance()
|
||||
TelemetryProtos.Telemetry.newBuilder().build() // Return an empty Telemetry object
|
||||
}
|
||||
|
||||
@TypeConverter fun telemetryToBytes(value: TelemetryProtos.Telemetry): ByteArray? = value.toByteArray()
|
||||
|
|
|
|||
|
|
@ -50,6 +50,44 @@ constructor(
|
|||
private fun parseTelemetryLog(log: MeshLog): Telemetry? = runCatching {
|
||||
Telemetry.parseFrom(log.fromRadio.packet.decoded.payload)
|
||||
.toBuilder()
|
||||
.apply {
|
||||
// Handle float metrics that default to 0.0f when not explicitly set or when 0.0f means no data
|
||||
if (!environmentMetrics.hasTemperature()) {
|
||||
environmentMetrics = environmentMetrics.toBuilder().setTemperature(Float.NaN).build()
|
||||
}
|
||||
if (!environmentMetrics.hasRelativeHumidity()) {
|
||||
environmentMetrics = environmentMetrics.toBuilder().setRelativeHumidity(Float.NaN).build()
|
||||
}
|
||||
if (!environmentMetrics.hasSoilTemperature()) {
|
||||
environmentMetrics = environmentMetrics.toBuilder().setSoilTemperature(Float.NaN).build()
|
||||
}
|
||||
if (!environmentMetrics.hasBarometricPressure()) {
|
||||
environmentMetrics = environmentMetrics.toBuilder().setBarometricPressure(Float.NaN).build()
|
||||
}
|
||||
if (!environmentMetrics.hasGasResistance()) {
|
||||
environmentMetrics = environmentMetrics.toBuilder().setGasResistance(Float.NaN).build()
|
||||
}
|
||||
if (!environmentMetrics.hasVoltage()) {
|
||||
environmentMetrics = environmentMetrics.toBuilder().setVoltage(Float.NaN).build()
|
||||
}
|
||||
if (!environmentMetrics.hasCurrent()) {
|
||||
environmentMetrics = environmentMetrics.toBuilder().setCurrent(Float.NaN).build()
|
||||
}
|
||||
if (!environmentMetrics.hasLux()) {
|
||||
environmentMetrics = environmentMetrics.toBuilder().setLux(Float.NaN).build()
|
||||
}
|
||||
if (!environmentMetrics.hasUvLux()) {
|
||||
environmentMetrics = environmentMetrics.toBuilder().setUvLux(Float.NaN).build()
|
||||
}
|
||||
|
||||
// Handle uint32 metrics that default to 0 when not explicitly set or when 0 means no data
|
||||
if (!environmentMetrics.hasIaq()) {
|
||||
environmentMetrics = environmentMetrics.toBuilder().setIaq(Int.MIN_VALUE).build()
|
||||
}
|
||||
if (!environmentMetrics.hasSoilMoisture()) {
|
||||
environmentMetrics = environmentMetrics.toBuilder().setSoilMoisture(Int.MIN_VALUE).build()
|
||||
}
|
||||
}
|
||||
.setTime((log.received_date / MILLIS_TO_SECONDS).toInt())
|
||||
.build()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ data class NodeEntity(
|
|||
@ColumnInfo(name = "is_favorite") var isFavorite: Boolean = false,
|
||||
@ColumnInfo(name = "is_ignored", defaultValue = "0") var isIgnored: Boolean = false,
|
||||
@ColumnInfo(name = "environment_metrics", typeAffinity = ColumnInfo.BLOB)
|
||||
var environmentTelemetry: TelemetryProtos.Telemetry = TelemetryProtos.Telemetry.getDefaultInstance(),
|
||||
var environmentTelemetry: TelemetryProtos.Telemetry = TelemetryProtos.Telemetry.newBuilder().build(),
|
||||
@ColumnInfo(name = "power_metrics", typeAffinity = ColumnInfo.BLOB)
|
||||
var powerTelemetry: TelemetryProtos.Telemetry = TelemetryProtos.Telemetry.getDefaultInstance(),
|
||||
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
|
||||
|
|
@ -192,17 +192,9 @@ data class NodeEntity(
|
|||
),
|
||||
channel = channel,
|
||||
environmentMetrics =
|
||||
EnvironmentMetrics(
|
||||
time = environmentTelemetry.time,
|
||||
temperature = environmentMetrics.temperature,
|
||||
relativeHumidity = environmentMetrics.relativeHumidity,
|
||||
soilTemperature = environmentMetrics.soilTemperature,
|
||||
soilMoisture = environmentMetrics.soilMoisture,
|
||||
barometricPressure = environmentMetrics.barometricPressure,
|
||||
gasResistance = environmentMetrics.gasResistance,
|
||||
voltage = environmentMetrics.voltage,
|
||||
current = environmentMetrics.current,
|
||||
iaq = environmentMetrics.iaq,
|
||||
EnvironmentMetrics.fromTelemetryProto(
|
||||
environmentTelemetry.environmentMetrics,
|
||||
environmentTelemetry.time,
|
||||
),
|
||||
hopsAway = hopsAway,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue