RF Sentinel (RFSentinel): free, open-source police detector app for Android. Spots police body cams, Flock ALPR cameras, AirTag trackers, Remote ID drones, smart glasses and fake cell towers from Bluetooth LE and WiFi. No root.
Kotlin airtagalprandroidandroid-autoanti-surveillancebluetooth-low-energybody-cameracounter-surveillancedrone-detectionflock-safetyimsi-catcher-detectorpolice-detectorpolice-scannerprivacyremote-idrtl-sdrsdrsurveillance-detectiontracker-detectionwifi
Radar places alerts from your turns and crosses them into a position; sweep uses raw timed readings
CIS-C0d61b7e21bcc6
diff --git a/app/src/main/java/com/rfsentinel/app/MainActivity.kt b/app/src/main/java/com/rfsentinel/app/MainActivity.ktindex 983c019..9faf7dc 100644--- a/app/src/main/java/com/rfsentinel/app/MainActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/MainActivity.kt@@ -782,15 +782,19 @@ class MainActivity : AppCompatActivity() {binding.radarView.setBlips(visible.take(200).map { s ->val alert = com.rfsentinel.app.ui.LiveWindow.alerting(s, now)val at = if (alert && fix != null) knownPosition(s, fix.latitude, fix.longitude) else null- // The device being located, once a chest sweep found its side.+ // Placed by your turns on the radar (crossed into a spot once you turned at two places), or the+ // device being located once a chest sweep found its side.+ val tracked = if (alert && at == null) com.rfsentinel.app.ui.RadarTrack.place(s.mac, fix?.latitude, fix?.longitude, now) else null+ val crossed = tracked?.takeIf { it.distanceM != null }val swept = if (at == null) com.rfsentinel.app.ui.LiveRead.sweptBearing(s.mac) else nullRadarView.Blip(s.mac, s.rssi,if (alert) colorFor(s) else binding.radarView.ordinaryColor(),alert,if (alert) s.best?.label else null,- at?.let { com.rfsentinel.app.alpr.KnownCameras.bearingTo(fix!!.latitude, fix.longitude, it.first, it.second).toFloat() } ?: swept,- at?.let { DeviceRegistry.metersBetween(fix!!.latitude, fix.longitude, it.first, it.second).toFloat() },+ at?.let { com.rfsentinel.app.alpr.KnownCameras.bearingTo(fix!!.latitude, fix.longitude, it.first, it.second).toFloat() }+ ?: crossed?.bearing ?: swept ?: tracked?.bearing,+ at?.let { DeviceRegistry.metersBetween(fix!!.latitude, fix.longitude, it.first, it.second).toFloat() } ?: crossed?.distanceM,now - s.lastSeen)} + radio)diff --git a/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.kt b/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.ktindex 146ce69..d17116b 100644--- a/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.kt+++ b/app/src/main/java/com/rfsentinel/app/service/DeviceRegistry.kt@@ -452,6 +452,9 @@ object DeviceRegistry {/** Full snapshot (history, path, raw advert) for the detail screen. */fun get(mac: String): Snapshot? = tracks[mac]?.let { t -> synchronized(t) { snap(t, full = true) } }+ /** When [mac] was last heard and its raw signal then: unsmoothed, so a direction sweep isn't seconds behind. */+ fun lastHeard(mac: String): Pair<Long, Int>? = tracks[mac]?.let { t -> synchronized(t) { t.lastSeen to (t.advert?.rssi ?: t.rssi) } }+/** Devices heard since [since] with their summary, for persisting to known_devices. */fun summaries(since: Long): List<Snapshot> =tracks.values.filter { it.lastSeen >= since }.map { t -> synchronized(t) { snap(t, full = false) } }diff --git a/app/src/main/java/com/rfsentinel/app/ui/LiveRead.kt b/app/src/main/java/com/rfsentinel/app/ui/LiveRead.ktindex b174ec1..705c004 100644--- a/app/src/main/java/com/rfsentinel/app/ui/LiveRead.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/LiveRead.kt@@ -70,6 +70,8 @@ object LiveRead {/** Compass degrees the phone faces, null without a compass or before its first reading. */val heading get() = compass?.degreesprivate var sweepFed = 0L+ private var tickAt = 0L+ private var tickHeading: Float? = null/** The direction the sweep locked on (kept until Sweep again or Locate stops), and where you stood then. */private var lock: Sweep.Estimate? = nullprivate var lockedAt: android.location.Location? = null@@ -152,20 +154,23 @@ object LiveRead {}/**- * Five times a second: each new signal reading with the way the phone faces now (a slow turn barely moves- * between the two). Locks the direction once the turn makes it clear, with a short buzz.+ * Five times a second: each new raw signal reading with the way the phone faced when it was heard. Locks the+ * direction once the turn makes it clear and it holds, with a short buzz.*/private val sample = object : Runnable {override fun run() {val mac = locating ?: returnmain.postDelayed(this, SAMPLE_MS)val h = heading ?: return- val s = DeviceRegistry.get(followed ?: mac) ?: return- if (s.lastSeen == sweepFed) return- sweepFed = s.lastSeen- sweep.add(s.lastSeen, h, s.rssi)+ val now = System.currentTimeMillis()+ val t0 = tickAt; val h0 = tickHeading ?: h+ tickAt = now; tickHeading = h+ val (seen, rssi) = DeviceRegistry.lastHeard(followed ?: mac) ?: return+ if (seen == sweepFed) return+ sweepFed = seen+ sweep.add(seen, Sweep.headingAt(seen, t0, h0, now, h), rssi)if (lock != null) return- val e = sweep.estimate(s.lastSeen)?.takeIf { Sweep.locks(it) } ?: return+ val e = sweep.settled(seen) ?: returnlock = elockedAt = com.rfsentinel.app.service.ScanForegroundService.lastFixappContext?.let { AlertPlayer.vibrate(it, longArrayOf(0, 60, 90, 60)) }@@ -193,6 +198,7 @@ object LiveRead {/** The scan stopped: no Locate, no pinpointing. */fun reset() = main.post {stopLocate()+ RadarTrack.clear()synchronized(this) { pinMac = null; pinUntil = 0L; dismissedPin = null }tick()}diff --git a/app/src/main/java/com/rfsentinel/app/ui/RadarTrack.kt b/app/src/main/java/com/rfsentinel/app/ui/RadarTrack.ktnew file mode 100644index 0000000..13b3074--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/ui/RadarTrack.kt@@ -0,0 +1,115 @@+package com.rfsentinel.app.ui++import com.rfsentinel.app.alpr.KnownCameras+import com.rfsentinel.app.service.DeviceRegistry+import kotlin.math.abs+import kotlin.math.cos+import kotlin.math.min+import kotlin.math.sin++/**+ * Places alerts on the main radar from the way you turn, with no Locate needed. While the radar is on screen every+ * alerting device gets its own [Sweep]: the phone held in front of you, your body shadows the signal from behind,+ * so a turn on the spot shows its side. Each direction a turn settles on is kept as a line from where you stood;+ * two or more lines from spots apart [cross] at the device, so its dot keeps its real place (direction and+ * distance) as you turn and walk. Main thread; [cross] is pure (unit-tested).+ */+object RadarTrack {++ /** A settled direction ([bearing], compass degrees) from where you stood (null without a GPS fix). */+ class Line(val lat: Double?, val lon: Double?, val bearing: Float, val weight: Float, val time: Long)++ /** Where an alert shows on the radar: its direction, and how far once lines crossed. */+ class Place(val bearing: Float, val distanceM: Float?)++ private class Track { val sweep = Sweep(); val lines = ArrayList<Line>(); var fed = 0L }+ private val tracks = HashMap<String, Track>()++ /** A new reading of [mac] ([rssi] raw, heard at [time] while facing [heading]); [lat]/[lon]: where you are. */+ fun feed(mac: String, time: Long, heading: Float, rssi: Int, lat: Double?, lon: Double?) {+ tracks.entries.removeAll { time - it.value.fed > LINE_MS }+ val t = tracks.getOrPut(mac) { Track() }+ if (time == t.fed) return+ t.fed = time+ t.sweep.add(time, heading, rssi)+ val e = t.sweep.settled(time) ?: return+ // The next turn gives a new, independent line.+ t.sweep.clear()+ // Another turn at the same spot replaces the line there.+ t.lines.removeAll { time - it.time > LINE_MS || near(it, lat, lon, SAME_SPOT_M) }+ t.lines += Line(lat, lon, e.bearing, e.confidence, time)+ while (t.lines.size > MAX_LINES) t.lines.removeAt(0)+ }++ /** Where [mac] shows from where you are now ([lat]/[lon], null without a fix); null when no turn settled it yet. */+ fun place(mac: String, lat: Double?, lon: Double?, now: Long): Place? {+ val t = tracks[mac] ?: return null+ t.lines.removeAll { now - it.time > LINE_MS }+ if (lat != null && lon != null) cross(t.lines)?.let { (dLat, dLon) ->+ val d = DeviceRegistry.metersBetween(lat, lon, dLat, dLon).toFloat()+ return Place(KnownCameras.bearingTo(lat, lon, dLat, dLon).toFloat(), d)+ }+ // Not crossed yet: the newest direction, while you still stand about where you took it.+ val l = t.lines.lastOrNull()?.takeIf { near(it, lat, lon, NEAR_M) } ?: return null+ return Place(l.bearing, null)+ }++ /** Forgets every line and sweep (scan stopped). */+ fun clear() = tracks.clear()++ private fun near(l: Line, lat: Double?, lon: Double?, m: Double): Boolean {+ if (l.lat == null || l.lon == null || lat == null || lon == null) return l.lat == null && lat == null+ return DeviceRegistry.metersBetween(l.lat, l.lon, lat, lon) <= m+ }++ /**+ * The weighted least-squares crossing (lat to lon) of the [lines] that have a position: null unless two of them+ * differ by [MIN_CROSS_DEG], and the crossing lies ahead of every line within [MAX_RANGE_M] (a crossing behind+ * you means one direction is wrong).+ */+ fun cross(lines: List<Line>): Pair<Double, Double>? {+ val ls = lines.filter { it.lat != null && it.lon != null }+ if (ls.size < 2) return null+ var spread = 0f+ for (i in ls.indices) for (j in i + 1 until ls.size) {+ val d = abs(Sweep.turn(ls[i].bearing, ls[j].bearing)).toFloat()+ spread = maxOf(spread, min(d, 180f - d))+ }+ if (spread < MIN_CROSS_DEG) return null+ val lat0 = ls[0].lat!!; val lon0 = ls[0].lon!!+ val mx = 111_320.0 * cos(Math.toRadians(lat0)); val my = 110_540.0+ fun x(l: Line) = (l.lon!! - lon0) * mx+ fun y(l: Line) = (l.lat!! - lat0) * my+ // Minimises the weighted squared distance across each line: sum w (I - d dT) (p - x) = 0.+ var a11 = 0.0; var a12 = 0.0; var a22 = 0.0; var b1 = 0.0; var b2 = 0.0+ for (l in ls) {+ val r = Math.toRadians(l.bearing.toDouble()); val dx = sin(r); val dy = cos(r)+ val w = l.weight.toDouble()+ val m11 = 1 - dx * dx; val m12 = -dx * dy; val m22 = 1 - dy * dy+ a11 += w * m11; a12 += w * m12; a22 += w * m22+ b1 += w * (m11 * x(l) + m12 * y(l)); b2 += w * (m12 * x(l) + m22 * y(l))+ }+ val det = a11 * a22 - a12 * a12+ if (abs(det) < 1e-9) return null+ val px = (b1 * a22 - b2 * a12) / det+ val py = (a11 * b2 - a12 * b1) / det+ for (l in ls) {+ val r = Math.toRadians(l.bearing.toDouble())+ val along = (px - x(l)) * sin(r) + (py - y(l)) * cos(r)+ if (along <= 0 || along > MAX_RANGE_M) return null+ }+ return lat0 + py / my to lon0 + px / mx+ }++ /** Lines older than this drop out: the device may have moved. */+ const val LINE_MS = 5 * 60_000L+ private const val MAX_LINES = 6+ /** A turn within this of an earlier one is the same spot. */+ private const val SAME_SPOT_M = 8.0+ /** A direction alone holds while you stay within this of where you took it. */+ private const val NEAR_M = 25.0+ /** Lines this close to parallel don't cross anywhere useful. */+ const val MIN_CROSS_DEG = 20f+ /** About as far as a phone hears Bluetooth. */+ private const val MAX_RANGE_M = 300.0+}diff --git a/app/src/main/java/com/rfsentinel/app/ui/RadarView.kt b/app/src/main/java/com/rfsentinel/app/ui/RadarView.ktindex 8ebadba..2138618 100644--- a/app/src/main/java/com/rfsentinel/app/ui/RadarView.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/RadarView.kt@@ -13,6 +13,7 @@ import android.view.Viewimport com.google.android.material.color.MaterialColorsimport com.rfsentinel.app.Rimport com.rfsentinel.app.detect.DeviceIntel+import com.rfsentinel.app.service.DeviceRegistryimport kotlin.math.cosimport kotlin.math.hypotimport kotlin.math.min@@ -60,6 +61,30 @@ class RadarView @JvmOverloads constructor(private val compass = Compass(context)private val fusion = HeadingFusion()private var fixTime = 0L+ private var lastFix: Location? = null+ private var tickAt = 0L+ private var tickHeading: Float? = null++ /**+ * Five times a second while on screen: each alert's new raw reading with the way you faced when it was heard,+ * so [RadarTrack] finds its side as you turn and crosses the lines as you walk.+ */+ private val sampler = object : Runnable {+ override fun run() {+ postDelayed(this, SAMPLE_MS)+ val h = compass.degrees ?: return+ val now = System.currentTimeMillis()+ val t0 = tickAt; val h0 = tickHeading ?: h+ tickAt = now; tickHeading = h+ val fix = lastFix+ // In a car its metal, not your body, shapes the signal.+ if (fix != null && fix.hasSpeed() && fix.speed > WALK_MS) return+ for (it in items) if (it.b.flagged) {+ val (seen, rssi) = DeviceRegistry.lastHeard(it.b.mac) ?: continue+ RadarTrack.feed(it.b.mac, seen, Sweep.headingAt(seen, t0, h0, now, h), rssi, fix?.latitude, fix?.longitude)+ }+ }+ }/** Compass degrees at the top, null for north-up. */private var heading: Float? = null@@ -107,11 +132,13 @@ class RadarView @JvmOverloads constructor(// The compass runs only while the radar is on screen.override fun onVisibilityAggregated(isVisible: Boolean) {super.onVisibilityAggregated(isVisible)- if (isVisible) compass.start() else compass.stop()+ removeCallbacks(sampler)+ if (isVisible) { compass.start(); post(sampler) } else compass.stop()}override fun onDetachedFromWindow() {compass.stop()+ removeCallbacks(sampler)super.onDetachedFromWindow()}@@ -141,6 +168,7 @@ class RadarView @JvmOverloads constructor(fun setFix(fix: Location?) {if (fix == null || fix.time == fixTime) returnfixTime = fix.time+ lastFix = fixcompass.setLocation(fix.latitude, fix.longitude, fix.altitude)val course = fix.bearing.takeIf { fix.hasBearing() && (!fix.hasBearingAccuracy() || fix.bearingAccuracyDegrees <= 30f) }fusion.fix(System.currentTimeMillis(), course, if (fix.hasSpeed()) fix.speed else 0f)@@ -280,6 +308,7 @@ class RadarView @JvmOverloads constructor(directional && heading != null && compass.unreliable && !fusion.gpsSet(now) ->pick("Compass needs calibrating: wave the phone in a figure 8", "Calibrate: wave phone in a figure 8")pinpointOff && unplaced -> pick("Pinpoint is off: Settings › Location shows where alerts are", "Pinpoint off: Settings › Location")+ unplaced && compass.degrees != null -> pick("Turn around slowly, phone in front of you, to place alerts", "Turn around slowly to place alerts")directional -> pick("Closer = stronger signal · lines point to located alerts", "Lines point to located alerts")else -> pick("Closer to centre = stronger signal · angle is not direction", "Closer = stronger · angle isn't direction")}@@ -309,4 +338,10 @@ class RadarView @JvmOverloads constructor(}override fun performClick(): Boolean = super.performClick()++ private companion object {+ const val SAMPLE_MS = 200L+ /** Faster than a brisk walk (m/s): driving. */+ const val WALK_MS = 3f+ }}diff --git a/app/src/main/java/com/rfsentinel/app/ui/Sweep.kt b/app/src/main/java/com/rfsentinel/app/ui/Sweep.ktindex d054d43..8040ee8 100644--- a/app/src/main/java/com/rfsentinel/app/ui/Sweep.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/Sweep.kt@@ -1,5 +1,6 @@package com.rfsentinel.app.ui+import kotlin.math.absimport kotlin.math.atan2import kotlin.math.cosimport kotlin.math.hypot@@ -31,20 +32,19 @@ class Sweep {while (readings.isNotEmpty() && now - readings.first().time > WINDOW_MS) readings.removeFirst()}- fun clear() = readings.clear()+ fun clear() { readings.clear(); candidate = null }/** Sectors with a reading in the last [WINDOW_MS] (out of [SECTORS]). */fun covered(now: Long) = sectors(now).count { it != null }- /** The average signal (dBm) heard facing each sector, null where you haven't faced yet. Sector i is centred on [centre]. */+ /**+ * The median signal (dBm) heard facing each sector, null where you haven't faced yet. Sector i is centred on+ * [centre]. The median, not the mean: one deep multipath fade or one lucky packet doesn't swing a sector.+ */fun sectors(now: Long): Array<Float?> {- val sum = FloatArray(SECTORS)- val n = IntArray(SECTORS)- for (r in readings) if (now - r.time <= WINDOW_MS) {- val i = (r.heading / SECTOR_DEG).toInt().coerceIn(0, SECTORS - 1)- sum[i] += r.rssi; n[i]++- }- return Array(SECTORS) { if (n[it] == 0) null else sum[it] / n[it] }+ val by = Array(SECTORS) { ArrayList<Int>() }+ for (r in readings) if (now - r.time <= WINDOW_MS) by[(r.heading / SECTOR_DEG).toInt().coerceIn(0, SECTORS - 1)] += r.rssi+ return Array(SECTORS) { i -> by[i].takeIf { it.isNotEmpty() }?.sorted()?.let { (it[(it.size - 1) / 2] + it[it.size / 2]) / 2f } }}/**@@ -69,8 +69,28 @@ class Sweep {val rest = sqrt(k.sumOf { i ->val r = m[i]!! - mean - amp * cos(Math.toRadians(centre(i).toDouble()) - peak); r * r} / k.size)- val confidence = k.size.toFloat() / SECTORS * (amp / (amp + rest + NOISE_DB)).toFloat()- return Estimate(((Math.toDegrees(peak) % 360 + 360) % 360).toFloat(), confidence.coerceIn(0f, 1f), (2 * amp).toFloat())+ val bearing = ((Math.toDegrees(peak) % 360 + 360) % 360).toFloat()+ // Body fade (as fox hunters use it): the sharp null is behind you. The weakest reading anywhere else is a+ // reflection or a fade, so the rise and fall it fitted is less sure.+ val weakest = k.minOf { m[it]!! }+ val behind = k.filter { abs(turn(bearing + 180f, centre(it))) <= NULL_SLACK_DEG }.minOfOrNull { m[it]!! }+ val nullFactor = if (behind != null && behind <= weakest + NULL_TOLERANCE_DB) 1f else 0.5f+ val confidence = k.size.toFloat() / SECTORS * (amp / (amp + rest + NOISE_DB)).toFloat() * nullFactor+ return Estimate(bearing, confidence.coerceIn(0f, 1f), (2 * amp).toFloat())+ }++ private var candidate: Estimate? = null+ private var candidateAt = 0L++ /**+ * An estimate good enough to keep: it [locks] and has stayed within [SETTLE_DEG] for [SETTLE_MS] of new+ * readings (one lucky reading at the end of a turn can't lock a wrong side). Null until then.+ */+ fun settled(now: Long): Estimate? {+ val e = estimate(now)?.takeIf { locks(it) } ?: run { candidate = null; return null }+ val c = candidate+ if (c == null || abs(turn(c.bearing, e.bearing)) > SETTLE_DEG) { candidate = e; candidateAt = now; return null }+ return if (now - candidateAt >= SETTLE_MS) e else null}companion object {@@ -85,6 +105,11 @@ class Sweep {const val LOCK_MIN_DB = 4f/** Signal readings jump about this much on their own; keeps a tiny wave on a quiet signal from looking sure. */private const val NOISE_DB = 0.5+ /** The null counts as behind you within this of the opposite side, and within this many dB of the weakest. */+ private const val NULL_SLACK_DEG = 60f+ private const val NULL_TOLERANCE_DB = 1f+ const val SETTLE_DEG = 20f+ const val SETTLE_MS = 1_500Lfun centre(sector: Int) = sector * SECTOR_DEG + SECTOR_DEG / 2@@ -94,6 +119,16 @@ class Sweep {private val POINTS = arrayOf("N", "NE", "E", "SE", "S", "SW", "W", "NW")fun compassPoint(deg: Float) = POINTS[(((deg % 360f + 360f) % 360f) / 45f).roundToInt() % 8]+ /**+ * The way you faced at [t], between two compass reads ([t0], [h0]) and ([t1], [h1]): a reading is picked up+ * to a sampling tick after it was heard, and a turn moves on meanwhile.+ */+ fun headingAt(t: Long, t0: Long, h0: Float, t1: Long, h1: Float): Float {+ if (t1 <= t0) return h1+ val f = ((t - t0).toFloat() / (t1 - t0)).coerceIn(0f, 1f)+ return h0 + (((h1 - h0) % 360f + 540f) % 360f - 180f) * f+ }+/** Degrees to turn from [heading] to face [target]: positive right, negative left (-180..180). */fun turn(heading: Float, target: Float): Int = (((target - heading) % 360f + 540f) % 360f - 180f).roundToInt()}diff --git a/app/src/test/java/com/rfsentinel/app/ui/RadarTrackTest.kt b/app/src/test/java/com/rfsentinel/app/ui/RadarTrackTest.ktnew file mode 100644index 0000000..2a0a64d--- /dev/null+++ b/app/src/test/java/com/rfsentinel/app/ui/RadarTrackTest.kt@@ -0,0 +1,34 @@+package com.rfsentinel.app.ui++import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test++class RadarTrackTest {++ // Metres east / north of a neutral origin (0, 0) to lat/lon.+ private fun line(east: Double, north: Double, bearing: Float) =+ RadarTrack.Line(north / 110_540.0, east / 111_320.0, bearing, 1f, 0L)++ @Test+ fun twoTurnsCrossAtTheDevice() {+ // Device 50 m east and 50 m north: seen NE from the start, NW from 100 m further east.+ val (lat, lon) = RadarTrack.cross(listOf(line(0.0, 0.0, 45f), line(100.0, 0.0, 315f)))!!+ assertEquals(50.0, lat * 110_540.0, 1.0)+ assertEquals(50.0, lon * 111_320.0, 1.0)+ // A third, slightly off line still lands close.+ val (lat3, lon3) = RadarTrack.cross(listOf(line(0.0, 0.0, 45f), line(100.0, 0.0, 315f), line(50.0, 0.0, 5f)))!!+ assertEquals(50.0, lat3 * 110_540.0, 5.0)+ assertEquals(50.0, lon3 * 111_320.0, 5.0)+ }++ @Test+ fun noCrossingWhenParallelBehindOrAlone() {+ assertNull(RadarTrack.cross(listOf(line(0.0, 0.0, 45f))))+ assertNull(RadarTrack.cross(listOf(line(0.0, 0.0, 45f), line(100.0, 0.0, 50f)))) // nearly parallel+ assertNull(RadarTrack.cross(listOf(line(0.0, 0.0, 45f), line(100.0, 0.0, 135f)))) // behind the second spot+ assertNull(RadarTrack.cross(listOf(RadarTrack.Line(null, null, 45f, 1f, 0L), line(100.0, 0.0, 315f))))+ assertNotNull(RadarTrack.cross(listOf(line(0.0, 0.0, 45f), line(100.0, 0.0, 315f))))+ }+}diff --git a/app/src/test/java/com/rfsentinel/app/ui/SweepTest.kt b/app/src/test/java/com/rfsentinel/app/ui/SweepTest.ktindex 8df69e4..10bf7ed 100644--- a/app/src/test/java/com/rfsentinel/app/ui/SweepTest.kt+++ b/app/src/test/java/com/rfsentinel/app/ui/SweepTest.kt@@ -43,6 +43,24 @@ class SweepTest {assertEquals(0, flat.covered(1_000L + Sweep.WINDOW_MS + 1))}+ @Test+ fun locksOnlyOnceItHolds() {+ val s = Sweep()+ for (h in 0 until 360 step 5) s.add(1_000L + h * 50, h.toFloat(), (-75 + 5 * cos(Math.toRadians(h - 120.0))).toInt())+ assertNull(s.settled(19_000L)) // just became clear+ s.add(19_500L, 120f, -70)+ assertNull(s.settled(19_500L))+ s.add(21_000L, 125f, -70)+ assertEquals(120f, s.settled(21_000L)!!.bearing, 15f)+ }++ @Test+ fun headingAtWhenHeardGoesTheShortWay() {+ assertEquals(360f, Sweep.headingAt(5L, 0L, 350f, 10L, 10f), 0.01f)+ assertEquals(15f, Sweep.headingAt(50L, 0L, 10f, 100L, 20f), 0.01f)+ assertEquals(20f, Sweep.headingAt(500L, 0L, 10f, 100L, 20f), 0.01f)+ }+@Testfun turnIsShortestWay() {assertEquals(30, Sweep.turn(10f, 40f))