Set up a radio radio knows when it's plugged in, with radio configure --auto
check / lint-and-test (push) Successful in 3m57s
check / packages (push) Successful in 24s

A udev rule starts the hampack-radio-plugged user service when a USB serial
port appears, and it runs `radio configure --auto`. That sets up a radio
recognised by its USB serial number, unless the radio set up already is
plugged in, and says what it did in a desktop notification. It never asks a
radio what it is, since that may key the transmitter, and never asks for
sudo, so a running Graywolf is skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 16:32:05 -07:00
co-authored by Claude Opus 5.5
parent f2e29ab46d
commit 8d15d2c81e
11 changed files with 309 additions and 18 deletions
+6 -3
View File
@@ -130,12 +130,15 @@ remove() {
[ -e "$HOME/.config/autostart/my-flrig.desktop" ]
}
@test "removes HamPack's udev rule" {
mkdir -p "$HAMPACK_UDEV_RULES_DIR"
@test "removes HamPack's udev rules, and the service that sets up a radio when it's plugged in" {
mkdir -p "$HAMPACK_UDEV_RULES_DIR" "$HOME/.config/systemd/user"
echo rule > "$HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules"
echo rule > "$HAMPACK_UDEV_RULES_DIR/70-hampack-radio.rules"
echo unit > "$HOME/.config/systemd/user/hampack-radio-plugged.service"
remove
[ "$status" -eq 0 ]
grep -qx "sudo rm -f $HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules" "$STUB_LOG"
grep -qx "sudo rm -f $HAMPACK_UDEV_RULES_DIR/70-hampack-cm108.rules $HAMPACK_UDEV_RULES_DIR/70-hampack-radio.rules" "$STUB_LOG"
[ ! -e "$HOME/.config/systemd/user/hampack-radio-plugged.service" ]
}
@test "does nothing unless confirmed" {
+91
View File
@@ -1495,3 +1495,94 @@ digirig() {
[ "$status" -eq 1 ]
[[ "$output" == *"no CM108 PTT pin"* ]]
}
# --- setting up a radio when it's plugged in ---
# radio configure --auto, as the hampack-radio-plugged service runs it, with
# desktop notifications logged
auto() {
stub notify-send 'exit 0'
RADIO_AUTO_WAIT=0 run bash "$REPO/radio" configure --auto
}
@test "--auto sets up a radio it knows by its USB serial number, and says so" {
configurable
auto
[ "$status" -eq 0 ]
[[ "$output" == *"Setting up the Icom IC-7300 (Hamlib model 3073)"* ]]
grep -qx "hamlib=3073" "$HAMPACK_STATE/radio"
grep -qx "systemctl --user restart hampack-rigctld" "$STUB_LOG"
grep -q "^notify-send --app-name=HamPack HamPack set up the Icom IC-7300 " "$STUB_LOG"
}
@test "--auto leaves Graywolf alone while it runs, rather than ask for sudo, and says what it skipped" {
configurable
FAKE_RUNNING=fldigi auto
[ "$status" -eq 0 ]
[[ "$output" == *"Graywolf: skipped: it's running, and stopping it to change its settings needs sudo. Run \`radio configure\` to set it up"* ]]
! grep -q "^sudo" "$STUB_LOG"
grep -q "^notify-send .* Skipped: fldigi, Graywolf. Run \`radio configure\` to see why" "$STUB_LOG"
}
@test "--auto doesn't ask a radio what it is" {
configurable
rm -r "$RADIO_SYSFS/class/tty/ttyUSB0" "$RADIO_SYSFS/class/sound/card1"
yaesu 1-3
answers ttyUSB0 "38400 cat_id 0670"
: > "$STUB_LOG"
auto
[ "$status" -eq 0 ]
[[ "$output" == "No radio that radio recognises by its USB serial number is plugged in"* ]]
! grep -q "^python3" "$STUB_LOG"
! grep -q "^notify-send" "$STUB_LOG"
[ ! -e "$HAMPACK_STATE/radio" ]
}
@test "--auto leaves the radio set up already, while it's plugged in" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
: > "$STUB_LOG"
auto
[ "$status" -eq 0 ]
[ "$output" = "The radio set up already, the Icom IC-7300, is plugged in, so it stays set up." ]
! grep -q "reenable" "$STUB_LOG"
! grep -q "^notify-send" "$STUB_LOG"
# A sound card with no serial port, set up with no CAT, counts while it's there
printf 'name=radio on the AIOC\nport=\ncard=hw:CARD=CODEC\n' > "$HAMPACK_STATE/radio"
auto
[[ "$output" == *"stays set up"* ]]
}
@test "--auto sets up a radio in place of one that isn't plugged in" {
configurable
mkdir -p "$HAMPACK_STATE"
printf 'name=Yaesu FT-991A\nport=/dev/serial/by-id/usb-gone-if00-port0\ncard=hw:CARD=Gone\n' > "$HAMPACK_STATE/radio"
auto
[ "$status" -eq 0 ]
grep -qx "name=Icom IC-7300" "$HAMPACK_STATE/radio"
}
@test "--auto leaves it to you when two radios it knows are plugged in" {
configurable
usb 1-5 10c4:ea60 "Silicon Labs" "CP2102 USB to UART Bridge Controller" "IC-705 12345678"
port 1-5 ttyUSB2
auto
[ "$status" -eq 0 ]
[ "$output" = "2 radios that radio recognises are plugged in: run \`radio configure N\` to set one up." ]
[ ! -e "$HAMPACK_STATE/radio" ]
}
@test "--auto says when it couldn't set the radio up" {
configurable
rm "$FAKE_RADIOS/ttyUSB0"
auto
[ "$status" -eq 1 ]
grep -qx "notify-send --app-name=HamPack HamPack couldn't set up the Icom IC-7300 Run \`radio configure\` to see why." "$STUB_LOG"
}
@test "--auto takes no other options" {
run bash "$REPO/radio" configure --auto --force
[ "$status" -eq 2 ]
}
+19
View File
@@ -84,6 +84,25 @@ setup() {
grep -q "^sudo install -m 644 .*70-hampack-cm108.rules" "$STUB_LOG"
}
@test "installs the udev rule and user service that set up a radio when it's plugged in" {
run bash "$REPO/update.sh"
[ "$status" -eq 0 ]
grep -qx "sudo install -m 644 $REPO/udev/70-hampack-radio.rules $HAMPACK_UDEV_RULES_DIR/70-hampack-radio.rules" "$STUB_LOG"
local unit="$HOME/.config/systemd/user/hampack-radio-plugged.service"
grep -qx "ExecStart=$REPO/radio configure --auto" "$unit"
grep -qx "systemctl --user daemon-reload" "$STUB_LOG"
# Only the CM108 rule needs applying to devices plugged in already
mkdir -p "$HAMPACK_UDEV_RULES_DIR"
cp "$REPO/udev/70-hampack-cm108.rules" "$HAMPACK_UDEV_RULES_DIR/"
: > "$STUB_LOG"
run bash "$REPO/update.sh"
grep -q "^sudo install -m 644 .*70-hampack-radio.rules" "$STUB_LOG"
grep -qx "udevadm control --reload-rules" "$STUB_LOG"
! grep -q "udevadm trigger" "$STUB_LOG"
! grep -q "daemon-reload" "$STUB_LOG"
}
@test "update leaves alone a radio command that isn't HamPack's" {
echo "theirs" > "$HOME/.local/bin/radio"
run bash "$REPO/update.sh"