Start radio configure: rigctld for the radio, with WSJT-X, JS8Call and Pat on it

`radio configure` asks the radio what it is and the baud rate it answers
at, then runs rigctld for it as the hampack-rigctld systemd user service
on 127.0.0.1:4532, using the port's /dev/serial/by-id name. WSJT-X (the
Flatpak) and JS8Call get Hamlib NET rigctl with PTT by CAT; Pat gets a
"hampack" rig, used by ARDOP and VARA where they had none. Rig settings
you've set are left alone unless --force, each file is backed up first,
and programs that are running are skipped. With several radios, give the
number `radio` now lists; --model sets the Hamlib model for a radio it
can't tell apart from others. Sound cards are left for you to choose.

hampackremove stops and removes the service. PLAN.md lists the programs
still to do; TEST.md has the checks on a real radio.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 12:22:16 -07:00
co-authored by Claude Opus 5.5
parent e71f1e59c2
commit eddd363e86
7 changed files with 627 additions and 92 deletions
+15 -9
View File
@@ -6,21 +6,27 @@ keeps the record. Checks that need real radios are in `TEST.md`.
## Radio autoconfiguration
Find the radios plugged into USB and set up HamPack's programs for them.
Done in 6c76f94: `radio detect` and `radio probe`, `radios.conf`, and adding
you to the uucp group.
Done: `radio detect` and `radio probe`, `radios.conf`, adding you to the uucp
group (6c76f94), and the start of `radio configure`.
- [ ] Run `TEST.md` against real radios, and mark the `radios.conf` values
they confirm `# verified`. Fix or remove the ones they don't
- [ ] Tell Elecraft's radios apart. The K3, KX3, KX2 and K4 all answer `ID017;`,
so `radio` lists all four. Find an Elecraft command whose reply names
the model
- [ ] `radio configure`: one rig controller, everything else pointed at it.
Write a rigctld systemd user service for the radio, using its
`/dev/serial/by-id` port, Hamlib model and the baud rate it answered at.
Then point each program at rigctld (localhost:4532) and at the radio's
sound card: WSJT-X, JS8Call, fldigi, flrig, Dire Wolf, Pat, QLog,
not1mm, POTACAT and Graywolf. Only fill in settings that are empty,
keep a `.bak` of each file changed, and test against sample config files
- [ ] `radio configure`, the rest. Started: it writes the rigctld user
service and points WSJT-X, JS8Call and Pat at it. Still to do:
- [ ] fldigi (Hamlib NET rigctl model 2 at 127.0.0.1:4532), Dire Wolf
(`PTT RIG 2 localhost:4532`), QLog, not1mm (its rigctld setting in
`not1mm.json`), POTACAT and Graywolf
- [ ] Sound cards. Each program saves its sound device under a name from
its audio backend (WSJT-X saved "pipewire" here), so find what each
saves for a USB codec on a real machine before writing it
- [ ] flrig can't use rigctld, so it can't run alongside it. Say so, or
offer flrig as the controller instead
- [ ] More than one radio at once: a rigctld for each, on its own port
- [ ] rigctld retries every 5 seconds while the radio is off or unplugged.
Start it when the radio is plugged in instead (see hotplug below)
- [ ] PTT through a CM108 sound card (Digirig, AIOC, SignaLink-style
interfaces): a udev rule so you can open its `hidraw` device, for
Dire Wolf and others
+4
View File
@@ -65,6 +65,10 @@ Controlling a radio means opening its serial port, and on Arch only members of t
Probing opens the port, which raises its DTR and RTS lines for a moment before `radio` drops them. Interfaces that key the transmitter with DTR or RTS may key it briefly, so probe with the radio on a dummy load or an antenna.
`radio configure` sets up the radio for HamPack's programs. It asks the radio what it is and at what baud rate it answers. Then it runs Hamlib's rigctld for it, as the `hampack-rigctld` systemd user service on 127.0.0.1:4532, and points WSJT-X, JS8Call and Pat at rigctld, with PTT by CAT. All three then share the radio through rigctld, without fighting over its serial port. Quit them first, since they save their settings when they quit.
`radio configure` only fills in rig settings you haven't set. `radio configure --force` replaces them, and every file it changes is backed up first. With more than one radio plugged in, give the number `radio` lists for it: `radio configure 2`. For a radio it can't tell apart from others, give its Hamlib model number: `radio configure --model 2045`. Choose the radio's sound card in each program yourself; `radio configure` says which it is.
The radios it knows are in `radios.conf`. If your radio isn't recognised, or answers with something `radio` doesn't know, please open an issue with what `radio detect --probe` printed.
## Why CoreDesktop and/or Arch Linux?
+26
View File
@@ -43,6 +43,32 @@ cable.
|------|--------|-------|-----------|---------------|--------------|--------------------|------|-----------|-------|
| | | | | | | | | | |
## radio configure
With the radio on a dummy load or an antenna, and WSJT-X, JS8Call and Pat quit:
1. Run `radio configure`. It should name the radio, its by-id port and a baud
rate, and say what it did for each program.
2. `systemctl --user status hampack-rigctld` is running, and
`rigctl -m 2 -r 127.0.0.1:4532 f` prints the radio's frequency.
3. Open WSJT-X. Settings > Radio shows "Hamlib NET rigctl", 127.0.0.1:4532
and PTT by CAT. "Test CAT" turns green, and "Test PTT" keys the radio.
Note whether WSJT-X kept the PTT setting, which `radio configure` writes in
Qt's own format; if it shows VOX, that format is wrong.
4. The same in JS8Call.
5. In Pat, `pat connect ardop:///...` (or the web UI) changes the radio's
frequency through rigctld.
6. Run `radio configure` again: each program is "already set up", and
rigctld restarts.
7. With a rig set by hand in WSJT-X, `radio configure` leaves it alone, and
`--force` replaces it. The `.bak-` copy has the old settings.
8. Unplug the radio, plug it in again, and check rigctld reconnects within
a few seconds. Reboot and check it starts at login.
| Date | Commit | Radio | rigctld | WSJT-X | JS8Call | Pat | Notes |
|------|--------|-------|---------|--------|---------|-----|-------|
| | | | | | | | |
## Pairing radios with sound cards
- Two radios plugged in at once: each gets its own sound card.
+10
View File
@@ -256,6 +256,16 @@ update-mime-database "$HOME/.local/share/mime" &> /dev/null
report_unrecorded
# The rigctld service `radio configure` set up. The programs it pointed at
# rigctld keep those settings, and the backups it made of them
RIGCTLD_UNIT="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/hampack-rigctld.service"
if [ -f "$RIGCTLD_UNIT" ]; then
echo "Removing the rigctld service radio configure set up..."
systemctl --user disable --now hampack-rigctld 2> /dev/null
rm -f "$RIGCTLD_UNIT"
systemctl --user daemon-reload 2> /dev/null
fi
# Take you out of the groups update.sh added you to
for group in $(recorded_installs added-groups); do
echo "Removing you from the $group group..."
+377 -66
View File
@@ -1,10 +1,12 @@
#!/bin/bash
#
# Purpose : Find the radios plugged into this computer's USB: each one's CAT
# serial port, its sound card, and what model it is
# serial port, its sound card, and what model it is. Then set up
# rigctld for one, and point HamPack's programs at it
#
# Usage : radio [detect] [--probe]
# radio probe PORT
# radio configure [--force] [--model N] [NUMBER]
# radio help
SELF="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
@@ -20,6 +22,17 @@ LOCKDIR="${RADIO_LOCKDIR:-/run/lock}"
# CAT baud rates to try, most likely first
BAUDS=(38400 115200 19200 9600 4800)
CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
RIGCTLD_UNIT="$CONFIG_HOME/systemd/user/hampack-rigctld.service"
RIGCTLD_ADDR=127.0.0.1:4532
WSJTX_FLATPAK=io.sourceforge.wsjt.wsjtx
WSJTX_CONF="$HOME/.var/app/$WSJTX_FLATPAK/config/WSJT-X.ini"
JS8CALL_CONF="$CONFIG_HOME/JS8Call.ini"
PAT_CONF="$CONFIG_HOME/pat/config.json"
# WSJT-X and JS8Call save PTT_method_CAT like this: a Qt variant holding the
# enum's name. The bytes before each name are its length, with the NUL
PTT_CAT='@Variant(\0\0\0\x7f\0\0\0\x1eTransceiverFactory::PTTMethod\0\0\0\0\xfPTT_method_CAT\0)'
usage() {
cat << EOF
Usage: radio [detect] [--probe]
@@ -31,6 +44,14 @@ Usage: radio [detect] [--probe]
detect --probe Also ask radios it doesn't recognise what they are, over each
serial port that no other program is using
probe PORT Ask the radio on serial port PORT what it is
configure Set up the radio (if there's more than one, give its number
from \`radio\`): run rigctld for it as a systemd user service,
and point WSJT-X, JS8Call and Pat at rigctld. Only changes
settings you haven't set, and backs up each file it changes.
Quit those programs first
--force Replace rig settings you've set yourself
--model N Use Hamlib model N (\`rigctl -l\`), for a radio that radio
can't tell apart from others, or doesn't know
EOF
}
@@ -117,8 +138,9 @@ port_path() {
echo "/dev/$1"
}
# Print the radios in radios.conf whose field matches: matching FIELD VALUE.
# usb_serial= is a pattern; the others must be equal (ignoring case)
# 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)
matching() {
MATCH_FIELD="$1" MATCH_VALUE="$2" MATCHES=()
parse_conf "$RADIOS_CONF" match_radio
@@ -133,7 +155,7 @@ match_radio() {
else
[ "${want,,}" = "${MATCH_VALUE,,}" ] || return 0
fi
MATCHES+=("${CONF[_name]} (Hamlib model ${CONF[hamlib]})")
MATCHES+=("${CONF[_name]}|${CONF[hamlib]}")
}
# Print why a port can't be probed, or nothing if it can
@@ -233,12 +255,27 @@ probe_port() {
[ -n "$ANSWER_VALUE" ]
}
# Join the radios matching prints into one line
one_of() {
if [ "$(wc -l <<< "$1")" -eq 1 ]; then
echo "$1"
# Describe the radios matching prints, in one line
models_text() {
local line names=()
while IFS= read -r line; do
names+=("${line%|*} (Hamlib model ${line##*|})")
done <<< "$1"
if [ ${#names[@]} -eq 1 ]; then
echo "${names[0]}"
else
echo "one of: $(paste -sd '|' <<< "$1" | sed 's/|/, /g')"
local IFS='|'
line="${names[*]}"
echo "one of: ${line//|/, }"
fi
}
# Describe a radio that answered, but that radios.conf doesn't know
unknown_answer_text() {
if [ "$ANSWER_FIELD" = civ ]; then
echo "an Icom radio at CI-V address $ANSWER_VALUE that radio doesn't know"
else
echo "a radio that answered ID$ANSWER_VALUE; that radio doesn't know"
fi
}
@@ -246,76 +283,106 @@ one_of() {
describe_answer() {
local models
models="$(matching "$ANSWER_FIELD" "$ANSWER_VALUE")"
if [ -z "$models" ]; then
if [ "$ANSWER_FIELD" = civ ]; then
echo "an Icom radio at CI-V address $ANSWER_VALUE that radio doesn't know"
else
echo "a radio that answered ID$ANSWER_VALUE; that radio doesn't know"
fi
else
one_of "$models"
fi
if [ -n "$models" ]; then models_text "$models"; else unknown_answer_text; fi
}
# radio detect: list each radio and what's known about it
detect() {
local probe=0 radio port dev card name serial reason found=0
[ "${1:-}" = --probe ] && probe=1
[ "${1:-}" = --probe ] || [ -z "${1:-}" ] || { usage >&2; return 2; }
# Find the radios: RADIOS lists them (the USB device or hub each is), and
# RADIO_PORTS[radio] its serial ports
find_radios() {
local port radio
declare -gA RADIO_PORTS=()
RADIOS=()
find_devices
if [ ${#PORT_USB[@]} -eq 0 ]; then
echo "No USB serial ports found: is the radio plugged in and switched on?"
return 1
fi
# Group the ports by radio
declare -A RADIO_PORTS=()
for port in $(printf '%s\n' "${!PORT_USB[@]}" | sort -V); do
radio="$(radio_of "${PORT_USB[$port]}")"
RADIO_PORTS["$radio"]+="$port "
done
mapfile -t RADIOS < <(printf '%s\n' "${!RADIO_PORTS[@]}" | sort | grep .)
[ ${#RADIOS[@]} -gt 0 ]
}
for radio in $(printf '%s\n' "${!RADIO_PORTS[@]}" | sort); do
(( found++ )) && echo
local ports=() usb_devs=() models="" how="" cat_port="" lines=()
read -ra ports <<< "${RADIO_PORTS[$radio]}"
# Recognise it by its USB serial number, or else by asking it
for port in "${ports[@]}"; do
# Work out what a radio is: identify RADIO WHEN, where WHEN says when to ask
# it: never, unknown (only if its USB serial number doesn't say) or always
# (to find its CAT port and baud rate). Sets:
# ID_PORTS, ID_USB its serial ports, and the USB devices they're on
# ID_MODELS the radios it could be, as matching prints them
# ID_HOW how it was recognised
# ID_CAT_PORT, ID_BAUD the port and baud rate it answered on
# ID_ANSWER what it answered, if radios.conf doesn't know it
# ID_NOTES ports it couldn't be asked on, and why
# ID_ASKED 1 if any port could be asked
identify() {
local radio="$1" when="$2" port dev serial reason
ID_PORTS=() ID_USB=() ID_MODELS="" ID_HOW="" ID_CAT_PORT="" ID_BAUD="" ID_ANSWER="" ID_NOTES=() ID_ASKED=0
read -ra ID_PORTS <<< "${RADIO_PORTS[$radio]}"
for port in "${ID_PORTS[@]}"; do
dev="${PORT_USB[$port]}"
[[ " ${usb_devs[*]} " == *" $dev "* ]] || usb_devs+=("$dev")
[[ " ${ID_USB[*]} " == *" $dev "* ]] || ID_USB+=("$dev")
done
for dev in "${usb_devs[@]}"; do
serial="$(attr "$dev" serial)"
[ -n "$serial" ] && models="$(matching usb_serial "$serial")" && break
done
[ -n "$models" ] && models="$(one_of "$models")" && how="recognised by its USB serial number"
if [ -z "$models" ] && (( probe )); then
for port in "${ports[@]}"; do
for dev in "${ID_USB[@]}"; do
serial="$(attr "$dev" serial)"
[ -n "$serial" ] && ID_MODELS="$(matching usb_serial "$serial")" && break
done
[ -z "$ID_MODELS" ] || ID_HOW="recognised by its USB serial number"
[ "$when" = always ] || { [ "$when" = unknown ] && [ -z "$ID_MODELS" ]; } || return 0
for port in "${ID_PORTS[@]}"; do
reason="$(cant_probe "$DEVDIR/$port")"
if [ -n "$reason" ]; then
lines+=(" Couldn't ask on $port: $reason")
elif probe_port "$DEVDIR/$port"; then
models="$(describe_answer)"
how="answered on $port at $ANSWER_BAUD baud"
cat_port="$port"
break
ID_NOTES+=("Couldn't ask on $port: $reason")
continue
fi
ID_ASKED=1
if probe_port "$DEVDIR/$port"; then
ID_CAT_PORT="$port" ID_BAUD="$ANSWER_BAUD"
if [ -z "$ID_MODELS" ]; then
ID_MODELS="$(matching "$ANSWER_FIELD" "$ANSWER_VALUE")"
[ -n "$ID_MODELS" ] || ID_ANSWER="$(unknown_answer_text)"
ID_HOW="answered on $port at $ANSWER_BAUD baud"
fi
return 0
elif [ -n "$PROBE_ERROR" ]; then
lines+=(" Couldn't ask on $port: $PROBE_ERROR")
ID_NOTES+=("Couldn't ask on $port: $PROBE_ERROR")
fi
done
}
# Print the radio's sound card as ALSA names it (hw:CARD=CODEC), or nothing
card_name() {
local card
card="$(card_of "$1")"
[ -z "$card" ] || echo "hw:CARD=$(attr "$SYSFS/class/sound/$card" id)"
}
# radio detect: list each radio and what's known about it
detect() {
local when=never radio port name card dev serial n=0
case "${1:-}" in
--probe) when=unknown ;;
"") ;;
*) usage >&2; return 2 ;;
esac
if ! find_radios; then
echo "No USB serial ports found: is the radio plugged in and switched on?"
return 1
fi
if [ -z "$models" ]; then
echo "Unknown radio or interface"
for radio in "${RADIOS[@]}"; do
(( n++ )) && echo
identify "$radio" "$when"
if [ -n "$ID_MODELS" ]; then
name="$(models_text "$ID_MODELS")"
echo "$n. ${name^}, $ID_HOW"
elif [ -n "$ID_ANSWER" ]; then
echo "$n. ${ID_ANSWER^}, $ID_HOW"
else
echo "${models^}, $how"
echo "$n. Unknown radio or interface"
fi
for port in "${ports[@]}"; do
if [ "$port" = "$cat_port" ]; then
for port in "${ID_PORTS[@]}"; do
if [ "$port" = "$ID_CAT_PORT" ]; then
name="CAT port: "
else
name="Serial port:"
@@ -324,22 +391,21 @@ detect() {
done
card="$(card_of "$radio")"
if [ -n "$card" ]; then
echo " Sound card: hw:CARD=$(attr "$SYSFS/class/sound/$card" id) ($card)"
echo " Sound card: $(card_name "$radio") ($card)"
else
echo " Sound card: none found with it"
fi
for dev in "${usb_devs[@]}"; do
for dev in "${ID_USB[@]}"; do
serial="$(attr "$dev" serial)"
echo " USB: $(attr "$dev" idVendor):$(attr "$dev" idProduct) $(attr "$dev" manufacturer) $(attr "$dev" product)${serial:+, serial $serial}"
done
[ ${#lines[@]} -eq 0 ] || printf '%s\n' "${lines[@]}"
[ ${#ID_NOTES[@]} -eq 0 ] || printf ' %s\n' "${ID_NOTES[@]}"
if [ -z "$models" ]; then
if (( probe )); then
[ ${#lines[@]} -eq ${#ports[@]} ] ||
echo " Nothing answered. If it's a radio, check it's switched on and its CAT rate is one of ${BAUDS[*]} baud. Interfaces like the Digirig answer only for a radio behind them"
else
if [ -z "$ID_MODELS$ID_ANSWER" ]; then
if [ "$when" = never ]; then
echo " Run \`radio detect --probe\` to ask it what it is"
elif (( ID_ASKED )); then
echo " Nothing answered. If it's a radio, check it's switched on and its CAT rate is one of ${BAUDS[*]} baud. Interfaces like the Digirig answer only for a radio behind them"
fi
fi
done
@@ -362,9 +428,254 @@ probe() {
fi
}
# Print a key's value from a section of an INI file: ini_get FILE SECTION KEY
ini_get() {
[ -f "$1" ] || return 0
S="$2" K="$3" awk '
/^\[/ { in_section = ($0 == "[" ENVIRON["S"] "]"); next }
in_section && index($0, ENVIRON["K"] "=") == 1 { print substr($0, length(ENVIRON["K"]) + 2); exit }
' "$1"
}
# Set a key in a section of an INI file, adding the section (and the file) if
# need be: ini_set FILE SECTION KEY VALUE. Values are written as they are, so
# Qt's escapes (\0, \x7f) stay as Qt wrote them
ini_set() {
local tmp
mkdir -p "$(dirname "$1")" && touch "$1" && tmp="$(mktemp "$1.XXXXXX")" || return 1
S="$2" K="$3" V="$4" awk '
function put() { print ENVIRON["K"] "=" ENVIRON["V"]; done = 1 }
/^\[/ {
if (in_section && !done) put()
in_section = ($0 == "[" ENVIRON["S"] "]")
if (in_section) found = 1
print
next
}
in_section && index($0, ENVIRON["K"] "=") == 1 { if (!done) put(); next }
{ print }
END {
if (in_section && !done) put()
if (!found) { if (NR) print ""; print "[" ENVIRON["S"] "]"; put() }
}
' "$1" > "$tmp" && chmod --reference="$1" "$tmp" && mv -f "$tmp" "$1"
}
# Copy a file before changing it, and say so
back_up() {
[ -f "$1" ] || return 0
local copy
copy="$1.bak-$(date +%Y%m%d-%H%M%S)"
cp -p "$1" "$copy" && BACKUPS+=("$copy")
}
# Say what happened to one program: report NAME MESSAGE
report() {
printf ' %-9s %s\n' "$1:" "$2"
}
running() {
pgrep -x "$1" > /dev/null 2>&1
}
# WSJT-X and JS8Call share their settings: point one at rigctld, with PTT by
# CAT. configure_qt_app NAME FILE PROCESS
configure_qt_app() {
local name="$1" file="$2" rig net
if running "$3"; then
report "$name" "skipped, because it's running and would overwrite its settings when it quits. Quit it and run \`radio configure\` again"
return
fi
rig="$(ini_get "$file" Configuration Rig)"
net="$(ini_get "$file" Configuration CATNetworkPort)"
if [ "$rig" = "Hamlib NET rigctl" ] && [ "$net" = "$RIGCTLD_ADDR" ]; then
report "$name" "already set up"
return
fi
if [ -n "$rig" ] && [ "$rig" != None ] && (( ! FORCE )); then
report "$name" "left alone: it's set up for $rig. \`radio configure --force\` replaces that"
return
fi
back_up "$file"
if ! { ini_set "$file" Configuration Rig "Hamlib NET rigctl" &&
ini_set "$file" Configuration CATNetworkPort "$RIGCTLD_ADDR" &&
ini_set "$file" Configuration PTTMethod "$PTT_CAT"; }; then
report "$name" "couldn't change $file"
return 1
fi
report "$name" "rig control through rigctld, PTT by CAT"
}
# Pat: add rigctld to its rigs as "hampack", and use it for ARDOP and VARA
# where no rig is set
configure_pat() {
local tmp addr modes='["ardop","varahf","varafm"]'
if ! command -v pat > /dev/null; then
report Pat "not installed"
return
fi
if [ ! -f "$PAT_CONF" ]; then
report Pat "skipped: it has no settings yet. Run \`pat configure\` once, then \`radio configure\` again"
return
fi
if running pat; then
report Pat "skipped, because it's running. Stop it and run \`radio configure\` again"
return
fi
addr="$(jq -r '.hamlib_rigs.hampack.address // empty' "$PAT_CONF")" ||
{ report Pat "couldn't read $PAT_CONF"; return 1; }
if [ "$addr" = "$RIGCTLD_ADDR" ] && (( ! FORCE )); then
report Pat "already set up"
return
fi
back_up "$PAT_CONF"
tmp="$(mktemp "$PAT_CONF.XXXXXX")" || return 1
if jq --arg addr "$RIGCTLD_ADDR" --argjson modes "$modes" --argjson force "$FORCE" '
.hamlib_rigs = ((.hamlib_rigs // {}) + {hampack: {address: $addr, network: "tcp"}})
| reduce $modes[] as $m (.;
if .[$m] != null and ($force == 1 or (.[$m].rig // "") == "") then .[$m].rig = "hampack" else . end)
' "$PAT_CONF" > "$tmp" && chmod --reference="$PAT_CONF" "$tmp" && mv -f "$tmp" "$PAT_CONF"; then
report Pat "rig \"hampack\" is rigctld, used by ARDOP and VARA where they had no rig"
else
rm -f "$tmp"
report Pat "couldn't change $PAT_CONF"
return 1
fi
}
# Write and (re)start rigctld's user service: write_rigctld NAME HAMLIB PORT BAUD
write_rigctld() {
local unit
unit="[Unit]
Description=Hamlib rigctld for the $1 (written by HamPack's radio configure)
[Service]
ExecStart=/usr/bin/rigctld -m $2 -r $3 -s $4 -T ${RIGCTLD_ADDR%:*} -t ${RIGCTLD_ADDR#*:}
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target"
mkdir -p "$(dirname "$RIGCTLD_UNIT")" || return 1
printf '%s\n' "$unit" > "$RIGCTLD_UNIT" || return 1
systemctl --user daemon-reload &&
systemctl --user enable hampack-rigctld 2> /dev/null &&
systemctl --user restart hampack-rigctld
}
# Print the name radios.conf gives a Hamlib model, or nothing
hamlib_name() {
awk -F= -v m="$1" '/^\[/ { name = substr($0, 2, length($0) - 2) } $1 == "hamlib" && $2 == m { print name; exit }' "$RADIOS_CONF"
}
# 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
FORCE=0 BACKUPS=()
while [ $# -gt 0 ]; do
case "$1" in
--force) FORCE=1 ;;
--model)
[[ "${2:-}" =~ ^[0-9]+$ ]] || { usage >&2; return 2; }
model="$2"
shift ;;
[1-9]*)
[[ "$1" =~ ^[0-9]+$ ]] || { usage >&2; return 2; }
number="$1" ;;
*) usage >&2; return 2 ;;
esac
shift
done
if ! find_radios; then
echo "No USB serial ports 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\`"
return 2
fi
number=1
fi
if (( number > ${#RADIOS[@]} )); then
echo "There's no radio $number: \`radio\` lists ${#RADIOS[@]}"
return 2
fi
radio="${RADIOS[number - 1]}"
# rigctld has the port open, if radio configure has run before
if systemctl --user is-active --quiet hampack-rigctld 2> /dev/null; then
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")."
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
port="$(port_path "$ID_CAT_PORT")"
baud="$ID_BAUD"
card="$(card_name "$radio")"
echo "Setting up the $name (Hamlib model $model), on $port at $baud baud"
echo
if write_rigctld "$name" "$model" "$port" "$baud"; then
report rigctld "runs as the hampack-rigctld user service, on $RIGCTLD_ADDR"
else
report rigctld "couldn't start: see \`systemctl --user status hampack-rigctld\`"
fi
[[ "$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
configure_qt_app WSJT-X "$WSJTX_CONF" wsjtx
else
report WSJT-X "not installed"
fi
if [ -x "$HOME/.local/bin/JS8Call" ]; then
configure_qt_app JS8Call "$JS8CALL_CONF" JS8Call
else
report JS8Call "not installed"
fi
configure_pat
mkdir -p "$HAMPACK_STATE" &&
printf 'name=%s\nhamlib=%s\nport=%s\nbaud=%s\ncard=%s\n' "$name" "$model" "$port" "$baud" "$card" > "$HAMPACK_STATE/radio"
echo
if [ -n "$card" ]; then
echo "Choose the radio's sound card in each program yourself: $card, \"$(attr "${CARD_USB[$(card_of "$radio")]}" product)\"."
else
echo "No sound card was found with the radio: choose the one it's connected to in each program yourself."
fi
[ ${#BACKUPS[@]} -eq 0 ] || { echo "The settings were backed up first, to:"; printf ' %s\n' "${BACKUPS[@]}"; }
}
case "${1:-detect}" in
detect) shift; detect "$@" ;;
probe) shift; probe "$@" ;;
configure) shift; configure "$@" ;;
help | -h | --help) usage ;;
--probe) detect --probe ;;
*) usage >&2; exit 2 ;;
+10
View File
@@ -110,6 +110,16 @@ remove() {
grep -qx uucp "$FAKE_GROUPS"
}
@test "stops and removes the rigctld service radio configure set up" {
local unit="$HOME/.config/systemd/user/hampack-rigctld.service"
mkdir -p "$(dirname "$unit")"
echo "[Service]" > "$unit"
remove
[ "$status" -eq 0 ]
grep -qx "systemctl --user disable --now hampack-rigctld" "$STUB_LOG"
[ ! -e "$unit" ]
}
@test "does nothing unless confirmed" {
mark_installed fldigi
mkdir -p "$HAMPACK_STATE"
+179 -11
View File
@@ -82,7 +82,7 @@ answers() {
ic7300
run bash "$REPO/radio"
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
[ "${lines[0]}" = "1. Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
[ "${lines[1]}" = " Serial port: /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0" ]
[ "${lines[2]}" = " Sound card: hw:CARD=CODEC (card1)" ]
[[ "${lines[3]}" == " USB: 10c4:ea60 Silicon Labs CP2102 USB to UART Bridge Controller, serial IC-7300 03001234" ]]
@@ -94,7 +94,7 @@ answers() {
answers ttyUSB0 "38400 cat_id 0670"
run bash "$REPO/radio" detect
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Unknown radio or interface" ]
[ "${lines[0]}" = "1. Unknown radio or interface" ]
[ "${lines[1]}" = " Serial port: /dev/ttyUSB0" ]
[ "${lines[2]}" = " Serial port: /dev/ttyUSB1" ]
[ "${lines[3]}" = " Sound card: hw:CARD=CODEC (card1)" ]
@@ -107,7 +107,7 @@ answers() {
answers ttyUSB1 "38400 cat_id 0670"
run bash "$REPO/radio" detect --probe
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Yaesu FT-991A (Hamlib model 1035), answered on ttyUSB1 at 38400 baud" ]
[ "${lines[0]}" = "1. Yaesu FT-991A (Hamlib model 1035), answered on ttyUSB1 at 38400 baud" ]
[ "${lines[1]}" = " Serial port: /dev/ttyUSB0" ]
[ "${lines[2]}" = " CAT port: /dev/ttyUSB1" ]
[ "$(grep -c '^python3' "$STUB_LOG")" -eq 2 ]
@@ -118,7 +118,7 @@ answers() {
port 1-4 ttyUSB0
answers ttyUSB0 "19200 civ 94"
run bash "$REPO/radio" --probe
[ "${lines[0]}" = "Icom IC-7300 (Hamlib model 3073), answered on ttyUSB0 at 19200 baud" ]
[ "${lines[0]}" = "1. Icom IC-7300 (Hamlib model 3073), answered on ttyUSB0 at 19200 baud" ]
[ "${lines[2]}" = " Sound card: none found with it" ]
}
@@ -127,7 +127,7 @@ answers() {
port 1-4 ttyUSB0
answers ttyUSB0 "38400 cat_id 017"
run bash "$REPO/radio" --probe
[ "${lines[0]}" = "One of: Elecraft K3 (Hamlib model 2029), Elecraft KX3 (Hamlib model 2045), Elecraft KX2 (Hamlib model 2044), Elecraft K4 (Hamlib model 2047), answered on ttyUSB0 at 38400 baud" ]
[ "${lines[0]}" = "1. One of: Elecraft K3 (Hamlib model 2029), Elecraft KX3 (Hamlib model 2045), Elecraft KX2 (Hamlib model 2044), Elecraft K4 (Hamlib model 2047), answered on ttyUSB0 at 38400 baud" ]
}
@test "says what answered when it doesn't know the radio" {
@@ -135,7 +135,7 @@ answers() {
port 1-4 ttyUSB0
answers ttyUSB0 "9600 civ 5E"
run bash "$REPO/radio" --probe
[ "${lines[0]}" = "An Icom radio at CI-V address 5E that radio doesn't know, answered on ttyUSB0 at 9600 baud" ]
[ "${lines[0]}" = "1. An Icom radio at CI-V address 5E that radio doesn't know, answered on ttyUSB0 at 9600 baud" ]
}
@test "says when nothing answers" {
@@ -143,7 +143,7 @@ answers() {
port 1-4 ttyUSB0
answers ttyUSB1 "38400 cat_id 0670"
run bash "$REPO/radio" --probe
[ "${lines[0]}" = "Unknown radio or interface" ]
[ "${lines[0]}" = "1. Unknown radio or interface" ]
[[ "$output" == *"Nothing answered. If it's a radio, check it's switched on"* ]]
}
@@ -155,7 +155,7 @@ answers() {
ln -s "$RADIO_DEV/ttyUSB0" "$RADIO_PROC/4242/fd/5"
touch "$RADIO_LOCKDIR/LCK..ttyUSB1"
run bash "$REPO/radio" --probe
[ "${lines[0]}" = "Unknown radio or interface" ]
[ "${lines[0]}" = "1. Unknown radio or interface" ]
[[ "$output" == *"Couldn't ask on ttyUSB0: $RADIO_DEV/ttyUSB0 is in use by rigctld (process 4242)"* ]]
[[ "$output" == *"Couldn't ask on ttyUSB1: $RADIO_DEV/ttyUSB1 is locked by another program"* ]]
[[ "$output" != *"Nothing answered"* ]]
@@ -169,9 +169,9 @@ answers() {
run bash "$REPO/radio"
[ "$status" -eq 0 ]
# bats leaves the blank line between radios out of lines
[ "${lines[0]}" = "Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
[ "${lines[0]}" = "1. Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
[ "${lines[2]}" = " Sound card: hw:CARD=CODEC (card1)" ]
[ "${lines[4]}" = "Unknown radio or interface" ]
[ "${lines[4]}" = "2. Unknown radio or interface" ]
[ "${lines[5]}" = " Serial port: /dev/ttyUSB1" ]
[ "${lines[6]}" = " Serial port: /dev/ttyUSB2" ]
[ "${lines[7]}" = " Sound card: hw:CARD=CODEC_1 (card2)" ]
@@ -182,7 +182,7 @@ answers() {
port 1-5 ttyACM0 "" 0
card 1-5 card1 IC705
run bash "$REPO/radio"
[ "${lines[0]}" = "Icom IC-705 (Hamlib model 3085), recognised by its USB serial number" ]
[ "${lines[0]}" = "1. Icom IC-705 (Hamlib model 3085), recognised by its USB serial number" ]
[ "${lines[2]}" = " Sound card: hw:CARD=IC705 (card1)" ]
}
@@ -308,3 +308,171 @@ teardown() {
[ "$status" -eq 1 ]
[ "$output" = "Nothing answered on $PTY at 38400 115200 19200 9600 4800 baud" ]
}
# --- radio configure ---
WSJTX_INI() { echo "$HOME/.var/app/io.sourceforge.wsjt.wsjtx/config/WSJT-X.ini"; }
PTT_CAT='PTTMethod=@Variant(\0\0\0\x7f\0\0\0\x1eTransceiverFactory::PTTMethod\0\0\0\0\xfPTT_method_CAT\0)'
# An IC-7300 that answers, with WSJT-X, JS8Call and Pat installed and none
# running. rigctld's service is running if $FAKE_RADIOS/rigctld-active exists;
# programs named in $FAKE_RUNNING are running
configurable() {
ic7300
answers ttyUSB0 "38400 civ 94"
touch "$FAKE_FLATPAKS/io.sourceforge.wsjt.wsjtx"
touch "$HOME/.local/bin/JS8Call"
chmod +x "$HOME/.local/bin/JS8Call"
stub pat 'exit 0'
stub pgrep '[[ " ${FAKE_RUNNING:-} " == *" $2 "* ]]'
stub systemctl '[ "$*" != "--user is-active --quiet hampack-rigctld" ] || [ -f "$FAKE_RADIOS/rigctld-active" ]'
mkdir -p "$HOME/.config/pat"
cat > "$HOME/.config/pat/config.json" << 'JSON'
{"mycall": "N0CALL", "hamlib_rigs": {}, "ardop": {"addr": "localhost:8515", "rig": ""},
"varahf": {"addr": "localhost:8300", "rig": "ft991"}, "varafm": {"addr": "localhost:8300", "rig": ""}}
JSON
chmod 600 "$HOME/.config/pat/config.json"
}
@test "configure runs rigctld for the radio on its stable port, at the rate it answered" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Setting up the Icom IC-7300 (Hamlib model 3073), on /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0 at 38400 baud" ]
local unit="$HOME/.config/systemd/user/hampack-rigctld.service"
grep -qx "ExecStart=/usr/bin/rigctld -m 3073 -r /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0 -s 38400 -T 127.0.0.1 -t 4532" "$unit"
grep -qx "systemctl --user enable hampack-rigctld" "$STUB_LOG"
grep -qx "systemctl --user restart hampack-rigctld" "$STUB_LOG"
[[ "$output" == *"Choose the radio's sound card in each program yourself: hw:CARD=CODEC, \"USB Audio CODEC\""* ]]
grep -qx "hamlib=3073" "$HAMPACK_STATE/radio"
grep -qx "card=hw:CARD=CODEC" "$HAMPACK_STATE/radio"
}
@test "configure stops its own rigctld to ask the radio, and starts it again if that fails" {
configurable
touch "$FAKE_RADIOS/rigctld-active"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
# Stopped before python3 asked the radio
local stopped asked
stopped="$(grep -n '^systemctl --user stop hampack-rigctld' "$STUB_LOG" | cut -d: -f1)"
asked="$(grep -n '^python3' "$STUB_LOG" | head -1 | cut -d: -f1)"
[ -n "$stopped" ] && [ "$stopped" -lt "$asked" ]
: > "$STUB_LOG"
rm "$FAKE_RADIOS/ttyUSB0"
run bash "$REPO/radio" configure
[ "$status" -eq 1 ]
[[ "$output" == *"Couldn't set it up: nothing answered on ttyUSB0."* ]]
grep -qx "systemctl --user start hampack-rigctld" "$STUB_LOG"
}
@test "configure sets up a new WSJT-X, and one with no rig, keeping its other settings" {
configurable
run bash "$REPO/radio" configure
[[ "$output" == *"WSJT-X: rig control through rigctld, PTT by CAT"* ]]
grep -qx "Rig=Hamlib NET rigctl" "$(WSJTX_INI)"
grep -qx "CATNetworkPort=127.0.0.1:4532" "$(WSJTX_INI)"
grep -qxF "$PTT_CAT" "$(WSJTX_INI)"
printf '[Configuration]\nMyCall=N0CALL\nRig=None\nPTTMethod=@Variant(\\0\\0\\0\\x7f\\0\\0\\0\\x1eTransceiverFactory::PTTMethod\\0\\0\\0\\0\\xfPTT_method_VOX\\0)\n\n[MultiSettings]\nOther\\Configuration\\Rig=Yaesu FT-991\n' > "$(WSJTX_INI)"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
grep -qx "MyCall=N0CALL" "$(WSJTX_INI)"
grep -qx "Rig=Hamlib NET rigctl" "$(WSJTX_INI)"
grep -qxF "$PTT_CAT" "$(WSJTX_INI)"
! grep -q "PTT_method_VOX" "$(WSJTX_INI)"
grep -qx 'Other\\Configuration\\Rig=Yaesu FT-991' "$(WSJTX_INI)"
[ "$(grep -c '^Rig=' "$(WSJTX_INI)")" -eq 1 ]
[[ "$output" == *"The settings were backed up first, to:"*"WSJT-X.ini.bak-"* ]]
ls "$(WSJTX_INI)".bak-* | grep -q .
run bash "$REPO/radio" configure
[[ "$output" == *"WSJT-X: already set up"* ]]
}
@test "configure leaves a rig you set yourself unless --force" {
configurable
printf '[Configuration]\nRig=Yaesu FT-991\nCATSerialPort=/dev/ttyUSB3\n' > "$(mkdir -p "$(dirname "$(WSJTX_INI)")"; WSJTX_INI)"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"WSJT-X: left alone: it's set up for Yaesu FT-991. \`radio configure --force\` replaces that"* ]]
grep -qx "Rig=Yaesu FT-991" "$(WSJTX_INI)"
run bash "$REPO/radio" configure --force
grep -qx "Rig=Hamlib NET rigctl" "$(WSJTX_INI)"
grep -qx "CATSerialPort=/dev/ttyUSB3" "$(WSJTX_INI)"
}
@test "configure skips programs that are running, and ones not installed" {
configurable
rm "$FAKE_FLATPAKS/io.sourceforge.wsjt.wsjtx"
export FAKE_RUNNING="JS8Call pat"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"WSJT-X: not installed"* ]]
[[ "$output" == *"JS8Call: skipped, because it's running"* ]]
[[ "$output" == *"Pat: skipped, because it's running"* ]]
[ ! -e "$HOME/.config/JS8Call.ini" ]
}
@test "configure sets up JS8Call like WSJT-X" {
configurable
run bash "$REPO/radio" configure
[[ "$output" == *"JS8Call: rig control through rigctld, PTT by CAT"* ]]
grep -qx "Rig=Hamlib NET rigctl" "$HOME/.config/JS8Call.ini"
grep -qxF "$PTT_CAT" "$HOME/.config/JS8Call.ini"
}
@test "configure adds rigctld to Pat, for ARDOP and VARA where they had no rig" {
configurable
run bash "$REPO/radio" configure
local conf="$HOME/.config/pat/config.json"
[[ "$output" == *"Pat: rig \"hampack\" is rigctld"* ]]
[ "$(jq -c .hamlib_rigs.hampack "$conf")" = '{"address":"127.0.0.1:4532","network":"tcp"}' ]
[ "$(jq -r .ardop.rig "$conf")" = hampack ]
[ "$(jq -r .varahf.rig "$conf")" = ft991 ]
[ "$(jq -r .varafm.rig "$conf")" = hampack ]
[ "$(jq -r .mycall "$conf")" = N0CALL ]
[ "$(stat -c %a "$conf")" = 600 ]
run bash "$REPO/radio" configure
[[ "$output" == *"Pat: already set up"* ]]
run bash "$REPO/radio" configure --force
[ "$(jq -r .varahf.rig "$conf")" = hampack ]
}
@test "configure asks which radio when there's more than one" {
configurable
yaesu 1-3 00B00001 ttyUSB1 ttyUSB2 card2 CODEC_1
answers ttyUSB1 "38400 cat_id 0670"
run bash "$REPO/radio" configure
[ "$status" -eq 2 ]
[[ "$output" == *"There are 2 radios or interfaces plugged in"*"radio configure 2"* ]]
[ ! -e "$HOME/.config/systemd/user/hampack-rigctld.service" ]
run bash "$REPO/radio" configure 2
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Setting up the Yaesu FT-991A (Hamlib model 1035), on /dev/ttyUSB1 at 38400 baud" ]
[[ "$output" == *"/dev/ttyUSB1 has no stable name"* ]]
run bash "$REPO/radio" configure 3
[ "$status" -eq 2 ]
[[ "$output" == *"There's no radio 3"* ]]
}
@test "configure needs --model for a radio it can't tell apart from others" {
configurable
answers ttyUSB0 "38400 cat_id 017"
# The IC-7300's USB serial number would say what it is; this radio's doesn't
echo 0001 > "$ROOT_HUB/1-2/1-2.1/serial"
run bash "$REPO/radio" configure
[ "$status" -eq 1 ]
[[ "$output" == *"Couldn't tell which radio it is: it's one of: Elecraft K3 (Hamlib model 2029), Elecraft KX3"* ]]
[[ "$output" == *"radio configure --model 2045"* ]]
run bash "$REPO/radio" configure --model 2045
[ "$status" -eq 0 ]
[ "${lines[0]}" = "Setting up the Elecraft KX3 (Hamlib model 2045), on /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0 at 38400 baud" ]
grep -q -- "-m 2045 " "$HOME/.config/systemd/user/hampack-rigctld.service"
}