Start rigctld when the radio is plugged in, and stop it when it goes

systemd makes a device unit for each USB serial port and its
/dev/serial/by-id link, so rigctld's user service is now wanted by and
bound to the radio's port: it starts when the radio is plugged in or
switched on (or at login if it's there already) and stops when it goes,
instead of retrying every 5 seconds. reenable clears the login link
earlier versions of the unit had. With --flrig, rigctld talks to flrig
rather than the port, so it still starts at login.

PLAN.md drops running more than one radio at once, for now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 13:50:09 -07:00
co-authored by Claude Opus 5.5
parent 357f72583e
commit fee5ce341a
5 changed files with 83 additions and 24 deletions
+38 -1
View File
@@ -472,7 +472,7 @@ DIREWOLF_CONF() { echo "$HAMPACK_STATE/conf.d/direwolf.conf"; }
[ "${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 reenable hampack-rigctld" "$STUB_LOG"
grep -qx "systemctl --user restart hampack-rigctld" "$STUB_LOG"
[[ "$output" == *"PipeWire didn't list the radio's sound card, hw:CARD=CODEC (\"USB Audio CODEC\"), so choose it yourself in WSJT-X, JS8Call and POTACAT."* ]]
grep -qx "hamlib=3073" "$HAMPACK_STATE/radio"
@@ -1189,3 +1189,40 @@ FLRIG_AUTOSTART() { echo "$HOME/.config/autostart/hampack-flrig.desktop"; }
[ -e "$(FLRIG_AUTOSTART)" ]
[ -e "$HOME/.config/autostart/my-flrig.desktop" ]
}
# --- rigctld and the radio's port ---
@test "configure ties rigctld to the radio's port, so it runs when the radio is plugged in" {
configurable
run bash "$REPO/radio" configure
[[ "$output" == *"rigctld: runs as the hampack-rigctld user service, on 127.0.0.1:4532, whenever the radio is plugged in and on"* ]]
local unit="$HOME/.config/systemd/user/hampack-rigctld.service" device
device="$(systemd-escape --path --suffix=device "$IC7300_PORT")"
[[ "$device" == dev-serial-by*id-usb*IC*7300*.device ]]
grep -qxF "BindsTo=$device" "$unit"
grep -qxF "After=$device" "$unit"
grep -qxF "WantedBy=$device" "$unit"
! grep -q "default.target" "$unit"
}
@test "configure --flrig starts rigctld at login, since flrig has the port" {
configurable
run bash "$REPO/radio" configure --flrig
local unit="$HOME/.config/systemd/user/hampack-rigctld.service"
grep -qx "WantedBy=default.target" "$unit"
! grep -q "^BindsTo=" "$unit"
}
@test "rigctld waits for a radio that isn't plugged in" {
export RADIO_DEV="$BATS_TEST_TMPDIR/dev"
run bash -c '
source <(sed -n "/^write_rigctld() {/,/^}/p" "$1")
RIGCTLD_UNIT="$HOME/.config/systemd/user/hampack-rigctld.service" RIGCTLD_ADDR=127.0.0.1:4532 DEVDIR="$RADIO_DEV"
write_rigctld "the Icom IC-7300" /dev/serial/by-id/usb-gone-if00-port0 -m 3073 -r /dev/serial/by-id/usb-gone-if00-port0 -s 38400
' _ "$REPO/radio"
[ "$status" -eq 0 ]
[ "$output" = waiting ]
grep -qx "systemctl --user reenable hampack-rigctld" "$STUB_LOG"
! grep -q "systemctl --user restart" "$STUB_LOG"
grep -qx "ExecStart=/usr/bin/rigctld -m 3073 -r /dev/serial/by-id/usb-gone-if00-port0 -s 38400 -T 127.0.0.1 -t 4532" "$HOME/.config/systemd/user/hampack-rigctld.service"
}