Set up radios with no CAT in radio configure, keyed by CM108, RTS, DTR or VOX

rigctld runs Hamlib's Dummy radio (model 1) with a PTT device, so the
programs reach the radio through rigctld as before and rigctld keys it.
Sound cards with no serial port are numbered in `radio`'s list and can be
chosen with `radio configure N`; serial interfaces take --no-cat --ptt HOW.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 16:20:12 -07:00
co-authored by Claude Opus 5.5
parent 81c6e0b73f
commit 1cccdcd1cc
5 changed files with 302 additions and 59 deletions
+163 -49
View File
@@ -6,7 +6,7 @@
#
# Usage : radio [detect] [--probe]
# radio probe PORT
# radio configure [--force] [--model N] [--flrig] [NUMBER]
# radio configure [--force] [--model N] [--flrig] [--no-cat --ptt HOW] [NUMBER]
# radio help
SELF="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
@@ -71,6 +71,14 @@ Usage: radio [detect] [--probe]
--flrig Put flrig in charge of the radio, with rigctld passing the
other programs through it. flrig then has to be running
for them to reach the radio
--no-cat For a radio with no CAT on an interface with a serial port
(a handheld on a Digirig): rigctld only keys it, so give
--ptt too. Sound cards with no serial port (an AIOC, a
SignaLink) are set up like this anyway
--ptt HOW How the interface keys the radio: cm108 (its sound card's
PTT pin), rts or dtr (its serial port's lines), or vox
(the radio keys itself on the audio). A sound card is
cm108 if it can be, and vox otherwise
EOF
}
@@ -137,6 +145,28 @@ cm108_ptt() {
echo "its GPIO pin, though its hidraw device is missing"
}
# Print the stable name of the hidraw device on a CM108 sound card's USB
# device: its link in /dev/input/by-id, unless another device has the same
# id (two cards of a kind, with no serial number), then its link in
# /dev/input/by-path, or else its /dev name. hidraw_path USB_DEVICE
hidraw_path() {
local h="" other link same=0
for other in $(printf '%s\n' "${!HIDRAW_USB[@]}" | sort -V); do
[ "${HIDRAW_USB[$other]}" = "$1" ] && { h="$other"; break; }
done
[ -n "$h" ] || return 1
for other in "${!HIDRAW_USB[@]}"; do
[ "$other" != "$h" ] || continue
[ "${HIDRAW_USB[$other]}" != "$1" ] || continue
[ "$(attr "${HIDRAW_USB[$other]}" idVendor):$(attr "${HIDRAW_USB[$other]}" idProduct):$(attr "${HIDRAW_USB[$other]}" serial)" = \
"$(attr "$1" idVendor):$(attr "$1" idProduct):$(attr "$1" serial)" ] && same=1
done
for link in $( ((same)) || echo "$DEVDIR"/input/by-id/*-hidraw) "$DEVDIR"/input/by-path/*-hidraw; do
[ -L "$link" ] && [ "$(basename "$(readlink -f "$link")")" = "$h" ] && { echo "/dev/${link#"$DEVDIR"/}"; return 0; }
done
echo "/dev/$h"
}
# 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() {
@@ -539,7 +569,7 @@ detect() {
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"
echo "$((++n)). hw:CARD=$id ($card): $(attr "$dev" manufacturer) $(attr "$dev" product), $(attr "$dev" idVendor):$(attr "$dev" idProduct). $ptt"
done <<< "$sound_only"
}
@@ -1542,12 +1572,18 @@ hamlib_name() {
# radio configure: set up rigctld for a radio and point the programs at it
configure() {
local number="" model="" radio was_running=0 name port baud card flrig_name="" flrig_port=12345
local number="" model="" radio="" sound_card="" sound_dev="" was_running=0 name port="" baud="" card card_sys
local flrig_name="" flrig_port=12345 no_cat=0 ptt="" ptt_type="" ptt_device="" ptt_text="" sound_only total
FORCE=0 BACKUPS=() USE_FLRIG=0
while [ $# -gt 0 ]; do
case "$1" in
--force) FORCE=1 ;;
--flrig) USE_FLRIG=1 ;;
--no-cat) no_cat=1 ;;
--ptt)
[[ "${2:-}" =~ ^(cm108|rts|dtr|vox)$ ]] || { usage >&2; return 2; }
ptt="$2"
shift ;;
--model)
[[ "${2:-}" =~ ^[0-9]+$ ]] || { usage >&2; return 2; }
model="$2"
@@ -1560,22 +1596,54 @@ configure() {
shift
done
if ! find_radios; then
echo "No USB serial ports found: is the radio plugged in and switched on?"
# Radios with a serial port, then sound cards with none, numbered as `radio` lists them
find_radios
sound_only="$(sound_only_cards)"
local sound_cards=()
[ -z "$sound_only" ] || mapfile -t sound_cards <<< "$sound_only"
total=$(( ${#RADIOS[@]} + ${#sound_cards[@]} ))
if (( total == 0 )); then
echo "No USB serial ports or sound cards found: is the radio plugged in and switched on?"
return 1
fi
if [ -z "$number" ]; then
if [ ${#RADIOS[@]} -gt 1 ]; then
echo "There are ${#RADIOS[@]} radios or interfaces plugged in. Give the number \`radio\` lists for the one to set up, as in \`radio configure 2\`"
if (( total > 1 )); then
echo "There are $total radios or interfaces plugged in. Give the number \`radio\` lists for the one to set up, as in \`radio configure 2\`"
return 2
fi
number=1
fi
if (( number > ${#RADIOS[@]} )); then
echo "There's no radio $number: \`radio\` lists ${#RADIOS[@]}"
if (( number > total )); then
echo "There's no radio $number: \`radio\` lists $total"
return 2
fi
if (( number <= ${#RADIOS[@]} )); then
radio="${RADIOS[number - 1]}"
else
read -r sound_card sound_dev <<< "${sound_cards[number - ${#RADIOS[@]} - 1]}"
no_cat=1
fi
if (( no_cat && USE_FLRIG )); then
echo "flrig needs a radio with CAT to control, so --flrig can't set up a radio with none."
return 2
fi
if (( no_cat )) && [ -n "$model" ]; then
echo "With no CAT, rigctld doesn't talk to the radio, so --model doesn't apply."
return 2
fi
if [ -n "$ptt" ] && (( ! no_cat )); then
echo "--ptt is for a radio with no CAT: with CAT, the radio is keyed through it. Add --no-cat if this radio has none."
return 2
fi
if [ -n "$sound_card" ] && [[ "$ptt" =~ ^(rts|dtr)$ ]]; then
echo "This sound card has no serial port for --ptt $ptt: use cm108 or vox."
return 2
fi
if [ -n "$radio" ] && (( no_cat )) && [ -z "$ptt" ]; then
echo "Give the way the interface keys the radio: --ptt rts or --ptt dtr (its serial port's lines; a Digirig Mobile uses rts), --ptt cm108 (its sound card's PTT pin) or --ptt vox."
return 2
fi
radio="${RADIOS[number - 1]}"
if (( USE_FLRIG )); then
if ! command -v flrig > /dev/null; then
echo "flrig isn't installed."
@@ -1592,60 +1660,106 @@ configure() {
systemctl --user stop hampack-rigctld
was_running=1
fi
identify "$radio" always
if [ -z "$ID_CAT_PORT" ]; then
echo "Couldn't set it up: nothing answered on ${ID_PORTS[*]}."
[ ${#ID_NOTES[@]} -eq 0 ] || printf ' %s\n' "${ID_NOTES[@]}"
(( ! ID_ASKED )) || echo "Check it's switched on and its CAT rate is one of ${BAUDS[*]} baud."
(( ! was_running )) || systemctl --user start hampack-rigctld
return 1
fi
if [ -n "$model" ]; then
name="$(hamlib_name "$model")"
name="${name:-radio}"
elif [ -n "$ID_MODELS" ] && [ "$(wc -l <<< "$ID_MODELS")" -eq 1 ]; then
name="${ID_MODELS%|*}"
model="${ID_MODELS#*|}"
else
if [ -n "$ID_MODELS" ]; then
echo "Couldn't tell which radio it is: it's $(models_text "$ID_MODELS")."
if (( no_cat )); then
# rigctld's Dummy radio (Hamlib model 1) only keys the radio, its own way
model=1
if [ -n "$radio" ]; then
read -ra ID_PORTS <<< "${RADIO_PORTS[$radio]}"
port="$(port_path "${ID_PORTS[0]}")"
card_sys="$(card_of "$radio")"
name="radio on the $(attr "${PORT_USB[${ID_PORTS[0]}]}" product)"
else
echo "Couldn't tell which radio it is: it's ${ID_ANSWER}."
card_sys="$sound_card"
name="radio on the $(attr "$sound_dev" manufacturer) $(attr "$sound_dev" product)"
name="${name// / }"
if [ -z "$ptt" ]; then
cm108_compatible "$sound_dev" && ptt=cm108 || ptt=vox
fi
fi
echo "Give its Hamlib model number (\`rigctl -l\` lists them), as in \`radio configure --model 2045\`"
(( ! was_running )) || systemctl --user start hampack-rigctld
return 1
fi
if (( USE_FLRIG )); then
flrig_name="$(conf_field "$name" flrig)"
if [ -z "$flrig_name" ]; then
echo "radio doesn't know flrig's name for the $name, if flrig has a driver for it. Choose the radio in flrig yourself, or run \`radio configure\` without --flrig."
case "$ptt" in
cm108)
local cm108_dev="${CARD_USB[$card_sys]:-}"
if [ -z "$cm108_dev" ] || ! cm108_compatible "$cm108_dev" || ! ptt_device="$(hidraw_path "$cm108_dev")"; then
echo "The radio's sound card has no CM108 PTT pin radio can find: give another --ptt."
(( ! was_running )) || systemctl --user start hampack-rigctld
return 1
fi
ptt_type=CM108
ptt_text="PTT through its sound card's CM108 pin, $ptt_device" ;;
rts | dtr)
ptt_device="$port"
ptt_type="${ptt^^}"
ptt_text="PTT by ${ptt^^} on $port" ;;
vox)
ptt_text="PTT by VOX: the radio keys itself on the audio" ;;
esac
else
identify "$radio" always
if [ -z "$ID_CAT_PORT" ]; then
echo "Couldn't set it up: nothing answered on ${ID_PORTS[*]}."
[ ${#ID_NOTES[@]} -eq 0 ] || printf ' %s\n' "${ID_NOTES[@]}"
(( ! ID_ASKED )) || echo "Check it's switched on and its CAT rate is one of ${BAUDS[*]} baud. If the radio has no CAT, \`radio configure --no-cat --ptt HOW\` sets it up to be keyed."
(( ! was_running )) || systemctl --user start hampack-rigctld
return 1
fi
flrig_port="$(fltk_get "$FLRIG_DIR/$flrig_name.prefs" xmlport)"
flrig_port="${flrig_port:-12345}"
if [ -n "$model" ]; then
name="$(hamlib_name "$model")"
name="${name:-radio}"
elif [ -n "$ID_MODELS" ] && [ "$(wc -l <<< "$ID_MODELS")" -eq 1 ]; then
name="${ID_MODELS%|*}"
model="${ID_MODELS#*|}"
else
if [ -n "$ID_MODELS" ]; then
echo "Couldn't tell which radio it is: it's $(models_text "$ID_MODELS")."
else
echo "Couldn't tell which radio it is: it's ${ID_ANSWER}."
fi
echo "Give its Hamlib model number (\`rigctl -l\` lists them), as in \`radio configure --model 2045\`"
(( ! was_running )) || systemctl --user start hampack-rigctld
return 1
fi
if (( USE_FLRIG )); then
flrig_name="$(conf_field "$name" flrig)"
if [ -z "$flrig_name" ]; then
echo "radio doesn't know flrig's name for the $name, if flrig has a driver for it. Choose the radio in flrig yourself, or run \`radio configure\` without --flrig."
(( ! was_running )) || systemctl --user start hampack-rigctld
return 1
fi
flrig_port="$(fltk_get "$FLRIG_DIR/$flrig_name.prefs" xmlport)"
flrig_port="${flrig_port:-12345}"
fi
port="$(port_path "$ID_CAT_PORT")"
baud="$ID_BAUD"
card_sys="$(card_of "$radio")"
fi
port="$(port_path "$ID_CAT_PORT")"
baud="$ID_BAUD"
card="$(card_name "$radio")"
local card_number="" pipewire=0
card_number="$(card_of "$radio")"
card_number="${card_number#card}"
card=""
[ -z "$card_sys" ] || card="hw:CARD=$(attr "$SYSFS/class/sound/$card_sys" id)"
local card_number="${card_sys#card}" pipewire=0
find_pipewire_nodes "$card_number" && pipewire=1
PORTAUDIO_DEVICES="$(portaudio_devices)" || PORTAUDIO_DEVICES=""
echo "Setting up the $name (Hamlib model $model), on $port at $baud baud$( (( USE_FLRIG )) && echo ", through flrig")"
if (( no_cat )); then
echo "Setting up the $name, with no CAT: $ptt_text"
else
echo "Setting up the $name (Hamlib model $model), on $port at $baud baud$( (( USE_FLRIG )) && echo ", through flrig")"
fi
echo
local rigctld=""
if (( USE_FLRIG )); then
rigctld="$(write_rigctld "flrig, which controls the $name" "" -m 4 -r "127.0.0.1:$flrig_port")"
elif (( no_cat )); then
rigctld="$(write_rigctld "the $name, which only keys it" "$port" -m 1 ${ptt_type:+-p "$ptt_device" -P "$ptt_type"})"
else
rigctld="$(write_rigctld "the $name" "$port" -m "$model" -r "$port" -s "$baud")"
fi
if [ "$rigctld" = started ] && (( USE_FLRIG )); then
report rigctld "runs as the hampack-rigctld user service, on $RIGCTLD_ADDR, and passes everything to flrig"
elif [ "$rigctld" = started ] && (( no_cat )) && [ -z "$port" ]; then
report rigctld "runs as the hampack-rigctld user service, on $RIGCTLD_ADDR, and keys the radio when the programs transmit"
elif [ "$rigctld" = started ] && (( no_cat )); then
report rigctld "runs as the hampack-rigctld user service, on $RIGCTLD_ADDR, whenever the interface is plugged in, and keys the radio when the programs transmit"
elif [ "$rigctld" = started ]; then
report rigctld "runs as the hampack-rigctld user service, on $RIGCTLD_ADDR, whenever the radio is plugged in and on"
elif [ "$rigctld" = waiting ]; then
@@ -1653,7 +1767,7 @@ configure() {
else
report rigctld "couldn't start: see \`systemctl --user status hampack-rigctld\`"
fi
[[ "$port" == /dev/serial/by-id/* ]] ||
[ -z "$port" ] || [[ "$port" == /dev/serial/by-id/* ]] ||
report "" "$port has no stable name, so it may be a different port after a reboot. Run \`radio configure\` again if so"
if flatpak info "$WSJTX_FLATPAK" > /dev/null 2>&1; then
@@ -1676,8 +1790,8 @@ configure() {
configure_graywolf "$card" "$name"
mkdir -p "$HAMPACK_STATE" &&
printf 'name=%s\nhamlib=%s\nport=%s\nbaud=%s\ncard=%s\ncontroller=%s\n' "$name" "$model" "$port" "$baud" "$card" \
"$( (( USE_FLRIG )) && echo flrig || echo rigctld)" > "$HAMPACK_STATE/radio"
printf 'name=%s\nhamlib=%s\nport=%s\nbaud=%s\ncard=%s\ncontroller=%s\nptt=%s\n' "$name" "$model" "$port" "$baud" "$card" \
"$( (( USE_FLRIG )) && echo flrig || echo rigctld)" "${ptt:-cat}" > "$HAMPACK_STATE/radio"
echo
if [ -z "$card" ]; then
@@ -1685,7 +1799,7 @@ configure() {
elif (( pipewire )); then
echo "The radio's sound card is \"$PW_OUT_DESC\" ($card)."
else
echo "PipeWire didn't list the radio's sound card, $card (\"$(attr "${CARD_USB[$(card_of "$radio")]}" product)\"), so choose it yourself in WSJT-X, JS8Call and POTACAT."
echo "PipeWire didn't list the radio's sound card, $card (\"$(attr "${CARD_USB[$card_sys]}" product)\"), so choose it yourself in WSJT-X, JS8Call and POTACAT."
fi
[ ${#BACKUPS[@]} -eq 0 ] || { echo "The settings were backed up first, to:"; printf ' %s\n' "${BACKUPS[@]}"; }
}