Skip to content

Commit

Permalink
ENF: Fix average RSSI calculation
Browse files Browse the repository at this point in the history
Correctly discard new measurements when the reported timestamp is older
than the timestamp in the database.
Fixes microg#1655.
  • Loading branch information
transistortim authored and mar-v-in committed Feb 1, 2022
1 parent 61957c3 commit 75aaeb1
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class ExposureDatabase private constructor(private val context: Context) : SQLit
}

fun noteAdvertisement(rpi: ByteArray, aem: ByteArray, rssi: Int, timestamp: Long = Date().time) = writableDatabase.run {
val update = compileStatement("UPDATE $TABLE_ADVERTISEMENTS SET rssi = IFNULL(((rssi * duration) + (? * MIN(0, ? - timestamp - duration))) / MAX(duration, ? - timestamp), -100), duration = MAX(duration, ? - timestamp) WHERE rpi = ? AND timestamp > ? AND timestamp < ?").run {
val update = compileStatement("UPDATE $TABLE_ADVERTISEMENTS SET rssi = IFNULL(((rssi * duration) + (? * MAX(0, ? - timestamp - duration))) / MAX(duration, ? - timestamp), -100), duration = MAX(duration, ? - timestamp) WHERE rpi = ? AND timestamp > ? AND timestamp < ?").run {
bindLong(1, rssi.toLong())
bindLong(2, timestamp)
bindLong(3, timestamp)
Expand Down

0 comments on commit 75aaeb1

Please sign in to comment.