tx: lowest documented PA table, test_burst, tx payload logging; 200ms delay improves SDR repeat decode 3%->30%
This commit is contained in:
+23
-32
@@ -2,55 +2,46 @@
|
||||
# Capture wM-Bus frames with the RTL-SDR for a fixed duration.
|
||||
# Usage: capture_sdr.sh DURATION_S OUTFILE [GAIN]
|
||||
#
|
||||
# Robustness notes (learned the hard way; see docs/FINDINGS.md):
|
||||
# Robustness notes (see docs/FINDINGS.md):
|
||||
# - timeout is applied to rtl_sdr itself; killing a wrapping shell orphans
|
||||
# the children and keeps the device claimed.
|
||||
# - The R820T PLL wedges ("PLL not locked") and rtl_sdr dies mid-stream
|
||||
# with "Library error -5". usbreset recovers it; sometimes it needs a
|
||||
# cool-down. We probe for the wedge before each capture attempt.
|
||||
# - "[R82XX] PLL not locked!" during tuning is BENIGN noise emitted while
|
||||
# rtl_sdr probes/disables direct-sampling mode. It is NOT a wedge
|
||||
# indicator; do not reset on it.
|
||||
# - The real failure is "Library error -5" (USB transfer death) which ends
|
||||
# the stream early. We restart until the deadline and record the total
|
||||
# streaming time so the report can tell "SDR was deaf" from "no traffic".
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
DUR=$1; OUT=$2; GAIN=${3:-42.1}
|
||||
|
||||
: > "$OUT"
|
||||
ERR="${OUT%.log}.err"
|
||||
STATS="${OUT%.log}.stats"
|
||||
: > "$ERR"
|
||||
|
||||
sdr_healthy() {
|
||||
# 2-second probe; wedged tuner prints "PLL not locked" on tune
|
||||
local probe
|
||||
probe=$(timeout 6 rtl_sdr -f 868950000 -s 1600000 -g "$GAIN" -n 3200000 /dev/null 2>&1 || true)
|
||||
echo "$probe" >> "$ERR"
|
||||
! grep -q "PLL not locked" <<< "$probe"
|
||||
}
|
||||
|
||||
ensure_healthy() {
|
||||
for i in 1 2 3; do
|
||||
if sdr_healthy; then return 0; fi
|
||||
echo "--- PLL wedged; usbreset (try $i)" >> "$ERR"
|
||||
usbreset 0bda:2838 >> "$ERR" 2>&1 || true
|
||||
sleep $((i * 5))
|
||||
done
|
||||
echo "--- SDR still wedged after 3 resets" >> "$ERR"
|
||||
return 1
|
||||
}
|
||||
|
||||
deadline=$(( $(date +%s) + DUR ))
|
||||
attempt=0
|
||||
streamed=0
|
||||
while :; do
|
||||
remaining=$(( deadline - $(date +%s) ))
|
||||
[ "$remaining" -le 10 ] && break
|
||||
now=$(date +%s)
|
||||
remaining=$(( deadline - now ))
|
||||
[ "$remaining" -le 3 ] && break
|
||||
attempt=$((attempt + 1))
|
||||
echo "--- rtl_sdr attempt $attempt (${remaining}s remaining)" >> "$ERR"
|
||||
ensure_healthy || true
|
||||
remaining=$(( deadline - $(date +%s) ))
|
||||
[ "$remaining" -le 2 ] && break
|
||||
t0=$(date +%s)
|
||||
timeout "$remaining" rtl_sdr -f 868950000 -s 1600000 -g "$GAIN" - 2>>"$ERR" \
|
||||
| rtl_wmbus -f >> "$OUT" 2>/dev/null || true
|
||||
remaining=$(( deadline - $(date +%s) ))
|
||||
if [ "$remaining" -gt 10 ]; then
|
||||
echo "--- rtl_sdr died early; usbreset and retry" >> "$ERR"
|
||||
t1=$(date +%s)
|
||||
streamed=$(( streamed + t1 - t0 ))
|
||||
remaining=$(( deadline - t1 ))
|
||||
if [ "$remaining" -gt 3 ]; then
|
||||
echo "--- stream died after $((t1 - t0))s; usbreset + settle" >> "$ERR"
|
||||
usbreset 0bda:2838 >> "$ERR" 2>&1 || true
|
||||
sleep 5
|
||||
sleep 4
|
||||
fi
|
||||
done
|
||||
|
||||
printf 'streamed_seconds=%s\nrequested_seconds=%s\nattempts=%s\n' \
|
||||
"$streamed" "$DUR" "$attempt" > "$STATS"
|
||||
echo "--- streamed ${streamed}s of ${DUR}s in $attempt attempt(s)" >> "$ERR"
|
||||
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
"""List RF bursts in a raw rtl_sdr u8 IQ capture and the gaps between them.
|
||||
|
||||
Usage: iq_bursts.py iq.raw [sample_rate] [threshold_db]
|
||||
|
||||
Purpose: distinguish "transmitter produced no RF" from "RF exists but the
|
||||
decoder cannot decode it". A repeater under test should produce burst PAIRS
|
||||
separated by approximately the configured repeat delay.
|
||||
"""
|
||||
import sys
|
||||
import numpy as np
|
||||
|
||||
path = sys.argv[1]
|
||||
fs = int(sys.argv[2]) if len(sys.argv) > 2 else 1_600_000
|
||||
thr_db = float(sys.argv[3]) if len(sys.argv) > 3 else 9.0
|
||||
|
||||
WIN = fs // 1000 # 1 ms resolution
|
||||
CHUNK = fs * 2 # 1 s of bytes
|
||||
|
||||
env = []
|
||||
with open(path, "rb") as f:
|
||||
while True:
|
||||
raw = f.read(CHUNK)
|
||||
if len(raw) < WIN * 2:
|
||||
break
|
||||
buf = np.frombuffer(raw, dtype=np.uint8).astype(np.float32) - 127.5
|
||||
iq = buf[0::2] + 1j * buf[1::2]
|
||||
p = np.abs(iq) ** 2
|
||||
p = p[: (len(p) // WIN) * WIN].reshape(-1, WIN).mean(axis=1)
|
||||
env.append(p)
|
||||
|
||||
db = 10 * np.log10(np.concatenate(env) + 1e-9)
|
||||
floor = np.median(db)
|
||||
print(f"windows={len(db)} floor={floor:.1f}dB p99={np.percentile(db,99):.1f} max={db.max():.1f}")
|
||||
|
||||
active = db > floor + thr_db
|
||||
idx = np.where(active)[0]
|
||||
bursts = []
|
||||
if len(idx):
|
||||
start = prev = idx[0]
|
||||
for i in idx[1:]:
|
||||
if i > prev + 3: # >3 ms silence splits bursts
|
||||
bursts.append((start, prev))
|
||||
start = i
|
||||
prev = i
|
||||
bursts.append((start, prev))
|
||||
|
||||
print(f"bursts (>{thr_db:.0f} dB over floor): {len(bursts)}")
|
||||
prev_end = None
|
||||
pairs = []
|
||||
for s, e in bursts:
|
||||
gap = (s - prev_end) if prev_end is not None else None
|
||||
dur = e - s + 1
|
||||
peak = db[s:e + 1].max() - floor
|
||||
gtxt = f"gap={gap:>5} ms" if gap is not None else "gap= - "
|
||||
print(f" t={s/1000:8.3f}s dur={dur:>3} ms peak=+{peak:5.1f} dB {gtxt}")
|
||||
if gap is not None and 10 <= gap <= 300:
|
||||
pairs.append((prev_end, s, gap))
|
||||
prev_end = e
|
||||
|
||||
print(f"\nburst pairs with 10-300 ms spacing (repeat candidates): {len(pairs)}")
|
||||
for a, b, g in pairs[:40]:
|
||||
print(f" original ends {a/1000:.3f}s -> next starts {b/1000:.3f}s (gap {g} ms)")
|
||||
Reference in New Issue
Block a user