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:
co-authored by
Claude Opus 5.5
parent
eddd363e86
commit
a02fa0cc85
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user