discovery: identify SDR by VID:PID with sysfs fallback; document three observer failure modes

This commit is contained in:
Lars Nolden
2026-09-01 10:07:50 +02:00
parent 3a2e23e204
commit 773343c178
2 changed files with 61 additions and 12 deletions
+30 -7
View File
@@ -22,15 +22,38 @@ fi
DUT_PORT="${dut_candidates[0]}"
[ -e "$DUT_PORT" ] || fail "DUT path vanished: $DUT_PORT"
# --- SDR: Nooelec NESDR SMArt v5 (RTL2832U) ---
# rtl_test -t enumerates devices without streaming.
# --- SDR: Nooelec NESDR SMArt v5 (RTL2832U, USB 0bda:2838) ---
# Identity is established by USB VID:PID, because this dongle sometimes
# enumerates with empty descriptor strings after a fault (rtl_test then
# prints "0: , , SN: "). A usbreset restores them, but discovery must not
# fail on it. Ambiguity (more than one RTL dongle) is still fatal.
if command -v lsusb >/dev/null 2>&1; then
usb_count=$(lsusb 2>/dev/null | grep -c '0bda:2838' || true)
else
# sysfs fallback: works without usbutils
usb_count=0
for v in /sys/bus/usb/devices/*/idVendor; do
[ -r "$v" ] || continue
p="${v%idVendor}idProduct"
[ "$(cat "$v" 2>/dev/null)" = "0bda" ] &&
[ "$(cat "$p" 2>/dev/null)" = "2838" ] &&
usb_count=$((usb_count + 1))
done
fi
[ "${usb_count:-0}" -eq 0 ] && fail "no RTL2832U (0bda:2838) on the USB bus"
[ "${usb_count:-0}" -gt 1 ] && fail "ambiguous SDR: $usb_count RTL2832U devices present"
sdr_list=$(timeout 10 rtl_test -t 2>&1 | grep -E '^\s+[0-9]+:' || true)
[ -z "$sdr_list" ] && fail "no RTL-SDR device found (rtl_test)"
sdr_matches=$(echo "$sdr_list" | grep -i "Nooelec" || true)
[ -z "$sdr_matches" ] && fail "RTL-SDR present but not a Nooelec: $sdr_list"
[ "$(echo "$sdr_matches" | wc -l)" -gt 1 ] && fail "ambiguous SDR: $sdr_matches"
[ -z "$sdr_list" ] && fail "RTL2832U on USB but librtlsdr cannot enumerate it"
[ "$(echo "$sdr_list" | wc -l)" -gt 1 ] && fail "ambiguous SDR: $sdr_list"
sdr_matches="$sdr_list"
SDR_INDEX=$(echo "$sdr_matches" | sed -E 's/^\s*([0-9]+):.*/\1/')
SDR_SERIAL=$(echo "$sdr_matches" | sed -E 's/.*SN: ([^ ]+).*/\1/')
SDR_SERIAL=$(echo "$sdr_matches" | sed -E 's/.*SN: ([^ ]*).*/\1/')
[ -z "$SDR_SERIAL" ] && SDR_SERIAL="unknown(descriptor_fault)"
if ! echo "$sdr_matches" | grep -qi "Nooelec"; then
echo "DISCOVER_WARN: RTL dongle descriptors unreadable ($sdr_matches);" \
"identified by VID:PID 0bda:2838" >&2
fi
echo "DUT_PORT=$DUT_PORT"
echo "SDR_INDEX=$SDR_INDEX"