Set up a radio radio knows when it's plugged in, with radio configure --auto
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:
co-authored by
Claude Opus 5.5
parent
f2e29ab46d
commit
8d15d2c81e
@@ -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 ]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user