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:
co-authored by
Claude Opus 5.5
parent
5f15ff3821
commit
0c2f9b5316
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user