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
+7 -6
View File
@@ -7,21 +7,22 @@ keeps the record. Checks that need real radios are in `TEST.md`.
Find the radios plugged into USB and set up HamPack's programs for them. Find the radios plugged into USB and set up HamPack's programs for them.
Done: `radio detect` and `radio probe`, `radios.conf`, adding you to the uucp Done: `radio detect` and `radio probe`, `radios.conf`, adding you to the uucp
group (6c76f94), and the start of `radio configure`. group (6c76f94), and `radio configure` for each of HamPack's programs that
control a radio.
- [ ] Run `TEST.md` against real radios, and mark the `radios.conf` values - [ ] Run `TEST.md` against real radios, and mark the `radios.conf` values
they confirm `# verified`. Fix or remove the ones they don't they confirm `# verified`. Fix or remove the ones they don't
- [ ] Tell Elecraft's radios apart. The K3, KX3, KX2 and K4 all answer `ID017;`, - [ ] Tell Elecraft's radios apart. The K3, KX3, KX2 and K4 all answer `ID017;`,
so `radio` lists all four. Find an Elecraft command whose reply names so `radio` lists all four. Find an Elecraft command whose reply names
the model the model
- [ ] `radio configure`, the rest. Started: it writes the rigctld user - [ ] `radio configure`, the rest. It writes the rigctld user service and
service and points WSJT-X, JS8Call, Pat, fldigi, Dire Wolf, not1mm and points WSJT-X, JS8Call, Pat, fldigi, Dire Wolf, not1mm, QLog, POTACAT
QLog at it. Still to do: and Graywolf at it. Still to do:
- [ ] POTACAT and Graywolf
- [ ] Sound cards. Each program saves its sound device under a name from - [ ] Sound cards. Each program saves its sound device under a name from
its audio backend (WSJT-X saved "pipewire" here), so find what each its audio backend (WSJT-X saved "pipewire" here), so find what each
saves for a USB codec on a real machine before writing it. Dire Wolf saves for a USB codec on a real machine before writing it. Dire Wolf
is done: it takes ALSA names is done: it takes ALSA names. Graywolf takes cpal device names, and
needs a channel with an audio device; POTACAT keeps audio per rig
- [ ] flrig can't use rigctld, so it can't run alongside it. Say so, or - [ ] flrig can't use rigctld, so it can't run alongside it. Say so, or
offer flrig as the controller instead offer flrig as the controller instead
- [ ] More than one radio at once: a rigctld for each, on its own port - [ ] More than one radio at once: a rigctld for each, on its own port
+1 -1
View File
@@ -65,7 +65,7 @@ Controlling a radio means opening its serial port, and on Arch only members of t
Probing opens the port, which raises its DTR and RTS lines for a moment before `radio` drops them. Interfaces that key the transmitter with DTR or RTS may key it briefly, so probe with the radio on a dummy load or an antenna. Probing opens the port, which raises its DTR and RTS lines for a moment before `radio` drops them. Interfaces that key the transmitter with DTR or RTS may key it briefly, so probe with the radio on a dummy load or an antenna.
`radio configure` sets up the radio for HamPack's programs. It asks the radio what it is and at what baud rate it answers. Then it runs Hamlib's rigctld for it, as the `hampack-rigctld` systemd user service on 127.0.0.1:4532, and points WSJT-X, JS8Call, Pat, fldigi, Dire Wolf, not1mm and QLog at rigctld, with PTT through it. QLog gets a rig profile named HamPack in its log, which is backed up first. Dire Wolf also gets the radio's sound card. They then share the radio through rigctld, without fighting over its serial port. Quit them first, since they save their settings when they quit. `radio configure` sets up the radio for HamPack's programs. It asks the radio what it is and at what baud rate it answers. Then it runs Hamlib's rigctld for it, as the `hampack-rigctld` systemd user service on 127.0.0.1:4532, and points WSJT-X, JS8Call, Pat, fldigi, Dire Wolf, not1mm, QLog, POTACAT and Graywolf at rigctld, with PTT through it. QLog gets a rig profile named HamPack in its log, which is backed up first. Graywolf's channels that transmit get PTT through rigctld; it's stopped for that with sudo, and started again. Dire Wolf also gets the radio's sound card. They then share the radio through rigctld, without fighting over its serial port. Quit them first, since they save their settings when they quit.
`radio configure` only fills in rig settings you haven't set. `radio configure --force` replaces them, and every file it changes is backed up first. With more than one radio plugged in, give the number `radio` lists for it: `radio configure 2`. For a radio it can't tell apart from others, give its Hamlib model number: `radio configure --model 2045`. Choose the radio's sound card in the other programs yourself; `radio configure` says which it is. `radio configure` only fills in rig settings you haven't set. `radio configure --force` replaces them, and every file it changes is backed up first. With more than one radio plugged in, give the number `radio` lists for it: `radio configure 2`. For a radio it can't tell apart from others, give its Hamlib model number: `radio configure --model 2045`. Choose the radio's sound card in the other programs yourself; `radio configure` says which it is.
+15 -7
View File
@@ -46,7 +46,7 @@ cable.
## radio configure ## radio configure
With the radio on a dummy load or an antenna, and WSJT-X, JS8Call, Pat, fldigi, With the radio on a dummy load or an antenna, and WSJT-X, JS8Call, Pat, fldigi,
Dire Wolf, not1mm and QLog quit: Dire Wolf, not1mm, QLog and POTACAT quit:
1. Run `radio configure`. It should name the radio, its by-id port and a baud 1. Run `radio configure`. It should name the radio, its by-id port and a baud
rate, and say what it did for each program. rate, and say what it did for each program.
@@ -76,16 +76,24 @@ Dire Wolf, not1mm and QLog quit:
written straight into QLog's log, with the values QLog 0.54.2's own form written straight into QLog's log, with the values QLog 0.54.2's own form
gives a new profile, so check that QLog shows and saves it without gives a new profile, so check that QLog shows and saves it without
complaint, and that your QSOs are all still there. complaint, and that your QSOs are all still there.
10. Run `radio configure` again: each program is "already set up", and 10. Open POTACAT (after running it once). My Rigs has "... (HamPack's
rigctld)" as a rigctld Network rig at 127.0.0.1:4532, it's the active rig,
and the frequency follows the radio. If you have an operator profile, check
POTACAT doesn't say the connection belongs to another rig.
11. In Graywolf's web UI, add a channel with the radio's sound card, then run
`radio configure` (it asks for sudo to stop Graywolf). The channel's PTT
is rigctld, 127.0.0.1:4532, Graywolf is running again, and "Test rigctld"
in its PTT page passes. Send a beacon and check it keys the radio.
12. Run `radio configure` again: each program is "already set up", and
rigctld restarts. rigctld restarts.
11. With a rig set by hand in WSJT-X, `radio configure` leaves it alone, and 13. With a rig set by hand in WSJT-X, `radio configure` leaves it alone, and
`--force` replaces it. The `.bak-` copy has the old settings. `--force` replaces it. The `.bak-` copy has the old settings.
12. Unplug the radio, plug it in again, and check rigctld reconnects within 14. Unplug the radio, plug it in again, and check rigctld reconnects within
a few seconds. Reboot and check it starts at login. a few seconds. Reboot and check it starts at login.
| Date | Commit | Radio | rigctld | WSJT-X | JS8Call | Pat | fldigi | Dire Wolf | not1mm | QLog | Notes | | Date | Commit | Radio | rigctld | WSJT-X | JS8Call | Pat | fldigi | Dire Wolf | not1mm | QLog | POTACAT | Graywolf | Notes |
|------|--------|-------|---------|--------|---------|-----|--------|-----------|--------|------|-------| |------|--------|-------|---------|--------|---------|-----|--------|-----------|--------|------|---------|----------|-------|
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
## Pairing radios with sound cards ## Pairing radios with sound cards
+168 -2
View File
@@ -33,6 +33,8 @@ FLDIGI_CONF="$HOME/.fldigi/fldigi_def.xml"
NOT1MM_CONF="$CONFIG_HOME/not1mm/not1mm.json" NOT1MM_CONF="$CONFIG_HOME/not1mm/not1mm.json"
QLOG_FLATPAK=io.github.foldynl.QLog QLOG_FLATPAK=io.github.foldynl.QLog
QLOG_DB="$HOME/.var/app/$QLOG_FLATPAK/data/hamradio/QLog/qlog.db" QLOG_DB="$HOME/.var/app/$QLOG_FLATPAK/data/hamradio/QLog/qlog.db"
POTACAT_DIR="$CONFIG_HOME/potacat"
GRAYWOLF_DB="$HOME/.local/share/graywolf/graywolf.db"
DIREWOLF_CONF="$HAMPACK_STATE/conf.d/direwolf.conf" DIREWOLF_CONF="$HAMPACK_STATE/conf.d/direwolf.conf"
# What HamPack's conf.d/direwolf.conf ships with, which configure replaces # What HamPack's conf.d/direwolf.conf ships with, which configure replaces
DIREWOLF_DEFAULT_ADEVICE="plughw:0,0" DIREWOLF_DEFAULT_ADEVICE="plughw:0,0"
@@ -54,8 +56,8 @@ Usage: radio [detect] [--probe]
probe PORT Ask the radio on serial port PORT what it is probe PORT Ask the radio on serial port PORT what it is
configure Set up the radio (if there's more than one, give its number configure Set up the radio (if there's more than one, give its number
from \`radio\`): run rigctld for it as a systemd user service, from \`radio\`): run rigctld for it as a systemd user service,
and point WSJT-X, JS8Call, Pat, fldigi, Dire Wolf, not1mm and point WSJT-X, JS8Call, Pat, fldigi, Dire Wolf, not1mm,
and QLog at rigctld. Only changes QLog, POTACAT and Graywolf at rigctld. Only changes
settings you haven't set, and backs up each file it changes. settings you haven't set, and backs up each file it changes.
Quit those programs first Quit those programs first
--force Replace rig settings you've set yourself --force Replace rig settings you've set yourself
@@ -826,6 +828,168 @@ configure_qlog() {
esac esac
} }
# POTACAT: add rigctld to My Rigs as a "rigctld Network" rig, and make it the
# active one, unless rigs are set up already. Rigs and the active rig are kept
# in settings.json; the connection (catTarget) is too, until there's an
# operator profile, which then keeps it in profiles/CALL/settings.json.
# configure_potacat NAME
configure_potacat() {
local global="$POTACAT_DIR/settings.json" profile cat_file state tmp target
target="$(jq -nc --arg host "${RIGCTLD_ADDR%:*}" --argjson port "${RIGCTLD_ADDR#*:}" '{type: "rigctldnet", host: $host, port: $port}')"
if [ ! -x "$HOME/.local/bin/POTACAT.AppImage" ]; then
report POTACAT "not installed"
return
fi
if [ ! -f "$global" ]; then
report POTACAT "skipped: it has no settings yet. Run POTACAT once, then \`radio configure\` again"
return
fi
if running potacat; then
report POTACAT "skipped, because it's running and would overwrite its settings when it quits. Quit it and run \`radio configure\` again"
return
fi
profile="$(jq -r 'if .activeProfile and (has("catTarget") | not) then .activeProfile else "" end' "$global")" ||
{ report POTACAT "couldn't read $global"; return 1; }
cat_file="$global"
[ -z "$profile" ] || cat_file="$POTACAT_DIR/profiles/$profile/settings.json"
local current active rigs
current="$(jq -c '.catTarget // null' "$cat_file" 2> /dev/null || echo null)"
if ! { active="$(jq -r '.activeRigId // ""' "$global")" && rigs="$(jq '.rigs // [] | length' "$global")"; }; then
report POTACAT "couldn't read $global"
return 1
fi
if [ "$active" = rig_hampack ] && jq -en --argjson a "$current" --argjson b "$target" '$a == $b' > /dev/null; then
state="already"
elif (( rigs > 0 )) || [ "$current" != null ]; then
state="theirs"
else
state="empty"
fi
case "$state" in
already) report POTACAT "already set up"; return ;;
theirs)
if (( ! FORCE )); then
report POTACAT "left alone: it has a radio set up already. \`radio configure --force\` adds rigctld to My Rigs and makes it active"
return
fi ;;
esac
back_up "$global"
tmp="$(mktemp "$global.XXXXXX")" || return 1
if ! jq --argjson t "$target" --arg name "$1 (HamPack's rigctld)" --arg cat "$cat_file" --arg global "$global" '
.rigs = ([(.rigs // [])[] | select(.id != "rig_hampack")] + [{id: "rig_hampack", name: $name, catTarget: $t}])
| .activeRigId = "rig_hampack"
| if $cat == $global then .catTarget = $t else . end
' "$global" > "$tmp" || ! chmod --reference="$global" "$tmp" || ! mv -f "$tmp" "$global"; then
rm -f "$tmp"
report POTACAT "couldn't change $global"
return 1
fi
if [ "$cat_file" != "$global" ]; then
back_up "$cat_file"
mkdir -p "$(dirname "$cat_file")" && { [ -f "$cat_file" ] || echo '{}' > "$cat_file"; } || return 1
tmp="$(mktemp "$cat_file.XXXXXX")" || return 1
if ! jq --argjson t "$target" '.catTarget = $t' "$cat_file" > "$tmp" || ! chmod --reference="$cat_file" "$tmp" || ! mv -f "$tmp" "$cat_file"; then
rm -f "$tmp"
report POTACAT "couldn't change $cat_file"
return 1
fi
fi
report POTACAT "rig \"$1 (HamPack's rigctld)\" is rigctld, and active"
}
# Graywolf keeps its settings in graywolf.db, with PTT set per channel. Set
# PTT to rigctld on each channel that can transmit and has none (or, with
# --force, any other). graywolf_ptt check|BACKUP prints the number of
# channels to change (or changed), then the number left alone, or "none"
# with no channel that transmits, or the error. With BACKUP, it makes the
# changes, backing up the database through SQLite first, which includes
# what's still in graywolf.db-wal.
graywolf_ptt() {
python3 -I -c '
import datetime, sqlite3, sys
db, backup, addr, force = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4] == "1"
try:
con = sqlite3.connect(db)
channels = [row[0] for row in con.execute("SELECT id FROM channels WHERE output_device_id != 0 ORDER BY id")]
if not channels:
print("none")
sys.exit(0)
ptt = {row[0]: (row[1], row[2]) for row in con.execute("SELECT channel_id, method, device FROM ptt_configs")}
change, kept = [], 0
for channel in channels:
method, device = ptt.get(channel, ("none", ""))
if (method, device) == ("rigctld", addr):
continue
if method in ("none", "") or force:
change.append(channel)
else:
kept += 1
if change and backup != "check":
copy = sqlite3.connect(backup)
con.backup(copy)
copy.close()
now = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S.%f+00:00")
with con:
for channel in change:
if channel in ptt:
con.execute("UPDATE ptt_configs SET method = ?, device = ?, updated_at = ? WHERE channel_id = ?",
("rigctld", addr, now, channel))
else:
con.execute("INSERT INTO ptt_configs (channel_id, method, device, gpio_pin, ptt_method, gpio_line, "
"invert, slot_time_ms, persist, dwait_ms, created_at, updated_at) "
"VALUES (?, ?, ?, 0, 0, 0, 0, 10, 63, 0, ?, ?)", (channel, "rigctld", addr, now, now))
print(len(change), kept)
except (sqlite3.Error, OSError) as e:
print(e)
' "$GRAYWOLF_DB" "$1" "$RIGCTLD_ADDR" "$FORCE"
}
configure_graywolf() {
local result changed kept backup was_active=0 web="http://localhost:8080"
local manual="in its web UI ($web), set each channel's PTT to rigctld, $RIGCTLD_ADDR"
if [ ! -x "$HOME/.local/bin/graywolf" ]; then
report Graywolf "not installed"
return
fi
if [ ! -f "$GRAYWOLF_DB" ]; then
report Graywolf "skipped: it has no settings yet. Open its web UI ($web) once, then \`radio configure\` again"
return
fi
result="$(graywolf_ptt check)"
read -r changed kept <<< "$result"
if [[ "$changed" =~ ^[1-9][0-9]*$ ]]; then
# It runs as a system service, and reads its settings when it starts
if systemctl is-active --quiet graywolf 2> /dev/null; then
if ! sudo systemctl stop graywolf; then
report Graywolf "skipped: couldn't stop it to change its settings. Instead, $manual"
return
fi
was_active=1
fi
backup="$GRAYWOLF_DB.bak-$(date +%Y%m%d-%H%M%S)"
result="$(graywolf_ptt "$backup")"
(( ! was_active )) || sudo systemctl start graywolf
read -r changed kept <<< "$result"
fi
if [ "$changed" = none ]; then
report Graywolf "skipped: it has no channel that transmits yet. Add one in its web UI ($web) with PTT rigctld, $RIGCTLD_ADDR"
elif ! [[ "$changed" =~ ^[0-9]+$ ]]; then
report Graywolf "couldn't change $GRAYWOLF_DB: $result"
return 1
elif (( changed == 0 && kept == 0 )); then
report Graywolf "already set up"
else
(( changed == 0 )) || BACKUPS+=("$backup")
local message=""
(( changed == 0 )) || message="PTT through rigctld on $changed channel$( ((changed == 1)) || echo s)"
(( kept == 0 )) ||
message="${message:+$message. }Left $kept channel$( ((kept == 1)) || echo s) with PTT of its own alone: \`radio configure --force\` replaces it"
report Graywolf "$message"
fi
}
# Write and (re)start rigctld's user service: write_rigctld NAME HAMLIB PORT BAUD # Write and (re)start rigctld's user service: write_rigctld NAME HAMLIB PORT BAUD
write_rigctld() { write_rigctld() {
local unit local unit
@@ -946,6 +1110,8 @@ configure() {
configure_direwolf "$card" configure_direwolf "$card"
configure_not1mm configure_not1mm
configure_qlog configure_qlog
configure_potacat "$name"
configure_graywolf
mkdir -p "$HAMPACK_STATE" && mkdir -p "$HAMPACK_STATE" &&
printf 'name=%s\nhamlib=%s\nport=%s\nbaud=%s\ncard=%s\n' "$name" "$model" "$port" "$baud" "$card" > "$HAMPACK_STATE/radio" printf 'name=%s\nhamlib=%s\nport=%s\nbaud=%s\ncard=%s\n' "$name" "$model" "$port" "$baud" "$card" > "$HAMPACK_STATE/radio"
+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" 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" touch "$FAKE_FLATPAKS/io.github.foldynl.QLog"
qlog_log 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"; } FLDIGI_XML() { echo "$HOME/.fldigi/fldigi_def.xml"; }
@@ -385,6 +390,31 @@ con.close()
PY 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 qlog_query() { "$REAL_PYTHON3" -I -c 'import sqlite3, sys
con = sqlite3.connect(sys.argv[1]) con = sqlite3.connect(sys.argv[1])
for row in con.execute(sys.argv[2]): print("|".join(map(str, row))) 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"* ]] [[ "$output" == *"QLog: skipped, because it's running"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM rig_profiles")" = 0 ] [ "$(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 ]
}