Point POTACAT and Graywolf at rigctld in radio configure

POTACAT gets a "rigctld Network" rig at 127.0.0.1:4532 in My Rigs, made
the active rig, with the connection written where POTACAT reads it: the
global settings, or the operator's profile once there is one. It's left
alone if it has a radio set up, unless --force.

Graywolf's web API needs its password, so its database gets the change:
PTT through rigctld on each channel that transmits and has none. It's
checked first without writing; only if something changes is Graywolf
stopped with sudo, its database backed up through SQLite, and Graywolf
started again. If sudo is refused, or no channel transmits, it says what
to set in the web UI instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 12:56:14 -07:00
co-authored by Claude Opus 5.5
parent 892bfb9df0
commit 04d973039a
5 changed files with 306 additions and 16 deletions
+115
View File
@@ -352,6 +352,11 @@ JSON
echo '{"mycall": "N0CALL", "userigctld": false, "useflrig": false, "usetci": false, "CAT_ip": "127.0.0.1", "CAT_port": 12345}' > "$HOME/.config/not1mm/not1mm.json"
touch "$FAKE_FLATPAKS/io.github.foldynl.QLog"
qlog_log
touch "$HOME/.local/bin/POTACAT.AppImage" "$HOME/.local/bin/graywolf"
chmod +x "$HOME/.local/bin/POTACAT.AppImage" "$HOME/.local/bin/graywolf"
mkdir -p "$HOME/.config/potacat"
echo '{"grid": "FN20jb", "catTarget": null, "firstRun": false}' > "$(POTACAT_JSON)"
graywolf_db 1:1
}
FLDIGI_XML() { echo "$HOME/.fldigi/fldigi_def.xml"; }
@@ -385,6 +390,31 @@ con.close()
PY
}
POTACAT_JSON() { echo "$HOME/.config/potacat/settings.json"; }
GRAYWOLF_DB() { echo "$HOME/.local/share/graywolf/graywolf.db"; }
# Graywolf's settings, with its channels and ptt_configs tables as 0.14.14
# has them: graywolf_db CHANNEL:OUTPUT_DEVICE... (0 is receive-only)
graywolf_db() {
mkdir -p "$(dirname "$(GRAYWOLF_DB)")"
"$REAL_PYTHON3" -I - "$(GRAYWOLF_DB)" "$@" << 'PY'
import sqlite3, sys
con = sqlite3.connect(sys.argv[1])
con.execute("PRAGMA journal_mode = WAL")
con.execute("CREATE TABLE channels (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, input_device_id INTEGER, "
"input_channel INTEGER NOT NULL DEFAULT 0, output_device_id INTEGER NOT NULL DEFAULT 0, enabled NUMERIC NOT NULL DEFAULT true)")
con.execute("CREATE TABLE ptt_configs (id INTEGER PRIMARY KEY AUTOINCREMENT, channel_id INTEGER NOT NULL UNIQUE, "
"method TEXT NOT NULL DEFAULT 'none', device TEXT, gpio_pin INTEGER, ptt_method INTEGER NOT NULL DEFAULT 0, "
"gpio_line INTEGER NOT NULL DEFAULT 0, invert NUMERIC NOT NULL DEFAULT false, slot_time_ms INTEGER NOT NULL DEFAULT 10, "
"persist INTEGER NOT NULL DEFAULT 63, dwait_ms INTEGER NOT NULL DEFAULT 0, created_at DATETIME, updated_at DATETIME)")
for arg in sys.argv[2:]:
channel, output = arg.split(":")
con.execute("INSERT INTO channels (id, name, output_device_id) VALUES (?, ?, ?)", (int(channel), "ch" + channel, int(output)))
con.commit()
con.close()
PY
}
qlog_query() { "$REAL_PYTHON3" -I -c 'import sqlite3, sys
con = sqlite3.connect(sys.argv[1])
for row in con.execute(sys.argv[2]): print("|".join(map(str, row)))
@@ -688,3 +718,88 @@ DIREWOLF_CONF() { echo "$HAMPACK_STATE/conf.d/direwolf.conf"; }
[[ "$output" == *"QLog: skipped, because it's running"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM rig_profiles")" = 0 ]
}
@test "configure adds rigctld to POTACAT's rigs and makes it active" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"POTACAT: rig \"Icom IC-7300 (HamPack's rigctld)\" is rigctld, and active"* ]]
[ "$(jq -c '[.rigs, .activeRigId, .catTarget, .grid]' "$(POTACAT_JSON)")" = '[[{"id":"rig_hampack","name":"Icom IC-7300 (HamPack'"'"'s rigctld)","catTarget":{"type":"rigctldnet","host":"127.0.0.1","port":4532}}],"rig_hampack",{"type":"rigctldnet","host":"127.0.0.1","port":4532},"FN20jb"]' ]
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: already set up"* ]]
}
@test "configure puts POTACAT's connection in the operator's profile, where POTACAT keeps it" {
configurable
echo '{"activeProfile": "N0CALL", "rigs": []}' > "$(POTACAT_JSON)"
mkdir -p "$HOME/.config/potacat/profiles/N0CALL"
echo '{"myCallsign": "N0CALL", "catTarget": null}' > "$HOME/.config/potacat/profiles/N0CALL/settings.json"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[ "$(jq -c '[.activeRigId, has("catTarget"), (.rigs | length)]' "$(POTACAT_JSON)")" = '["rig_hampack",false,1]' ]
[ "$(jq -c '[.catTarget.type, .myCallsign]' "$HOME/.config/potacat/profiles/N0CALL/settings.json")" = '["rigctldnet","N0CALL"]' ]
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: already set up"* ]]
}
@test "configure leaves POTACAT's own rig unless --force, which adds and selects its own" {
configurable
echo '{"rigs": [{"id": "rig_1", "name": "FT710", "catTarget": {"type": "serial", "path": "/dev/ttyUSB3"}}], "activeRigId": "rig_1", "catTarget": {"type": "serial", "path": "/dev/ttyUSB3"}}' > "$(POTACAT_JSON)"
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: left alone: it has a radio set up already"* ]]
[ "$(jq -r .activeRigId "$(POTACAT_JSON)")" = rig_1 ]
FAKE_RUNNING=potacat run bash "$REPO/radio" configure --force
[[ "$output" == *"POTACAT: skipped, because it's running"* ]]
run bash "$REPO/radio" configure --force
[ "$(jq -c '[.activeRigId, [.rigs[].id], .catTarget.type]' "$(POTACAT_JSON)")" = '["rig_hampack",["rig_1","rig_hampack"],"rigctldnet"]' ]
}
@test "configure sets PTT to rigctld on Graywolf's transmitting channels, stopping it to do so" {
configurable
rm "$(GRAYWOLF_DB)"*
graywolf_db 1:1 2:1 3:0
"$REAL_PYTHON3" -I -c 'import sqlite3, sys
con = sqlite3.connect(sys.argv[1]); con.execute("INSERT INTO ptt_configs (channel_id, method) VALUES (2, \"none\")"); con.commit()' "$(GRAYWOLF_DB)"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"Graywolf: PTT through rigctld on 2 channels"* ]]
[ "$(qlog_query "SELECT channel_id, method, device, slot_time_ms, persist FROM ptt_configs ORDER BY channel_id" "$(GRAYWOLF_DB)")" = "$(printf '1|rigctld|127.0.0.1:4532|10|63\n2|rigctld|127.0.0.1:4532|10|63')" ]
grep -qx "systemctl stop graywolf" "$STUB_LOG"
grep -qx "systemctl start graywolf" "$STUB_LOG"
local backup
backup="$(ls "$(GRAYWOLF_DB)".bak-*)"
[ "$(qlog_query "SELECT COUNT(*) FROM ptt_configs WHERE method = 'rigctld'" "$backup")" = 0 ]
: > "$STUB_LOG"
run bash "$REPO/radio" configure
[[ "$output" == *"Graywolf: already set up"* ]]
! grep -q "systemctl stop graywolf" "$STUB_LOG"
}
@test "configure leaves Graywolf's own PTT unless --force, and says when there's no channel" {
configurable
"$REAL_PYTHON3" -I -c 'import sqlite3, sys
con = sqlite3.connect(sys.argv[1]); con.execute("INSERT INTO ptt_configs (channel_id, method, device) VALUES (1, \"cm108\", \"/dev/hidraw0\")"); con.commit()' "$(GRAYWOLF_DB)"
run bash "$REPO/radio" configure
[[ "$output" == *"Graywolf: Left 1 channel with PTT of its own alone"* ]]
! grep -q "systemctl stop graywolf" "$STUB_LOG"
run bash "$REPO/radio" configure --force
[ "$(qlog_query "SELECT method FROM ptt_configs" "$(GRAYWOLF_DB)")" = rigctld ]
rm "$(GRAYWOLF_DB)"*
graywolf_db 1:0
run bash "$REPO/radio" configure
[[ "$output" == *"Graywolf: skipped: it has no channel that transmits yet. Add one in its web UI (http://localhost:8080) with PTT rigctld, 127.0.0.1:4532"* ]]
}
@test "configure tells you what to set in Graywolf when it can't stop it" {
configurable
stub sudo 'exit 1'
run bash "$REPO/radio" configure
[[ "$output" == *"Graywolf: skipped: couldn't stop it to change its settings. Instead, in its web UI (http://localhost:8080), set each channel's PTT to rigctld, 127.0.0.1:4532"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM ptt_configs" "$(GRAYWOLF_DB)")" = 0 ]
}