Skip to content

Commit

Permalink
feat: replace invalid MeshPacket times (earlier than build time)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrekir committed Oct 23, 2024
1 parent 199b9a2 commit 9f099f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ android {
ndk {
// abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}

buildConfigField "int", "TIMESTAMP", System.currentTimeSeconds().toString()
}
bundle {
language {
Expand Down
17 changes: 7 additions & 10 deletions app/src/main/java/com/geeksville/mesh/service/MeshService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,10 @@ class MeshService : Service(), Logging {
} else {
val data = packet.decoded

// If the rxTime was not set by the device (because device software was old), guess at a time
val rxTime = if (packet.rxTime != 0) packet.rxTime else currentSecond()

DataPacket(
from = toNodeID(packet.from),
to = toNodeID(packet.to),
time = rxTime * 1000L,
time = packet.rxTime * 1000L,
id = packet.id,
dataType = data.portnumValue,
bytes = data.payload.toByteArray(),
Expand Down Expand Up @@ -913,7 +910,10 @@ class MeshService : Service(), Logging {
// Update our model and resend as needed for a MeshPacket we just received from the radio
private fun handleReceivedMeshPacket(packet: MeshPacket) {
if (haveNodeDB) {
processReceivedMeshPacket(packet)
processReceivedMeshPacket(packet.toBuilder().apply {
// If the rxTime is invalid (earlier than build time), update with current time
if (packet.rxTime < BuildConfig.TIMESTAMP) setRxTime(currentSecond())
}.build())
onNodeDBChanged()
} else {
warn("Ignoring early received packet: ${packet.toOneLineString()}")
Expand Down Expand Up @@ -1045,7 +1045,7 @@ class MeshService : Service(), Logging {
// decided to pass through to us (except for broadcast packets)
// val toNum = packet.to

// debug("Recieved: $packet")
// debug("Received: $packet")
if (packet.hasDecoded()) {
val packetToSave = MeshLog(
uuid = UUID.randomUUID().toString(),
Expand Down Expand Up @@ -1073,11 +1073,8 @@ class MeshService : Service(), Logging {
// Do not generate redundant broadcasts of node change for this bookkeeping updateNodeInfo call
// because apps really only care about important updates of node state - which handledReceivedData will give them
updateNodeInfo(fromNum, withBroadcast = false) {
// If the rxTime was not set by the device (because device software was old), guess at a time
val rxTime = if (packet.rxTime != 0) packet.rxTime else currentSecond()

// Update our last seen based on any valid timestamps. If the device didn't provide a timestamp make one
it.lastHeard = rxTime
it.lastHeard = packet.rxTime
it.snr = packet.rxSnr
it.rssi = packet.rxRssi

Expand Down

0 comments on commit 9f099f3

Please sign in to comment.