harden SDR capture with restart, correlator counts crc-ok only
This commit is contained in:
+26
-4
@@ -1,11 +1,33 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Capture wM-Bus frames with the RTL-SDR for a fixed duration.
|
# Capture wM-Bus frames with the RTL-SDR for a fixed duration.
|
||||||
# Usage: capture_sdr.sh DURATION_S OUTFILE [GAIN]
|
# Usage: capture_sdr.sh DURATION_S OUTFILE [GAIN]
|
||||||
# timeout is applied to rtl_sdr itself so the pipeline dies cleanly
|
#
|
||||||
# (killing a wrapping shell orphans the children -- learned the hard way).
|
# Robustness notes (learned the hard way):
|
||||||
|
# - timeout is applied to rtl_sdr itself; killing a wrapping shell orphans
|
||||||
|
# the children and keeps the device claimed.
|
||||||
|
# - rtl_sdr occasionally dies mid-stream with USB transfer errors
|
||||||
|
# ("Library error -5"); we usbreset and restart until the deadline.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
cd "$(dirname "$0")/.."
|
cd "$(dirname "$0")/.."
|
||||||
DUR=$1; OUT=$2; GAIN=${3:-42.1}
|
DUR=$1; OUT=$2; GAIN=${3:-42.1}
|
||||||
|
|
||||||
timeout "$DUR" rtl_sdr -f 868950000 -s 1600000 -g "$GAIN" - 2>"${OUT%.log}.err" \
|
: > "$OUT"
|
||||||
| rtl_wmbus -f > "$OUT" 2>/dev/null || true
|
ERR="${OUT%.log}.err"
|
||||||
|
: > "$ERR"
|
||||||
|
|
||||||
|
deadline=$(( $(date +%s) + DUR ))
|
||||||
|
attempt=0
|
||||||
|
while :; do
|
||||||
|
remaining=$(( deadline - $(date +%s) ))
|
||||||
|
[ "$remaining" -le 2 ] && break
|
||||||
|
attempt=$((attempt + 1))
|
||||||
|
echo "--- rtl_sdr attempt $attempt (${remaining}s remaining)" >> "$ERR"
|
||||||
|
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 2 ]; then
|
||||||
|
echo "--- rtl_sdr died early; usbreset and retry" >> "$ERR"
|
||||||
|
usbreset 0bda:2838 >> "$ERR" 2>&1 || true
|
||||||
|
sleep 3
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|||||||
+1
-1
@@ -171,7 +171,7 @@ def main():
|
|||||||
break
|
break
|
||||||
|
|
||||||
for r in heltec_rx:
|
for r in heltec_rx:
|
||||||
if r["_cooked"] is None:
|
if r["_cooked"] is None or not r.get("crc_ok"):
|
||||||
continue
|
continue
|
||||||
ser = r["_cooked"][4:8][::-1].hex() if len(r["_cooked"]) >= 8 else "?"
|
ser = r["_cooked"][4:8][::-1].hex() if len(r["_cooked"]) >= 8 else "?"
|
||||||
per_meter.setdefault(ser, {"sdr": 0, "heltec": 0, "matched": 0})
|
per_meter.setdefault(ser, {"sdr": 0, "heltec": 0, "matched": 0})
|
||||||
|
|||||||
Reference in New Issue
Block a user