Point fldigi and Dire Wolf at rigctld in radio configure

fldigi gets Hamlib rig control through rigctld (NET rigctl at
127.0.0.1:4532) with PTT by Hamlib, and its other rig control modes
turned off, unless it has rig control set up already. It's skipped until
fldigi has made its settings, so its first-run wizard still appears.

Dire Wolf gets PTT RIG 2 127.0.0.1:4532 and the radio's sound card as
plughw:CARD=...,DEV=0, replacing only the values HamPack ships with.
Settings you've changed are left alone unless --force.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 12:36:17 -07:00
co-authored by Claude Opus 5.5
parent eddd363e86
commit a02fa0cc85
5 changed files with 286 additions and 25 deletions
+6 -5
View File
@@ -15,13 +15,14 @@ group (6c76f94), and the start of `radio configure`.
so `radio` lists all four. Find an Elecraft command whose reply names
the model
- [ ] `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
service and points WSJT-X, JS8Call, Pat, fldigi and Dire Wolf at it.
Still to do:
- [ ] 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
saves for a USB codec on a real machine before writing it. Dire Wolf
is done: it takes ALSA names
- [ ] 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
+2 -2
View File
@@ -65,9 +65,9 @@ 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` 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, Pat, fldigi and Dire Wolf at rigctld, with PTT through it. Dire Wolf also gets the radio's sound card. They 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.
`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 the other programs 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.
+17 -7
View File
@@ -45,7 +45,8 @@ cable.
## radio configure
With the radio on a dummy load or an antenna, and WSJT-X, JS8Call and Pat quit:
With the radio on a dummy load or an antenna, and WSJT-X, JS8Call, Pat, fldigi
and Dire Wolf 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.
@@ -58,16 +59,25 @@ With the radio on a dummy load or an antenna, and WSJT-X, JS8Call and Pat quit:
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
6. Open fldigi (after running it once, so it has settings). Configure >
Rig Control > Hamlib shows rig control on, "Hamlib NET rigctl",
127.0.0.1:4532 and "PTT via Hamlib command". The frequency follows the
radio, and T/R keys it. The settings were checked against fldigi 4.1's
source; Arch has 4.2, so note anything it doesn't pick up.
7. Run Dire Wolf with `direwolf -c ~/.local/state/HamPack/conf.d/direwolf.conf`.
It should open plughw:CARD=...,DEV=0 and not complain about
"PTT RIG 2 127.0.0.1:4532". If it says RIG needs hamlib support, its
build didn't find Hamlib. Send a beacon and check it keys the radio.
8. 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
9. 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
10. 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 |
|------|--------|-------|---------|--------|---------|-----|-------|
| | | | | | | | |
| Date | Commit | Radio | rigctld | WSJT-X | JS8Call | Pat | fldigi | Dire Wolf | Notes |
|------|--------|-------|---------|--------|---------|-----|--------|-----------|-------|
| | | | | | | | | | |
## Pairing radios with sound cards
+161 -2
View File
@@ -29,6 +29,11 @@ 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"
FLDIGI_CONF="$HOME/.fldigi/fldigi_def.xml"
DIREWOLF_CONF="$HAMPACK_STATE/conf.d/direwolf.conf"
# What HamPack's conf.d/direwolf.conf ships with, which configure replaces
DIREWOLF_DEFAULT_ADEVICE="plughw:0,0"
DIREWOLF_DEFAULT_PTT="CM108"
# 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)'
@@ -46,7 +51,8 @@ Usage: radio [detect] [--probe]
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
and point WSJT-X, JS8Call, Pat, fldigi and Dire Wolf 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
@@ -471,7 +477,7 @@ back_up() {
# Say what happened to one program: report NAME MESSAGE
report() {
printf ' %-9s %s\n' "$1:" "$2"
printf ' %-10s %s\n' "$1:" "$2"
}
running() {
@@ -543,6 +549,157 @@ configure_pat() {
fi
}
# Print a setting from fldigi's fldigi_def.xml: xml_get FILE TAG
xml_get() {
[ -f "$1" ] || return 0
T="$2" awk '
index($0, "<" ENVIRON["T"] ">") == 1 {
v = substr($0, length(ENVIRON["T"]) + 3)
sub("</" ENVIRON["T"] ">.*$", "", v)
print v
exit
}' "$1"
}
# Set one, adding it before the closing tag if it isn't there: xml_set FILE TAG VALUE
xml_set() {
local tmp
tmp="$(mktemp "$1.XXXXXX")" || return 1
T="$2" V="$3" awk '
function put() { print "<" ENVIRON["T"] ">" ENVIRON["V"] "</" ENVIRON["T"] ">"; done = 1 }
index($0, "<" ENVIRON["T"] ">") == 1 { if (!done) put(); next }
/^<\/FLDIGI_DEFS>/ && !done { put(); print ""; print; next }
{ print }
END { if (!done) put() }
' "$1" > "$tmp" && chmod --reference="$1" "$tmp" && mv -f "$tmp" "$1"
}
# fldigi: rig control through rigctld (Hamlib's NET rigctl, model 2), with PTT
# by Hamlib, unless it has rig control set up already
configure_fldigi() {
local tag
if ! command -v fldigi > /dev/null; then
report fldigi "not installed"
return
fi
if [ ! -f "$FLDIGI_CONF" ]; then
report fldigi "skipped: it has no settings yet. Run fldigi once, then \`radio configure\` again"
return
fi
if running fldigi; then
report fldigi "skipped, because it's running and would overwrite its settings when it quits. Quit it and run \`radio configure\` again"
return
fi
if [ "$(xml_get "$FLDIGI_CONF" CHKUSEHAMLIBIS)" = 1 ] && [ "$(xml_get "$FLDIGI_CONF" HAMRIGMODEL)" = 2 ] &&
[ "$(xml_get "$FLDIGI_CONF" HAMRIGDEVICE)" = "$RIGCTLD_ADDR" ]; then
report fldigi "already set up"
return
fi
if (( ! FORCE )); then
for tag in CHKUSEHAMLIBIS CHKUSERIGCATIS CHKUSEXMLRPCIS CLIENT_TO_FLRIG; do
if [ "$(xml_get "$FLDIGI_CONF" "$tag")" = 1 ]; then
report fldigi "left alone: it has rig control set up already. \`radio configure --force\` replaces that"
return
fi
done
fi
back_up "$FLDIGI_CONF"
if ! { xml_set "$FLDIGI_CONF" CHKUSEHAMLIBIS 1 && xml_set "$FLDIGI_CONF" CHKUSERIGCATIS 0 &&
xml_set "$FLDIGI_CONF" CHKUSEXMLRPCIS 0 && xml_set "$FLDIGI_CONF" CLIENT_TO_FLRIG 0 &&
xml_set "$FLDIGI_CONF" HAMRIGMODEL 2 && xml_set "$FLDIGI_CONF" HAMRIGDEVICE "$RIGCTLD_ADDR" &&
xml_set "$FLDIGI_CONF" HAMLIBCMDPTT 1; }; then
report fldigi "couldn't change $FLDIGI_CONF"
return 1
fi
report fldigi "rig control through rigctld, PTT by Hamlib"
}
# Print the value of the first line for a Dire Wolf setting: dw_get FILE KEYWORD
dw_get() {
K="$2" awk '
$1 == ENVIRON["K"] { sub(/^[ \t]*[^ \t]+[ \t]*/, ""); sub(/[ \t]+$/, ""); print; exit }
' "$1"
}
# Replace the first line for a setting, or add one: at the top for ADEVICE,
# which comes before any CHANNEL, or at the end for others. dw_set FILE KEYWORD VALUE
dw_set() {
local tmp
tmp="$(mktemp "$1.XXXXXX")" || return 1
if [ "$2" = ADEVICE ] && ! grep -Eq '^[[:space:]]*ADEVICE([[:space:]]|$)' "$1"; then
{ echo "ADEVICE $3"; cat "$1"; } > "$tmp"
else
K="$2" V="$3" awk '
function put() { print ENVIRON["K"] " " ENVIRON["V"]; done = 1 }
$1 == ENVIRON["K"] && !done { put(); next }
{ print }
END { if (!done) put() }
' "$1" > "$tmp"
fi || { rm -f "$tmp"; return 1; }
chmod --reference="$1" "$tmp" && mv -f "$tmp" "$1"
}
# Dire Wolf: its sound card, and PTT through rigctld, where its settings are
# still the ones HamPack ships. configure_direwolf CARD
configure_direwolf() {
local card="$1" adevice ptt want_adevice="" want_ptt="RIG 2 $RIGCTLD_ADDR" set=() kept=()
if [ ! -x "$HOME/.local/bin/direwolf" ]; then
report "Dire Wolf" "not installed"
return
fi
if [ ! -f "$DIREWOLF_CONF" ]; then
report "Dire Wolf" "skipped: $DIREWOLF_CONF is missing. \`update\` puts it back"
return
fi
if running direwolf; then
report "Dire Wolf" "skipped, because it's running. Stop it and run \`radio configure\` again"
return
fi
adevice="$(dw_get "$DIREWOLF_CONF" ADEVICE)"
ptt="$(dw_get "$DIREWOLF_CONF" PTT)"
[ -z "$card" ] || want_adevice="plug$card,DEV=0"
if [ -n "$want_adevice" ] && [ "$adevice" != "$want_adevice" ]; then
if (( FORCE )) || [ -z "$adevice" ] || [ "$adevice" = "$DIREWOLF_DEFAULT_ADEVICE" ]; then
set+=(ADEVICE)
else
kept+=("ADEVICE $adevice")
fi
fi
if [ "$ptt" != "$want_ptt" ]; then
if (( FORCE )) || [ -z "$ptt" ] || [ "$ptt" = "$DIREWOLF_DEFAULT_PTT" ]; then
set+=(PTT)
else
kept+=("PTT $ptt")
fi
fi
if [ ${#set[@]} -eq 0 ] && [ ${#kept[@]} -eq 0 ]; then
report "Dire Wolf" "already set up"
return
fi
local changed=()
if [ ${#set[@]} -gt 0 ]; then
back_up "$DIREWOLF_CONF"
if [[ " ${set[*]} " == *" ADEVICE "* ]]; then
dw_set "$DIREWOLF_CONF" ADEVICE "$want_adevice" || { report "Dire Wolf" "couldn't change $DIREWOLF_CONF"; return 1; }
changed+=("sound card $want_adevice")
fi
if [[ " ${set[*]} " == *" PTT "* ]]; then
dw_set "$DIREWOLF_CONF" PTT "$want_ptt" || { report "Dire Wolf" "couldn't change $DIREWOLF_CONF"; return 1; }
changed+=("PTT through rigctld")
fi
fi
local message="" IFS=';'
[ ${#changed[@]} -eq 0 ] || message="${changed[*]}"
message="${message//;/, }"
if [ ${#kept[@]} -gt 0 ]; then
local kept_text="${kept[*]}"
message="${message:+$message. }Left your ${kept_text//;/ and } alone: \`radio configure --force\` replaces them"
fi
report "Dire Wolf" "$message"
}
# Write and (re)start rigctld's user service: write_rigctld NAME HAMLIB PORT BAUD
write_rigctld() {
local unit
@@ -659,6 +816,8 @@ configure() {
report JS8Call "not installed"
fi
configure_pat
configure_fldigi
configure_direwolf "$card"
mkdir -p "$HAMPACK_STATE" &&
printf 'name=%s\nhamlib=%s\nport=%s\nbaud=%s\ncard=%s\n' "$name" "$model" "$port" "$baud" "$card" > "$HAMPACK_STATE/radio"
+91
View File
@@ -332,8 +332,18 @@ configurable() {
"varahf": {"addr": "localhost:8300", "rig": "ft991"}, "varafm": {"addr": "localhost:8300", "rig": ""}}
JSON
chmod 600 "$HOME/.config/pat/config.json"
stub fldigi 'exit 0'
mkdir -p "$HOME/.fldigi"
printf '<FLDIGI_DEFS>\n\n<!-- My call -->\n<MYCALL>N0CALL</MYCALL>\n\n<CHKUSEHAMLIBIS>0</CHKUSEHAMLIBIS>\n\n<CHKUSERIGCATIS>0</CHKUSERIGCATIS>\n\n<HAMRIGMODEL>0</HAMRIGMODEL>\n\n<HAMRIGDEVICE>/dev/rig</HAMRIGDEVICE>\n\n</FLDIGI_DEFS>\n' > "$HOME/.fldigi/fldigi_def.xml"
touch "$HOME/.local/bin/direwolf"
chmod +x "$HOME/.local/bin/direwolf"
mkdir -p "$HAMPACK_STATE/conf.d"
cp "$REPO/conf.d/direwolf.conf" "$HAMPACK_STATE/conf.d/"
}
FLDIGI_XML() { echo "$HOME/.fldigi/fldigi_def.xml"; }
DIREWOLF_CONF() { echo "$HAMPACK_STATE/conf.d/direwolf.conf"; }
@test "configure runs rigctld for the radio on its stable port, at the rate it answered" {
configurable
run bash "$REPO/radio" configure
@@ -476,3 +486,84 @@ JSON
[ "${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"
}
@test "configure points fldigi at rigctld, keeping its other settings" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"fldigi: rig control through rigctld, PTT by Hamlib"* ]]
grep -qx "<CHKUSEHAMLIBIS>1</CHKUSEHAMLIBIS>" "$(FLDIGI_XML)"
grep -qx "<HAMRIGMODEL>2</HAMRIGMODEL>" "$(FLDIGI_XML)"
grep -qx "<HAMRIGDEVICE>127.0.0.1:4532</HAMRIGDEVICE>" "$(FLDIGI_XML)"
grep -qx "<HAMLIBCMDPTT>1</HAMLIBCMDPTT>" "$(FLDIGI_XML)"
grep -qx "<CHKUSEXMLRPCIS>0</CHKUSEXMLRPCIS>" "$(FLDIGI_XML)"
grep -qx "<MYCALL>N0CALL</MYCALL>" "$(FLDIGI_XML)"
grep -qx "<!-- My call -->" "$(FLDIGI_XML)"
[ "$(grep -c '<HAMRIGMODEL>' "$(FLDIGI_XML)")" -eq 1 ]
[ "$(tail -1 "$(FLDIGI_XML)")" = "</FLDIGI_DEFS>" ]
run bash "$REPO/radio" configure
[[ "$output" == *"fldigi: already set up"* ]]
}
@test "configure leaves fldigi's own rig control alone unless --force" {
configurable
sed -i 's|<CHKUSERIGCATIS>0|<CHKUSERIGCATIS>1|' "$(FLDIGI_XML)"
run bash "$REPO/radio" configure
[[ "$output" == *"fldigi: left alone: it has rig control set up already"* ]]
grep -qx "<CHKUSEHAMLIBIS>0</CHKUSEHAMLIBIS>" "$(FLDIGI_XML)"
run bash "$REPO/radio" configure --force
grep -qx "<CHKUSEHAMLIBIS>1</CHKUSEHAMLIBIS>" "$(FLDIGI_XML)"
grep -qx "<CHKUSERIGCATIS>0</CHKUSERIGCATIS>" "$(FLDIGI_XML)"
}
@test "configure waits for fldigi to make its settings" {
configurable
rm "$(FLDIGI_XML)"
run bash "$REPO/radio" configure
[[ "$output" == *"fldigi: skipped: it has no settings yet. Run fldigi once"* ]]
[ ! -e "$(FLDIGI_XML)" ]
}
@test "configure gives Dire Wolf the radio's sound card and PTT through rigctld" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"Dire Wolf: sound card plughw:CARD=CODEC,DEV=0, PTT through rigctld"* ]]
[ "$(grep -E '^ADEVICE' "$(DIREWOLF_CONF)")" = "ADEVICE plughw:CARD=CODEC,DEV=0" ]
[ "$(grep -E '^PTT' "$(DIREWOLF_CONF)")" = "PTT RIG 2 127.0.0.1:4532" ]
grep -qx "MYCALL NOCALL" "$(DIREWOLF_CONF)"
# Only the settings changed, not the comments about them
[ "$(diff "$REPO/conf.d/direwolf.conf" "$(DIREWOLF_CONF)" | grep -c '^>')" -eq 2 ]
run bash "$REPO/radio" configure
[[ "$output" == *"Dire Wolf: already set up"* ]]
}
@test "configure leaves Dire Wolf settings you changed, unless --force" {
configurable
sed -i 's|^ADEVICE .*|ADEVICE plughw:2,0|' "$(DIREWOLF_CONF)"
run bash "$REPO/radio" configure
[[ "$output" == *"Dire Wolf: PTT through rigctld. Left your ADEVICE plughw:2,0 alone"* ]]
grep -qx "ADEVICE plughw:2,0" "$(DIREWOLF_CONF)"
grep -qx "PTT RIG 2 127.0.0.1:4532" "$(DIREWOLF_CONF)"
run bash "$REPO/radio" configure --force
grep -qx "ADEVICE plughw:CARD=CODEC,DEV=0" "$(DIREWOLF_CONF)"
}
@test "configure adds Dire Wolf's settings if they're missing, and needs a sound card for ADEVICE" {
configurable
sed -i '/^ADEVICE /d; /^PTT /d' "$(DIREWOLF_CONF)"
run bash "$REPO/radio" configure
[ "$(head -1 "$(DIREWOLF_CONF)")" = "ADEVICE plughw:CARD=CODEC,DEV=0" ]
[ "$(tail -1 "$(DIREWOLF_CONF)")" = "PTT RIG 2 127.0.0.1:4532" ]
# A radio with no sound card: PTT only
rm -r "$RADIO_SYSFS/class/sound/card1"
cp "$REPO/conf.d/direwolf.conf" "$(DIREWOLF_CONF)"
run bash "$REPO/radio" configure
[[ "$output" == *"Dire Wolf: PTT through rigctld"* ]]
grep -qx "ADEVICE plughw:0,0" "$(DIREWOLF_CONF)"
}