Add radio configure --flrig, which puts flrig in charge of the radio
flrig can't reach a radio through rigctld, and the two can't share its port, so `radio configure` leaves flrig alone and says why. With --flrig, flrig gets the radio, its by-id port, the baud rate it answered at and PTT by CAT, and rigctld runs Hamlib's FLRig backend (model 4) against flrig's XML-RPC port, so every other program still talks to rigctld. Running it again without --flrig gives the port back to rigctld. flrig's settings are FLTK preferences files: flrig.prefs names the radio, and <radio>.prefs (which flrig reads only with a version in it) has its port, baud rate (as its place in flrig's list) and PTT. Long values carry on in lines starting with +, as FLTK writes them. A different radio or port you set is left alone unless --force. radios.conf gets flrig's names for the radios, from flrig 2.0.12. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b2ffaf9592
commit
53e748ccb9
@@ -6,7 +6,7 @@
|
||||
#
|
||||
# Usage : radio [detect] [--probe]
|
||||
# radio probe PORT
|
||||
# radio configure [--force] [--model N] [NUMBER]
|
||||
# radio configure [--force] [--model N] [--flrig] [NUMBER]
|
||||
# radio help
|
||||
|
||||
SELF="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
||||
@@ -35,6 +35,9 @@ QLOG_FLATPAK=io.github.foldynl.QLog
|
||||
QLOG_DB="$HOME/.var/app/$QLOG_FLATPAK/data/hamradio/QLog/qlog.db"
|
||||
POTACAT_DIR="$CONFIG_HOME/potacat"
|
||||
GRAYWOLF_DB="$HOME/.local/share/graywolf/graywolf.db"
|
||||
FLRIG_DIR="$HOME/.flrig"
|
||||
# flrig's baud rates; it saves the rate as its place in this list
|
||||
FLRIG_BAUDS=(300 600 1200 2400 4800 9600 19200 38400 57600 115200 230400 460800)
|
||||
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"
|
||||
@@ -63,6 +66,9 @@ Usage: radio [detect] [--probe]
|
||||
--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
|
||||
--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
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -591,6 +597,86 @@ configure_qt_app() {
|
||||
say_changes "$name"
|
||||
}
|
||||
|
||||
# Print a value from an FLTK preferences file, as flrig keeps its settings:
|
||||
# fltk_get FILE KEY. A long value carries on in lines that start with +
|
||||
fltk_get() {
|
||||
[ -f "$1" ] || return 0
|
||||
K="$2" awk '
|
||||
found && /^\+/ { value = value substr($0, 2); next }
|
||||
found { exit }
|
||||
index($0, ENVIRON["K"] ":") == 1 { value = substr($0, length(ENVIRON["K"]) + 2); found = 1 }
|
||||
END { if (found) print value }
|
||||
' "$1"
|
||||
}
|
||||
|
||||
# Set a value in an FLTK preferences file, making the file if need be:
|
||||
# fltk_set FILE APPLICATION KEY VALUE. Values are written as FLTK writes them:
|
||||
# 60 characters on the key's line, then 80 a line on lines starting with +
|
||||
fltk_set() {
|
||||
local tmp
|
||||
mkdir -p "$(dirname "$1")" || return 1
|
||||
[ -f "$1" ] || printf '; FLTK preferences file format 1.0\n; vendor: w1hkj.com\n; application: %s\n\n[.]\n\n' "$2" > "$1" || return 1
|
||||
tmp="$(mktemp "$1.XXXXXX")" || return 1
|
||||
K="$3" V="$4" awk '
|
||||
function put( v) {
|
||||
v = ENVIRON["V"]
|
||||
print ENVIRON["K"] ":" substr(v, 1, 60)
|
||||
for (v = substr(v, 61); v != ""; v = substr(v, 81)) print "+" substr(v, 1, 80)
|
||||
done = 1
|
||||
}
|
||||
skipping && /^\+/ { next }
|
||||
{ skipping = 0 }
|
||||
index($0, ENVIRON["K"] ":") == 1 { skipping = 1; next }
|
||||
{ print }
|
||||
$0 == "[.]" && !done { put() }
|
||||
END { if (!done) put() }
|
||||
' "$1" > "$tmp" && chmod --reference="$1" "$tmp" && mv -f "$tmp" "$1"
|
||||
}
|
||||
|
||||
# flrig can't reach a radio through rigctld, and the two can't both have its
|
||||
# port open. With --flrig, flrig gets the radio, its port, baud rate and PTT
|
||||
# by CAT, and rigctld (Hamlib's FLRig backend) passes everything to it;
|
||||
# otherwise flrig is left alone. configure_flrig FLRIG_NAME PORT BAUD
|
||||
configure_flrig() {
|
||||
local main="$FLRIG_DIR/flrig.prefs" rig="$FLRIG_DIR/$1.prefs" current_name current_port index i version
|
||||
if ! command -v flrig > /dev/null; then
|
||||
report flrig "not installed"
|
||||
return
|
||||
fi
|
||||
if (( ! USE_FLRIG )); then
|
||||
report flrig "not set up: it and rigctld can't both use the radio's port. \`radio configure --flrig\` puts flrig in charge of the radio, with rigctld passing the other programs through it"
|
||||
return
|
||||
fi
|
||||
for i in "${!FLRIG_BAUDS[@]}"; do
|
||||
[ "${FLRIG_BAUDS[i]}" = "$3" ] && index="$i"
|
||||
done
|
||||
current_name="$(fltk_get "$main" xcvr_name)"
|
||||
current_port="$(fltk_get "$rig" xcvr_serial_port)"
|
||||
SAID=() LEFT=()
|
||||
if [ "$current_name" = "$1" ] && [ "$current_port" = "$2" ] && [ "$(fltk_get "$rig" serial_baudrate)" = "$index" ] &&
|
||||
[ "$(fltk_get "$rig" ptt_via_cat)" = 1 ]; then
|
||||
report flrig "already set up. Start it before the other programs, and leave it running"
|
||||
return
|
||||
fi
|
||||
if (( ! FORCE )) && { [[ ! "$current_name" =~ ^(|NONE|$1)$ ]] || [[ ! "$current_port" =~ ^(|NONE)$ && "$current_port" != "$2" ]]; }; then
|
||||
[[ "$current_name" =~ ^(|NONE|$1)$ ]] && LEFT+=("its port ($current_port)") || LEFT+=("its radio ($current_name)")
|
||||
say_changes flrig
|
||||
return
|
||||
fi
|
||||
back_up "$main"
|
||||
back_up "$rig"
|
||||
# flrig only reads a radio's settings file that has a version in it
|
||||
version="$(fltk_get "$rig" version)"
|
||||
[ -n "$version" ] || version="$(pacman -Q flrig 2> /dev/null | awk '{ sub(/-[^-]*$/, "", $2); print $2 }')"
|
||||
if ! { fltk_set "$main" flrig xcvr_name "$1" && fltk_set "$rig" "$1" version "${version:-2.0}" &&
|
||||
fltk_set "$rig" "$1" xcvr_serial_port "$2" && fltk_set "$rig" "$1" serial_baudrate "$index" &&
|
||||
fltk_set "$rig" "$1" ptt_via_cat 1; }; then
|
||||
report flrig "couldn't change its settings in $FLRIG_DIR"
|
||||
return 1
|
||||
fi
|
||||
report flrig "controls the $1 on $2 at $3 baud, PTT by CAT. Start it before the other programs, and leave it running"
|
||||
}
|
||||
|
||||
# Pat: add rigctld to its rigs as "hampack", and use it for ARDOP and VARA
|
||||
# where no rig is set
|
||||
configure_pat() {
|
||||
@@ -1236,14 +1322,16 @@ configure_graywolf() {
|
||||
say_changes Graywolf
|
||||
}
|
||||
|
||||
# Write and (re)start rigctld's user service: write_rigctld NAME HAMLIB PORT BAUD
|
||||
# Write and (re)start rigctld's user service: write_rigctld DESCRIPTION
|
||||
# RIGCTLD_ARGS..., the arguments that say which radio and how to reach it
|
||||
write_rigctld() {
|
||||
local unit
|
||||
local unit description="$1"
|
||||
shift
|
||||
unit="[Unit]
|
||||
Description=Hamlib rigctld for the $1 (written by HamPack's radio configure)
|
||||
Description=Hamlib rigctld for $description (written by HamPack's radio configure)
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/rigctld -m $2 -r $3 -s $4 -T ${RIGCTLD_ADDR%:*} -t ${RIGCTLD_ADDR#*:}
|
||||
ExecStart=/usr/bin/rigctld $* -T ${RIGCTLD_ADDR%:*} -t ${RIGCTLD_ADDR#*:}
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
@@ -1256,6 +1344,14 @@ WantedBy=default.target"
|
||||
systemctl --user restart hampack-rigctld
|
||||
}
|
||||
|
||||
# Print a field of a radio in radios.conf: conf_field NAME FIELD
|
||||
conf_field() {
|
||||
awk -v name="$1" -v field="$2" '
|
||||
/^\[/ { in_radio = ($0 == "[" name "]"); next }
|
||||
in_radio && index($0, field "=") == 1 { print substr($0, length(field) + 2); exit }
|
||||
' "$RADIOS_CONF"
|
||||
}
|
||||
|
||||
# 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"
|
||||
@@ -1263,11 +1359,12 @@ 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
|
||||
FORCE=0 BACKUPS=()
|
||||
local number="" model="" radio was_running=0 name port baud card flrig_name="" flrig_port=12345
|
||||
FORCE=0 BACKUPS=() USE_FLRIG=0
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--force) FORCE=1 ;;
|
||||
--flrig) USE_FLRIG=1 ;;
|
||||
--model)
|
||||
[[ "${2:-}" =~ ^[0-9]+$ ]] || { usage >&2; return 2; }
|
||||
model="$2"
|
||||
@@ -1296,6 +1393,16 @@ configure() {
|
||||
return 2
|
||||
fi
|
||||
radio="${RADIOS[number - 1]}"
|
||||
if (( USE_FLRIG )); then
|
||||
if ! command -v flrig > /dev/null; then
|
||||
echo "flrig isn't installed."
|
||||
return 1
|
||||
fi
|
||||
if running flrig; then
|
||||
echo "Quit flrig first: it has the radio's port open, and saves its settings when it quits."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# rigctld has the port open, if radio configure has run before
|
||||
if systemctl --user is-active --quiet hampack-rigctld 2> /dev/null; then
|
||||
@@ -1327,6 +1434,16 @@ configure() {
|
||||
(( ! 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="$(card_name "$radio")"
|
||||
@@ -1336,9 +1453,11 @@ configure() {
|
||||
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"
|
||||
echo "Setting up the $name (Hamlib model $model), on $port at $baud baud$( (( USE_FLRIG )) && echo ", through flrig")"
|
||||
echo
|
||||
if write_rigctld "$name" "$model" "$port" "$baud"; then
|
||||
if (( USE_FLRIG )) && write_rigctld "flrig, which controls the $name" -m 4 -r "127.0.0.1:$flrig_port"; then
|
||||
report rigctld "runs as the hampack-rigctld user service, on $RIGCTLD_ADDR, and passes everything to flrig"
|
||||
elif (( ! USE_FLRIG )) && write_rigctld "the $name" -m "$model" -r "$port" -s "$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\`"
|
||||
@@ -1356,6 +1475,7 @@ configure() {
|
||||
else
|
||||
report JS8Call "not installed"
|
||||
fi
|
||||
configure_flrig "$flrig_name" "$port" "$baud"
|
||||
configure_pat
|
||||
configure_fldigi "$card_number"
|
||||
configure_direwolf "$card"
|
||||
@@ -1365,7 +1485,8 @@ configure() {
|
||||
configure_graywolf "$card" "$name"
|
||||
|
||||
mkdir -p "$HAMPACK_STATE" &&
|
||||
printf 'name=%s\nhamlib=%s\nport=%s\nbaud=%s\ncard=%s\n' "$name" "$model" "$port" "$baud" "$card" > "$HAMPACK_STATE/radio"
|
||||
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"
|
||||
|
||||
echo
|
||||
if [ -z "$card" ]; then
|
||||
|
||||
Reference in New Issue
Block a user