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
-3
View File
@@ -21,9 +21,6 @@ control a radio, with rigctld started when the radio is plugged in.
already lets you open the card's `hidraw` device
- [ ] Check that the WSJT-X and QLog Flatpaks can open serial ports
(`--device=all`), in `hampackcheck` or the smoketest
- [ ] List USB sound cards with no serial port (SignaLink USB, VOX-keyed
interfaces). `radio` shows only devices with a serial port, so these
don't appear
- [ ] Later: run `radio configure` when a known radio is plugged in (a udev
rule starting a systemd user unit)
+1 -1
View File
@@ -59,7 +59,7 @@ Graywolf's web UI is at http://localhost:8080 and, by default, can only be reach
### Finding your radio
`radio` lists the radios plugged into USB: each one's serial port, the sound card that came with it, and its model and Hamlib model number when it recognises it. Most Icoms are recognised from their USB serial number alone. For other radios, run `radio detect --probe`. This asks each one what it is (the CAT `ID;` command, or Icom's CI-V equivalent) over every serial port no other program is using. `radio probe /dev/ttyUSB0` asks a single port.
`radio` lists the radios plugged into USB: each one's serial port, the sound card that came with it, and its model and Hamlib model number when it recognises it. It also lists USB sound cards with no serial port, such as a SignaLink or an AIOC, for radios keyed by VOX or a PTT line, and says which sound cards can key a radio through a CM108 PTT pin. Most Icoms are recognised from their USB serial number alone. For other radios, run `radio detect --probe`. This asks each one what it is (the CAT `ID;` command, or Icom's CI-V equivalent) over every serial port no other program is using. `radio probe /dev/ttyUSB0` asks a single port.
Controlling a radio means opening its serial port, and on Arch only members of the `uucp` group can. Keying a radio through the PTT line on a CM108-family sound card (a Digirig, an AIOC) means opening the card's `hidraw` device, which normally only root can; HamPack installs a udev rule, `/etc/udev/rules.d/70-hampack-cm108.rules`, that lets whoever is logged in at the desktop use it, as they can the sound card. HamPack adds you to it when it installs. Log out and back in once afterwards for it to take effect. `hampackremove` takes you out of the group again, unless you were already in it before HamPack.
+5
View File
@@ -144,6 +144,11 @@ With a Digirig, an AIOC or another CM108-family interface plugged in, after
3. Dire Wolf's `cm108` tool lists the device with "**" and you can run it
without sudo. With `PTT CM108` in direwolf.conf, a beacon keys the radio.
4. A C-Media USB headset that isn't CM108-compatible gets no ACL.
5. `radio` lists the interface: with a radio's serial port (a Digirig), as
that radio's "CM108 PTT: /dev/hidrawN"; without one (an AIOC, a CM108
cable), under "USB sound cards with no serial port", as "PTT through
CM108 on /dev/hidrawN". A SignaLink USB is listed there with "PTT by
VOX", and a webcam isn't listed at all.
| Date | Commit | Interface | ACL | Keys the radio | Notes |
|------|--------|-----------|-----|----------------|-------|
+76 -3
View File
@@ -94,14 +94,73 @@ usb_device() {
# Find the USB serial ports and USB sound cards: PORT_USB[ttyUSB0] and
# CARD_USB[card1] are the USB devices they belong to
find_devices() {
declare -gA PORT_USB=() CARD_USB=()
local t c dev
declare -gA PORT_USB=() CARD_USB=() HIDRAW_USB=()
local t c h dev
for t in "$SYSFS"/class/tty/tty{USB,ACM}*; do
[ -e "$t/device" ] && dev="$(usb_device "$t/device")" && PORT_USB["${t##*/}"]="$dev"
done
for c in "$SYSFS"/class/sound/card*; do
[ -e "$c/device" ] && dev="$(usb_device "$c/device")" && CARD_USB["${c##*/}"]="$dev"
done
for h in "$SYSFS"/class/hidraw/hidraw*; do
[ -e "$h/device" ] && dev="$(usb_device "$h/device")" && HIDRAW_USB["${h##*/}"]="$dev"
done
return 0
}
# Whether a USB device is a CM108-family sound card, whose GPIO pin can key a
# radio: the devices Dire Wolf 1.8 treats as CM108-compatible, as
# udev/70-hampack-cm108.rules does. cm108_compatible USB_DEVICE
cm108_compatible() {
case "$(attr "$1" idVendor):$(attr "$1" idProduct)" in
0d8c:000[89a-f] | 0d8c:0012 | 0d8c:0013 | 0d8c:0139 | 0d8c:013a | 0d8c:013c) return 0 ;;
0c76:1605 | 0c76:1607 | 0c76:160b) return 0 ;;
1209:7388) return 0 ;;
*) return 1 ;;
esac
}
# Describe the CM108 PTT on a sound card's USB device, if it has one: the
# hidraw device it's keyed through, and whether you can open it
cm108_ptt() {
local h
cm108_compatible "$1" || return 1
for h in $(printf '%s\n' "${!HIDRAW_USB[@]}" | sort -V); do
[ "${HIDRAW_USB[$h]}" = "$1" ] || continue
if [ -r "$DEVDIR/$h" ] && [ -w "$DEVDIR/$h" ]; then
echo "/dev/$h"
else
echo "/dev/$h, which you can't open yet: \`update\` installs HamPack's udev rule for it, which lets whoever is at the desktop use it"
fi
return 0
done
echo "its GPIO pin, though its hidraw device is missing"
}
# Whether a sound card can both play and record, as an interface to a radio
# must: not a webcam's microphone, say
plays_and_records() {
local n="${1#card}" p c
for p in "$SYSFS"/class/sound/pcmC"${n}"D*p; do
[ -e "$p" ] || continue
for c in "$SYSFS"/class/sound/pcmC"${n}"D*c; do
[ -e "$c" ] && return 0
done
done
return 1
}
# Print the USB sound cards that no serial port goes with, as interfaces to
# a radio with no CAT control: "CARD USB_DEVICE", one to a line
sound_only_cards() {
local card radio paired=" "
for radio in "${RADIOS[@]}"; do
paired+="$(card_of "$radio") "
done
for card in $(printf '%s\n' "${!CARD_USB[@]}" | sort -V); do
[[ "$paired" == *" $card "* ]] && continue
plays_and_records "$card" && echo "$card ${CARD_USB[$card]}"
done
return 0
}
@@ -383,7 +442,10 @@ detect() {
*) usage >&2; return 2 ;;
esac
if ! find_radios; then
local sound_only
find_radios
sound_only="$(sound_only_cards)"
if [ ${#RADIOS[@]} -eq 0 ] && [ -z "$sound_only" ]; then
echo "No USB serial ports found: is the radio plugged in and switched on?"
return 1
fi
@@ -411,6 +473,7 @@ detect() {
card="$(card_of "$radio")"
if [ -n "$card" ]; then
echo " Sound card: $(card_name "$radio") ($card)"
name="$(cm108_ptt "${CARD_USB[$card]}")" && echo " CM108 PTT: $name"
else
echo " Sound card: none found with it"
fi
@@ -428,6 +491,16 @@ detect() {
fi
fi
done
[ -n "$sound_only" ] || return 0
(( n == 0 )) || echo
echo "USB sound cards with no serial port, for a radio keyed by VOX or a PTT line:"
local id ptt
while read -r card dev; do
id="$(attr "$SYSFS/class/sound/$card" id)"
ptt="$(cm108_ptt "$dev")" && ptt="PTT through CM108 on $ptt" || ptt="PTT by VOX, or a line of its own"
echo " hw:CARD=$id ($card): $(attr "$dev" manufacturer) $(attr "$dev" product), $(attr "$dev" idVendor):$(attr "$dev" idProduct). $ptt"
done <<< "$sound_only"
}
# radio probe PORT: ask one port
+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
}