Start radio configure: rigctld for the radio, with WSJT-X, JS8Call and Pat on it
`radio configure` asks the radio what it is and the baud rate it answers at, then runs rigctld for it as the hampack-rigctld systemd user service on 127.0.0.1:4532, using the port's /dev/serial/by-id name. WSJT-X (the Flatpak) and JS8Call get Hamlib NET rigctl with PTT by CAT; Pat gets a "hampack" rig, used by ARDOP and VARA where they had none. Rig settings you've set are left alone unless --force, each file is backed up first, and programs that are running are skipped. With several radios, give the number `radio` now lists; --model sets the Hamlib model for a radio it can't tell apart from others. Sound cards are left for you to choose. hampackremove stops and removes the service. PLAN.md lists the programs still to do; TEST.md has the checks on a real radio. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e71f1e59c2
commit
eddd363e86
+179
-11
@@ -82,7 +82,7 @@ answers() {
|
||||
ic7300
|
||||
run bash "$REPO/radio"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
|
||||
[ "${lines[0]}" = "1. Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
|
||||
[ "${lines[1]}" = " Serial port: /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0" ]
|
||||
[ "${lines[2]}" = " Sound card: hw:CARD=CODEC (card1)" ]
|
||||
[[ "${lines[3]}" == " USB: 10c4:ea60 Silicon Labs CP2102 USB to UART Bridge Controller, serial IC-7300 03001234" ]]
|
||||
@@ -94,7 +94,7 @@ answers() {
|
||||
answers ttyUSB0 "38400 cat_id 0670"
|
||||
run bash "$REPO/radio" detect
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "Unknown radio or interface" ]
|
||||
[ "${lines[0]}" = "1. Unknown radio or interface" ]
|
||||
[ "${lines[1]}" = " Serial port: /dev/ttyUSB0" ]
|
||||
[ "${lines[2]}" = " Serial port: /dev/ttyUSB1" ]
|
||||
[ "${lines[3]}" = " Sound card: hw:CARD=CODEC (card1)" ]
|
||||
@@ -107,7 +107,7 @@ answers() {
|
||||
answers ttyUSB1 "38400 cat_id 0670"
|
||||
run bash "$REPO/radio" detect --probe
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "Yaesu FT-991A (Hamlib model 1035), answered on ttyUSB1 at 38400 baud" ]
|
||||
[ "${lines[0]}" = "1. Yaesu FT-991A (Hamlib model 1035), answered on ttyUSB1 at 38400 baud" ]
|
||||
[ "${lines[1]}" = " Serial port: /dev/ttyUSB0" ]
|
||||
[ "${lines[2]}" = " CAT port: /dev/ttyUSB1" ]
|
||||
[ "$(grep -c '^python3' "$STUB_LOG")" -eq 2 ]
|
||||
@@ -118,7 +118,7 @@ answers() {
|
||||
port 1-4 ttyUSB0
|
||||
answers ttyUSB0 "19200 civ 94"
|
||||
run bash "$REPO/radio" --probe
|
||||
[ "${lines[0]}" = "Icom IC-7300 (Hamlib model 3073), answered on ttyUSB0 at 19200 baud" ]
|
||||
[ "${lines[0]}" = "1. Icom IC-7300 (Hamlib model 3073), answered on ttyUSB0 at 19200 baud" ]
|
||||
[ "${lines[2]}" = " Sound card: none found with it" ]
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ answers() {
|
||||
port 1-4 ttyUSB0
|
||||
answers ttyUSB0 "38400 cat_id 017"
|
||||
run bash "$REPO/radio" --probe
|
||||
[ "${lines[0]}" = "One of: Elecraft K3 (Hamlib model 2029), Elecraft KX3 (Hamlib model 2045), Elecraft KX2 (Hamlib model 2044), Elecraft K4 (Hamlib model 2047), answered on ttyUSB0 at 38400 baud" ]
|
||||
[ "${lines[0]}" = "1. One of: Elecraft K3 (Hamlib model 2029), Elecraft KX3 (Hamlib model 2045), Elecraft KX2 (Hamlib model 2044), Elecraft K4 (Hamlib model 2047), answered on ttyUSB0 at 38400 baud" ]
|
||||
}
|
||||
|
||||
@test "says what answered when it doesn't know the radio" {
|
||||
@@ -135,7 +135,7 @@ answers() {
|
||||
port 1-4 ttyUSB0
|
||||
answers ttyUSB0 "9600 civ 5E"
|
||||
run bash "$REPO/radio" --probe
|
||||
[ "${lines[0]}" = "An Icom radio at CI-V address 5E that radio doesn't know, answered on ttyUSB0 at 9600 baud" ]
|
||||
[ "${lines[0]}" = "1. An Icom radio at CI-V address 5E that radio doesn't know, answered on ttyUSB0 at 9600 baud" ]
|
||||
}
|
||||
|
||||
@test "says when nothing answers" {
|
||||
@@ -143,7 +143,7 @@ answers() {
|
||||
port 1-4 ttyUSB0
|
||||
answers ttyUSB1 "38400 cat_id 0670"
|
||||
run bash "$REPO/radio" --probe
|
||||
[ "${lines[0]}" = "Unknown radio or interface" ]
|
||||
[ "${lines[0]}" = "1. Unknown radio or interface" ]
|
||||
[[ "$output" == *"Nothing answered. If it's a radio, check it's switched on"* ]]
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ answers() {
|
||||
ln -s "$RADIO_DEV/ttyUSB0" "$RADIO_PROC/4242/fd/5"
|
||||
touch "$RADIO_LOCKDIR/LCK..ttyUSB1"
|
||||
run bash "$REPO/radio" --probe
|
||||
[ "${lines[0]}" = "Unknown radio or interface" ]
|
||||
[ "${lines[0]}" = "1. Unknown radio or interface" ]
|
||||
[[ "$output" == *"Couldn't ask on ttyUSB0: $RADIO_DEV/ttyUSB0 is in use by rigctld (process 4242)"* ]]
|
||||
[[ "$output" == *"Couldn't ask on ttyUSB1: $RADIO_DEV/ttyUSB1 is locked by another program"* ]]
|
||||
[[ "$output" != *"Nothing answered"* ]]
|
||||
@@ -169,9 +169,9 @@ answers() {
|
||||
run bash "$REPO/radio"
|
||||
[ "$status" -eq 0 ]
|
||||
# bats leaves the blank line between radios out of lines
|
||||
[ "${lines[0]}" = "Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
|
||||
[ "${lines[0]}" = "1. Icom IC-7300 (Hamlib model 3073), recognised by its USB serial number" ]
|
||||
[ "${lines[2]}" = " Sound card: hw:CARD=CODEC (card1)" ]
|
||||
[ "${lines[4]}" = "Unknown radio or interface" ]
|
||||
[ "${lines[4]}" = "2. Unknown radio or interface" ]
|
||||
[ "${lines[5]}" = " Serial port: /dev/ttyUSB1" ]
|
||||
[ "${lines[6]}" = " Serial port: /dev/ttyUSB2" ]
|
||||
[ "${lines[7]}" = " Sound card: hw:CARD=CODEC_1 (card2)" ]
|
||||
@@ -182,7 +182,7 @@ answers() {
|
||||
port 1-5 ttyACM0 "" 0
|
||||
card 1-5 card1 IC705
|
||||
run bash "$REPO/radio"
|
||||
[ "${lines[0]}" = "Icom IC-705 (Hamlib model 3085), recognised by its USB serial number" ]
|
||||
[ "${lines[0]}" = "1. Icom IC-705 (Hamlib model 3085), recognised by its USB serial number" ]
|
||||
[ "${lines[2]}" = " Sound card: hw:CARD=IC705 (card1)" ]
|
||||
}
|
||||
|
||||
@@ -308,3 +308,171 @@ teardown() {
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = "Nothing answered on $PTY at 38400 115200 19200 9600 4800 baud" ]
|
||||
}
|
||||
|
||||
# --- radio configure ---
|
||||
|
||||
WSJTX_INI() { echo "$HOME/.var/app/io.sourceforge.wsjt.wsjtx/config/WSJT-X.ini"; }
|
||||
PTT_CAT='PTTMethod=@Variant(\0\0\0\x7f\0\0\0\x1eTransceiverFactory::PTTMethod\0\0\0\0\xfPTT_method_CAT\0)'
|
||||
|
||||
# An IC-7300 that answers, with WSJT-X, JS8Call and Pat installed and none
|
||||
# running. rigctld's service is running if $FAKE_RADIOS/rigctld-active exists;
|
||||
# programs named in $FAKE_RUNNING are running
|
||||
configurable() {
|
||||
ic7300
|
||||
answers ttyUSB0 "38400 civ 94"
|
||||
touch "$FAKE_FLATPAKS/io.sourceforge.wsjt.wsjtx"
|
||||
touch "$HOME/.local/bin/JS8Call"
|
||||
chmod +x "$HOME/.local/bin/JS8Call"
|
||||
stub pat 'exit 0'
|
||||
stub pgrep '[[ " ${FAKE_RUNNING:-} " == *" $2 "* ]]'
|
||||
stub systemctl '[ "$*" != "--user is-active --quiet hampack-rigctld" ] || [ -f "$FAKE_RADIOS/rigctld-active" ]'
|
||||
mkdir -p "$HOME/.config/pat"
|
||||
cat > "$HOME/.config/pat/config.json" << 'JSON'
|
||||
{"mycall": "N0CALL", "hamlib_rigs": {}, "ardop": {"addr": "localhost:8515", "rig": ""},
|
||||
"varahf": {"addr": "localhost:8300", "rig": "ft991"}, "varafm": {"addr": "localhost:8300", "rig": ""}}
|
||||
JSON
|
||||
chmod 600 "$HOME/.config/pat/config.json"
|
||||
}
|
||||
|
||||
@test "configure runs rigctld for the radio on its stable port, at the rate it answered" {
|
||||
configurable
|
||||
run bash "$REPO/radio" configure
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${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 restart hampack-rigctld" "$STUB_LOG"
|
||||
[[ "$output" == *"Choose the radio's sound card in each program yourself: hw:CARD=CODEC, \"USB Audio CODEC\""* ]]
|
||||
grep -qx "hamlib=3073" "$HAMPACK_STATE/radio"
|
||||
grep -qx "card=hw:CARD=CODEC" "$HAMPACK_STATE/radio"
|
||||
}
|
||||
|
||||
@test "configure stops its own rigctld to ask the radio, and starts it again if that fails" {
|
||||
configurable
|
||||
touch "$FAKE_RADIOS/rigctld-active"
|
||||
run bash "$REPO/radio" configure
|
||||
[ "$status" -eq 0 ]
|
||||
# Stopped before python3 asked the radio
|
||||
local stopped asked
|
||||
stopped="$(grep -n '^systemctl --user stop hampack-rigctld' "$STUB_LOG" | cut -d: -f1)"
|
||||
asked="$(grep -n '^python3' "$STUB_LOG" | head -1 | cut -d: -f1)"
|
||||
[ -n "$stopped" ] && [ "$stopped" -lt "$asked" ]
|
||||
|
||||
: > "$STUB_LOG"
|
||||
rm "$FAKE_RADIOS/ttyUSB0"
|
||||
run bash "$REPO/radio" configure
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"Couldn't set it up: nothing answered on ttyUSB0."* ]]
|
||||
grep -qx "systemctl --user start hampack-rigctld" "$STUB_LOG"
|
||||
}
|
||||
|
||||
@test "configure sets up a new WSJT-X, and one with no rig, keeping its other settings" {
|
||||
configurable
|
||||
run bash "$REPO/radio" configure
|
||||
[[ "$output" == *"WSJT-X: rig control through rigctld, PTT by CAT"* ]]
|
||||
grep -qx "Rig=Hamlib NET rigctl" "$(WSJTX_INI)"
|
||||
grep -qx "CATNetworkPort=127.0.0.1:4532" "$(WSJTX_INI)"
|
||||
grep -qxF "$PTT_CAT" "$(WSJTX_INI)"
|
||||
|
||||
printf '[Configuration]\nMyCall=N0CALL\nRig=None\nPTTMethod=@Variant(\\0\\0\\0\\x7f\\0\\0\\0\\x1eTransceiverFactory::PTTMethod\\0\\0\\0\\0\\xfPTT_method_VOX\\0)\n\n[MultiSettings]\nOther\\Configuration\\Rig=Yaesu FT-991\n' > "$(WSJTX_INI)"
|
||||
run bash "$REPO/radio" configure
|
||||
[ "$status" -eq 0 ]
|
||||
grep -qx "MyCall=N0CALL" "$(WSJTX_INI)"
|
||||
grep -qx "Rig=Hamlib NET rigctl" "$(WSJTX_INI)"
|
||||
grep -qxF "$PTT_CAT" "$(WSJTX_INI)"
|
||||
! grep -q "PTT_method_VOX" "$(WSJTX_INI)"
|
||||
grep -qx 'Other\\Configuration\\Rig=Yaesu FT-991' "$(WSJTX_INI)"
|
||||
[ "$(grep -c '^Rig=' "$(WSJTX_INI)")" -eq 1 ]
|
||||
[[ "$output" == *"The settings were backed up first, to:"*"WSJT-X.ini.bak-"* ]]
|
||||
ls "$(WSJTX_INI)".bak-* | grep -q .
|
||||
|
||||
run bash "$REPO/radio" configure
|
||||
[[ "$output" == *"WSJT-X: already set up"* ]]
|
||||
}
|
||||
|
||||
@test "configure leaves a rig you set yourself unless --force" {
|
||||
configurable
|
||||
printf '[Configuration]\nRig=Yaesu FT-991\nCATSerialPort=/dev/ttyUSB3\n' > "$(mkdir -p "$(dirname "$(WSJTX_INI)")"; WSJTX_INI)"
|
||||
run bash "$REPO/radio" configure
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"WSJT-X: left alone: it's set up for Yaesu FT-991. \`radio configure --force\` replaces that"* ]]
|
||||
grep -qx "Rig=Yaesu FT-991" "$(WSJTX_INI)"
|
||||
|
||||
run bash "$REPO/radio" configure --force
|
||||
grep -qx "Rig=Hamlib NET rigctl" "$(WSJTX_INI)"
|
||||
grep -qx "CATSerialPort=/dev/ttyUSB3" "$(WSJTX_INI)"
|
||||
}
|
||||
|
||||
@test "configure skips programs that are running, and ones not installed" {
|
||||
configurable
|
||||
rm "$FAKE_FLATPAKS/io.sourceforge.wsjt.wsjtx"
|
||||
export FAKE_RUNNING="JS8Call pat"
|
||||
run bash "$REPO/radio" configure
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"WSJT-X: not installed"* ]]
|
||||
[[ "$output" == *"JS8Call: skipped, because it's running"* ]]
|
||||
[[ "$output" == *"Pat: skipped, because it's running"* ]]
|
||||
[ ! -e "$HOME/.config/JS8Call.ini" ]
|
||||
}
|
||||
|
||||
@test "configure sets up JS8Call like WSJT-X" {
|
||||
configurable
|
||||
run bash "$REPO/radio" configure
|
||||
[[ "$output" == *"JS8Call: rig control through rigctld, PTT by CAT"* ]]
|
||||
grep -qx "Rig=Hamlib NET rigctl" "$HOME/.config/JS8Call.ini"
|
||||
grep -qxF "$PTT_CAT" "$HOME/.config/JS8Call.ini"
|
||||
}
|
||||
|
||||
@test "configure adds rigctld to Pat, for ARDOP and VARA where they had no rig" {
|
||||
configurable
|
||||
run bash "$REPO/radio" configure
|
||||
local conf="$HOME/.config/pat/config.json"
|
||||
[[ "$output" == *"Pat: rig \"hampack\" is rigctld"* ]]
|
||||
[ "$(jq -c .hamlib_rigs.hampack "$conf")" = '{"address":"127.0.0.1:4532","network":"tcp"}' ]
|
||||
[ "$(jq -r .ardop.rig "$conf")" = hampack ]
|
||||
[ "$(jq -r .varahf.rig "$conf")" = ft991 ]
|
||||
[ "$(jq -r .varafm.rig "$conf")" = hampack ]
|
||||
[ "$(jq -r .mycall "$conf")" = N0CALL ]
|
||||
[ "$(stat -c %a "$conf")" = 600 ]
|
||||
|
||||
run bash "$REPO/radio" configure
|
||||
[[ "$output" == *"Pat: already set up"* ]]
|
||||
run bash "$REPO/radio" configure --force
|
||||
[ "$(jq -r .varahf.rig "$conf")" = hampack ]
|
||||
}
|
||||
|
||||
@test "configure asks which radio when there's more than one" {
|
||||
configurable
|
||||
yaesu 1-3 00B00001 ttyUSB1 ttyUSB2 card2 CODEC_1
|
||||
answers ttyUSB1 "38400 cat_id 0670"
|
||||
run bash "$REPO/radio" configure
|
||||
[ "$status" -eq 2 ]
|
||||
[[ "$output" == *"There are 2 radios or interfaces plugged in"*"radio configure 2"* ]]
|
||||
[ ! -e "$HOME/.config/systemd/user/hampack-rigctld.service" ]
|
||||
|
||||
run bash "$REPO/radio" configure 2
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "Setting up the Yaesu FT-991A (Hamlib model 1035), on /dev/ttyUSB1 at 38400 baud" ]
|
||||
[[ "$output" == *"/dev/ttyUSB1 has no stable name"* ]]
|
||||
|
||||
run bash "$REPO/radio" configure 3
|
||||
[ "$status" -eq 2 ]
|
||||
[[ "$output" == *"There's no radio 3"* ]]
|
||||
}
|
||||
|
||||
@test "configure needs --model for a radio it can't tell apart from others" {
|
||||
configurable
|
||||
answers ttyUSB0 "38400 cat_id 017"
|
||||
# The IC-7300's USB serial number would say what it is; this radio's doesn't
|
||||
echo 0001 > "$ROOT_HUB/1-2/1-2.1/serial"
|
||||
run bash "$REPO/radio" configure
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"Couldn't tell which radio it is: it's one of: Elecraft K3 (Hamlib model 2029), Elecraft KX3"* ]]
|
||||
[[ "$output" == *"radio configure --model 2045"* ]]
|
||||
|
||||
run bash "$REPO/radio" configure --model 2045
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "Setting up the Elecraft KX3 (Hamlib model 2045), on /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_IC-7300_03001234-if00-port0 at 38400 baud" ]
|
||||
grep -q -- "-m 2045 " "$HOME/.config/systemd/user/hampack-rigctld.service"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user