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
Log pager listen counters: samples, channel rise, syncs, frames
CIS-C0e333cea83b92
diff --git a/app/src/main/java/com/rfsentinel/app/sdr/Flex.kt b/app/src/main/java/com/rfsentinel/app/sdr/Flex.ktindex 6e948a0..4e73191 100644--- a/app/src/main/java/com/rfsentinel/app/sdr/Flex.kt+++ b/app/src/main/java/com/rfsentinel/app/sdr/Flex.kt@@ -44,6 +44,8 @@ class Flex(sampleRate: Int, private val onPage: (PagerLog.Page) -> Unit) {/** Frame headers that passed their checks: a real FLEX signal, even with no page in it. */var frames = 0; private set+ /** Frame syncs found, whatever followed them. */+ var syncs = 0; private setprivate val clock = SymbolClock(sampleRate, HEADER_BAUD)private val zeroSamples = sampleRate * ZERO_S@@ -107,7 +109,7 @@ class Flex(sampleRate: Int, private val onPage: (PagerLog.Page) -> Unit) {when (state) {State.SYNC1 -> {val code = sync(raw)- if (code != 0 && mode(code)) state = State.FIW+ if (code != 0 && mode(code)) { syncs++; state = State.FIW }fiwCount = 0; fiw = 0}State.FIW -> {diff --git a/app/src/main/java/com/rfsentinel/app/sdr/PagerDemod.kt b/app/src/main/java/com/rfsentinel/app/sdr/PagerDemod.ktindex 387af43..8bf4e58 100644--- a/app/src/main/java/com/rfsentinel/app/sdr/PagerDemod.kt+++ b/app/src/main/java/com/rfsentinel/app/sdr/PagerDemod.kt@@ -2,6 +2,7 @@ package com.rfsentinel.app.sdrimport kotlin.math.PIimport kotlin.math.atan2+import kotlin.math.log10/*** Pager messages, first stage: the SDR's raw I/Q to pages. Picks the channel [offsetHz] from the tuned centre (mixed and@@ -28,6 +29,14 @@ class PagerDemod(offsetHz: Long, speeds: Set<Int> = SPEEDS, onPage: (PagerLog.Pa/** POCSAG batches and FLEX frames that checked out: the channel really carries pages. */val frames get() = flex.frames + pocsag.sumOf { it.decoder.batches }+ /** Frame syncs, good page or not: a channel with these is paging, whatever became of the pages. */+ val syncs get() = flex.syncs + pocsag.sumOf { it.decoder.syncs }++ /** How far the channel's loudest 50 ms stood above its quietest, in dB: high when a transmitter came on. */+ val riseDb get() = if (quietest > 0 && loudest > 0) 10 * log10(loudest / quietest) else 0.0+ private var blockSum = 0.0; private var blockN = 0; private var blocks = 0+ private var quietest = 0.0; private var loudest = 0.0+private val firR = DoubleArray(TAPS.size); private val firI = DoubleArray(TAPS.size); private var firAt = 0private var lastR = 0.0; private var lastI = 0.0private val box = DoubleArray(BOX); private var boxAt = 0; private var boxSum = 0.0@@ -41,6 +50,14 @@ class PagerDemod(offsetHz: Long, speeds: Set<Int> = SPEEDS, onPage: (PagerLog.Pavar yr = 0.0; var yi = 0.0; var j = firAtfor (t in TAPS) { yr += t * firR[j]; yi += t * firI[j]; if (--j < 0) j = TAPS.size - 1 }if (++firAt == TAPS.size) firAt = 0+ blockSum += yr * yr + yi * yi+ if (++blockN == BLOCK) {+ if (blocks++ > 0) { // the first still holds the filter's empty start+ quietest = if (quietest == 0.0) blockSum else minOf(quietest, blockSum)+ loudest = maxOf(loudest, blockSum)+ }+ blockSum = 0.0; blockN = 0+ }val hz = atan2(yi * lastR - yr * lastI, yr * lastR + yi * lastI) * RATE / (2 * PI)lastR = yr; lastI = yi// Smoothed, or noise on the discriminator makes false zero crossings for the symbol clocks.@@ -59,6 +76,7 @@ class PagerDemod(offsetHz: Long, speeds: Set<Int> = SPEEDS, onPage: (PagerLog.Paprivate const val CLOCK_RATE = 0.05private const val BOX = 6private const val DC_SAMPLES = 2_400.0 // 50 ms+ private const val BLOCK = 2_400 // 50 ms/** Up to ±4.8 kHz deviation, plus the signal's own width. */private val TAPS = P25Demod.lowPass(8_000.0)}diff --git a/app/src/main/java/com/rfsentinel/app/sdr/PagerHunt.kt b/app/src/main/java/com/rfsentinel/app/sdr/PagerHunt.ktindex eb9e465..29a8104 100644--- a/app/src/main/java/com/rfsentinel/app/sdr/PagerHunt.kt+++ b/app/src/main/java/com/rfsentinel/app/sdr/PagerHunt.kt@@ -53,6 +53,7 @@ class PagerHunt(repeat(sdr.settleReads) { sdr.read(buf) }val demod = PagerDemod(OFFSET_HZ, speeds()) { onPage(it, hz) }var samples = 0L; var lastGood = 0L; var seen = 0; var fails = 0+ val began = System.nanoTime()while (!stop()) {val n = sdr.read(buf)if (n <= 0) {@@ -73,6 +74,10 @@ class PagerHunt(}if (samples - lastGood > quietS * P25Demod.SAMPLE_RATE) break}+ // Counts and levels only. Under 100%: the dongle dropped samples. A rise with no syncs: a signal that isn't paging, or won't decode.+ val secs = (System.nanoTime() - began) / 1e9+ if (samples > 0) log("Pager listen: %.0f s, %.0f%% of the samples, channel rose %.0f dB, %d syncs, %d frames".format(+ java.util.Locale.US, secs, samples * 100 / (secs * P25Demod.SAMPLE_RATE), demod.riseDb, demod.syncs, demod.frames))return seen > 0}diff --git a/app/src/main/java/com/rfsentinel/app/sdr/Pocsag.kt b/app/src/main/java/com/rfsentinel/app/sdr/Pocsag.ktindex dff5b6e..3b8e3e1 100644--- a/app/src/main/java/com/rfsentinel/app/sdr/Pocsag.kt+++ b/app/src/main/java/com/rfsentinel/app/sdr/Pocsag.kt@@ -59,6 +59,8 @@ class Pocsag(private val baud: Int, private val onPage: (PagerLog.Page) -> Unit)/** Batches that ended in a sync or held a page: a real POCSAG signal. */var batches = 0; private set+ /** Frame syncs found, whatever followed them. */+ var syncs = 0; private setprivate var reg = 0private var synced = false@@ -76,7 +78,7 @@ class Pocsag(private val baud: Int, private val onPage: (PagerLog.Page) -> Unit)if (!synced) {val d = bitCount(reg xor SYNC)if (d <= SYNC_ERRORS || d >= 32 - SYNC_ERRORS) {- synced = true; inverted = d > SYNC_ERRORS+ synced = true; inverted = d > SYNC_ERRORS; syncs++bits = 0; at = 0; bad = 0}returndiff --git a/app/src/test/java/com/rfsentinel/app/sdr/PagerTest.kt b/app/src/test/java/com/rfsentinel/app/sdr/PagerTest.ktindex 5ff3d82..4c5abb3 100644--- a/app/src/test/java/com/rfsentinel/app/sdr/PagerTest.kt+++ b/app/src/test/java/com/rfsentinel/app/sdr/PagerTest.kt@@ -1,6 +1,7 @@package com.rfsentinel.app.sdrimport org.junit.Assert.assertEquals+import org.junit.Assert.assertFalseimport org.junit.Assert.assertNotNullimport org.junit.Assert.assertNullimport org.junit.Assert.assertTrue@@ -326,7 +327,27 @@ class PagerTest {dongle.stall = 9 // the settle read takes one, then one stall's worthhunt.listen(929_612_500L, { dongle.reads > 20 }) { _, _ -> }assertEquals(listOf(true, false), stalls)- assertEquals(1, logs.size)+ assertEquals(1, logs.count { !it.startsWith("Pager listen") })+ }++ @Test fun `the listen counters show syncs and a transmitter coming on`() {+ val words = pocsag(listOf(1234567 to listOf(address(1234567, 1)))).take(17)+ val iq = pocsagSignal(1200, words).iq(OFFSET + CARRIER_ERROR_HZ)+ val d = PagerDemod(OFFSET) { }+ val silence = ByteArray(768_000) { 128.toByte() } // 200 ms+ d.feed(silence, silence.size / 2)+ assertEquals(0, d.syncs)+ d.feed(iq, iq.size / 2)+ assertEquals(1, d.syncs)+ assertTrue("rose ${d.riseDb} dB", d.riseDb > 10)+ }++ @Test fun `a typed frequency logs its counters, and they name no frequency`() {+ val dongle = FakeDongle(929_612_500L, Fsk())+ val logs = ArrayList<String>()+ PagerHunt(dongle, log = { logs += it }).listen(929_612_500L, { dongle.reads > 20 }) { _, _ -> }+ val line = logs.single { it.startsWith("Pager listen") }+ assertFalse(line, "929612500" in line || "929.6" in line)}@Test fun `a lone batch counts as a frame, so the hunt stays on a channel of short pages`() {