Point not1mm and QLog at rigctld in radio configure

not1mm gets rigctld at 127.0.0.1:4532, with flrig and TCI off, unless it
has rig control set up already.

QLog keeps rig profiles in its log database, so it gets a "HamPack"
profile there (Hamlib NET rigctl, 127.0.0.1:4532), selected, with the
values QLog 0.54.2's own form gives a new profile. It's added only if
there are no profiles yet, or with --force, and only when QLog isn't
running and its log has the columns it needs. The log is backed up first
through SQLite, so the backup includes what's still in qlog.db-wal.

The probe tests' python3 stub now fakes only the probe, so QLog's step
runs against a real SQLite log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 12:43:27 -07:00
co-authored by Claude Opus 5.5
parent a02fa0cc85
commit 892bfb9df0
5 changed files with 274 additions and 18 deletions
+123 -2
View File
@@ -13,6 +13,8 @@ setup() {
export RADIO_LOCKDIR="$BATS_TEST_TMPDIR/lock"
export FAKE_RADIOS="$BATS_TEST_TMPDIR/radios"
ROOT_HUB="$RADIO_SYSFS/devices/pci0000:00/0000:00:14.0/usb1"
REAL_PYTHON3="$(command -v python3)"
export REAL_PYTHON3
mkdir -p "$ROOT_HUB" "$RADIO_SYSFS/class/tty" "$RADIO_SYSFS/class/sound" \
"$RADIO_DEV/serial/by-id" "$RADIO_PROC" "$RADIO_LOCKDIR" "$FAKE_RADIOS"
}
@@ -74,7 +76,12 @@ yaesu() {
# The radio on a port answers the probe with ANSWER ("38400 cat_id 0670")
answers() {
echo "$2" > "$FAKE_RADIOS/$1"
stub python3 'f="$FAKE_RADIOS/${4##*/}"; [ -f "$f" ] && cat "$f"; exit 0'
# Only the probe is faked; other Python (QLog's log) runs for real
stub python3 '
case "$3" in
*TIOCMBIC*) f="$FAKE_RADIOS/${4##*/}"; [ -f "$f" ] && cat "$f"; exit 0 ;;
esac
exec "$REAL_PYTHON3" "$@"'
}
@test "recognises an Icom by its USB serial number, with its port and sound card" {
@@ -339,9 +346,49 @@ JSON
chmod +x "$HOME/.local/bin/direwolf"
mkdir -p "$HAMPACK_STATE/conf.d"
cp "$REPO/conf.d/direwolf.conf" "$HAMPACK_STATE/conf.d/"
touch "$HOME/.local/bin/not1mm"
chmod +x "$HOME/.local/bin/not1mm"
mkdir -p "$HOME/.config/not1mm"
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
}
FLDIGI_XML() { echo "$HOME/.fldigi/fldigi_def.xml"; }
NOT1MM_JSON() { echo "$HOME/.config/not1mm/not1mm.json"; }
QLOG_DB() { echo "$HOME/.var/app/io.github.foldynl.QLog/data/hamradio/QLog/qlog.db"; }
# QLog's log, with rig_profiles as QLog 0.54 has it, and a QSO to show the
# rest of the log is untouched. qlog_log [old] leaves out the newest column
qlog_log() {
mkdir -p "$(dirname "$(QLOG_DB)")"
"$REAL_PYTHON3" -I - "$(QLOG_DB)" "${1:-}" << 'PY'
import sqlite3, sys
columns = ("profile_name TEXT PRIMARY KEY, model NUMBER NOT NULL, port_pathname TEXT, hostname TEXT, "
"netport NUMBER, baudrate NUMBER, databits NUMBER, stopbits REAL, flowcontrol TEXT, parity TEXT, "
"pollinterval INTEGER, txfreq_start REAL, txfreq_end REAL, get_freq INTEGER, get_mode INTEGER, "
"get_vfo INTEGER, get_pwr INTEGER, rit_offset REAL, xit_offset REAL, get_rit INTEGER, get_xit INTEGER, "
"get_ptt INTEGER DEFAULT 0, default_pwr REAL DEFAULT 100.0, qsy_wiping INTEGER DEFAULT 0, "
"get_key_speed INTEGER DEFAULT 1, assigned_cw_key TEXT DEFAULT ' ', key_speed_sync INTEGER DEFAULT 0, "
"dxspot2rig INTEGER DEFAULT 0, driver INTEGER DEFAULT 0, selected INTEGER, ptt_type TEXT, "
"ptt_port_pathname TEXT, rts TEXT, dtr TEXT, civaddr INTEGER, get_split INTEGER DEFAULT 0, "
"share_rigctld INTEGER DEFAULT 0, rigctld_port INTEGER DEFAULT 4532, rigctld_path TEXT, rigctld_args TEXT")
if sys.argv[2] != "old":
columns += ", cwkey_output INTEGER DEFAULT 0"
con = sqlite3.connect(sys.argv[1])
con.execute("PRAGMA journal_mode = WAL")
con.execute("CREATE TABLE rig_profiles (%s)" % columns)
con.execute("CREATE TABLE contacts (callsign TEXT)")
con.execute("INSERT INTO contacts VALUES ('W1AW')")
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)))
con.commit()' "${2:-$(QLOG_DB)}" "$1"; }
DIREWOLF_CONF() { echo "$HAMPACK_STATE/conf.d/direwolf.conf"; }
@test "configure runs rigctld for the radio on its stable port, at the rate it answered" {
@@ -353,7 +400,7 @@ DIREWOLF_CONF() { echo "$HAMPACK_STATE/conf.d/direwolf.conf"; }
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\""* ]]
[[ "$output" == *"Choose the radio's sound card in the other programs yourself: hw:CARD=CODEC, \"USB Audio CODEC\""* ]]
grep -qx "hamlib=3073" "$HAMPACK_STATE/radio"
grep -qx "card=hw:CARD=CODEC" "$HAMPACK_STATE/radio"
}
@@ -567,3 +614,77 @@ DIREWOLF_CONF() { echo "$HAMPACK_STATE/conf.d/direwolf.conf"; }
[[ "$output" == *"Dire Wolf: PTT through rigctld"* ]]
grep -qx "ADEVICE plughw:0,0" "$(DIREWOLF_CONF)"
}
@test "configure points not1mm at rigctld" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"not1mm: rig control through rigctld"* ]]
[ "$(jq -c '[.userigctld, .useflrig, .usetci, .CAT_ip, .CAT_port, .mycall]' "$(NOT1MM_JSON)")" = '[true,false,false,"127.0.0.1",4532,"N0CALL"]' ]
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: already set up"* ]]
}
@test "configure leaves not1mm on flrig unless --force, and skips it while it runs" {
configurable
jq '.useflrig = true' "$(NOT1MM_JSON)" > "$BATS_TEST_TMPDIR/n.json" && mv "$BATS_TEST_TMPDIR/n.json" "$(NOT1MM_JSON)"
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: left alone: it has rig control set up already"* ]]
[ "$(jq .useflrig "$(NOT1MM_JSON)")" = true ]
FAKE_RUNNING=not1mm run bash "$REPO/radio" configure --force
[[ "$output" == *"not1mm: skipped, because it's running"* ]]
[ "$(jq .useflrig "$(NOT1MM_JSON)")" = true ]
run bash "$REPO/radio" configure --force
[ "$(jq -c '[.userigctld, .useflrig]' "$(NOT1MM_JSON)")" = '[true,false]' ]
}
@test "configure adds and selects a rigctld profile in QLog, backing up the log first" {
configurable
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "$output" == *"QLog: rig profile \"HamPack\" is rigctld, and selected"* ]]
[ "$(qlog_query "SELECT profile_name, driver, model, hostname, netport, selected, get_freq, pollinterval FROM rig_profiles")" = "HamPack|1|2|127.0.0.1|4532|1|1|500" ]
[ "$(qlog_query "SELECT callsign FROM contacts")" = W1AW ]
# The backup is the log as it was
local backup
backup="$(ls "$(QLOG_DB)".bak-*)"
[ "$(qlog_query "SELECT COUNT(*) FROM rig_profiles" "$backup")" = 0 ]
[ "$(qlog_query "SELECT callsign FROM contacts" "$backup")" = W1AW ]
run bash "$REPO/radio" configure
[[ "$output" == *"QLog: already set up"* ]]
[ "$(ls "$(QLOG_DB)".bak-* | wc -l)" -eq 1 ]
}
@test "configure leaves QLog's own rig profiles unless --force, which selects its own" {
configurable
qlog_query "INSERT INTO rig_profiles (profile_name, model, driver, port_pathname, selected) VALUES ('IC-7300', 3073, 1, '/dev/ttyUSB0', 1)" > /dev/null
run bash "$REPO/radio" configure
[[ "$output" == *"QLog: left alone: it has rig profiles already"* ]]
[ "$(qlog_query "SELECT profile_name FROM rig_profiles")" = "IC-7300" ]
! ls "$(QLOG_DB)".bak-* 2> /dev/null
run bash "$REPO/radio" configure --force
[ "$(qlog_query "SELECT profile_name, selected FROM rig_profiles ORDER BY profile_name")" = "$(printf 'HamPack|1\nIC-7300|0')" ]
}
@test "configure skips QLog when its log is missing, older than it knows, or QLog is running" {
configurable
rm "$(QLOG_DB)"
run bash "$REPO/radio" configure
[[ "$output" == *"QLog: skipped: it has no log yet. Run QLog once"* ]]
qlog_log old
run bash "$REPO/radio" configure
[[ "$output" == *"QLog: skipped: its log is older than this radio knows"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM rig_profiles")" = 0 ]
rm "$(QLOG_DB)"*
qlog_log
FAKE_RUNNING=qlog run bash "$REPO/radio" configure
[[ "$output" == *"QLog: skipped, because it's running"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM rig_profiles")" = 0 ]
}