List USB sound cards with no serial port, and CM108 PTT, in radio

`radio` now lists, after the radios, the USB sound cards that no serial
port goes with and that both play and record (not a webcam's
microphone): interfaces such as a SignaLink, an AIOC or a CM108 cable,
for a radio keyed by VOX or a PTT line. They aren't numbered, so
`radio configure`'s numbers don't change. A CM108-compatible card, alone
or as a radio's (a Digirig), is shown with the hidraw device it keys the
radio through, and whether you can open it. With only sound cards
plugged in, `radio` lists them rather than saying nothing was found.

radio's list of CM108-compatible devices is the udev rule's, and a test
keeps them the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 14:02:03 -07:00
co-authored by Claude Opus 5.5
parent 5f15ff3821
commit 0c2f9b5316
5 changed files with 188 additions and 7 deletions
+106
View File
@@ -52,6 +52,23 @@ card() {
echo "$3" > "$RADIO_SYSFS/class/sound/$2/id"
}
# A card's PCM devices: pcm CARD p|c..., playback and capture
pcm() {
local n="${1#card}" dir
shift
for dir; do mkdir -p "$RADIO_SYSFS/class/sound/pcmC${n}D0$dir"; done
}
# A hidraw device on a USB device, which you can open unless "locked":
# hidraw USBPATH HIDRAW [locked]
hidraw() {
local iface="$ROOT_HUB/$1/${1##*/}:1.3"
mkdir -p "$iface/hidraw/$2" "$RADIO_SYSFS/class/hidraw/$2"
ln -s "$iface" "$RADIO_SYSFS/class/hidraw/$2/device"
touch "$RADIO_DEV/$2"
[ "${3:-}" != locked ] || chmod 000 "$RADIO_DEV/$2"
}
# A computer's own sound card, not on USB
onboard_card() {
mkdir -p "$RADIO_SYSFS/devices/pci0000:00/0000:00:1f.3/sound/card0" "$RADIO_SYSFS/class/sound/card0"
@@ -1226,3 +1243,92 @@ FLRIG_AUTOSTART() { echo "$HOME/.config/autostart/hampack-flrig.desktop"; }
! grep -q "systemctl --user restart" "$STUB_LOG"
grep -qx "ExecStart=/usr/bin/rigctld -m 3073 -r /dev/serial/by-id/usb-gone-if00-port0 -s 38400 -T 127.0.0.1 -t 4532" "$HOME/.config/systemd/user/hampack-rigctld.service"
}
# --- sound cards with no serial port ---
@test "lists USB sound cards with no serial port, and how they key the radio" {
ic7300
pcm card1 p c
# An AIOC: a CM108-compatible sound card with no CAT
usb 1-3 1209:7388 "AIOC" "All-In-One-Cable"
card 1-3 card2 AIOC
pcm card2 p c
hidraw 1-3 hidraw2
# A SignaLink: a sound card keyed by VOX
usb 1-4 08bb:2904 "Burr-Brown from TI" "USB Audio CODEC"
card 1-4 card3 CODEC_1
pcm card3 p c
# A webcam's microphone: records, doesn't play
usb 1-5 046d:085e Logitech "BRIO"
card 1-5 card4 BRIO
pcm card4 c
run bash "$REPO/radio"
[ "$status" -eq 0 ]
[ "${lines[0]}" = "1. Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
[ "${lines[4]}" = "USB sound cards with no serial port, for a radio keyed by VOX or a PTT line:" ]
[ "${lines[5]}" = " hw:CARD=AIOC (card2): AIOC All-In-One-Cable, 1209:7388. PTT through CM108 on /dev/hidraw2" ]
[ "${lines[6]}" = " hw:CARD=CODEC_1 (card3): Burr-Brown from TI USB Audio CODEC, 08bb:2904. PTT by VOX, or a line of its own" ]
[ ${#lines[@]} -eq 7 ]
# The radio sound card isn't listed again
[[ "$output" != *"(card1):"* ]]
}
@test "lists sound cards when there's no serial port at all" {
usb 1-4 08bb:2904 "Burr-Brown from TI" "USB Audio CODEC"
card 1-4 card1 CODEC
pcm card1 p c
run bash "$REPO/radio"
[ "$status" -eq 0 ]
[ "${lines[0]}" = "USB sound cards with no serial port, for a radio keyed by VOX or a PTT line:" ]
[[ "$output" != *"No USB serial ports found"* ]]
run bash "$REPO/radio" configure
[ "$status" -eq 1 ]
[[ "$output" == *"No USB serial ports found"* ]]
}
@test "shows a radio's CM108 PTT, and says when you can't open it" {
# A Digirig: a CP2102 and a CM108B behind its own hub
usb 1-6 1a40:0101
usb 1-6/1-6.1 10c4:ea60 "Silicon Labs" "CP2102 USB to UART Bridge Controller" 0001
port 1-6/1-6.1 ttyUSB0
usb 1-6/1-6.2 0d8c:0012 "C-Media Electronics Inc." "USB Audio Device"
card 1-6/1-6.2 card1 Device
pcm card1 p c
hidraw 1-6/1-6.2 hidraw0 locked
run bash "$REPO/radio"
[ "${lines[2]}" = " Sound card: hw:CARD=Device (card1)" ]
[ "${lines[3]}" = " CM108 PTT: /dev/hidraw0, which you can't open yet: \`update\` installs HamPack's udev rule for it, which lets whoever is at the desktop use it" ]
[[ "$output" != *"USB sound cards with no serial port"* ]]
chmod 600 "$RADIO_DEV/hidraw0"
run bash "$REPO/radio"
[ "${lines[3]}" = " CM108 PTT: /dev/hidraw0" ]
}
@test "doesn't call other C-Media cards CM108-compatible" {
usb 1-4 0d8c:0014 "C-Media Electronics Inc." "USB Audio Device"
card 1-4 card1 Device
pcm card1 p c
hidraw 1-4 hidraw0
run bash "$REPO/radio"
[ "${lines[1]}" = " hw:CARD=Device (card1): C-Media Electronics Inc. USB Audio Device, 0d8c:0014. PTT by VOX, or a line of its own" ]
}
@test "radio's CM108 list is the udev rule's" {
local rule device vid pid
rule="$(grep -v '^#' "$REPO/udev/70-hampack-cm108.rules" | grep .)"
for device in 0d8c:0008 0d8c:000a 0d8c:000f 0d8c:0012 0d8c:0013 0d8c:0139 0d8c:013a 0d8c:013c 0c76:1605 0c76:1607 0c76:160b 1209:7388 0d8c:0014 0d8c:0001 0c76:1600 1209:0001; do
vid="${device%:*}" pid="${device#*:}"
mkdir -p "$BATS_TEST_TMPDIR/d/$device"
echo "$vid" > "$BATS_TEST_TMPDIR/d/$device/idVendor"
echo "$pid" > "$BATS_TEST_TMPDIR/d/$device/idProduct"
local in_radio=no in_rule=no pattern
bash -c 'source <(sed -n "/^attr() {/,/^}/p; /^cm108_compatible() {/,/^}/p" "$1"); cm108_compatible "$2"' _ "$REPO/radio" "$BATS_TEST_TMPDIR/d/$device" && in_radio=yes
for pattern in $(grep "idVendor}==\"$vid\"" <<< "$rule" | grep -oE 'idProduct}=="[^"]+"' | cut -d'"' -f2 | tr '|' ' '); do
# shellcheck disable=SC2053
[[ "$pid" == $pattern ]] && in_rule=yes
done
[ "$in_radio" = "$in_rule" ] || { echo "$device: radio $in_radio, rule $in_rule"; return 1; }
done
}