cleanup lastHeard in node info (instead of position.time)

1.2-legacy
Kevin Hester 2021-03-27 10:53:39 +08:00
rodzic 3be55f8c7f
commit bff21e0026
5 zmienionych plików z 12 dodań i 20 usunięć

Wyświetl plik

@ -84,11 +84,13 @@ data class NodeInfo(
var user: MeshUser? = null,
var position: Position? = null,
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
) : Parcelable {
/// Return the last time we've seen this node in secs since 1970
val lastSeen get() = position?.time ?: 0
/**
* Return the last time we've seen this node in secs since 1970
*/
val batteryPctLevel get() = position?.batteryPctLevel
@ -104,7 +106,7 @@ data class NodeInfo(
// FIXME - use correct timeout from the device settings
val timeout =
15 * 60 // Don't set this timeout too tight, or otherwise we will stop sending GPS helper positions to our device
return (now - lastSeen <= timeout) || lastSeen == 0
return (now - lastHeard <= timeout) || lastHeard == 0
}
/// return the position if it is valid, else null

Wyświetl plik

@ -831,7 +831,6 @@ class MeshService : Service(), Logging {
updateNodeInfo(fromNum) {
debug("update ${it.user?.longName} with ${p.toOneLineString()}")
it.position = Position(p)
updateNodeInfoTime(it, (defaultTime / 1000).toInt())
}
}
@ -959,8 +958,8 @@ class MeshService : Service(), Logging {
if (!mi.hasGPS) {
var broadcastSecs = prefs.positionBroadcastSecs
desiredInterval = if(broadcastSecs == 0) // unset by device, use default
15 * 60 * 1000
desiredInterval = if (broadcastSecs == 0) // unset by device, use default
15 * 60 * 1000
else
broadcastSecs * 1000L
}
@ -1821,6 +1820,5 @@ class MeshService : Service(), Logging {
}
fun updateNodeInfoTime(it: NodeInfo, rxTime: Int) {
if (it.position?.time == null || it.position?.time!! < rxTime)
it.position = it.position?.copy(time = rxTime)
it.lastHeard = rxTime
}

Wyświetl plik

@ -141,7 +141,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
}
renderBattery(n.batteryPctLevel, holder)
holder.lastTime.text = formatAgo(n.lastSeen);
holder.lastTime.text = formatAgo(n.lastHeard);
if ((n.num == ourNodeInfo?.num) || (n.snr > 100f)) {
holder.signalView.visibility = View.INVISIBLE

@ -1 +1 @@
Subproject commit 820fa497dfde07e129cad6955bf2f4b2b9cecebc
Subproject commit f9c4f875818c9aa6995e6e25803d52557a1779c7

Wyświetl plik

@ -17,15 +17,7 @@ class MeshServiceTest {
val newerTime = 20
updateNodeInfoTime(nodeInfo, newerTime)
Assert.assertEquals(newerTime, nodeInfo.position?.time)
}
@Test
fun givenNodeInfo_whenUpdatingWithOldTime_thenPositionTimeIsNotUpdated() {
val olderTime = 5
val timeBeforeTryingToUpdate = nodeInfo.position?.time
updateNodeInfoTime(nodeInfo, olderTime)
Assert.assertEquals(timeBeforeTryingToUpdate, nodeInfo.position?.time)
Assert.assertEquals(newerTime, nodeInfo.lastHeard)
}
}