Know twin interfaces by their USB socket, and say so
Two interfaces with the same vendor, product and serial number (none, often) share a /dev/serial/by-id name, which udev points at whichever came last, so their serial ports are named by /dev/serial/by-path instead. radio and radio configure say when an interface has a twin, and that its sound card goes by the order the two came up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d910982ea7
commit
7697a785d3
@@ -14,8 +14,10 @@ unconfigure` to undo it.
|
||||
|
||||
- [ ] Run `TEST.md` against real radios, and mark the `radios.conf` values
|
||||
they confirm `# verified`. Fix or remove the ones they don't
|
||||
- [ ] Two interfaces of the same kind with no serial number (two AIOCs, two
|
||||
CM108 cables): `radio` names their PTT devices by USB socket
|
||||
(`/dev/input/by-path`), and their sound cards by ALSA card id, so they
|
||||
stay right only while each stays in its socket. Find a name that
|
||||
follows the interface, or say so when you set one up
|
||||
- [ ] Two interfaces of the same kind with no serial number: `radio` knows
|
||||
their serial ports and PTT by USB socket, and says so, but their sound
|
||||
cards by the order they came up (ALSA's card id, PipeWire's node name),
|
||||
which may change between boots. A udev rule could give the ALSA card an
|
||||
id by socket, for Dire Wolf and Graywolf; PipeWire's names would still
|
||||
go by order. Decide whether that's worth a rule per radio, installed
|
||||
with sudo
|
||||
|
||||
@@ -73,6 +73,8 @@ It also gives WSJT-X, JS8Call, fldigi, Dire Wolf, not1mm's voice keyer and POTAC
|
||||
|
||||
A radio with no CAT can be set up too, on an interface that keys it: rigctld then runs Hamlib's Dummy radio, which only keys the radio, and the programs reach it as before. A sound card with no serial port (an AIOC, a CM108 cable, a SignaLink) is numbered after the radios in `radio`'s list: `radio configure 2` keys the radio through its CM108 PTT pin if it has one, or leaves it to the radio's VOX. For an interface with a serial port, such as a Digirig on a handheld, say how it keys the radio: `radio configure --no-cat --ptt rts` (or `dtr`, `cm108` or `vox`).
|
||||
|
||||
Two interfaces of the same kind with no serial number of their own (two CH340 cables, two CM108 cables) can only be told apart by the USB socket each is plugged into. `radio` then knows their serial ports (by `/dev/serial/by-path`) and PTT by socket, and says so. Their sound cards go by the order the two came up, which may change between boots: keep each in its socket, and if the radios get each other's audio, run `radio configure` again.
|
||||
|
||||
A radio `radio` recognises by its USB serial number (most Icoms) is set up by itself when you plug it in, as if you'd run `radio configure`, unless the radio set up already is plugged in. A notification says what it did, and `journalctl --user -u hampack-radio-plugged` has the details. Programs that are running are skipped, as is Graywolf if it's running, since stopping it needs sudo; run `radio configure` for those afterwards. Radios it would have to ask what they are, and interfaces with no CAT, are left for you to set up, since asking raises the port's DTR and RTS lines, which may key the transmitter while nobody's there. A udev rule, `/etc/udev/rules.d/70-hampack-radio.rules`, starts the `hampack-radio-plugged` user service when a USB serial port appears. To turn it off, run `systemctl --user mask hampack-radio-plugged`.
|
||||
|
||||
flrig can't reach a radio through rigctld, and the two can't share its port, so `radio configure` leaves flrig alone. If you'd rather flrig controlled the radio, run `radio configure --flrig`: flrig gets the radio, and rigctld passes the other programs through it, using Hamlib's FLRig support. flrig then starts when you log in (unless you have it starting already), so it's there before the other programs; leave it running. `radio configure` without --flrig gives the radio back to rigctld, and stops flrig starting at login. `radio configure` also says which sound card is the radio's.
|
||||
|
||||
@@ -178,6 +178,13 @@ With a Digirig, an AIOC or another CM108-family interface plugged in, after
|
||||
your Digirig keys with): "Test PTT" keys the radio. Unplug the Digirig:
|
||||
rigctld stops; plug it in: rigctld starts.
|
||||
|
||||
With two interfaces of the same kind plugged in (two CM108 cables, or two
|
||||
CH340 cables): `radio` says each has a twin, and `radio configure` names the
|
||||
serial port by `/dev/serial/by-path`. Note whether `/dev/serial/by-id` had one
|
||||
link for the two. Reboot a few times with both plugged in, and note whether
|
||||
their ALSA card ids (`cat /proc/asound/cards`) and PipeWire names ever swap.
|
||||
Check whether two AIOCs have serial numbers, which would make them no twins.
|
||||
|
||||
| Date | Commit | Interface | ACL | Keys the radio | Notes |
|
||||
|------|--------|-----------|-----|----------------|-------|
|
||||
| 2026-11-28 | 1cccdcd | C-Media USB Audio Device, 0d8c:0012, no radio attached | Yes, but from another rule (60-xara-ptt.rules); HamPack's rule not yet installed here | Not tried | Steps 1, 3 and 5 pass: `radio` lists it as "PTT through CM108 on /dev/hidraw3" and leaves out a Logitech BRIO webcam; Dire Wolf's `cm108` marks it `**`. Hamlib 4.7.2 `rigctl -m 1 -p /dev/input/by-id/...-if03-hidraw -P CM108 T 0` opens the by-id link, detects it as CM108-compatible and sets GPIO3, with no error. Getting PTT state (`t`) gives "Feature not implemented", which is Hamlib's CM108 support, and doesn't matter to the programs |
|
||||
|
||||
@@ -262,14 +262,45 @@ card_of() {
|
||||
}
|
||||
|
||||
# Print the port's stable name in /dev/serial/by-id, or its /dev name if it has none
|
||||
# Print the stable name of a serial port: its link in /dev/serial/by-id,
|
||||
# unless a twin of its USB device is plugged in, when udev gives both the
|
||||
# same by-id name and the link is to whichever came last; then its link in
|
||||
# /dev/serial/by-path, which follows the USB socket. Or else its /dev name
|
||||
port_path() {
|
||||
local link
|
||||
for link in "$DEVDIR"/serial/by-id/*; do
|
||||
[ -L "$link" ] && [ "$(basename "$(readlink -f "$link")")" = "$1" ] && { echo "/dev/serial/by-id/${link##*/}"; return; }
|
||||
local link dir=by-id
|
||||
! has_twin "${PORT_USB[$1]:-}" || dir=by-path
|
||||
for link in "$DEVDIR"/serial/"$dir"/*; do
|
||||
[ -L "$link" ] && [ "$(basename "$(readlink -f "$link")")" = "$1" ] && { echo "/dev/serial/$dir/${link##*/}"; return; }
|
||||
done
|
||||
echo "/dev/$1"
|
||||
}
|
||||
|
||||
# Whether a USB device has a twin plugged in: another serial port, sound card
|
||||
# or hidraw device's USB device with its vendor, product and serial number
|
||||
# (none, often), which nothing then tells apart but the USB socket
|
||||
has_twin() {
|
||||
[ -n "$1" ] || return 1
|
||||
local other me
|
||||
me="$(attr "$1" idVendor):$(attr "$1" idProduct):$(attr "$1" serial)"
|
||||
for other in "${PORT_USB[@]}" "${CARD_USB[@]}" "${HIDRAW_USB[@]}"; do
|
||||
[ "$other" != "$1" ] || continue
|
||||
[ "$(attr "$other" idVendor):$(attr "$other" idProduct):$(attr "$other" serial)" = "$me" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Say how radio knows an interface that has a twin plugged in, if it has:
|
||||
# twin_note PORT_USB_DEVICE CARD_USB_DEVICE, either of them empty
|
||||
twin_note() {
|
||||
local dev
|
||||
for dev in "$1" "$2"; do
|
||||
has_twin "$dev" || continue
|
||||
echo "There's another $(attr "$dev" manufacturer) $(attr "$dev" product) plugged in, which nothing tells apart from this one but the USB socket each is in. Its serial port and PTT are known by socket, and its sound card by the order the two came up. Keep each in its socket, and if the radios get each other's audio, run \`radio configure\` again"
|
||||
return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Print the radios in radios.conf whose field matches, as NAME|HAMLIB, one to
|
||||
# a line: matching FIELD VALUE. usb_serial= is a pattern; the others must be
|
||||
# equal (ignoring case)
|
||||
@@ -577,6 +608,7 @@ detect() {
|
||||
echo " USB: $(attr "$dev" idVendor):$(attr "$dev" idProduct) $(attr "$dev" manufacturer) $(attr "$dev" product)${serial:+, serial $serial}"
|
||||
done
|
||||
[ ${#ID_NOTES[@]} -eq 0 ] || printf ' %s\n' "${ID_NOTES[@]}"
|
||||
twin_note "${PORT_USB[${ID_PORTS[0]}]:-}" "${card:+${CARD_USB[$card]}}" | sed 's/^/ /;s/, and if the radios.*//'
|
||||
|
||||
if [ -z "$ID_MODELS$ID_ANSWER" ]; then
|
||||
if [ "$when" = never ]; then
|
||||
@@ -596,6 +628,7 @@ detect() {
|
||||
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 "$((++n)). hw:CARD=$id ($card): $(attr "$dev" manufacturer) $(attr "$dev" product), $(attr "$dev" idVendor):$(attr "$dev" idProduct). $ptt"
|
||||
twin_note "" "$dev" | sed 's/^/ /;s/, and if the radios.*//'
|
||||
done <<< "$sound_only"
|
||||
}
|
||||
|
||||
@@ -1848,8 +1881,13 @@ configure() {
|
||||
else
|
||||
report rigctld "couldn't start: see \`systemctl --user status hampack-rigctld\`"
|
||||
fi
|
||||
[ -z "$port" ] || [[ "$port" == /dev/serial/by-id/* ]] ||
|
||||
[ -z "$port" ] || [[ "$port" == /dev/serial/by-* ]] ||
|
||||
report "" "$port has no stable name, so it may be a different port after a reboot. Run \`radio configure\` again if so"
|
||||
local tty="" twin
|
||||
[ -z "$port" ] || tty="$(basename "$(readlink -f "$DEVDIR/${port#/dev/}")")"
|
||||
if twin="$(twin_note "${tty:+${PORT_USB[$tty]:-}}" "${card_sys:+${CARD_USB[$card_sys]:-}}")"; then
|
||||
report "" "$twin"
|
||||
fi
|
||||
|
||||
if flatpak info "$WSJTX_FLATPAK" > /dev/null 2>&1; then
|
||||
configure_qt_app WSJT-X "$WSJTX_CONF" wsjtx wsjtx
|
||||
|
||||
@@ -1461,6 +1461,48 @@ digirig() {
|
||||
grep -q -- "-p /dev/input/by-path/pci-0000:00:14.0-usb-0:1-3:1.3-hidraw -P CM108" "$HOME/.config/systemd/user/hampack-rigctld.service"
|
||||
}
|
||||
|
||||
@test "says when an interface has a twin that only its USB socket tells apart" {
|
||||
configurable
|
||||
rm -r "$RADIO_SYSFS/class/tty/ttyUSB0" "$RADIO_SYSFS/class/sound/card1"
|
||||
aioc
|
||||
usb 1-4 1209:7388 "AIOC" "All-In-One-Cable"
|
||||
card 1-4 card3 AIOC_1
|
||||
pcm card3 p c
|
||||
hidraw 1-4 hidraw3 open usb-AIOC_All-In-One-Cable-if03
|
||||
run bash "$REPO/radio"
|
||||
[ "$(grep -c "There's another AIOC All-In-One-Cable plugged in, which nothing tells apart from this one but the USB socket each is in" <<< "$output")" -eq 2 ]
|
||||
[[ "$output" != *"if the radios get each other's audio"* ]]
|
||||
run bash "$REPO/radio" configure 2
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Keep each in its socket, and if the radios get each other's audio, run \`radio configure\` again"* ]]
|
||||
}
|
||||
|
||||
@test "names a serial port by its USB socket when a twin shares its by-id name" {
|
||||
configurable
|
||||
rm -r "$RADIO_SYSFS/class/tty/ttyUSB0" "$RADIO_SYSFS/class/sound/card1"
|
||||
# Two CH340 cables with no serial number: udev's by-id link is the last one's
|
||||
usb 1-4 1a86:7523 "QinHeng Electronics" "USB Serial"
|
||||
port 1-4 ttyUSB1
|
||||
usb 1-5 1a86:7523 "QinHeng Electronics" "USB Serial"
|
||||
port 1-5 ttyUSB2
|
||||
ln -s ../../ttyUSB2 "$RADIO_DEV/serial/by-id/usb-1a86_USB_Serial-if00-port0"
|
||||
mkdir -p "$RADIO_DEV/serial/by-path"
|
||||
ln -s ../../ttyUSB1 "$RADIO_DEV/serial/by-path/pci-0000:00:14.0-usb-0:4:1.0-port0"
|
||||
ln -s ../../ttyUSB2 "$RADIO_DEV/serial/by-path/pci-0000:00:14.0-usb-0:5:1.0-port0"
|
||||
run bash "$REPO/radio" configure --model 1020 1
|
||||
[ "$status" -eq 0 ]
|
||||
grep -q -- "-r /dev/serial/by-path/pci-0000:00:14.0-usb-0:4:1.0-port0 " "$HOME/.config/systemd/user/hampack-rigctld.service"
|
||||
[[ "$output" == *"There's another QinHeng Electronics USB Serial plugged in"* ]]
|
||||
[[ "$output" != *"has no stable name"* ]]
|
||||
|
||||
# On its own, it has its by-id name
|
||||
rm -r "$RADIO_SYSFS/class/tty/ttyUSB2"
|
||||
ln -sfn ../../ttyUSB1 "$RADIO_DEV/serial/by-id/usb-1a86_USB_Serial-if00-port0"
|
||||
run bash "$REPO/radio" configure --model 1020
|
||||
grep -q -- "-r /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0 " "$HOME/.config/systemd/user/hampack-rigctld.service"
|
||||
[[ "$output" != *"There's another"* ]]
|
||||
}
|
||||
|
||||
@test "configure sets up a handheld on a Digirig with --no-cat and --ptt" {
|
||||
configurable
|
||||
rm -r "$RADIO_SYSFS/class/tty/ttyUSB0" "$RADIO_SYSFS/class/sound/card1" "$RADIO_DEV/serial/by-id/"* "$FAKE_RADIOS/ttyUSB0"
|
||||
|
||||
Reference in New Issue
Block a user