Know twin interfaces by their USB socket, and say so
check / lint-and-test (push) Failing after 4m13s
check / packages (push) Successful in 25s

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:
David Young
2026-11-29 13:41:06 -07:00
co-authored by Claude Opus 5.5
parent d910982ea7
commit 7697a785d3
5 changed files with 100 additions and 9 deletions
+42 -4
View File
@@ -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