Set not1mm's sound card in radio configure

not1mm's voice keyer gets the radio's sound card, named exactly as the
sounddevice library in not1mm's own Python lists it: its settings dialog
finds the device by exact name, and falls back to the first one listed.
PipeWire's name for the card, through PortAudio's JACK support, comes
first, since it stays the same from boot to boot. Without it, or with two
cards of the same name, it's ALSA's, which has the card's number in it;
a number radio wrote before is updated when the card's number changes.

The closing message now leaves only fldigi and POTACAT for you to set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 13:11:16 -07:00
co-authored by Claude Opus 5.5
parent 4053664d77
commit c2cb2bc2f4
5 changed files with 168 additions and 43 deletions
+7 -6
View File
@@ -18,12 +18,13 @@ control a radio.
- [ ] `radio configure`, the rest. It writes the rigctld user service and
points WSJT-X, JS8Call, Pat, fldigi, Dire Wolf, not1mm, QLog, POTACAT
and Graywolf at it. Still to do:
- [ ] Sound cards for fldigi, not1mm and POTACAT. fldigi (PortAudio) and
not1mm (sounddevice) name a card with its number, as in
"USB Audio CODEC: - (hw:1,0)", which can change between boots; a
sounddevice name can match part of a name, so not1mm might take
"USB Audio CODEC". POTACAT keeps browser device ids, which only it
can see. WSJT-X, JS8Call, Dire Wolf and Graywolf are done
- [ ] Sound cards for fldigi and POTACAT. fldigi (PortAudio) names a card
with its number, as in "USB Audio Device: - (hw:3,0)", which can
change between boots. PortAudio also lists PipeWire's devices through
JACK under stable names, as not1mm now uses; check whether fldigi's
PortAudio list includes them. POTACAT keeps browser device ids, which
only it can see. WSJT-X, JS8Call, Dire Wolf, Graywolf and not1mm are
done
- [ ] flrig can't use rigctld, so it can't run alongside it. Say so, or
offer flrig as the controller instead
- [ ] More than one radio at once: a rigctld for each, on its own port
+2 -2
View File
@@ -67,9 +67,9 @@ Probing opens the port, which raises its DTR and RTS lines for a moment before `
`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. They then share the radio through rigctld, without fighting over its serial port. Quit them first, since they save their settings when they quit.
It also gives WSJT-X, JS8Call and Dire Wolf the radio's sound card. WSJT-X and JS8Call get it as PipeWire names it, so PipeWire must be running. If Graywolf has no channels yet, it gets one on the radio's sound card, for 1200 baud APRS.
It also gives WSJT-X, JS8Call, Dire Wolf and not1mm's voice keyer the radio's sound card. WSJT-X and JS8Call get it as PipeWire names it, so PipeWire must be running. not1mm gets PipeWire's name for it too where it can, since ALSA's name for it has a card number that can change between boots; if it does, run `radio configure` again. If Graywolf has no channels yet, it gets one on the radio's sound card, for 1200 baud APRS.
`radio configure` only fills in rig and sound settings you haven't set (a sound device of "default" or "pipewire" counts as not 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 yourself in fldigi, not1mm and POTACAT; `radio configure` says which it is.
`radio configure` only fills in rig and sound settings you haven't set (a sound device of "default" or "pipewire" counts as not 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 yourself in fldigi and POTACAT; `radio configure` says which it is.
The radios it knows are in `radios.conf`. If your radio isn't recognised, or answers with something `radio` doesn't know, please open an issue with what `radio detect --probe` printed.
+6 -1
View File
@@ -73,7 +73,12 @@ Dire Wolf, not1mm, QLog and POTACAT quit:
"PTT RIG 2 127.0.0.1:4532". If it says RIG needs hamlib support, its
build didn't find Hamlib. Send a beacon and check it keys the radio.
8. Open not1mm (after running it once). Its settings show rigctld at
127.0.0.1:4532, and the frequency follows the radio.
127.0.0.1:4532, and the frequency follows the radio. Its sound device is
the radio's card, by PipeWire's name ("... Analog Stereo") if PipeWire's
JACK support is installed, or else ALSA's ("...: USB Audio (hw:N,0)").
Open and OK its settings dialog, and check the sound device is still the
radio's afterwards. In a phone contest, a voice macro keys the radio and
plays through it.
9. Open QLog (after running it once, so it has a log). Settings > Equipment >
Rig has a "HamPack" profile (Hamlib, NET rigctl, 127.0.0.1:4532), it's the
one selected, and connecting shows the radio's frequency. The profile was
+78 -25
View File
@@ -779,10 +779,42 @@ configure_direwolf() {
report "Dire Wolf" "$message"
}
# Print the output devices not1mm can play to, as "NAME<tab>HOST API", one to
# a line, using the sounddevice library in not1mm's own Python
not1mm_outputs() {
local python="${UV_TOOL_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/uv/tools}/not1mm/bin/python"
[ -x "$python" ] || return 1
"$python" -I -c '
import sounddevice as sd
for d in sd.query_devices():
if d["max_output_channels"] > 0:
print(d["name"] + "\t" + sd.query_hostapis(d["hostapi"])["name"])
' 2> /dev/null
}
# Print the name not1mm's voice keyer should use for the radio's sound card:
# PipeWire's description of it, through PortAudio's JACK support, which stays
# the same from boot to boot. Failing that, ALSA's name for it, which has the
# card's number in it: "USB Audio CODEC: USB Audio (hw:1,0)".
# not1mm_device CARD_NUMBER
not1mm_device() {
local outputs
outputs="$(not1mm_outputs)" || return 1
if [ -n "$PW_OUT_DESC" ] && [ "$(cut -f1 <<< "$outputs" | grep -cxF "$PW_OUT_DESC")" -eq 1 ]; then
echo "$PW_OUT_DESC"
elif [ -n "$1" ]; then
cut -f1 <<< "$outputs" | grep -F "(hw:$1," | head -1 | grep .
else
return 1
fi
}
# not1mm: rig control through rigctld, unless it uses flrig, TCI or another
# rigctld already
# rigctld already, and the radio's sound card for its voice keyer.
# configure_not1mm CARD_NUMBER
configure_not1mm() {
local tmp
local tmp rig_state device current set_rig=0 set_sound=0
SAID=() LEFT=()
if [ ! -x "$HOME/.local/bin/not1mm" ]; then
report not1mm "not installed"
return
@@ -795,34 +827,55 @@ configure_not1mm() {
report not1mm "skipped, because it's running and would overwrite its settings when it quits. Quit it and run \`radio configure\` again"
return
fi
case "$(jq -r --arg addr "$RIGCTLD_ADDR" '
if .userigctld == true and "\(.CAT_ip):\(.CAT_port)" == $addr then "done"
elif .userigctld == true or .useflrig == true or .usetci == true then "set"
else "unset" end' "$NOT1MM_CONF")" in
done)
report not1mm "already set up"
return ;;
set)
if (( ! FORCE )); then
report not1mm "left alone: it has rig control set up already. \`radio configure --force\` replaces that"
return
rig_state="$(jq -r --arg addr "$RIGCTLD_ADDR" '
if .userigctld == true and "\(.CAT_ip):\(.CAT_port)" == $addr then "already"
elif .userigctld == true or .useflrig == true or .usetci == true then "theirs"
else "empty" end' "$NOT1MM_CONF")" ||
{ report not1mm "couldn't read $NOT1MM_CONF"; return 1; }
case "$rig_state" in
already) ;;
theirs)
if (( FORCE )); then
set_rig=1
else
LEFT+=("its rig control")
fi ;;
unset) ;;
*)
report not1mm "couldn't read $NOT1MM_CONF"
return 1 ;;
*) set_rig=1 ;;
esac
(( ! set_rig )) || SAID+=("rig control through rigctld")
if [ -n "$1" ]; then
if device="$(not1mm_device "$1")"; then
current="$(jq -r '.sounddevice // ""' "$NOT1MM_CONF")"
if [ "$current" = "$device" ]; then
:
elif is_default_device "$current" || (( FORCE )) ||
# The same card under the number it had before
{ [[ "$device" == *"(hw:"* ]] && [[ "$current" == "${device%(hw:*}(hw:"*")" ]]; }; then
set_sound=1
SAID+=("voice keyer on \"$device\"")
else
LEFT+=("its sound card ($current)")
fi
else
SAID+=("choose its sound card yourself: its sounddevice library doesn't list the radio's")
fi
fi
if (( set_rig || set_sound )); then
back_up "$NOT1MM_CONF"
tmp="$(mktemp "$NOT1MM_CONF.XXXXXX")" || return 1
if jq --arg ip "${RIGCTLD_ADDR%:*}" --argjson port "${RIGCTLD_ADDR#*:}" '
.userigctld = true | .useflrig = false | .usetci = false | .CAT_ip = $ip | .CAT_port = $port
' "$NOT1MM_CONF" > "$tmp" && chmod --reference="$NOT1MM_CONF" "$tmp" && mv -f "$tmp" "$NOT1MM_CONF"; then
report not1mm "rig control through rigctld"
else
if ! jq --arg ip "${RIGCTLD_ADDR%:*}" --argjson port "${RIGCTLD_ADDR#*:}" --arg device "${device:-}" \
--argjson rig "$set_rig" --argjson sound "$set_sound" '
(if $rig == 1 then .userigctld = true | .useflrig = false | .usetci = false | .CAT_ip = $ip | .CAT_port = $port else . end)
| (if $sound == 1 then .sounddevice = $device else . end)
' "$NOT1MM_CONF" > "$tmp" || ! chmod --reference="$NOT1MM_CONF" "$tmp" || ! mv -f "$tmp" "$NOT1MM_CONF"; then
rm -f "$tmp"
report not1mm "couldn't change $NOT1MM_CONF"
return 1
fi
fi
say_changes not1mm
}
# QLog keeps its rig profiles in its log database. Add a "HamPack" profile for
@@ -1205,7 +1258,7 @@ configure() {
configure_pat
configure_fldigi
configure_direwolf "$card"
configure_not1mm
configure_not1mm "$card_number"
configure_qlog
configure_potacat "$name"
configure_graywolf "$card" "$name"
@@ -1217,9 +1270,9 @@ configure() {
if [ -z "$card" ]; then
echo "No sound card was found with the radio: choose the one it's connected to in each program yourself."
elif (( pipewire )); then
echo "Choose the radio's sound card yourself in fldigi, not1mm and POTACAT, which name it in ways radio can't: it's \"$PW_OUT_DESC\" ($card)."
echo "Choose the radio's sound card yourself in fldigi and POTACAT, which name it in ways radio can't: it's \"$PW_OUT_DESC\" ($card)."
else
echo "PipeWire didn't list the radio's sound card, $card (\"$(attr "${CARD_USB[$(card_of "$radio")]}" product)\"), so choose it yourself in WSJT-X, JS8Call, fldigi, not1mm and POTACAT."
echo "PipeWire didn't list the radio's sound card, $card (\"$(attr "${CARD_USB[$(card_of "$radio")]}" product)\"), so choose it yourself in WSJT-X, JS8Call, fldigi and POTACAT."
fi
[ ${#BACKUPS[@]} -eq 0 ] || { echo "The settings were backed up first, to:"; printf ' %s\n' "${BACKUPS[@]}"; }
}
+70 -4
View File
@@ -15,6 +15,7 @@ setup() {
ROOT_HUB="$RADIO_SYSFS/devices/pci0000:00/0000:00:14.0/usb1"
REAL_PYTHON3="$(command -v python3)"
export REAL_PYTHON3
unset XDG_DATA_HOME XDG_CONFIG_HOME UV_TOOL_DIR
# PipeWire's sources and sinks, as `pactl -f json list` prints them: none
# unless a test calls pipewire_card
stub pactl '[ -f "$FAKE_RADIOS/pw-$4" ] && cat "$FAKE_RADIOS/pw-$4" || echo "[]"'
@@ -92,6 +93,18 @@ pipewire_card() {
properties: {"alsa.card": $n, "device.class": "sound"}}]' > "$FAKE_RADIOS/pw-sinks"
}
# The output devices not1mm's sounddevice lists: sd_outputs NAME... Names
# with (hw:...) are ALSA's; the rest are JACK's, except ALSA's pipewire and default
sd_outputs() {
local name
for name; do
case "$name" in
*"(hw:"* | pipewire | default) printf '%s\tALSA\n' "$name" ;;
*) printf '%s\tJACK Audio Connection Kit\n' "$name" ;;
esac
done > "$FAKE_RADIOS/sd-outputs"
}
# The radio on a port answers the probe with ANSWER ("38400 cat_id 0670")
answers() {
echo "$2" > "$FAKE_RADIOS/$1"
@@ -368,7 +381,12 @@ JSON
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"
echo '{"mycall": "N0CALL", "userigctld": false, "useflrig": false, "usetci": false, "CAT_ip": "127.0.0.1", "CAT_port": 12345, "sounddevice": "default"}' > "$HOME/.config/not1mm/not1mm.json"
# not1mm's Python, whose sounddevice lists the outputs in $FAKE_RADIOS/sd-outputs
mkdir -p "$HOME/.local/share/uv/tools/not1mm/bin"
printf '#!/bin/bash\ncat "$FAKE_RADIOS/sd-outputs" 2> /dev/null\n' > "$HOME/.local/share/uv/tools/not1mm/bin/python"
chmod +x "$HOME/.local/share/uv/tools/not1mm/bin/python"
sd_outputs "HD-Audio Generic: ALC897 Analog (hw:0,0)" "USB Audio CODEC: USB Audio (hw:1,0)" pipewire default
touch "$FAKE_FLATPAKS/io.github.foldynl.QLog"
qlog_log
touch "$HOME/.local/bin/POTACAT.AppImage" "$HOME/.local/bin/graywolf"
@@ -454,7 +472,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" == *"PipeWire didn't list the radio's sound card, hw:CARD=CODEC (\"USB Audio CODEC\"), so choose it yourself in WSJT-X, JS8Call, fldigi, not1mm and POTACAT."* ]]
[[ "$output" == *"PipeWire didn't list the radio's sound card, hw:CARD=CODEC (\"USB Audio CODEC\"), so choose it yourself in WSJT-X, JS8Call, fldigi and POTACAT."* ]]
grep -qx "hamlib=3073" "$HAMPACK_STATE/radio"
grep -qx "card=hw:CARD=CODEC" "$HAMPACK_STATE/radio"
}
@@ -684,7 +702,7 @@ DIREWOLF_CONF() { echo "$HAMPACK_STATE/conf.d/direwolf.conf"; }
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"* ]]
[[ "$output" == *"not1mm: voice keyer on \"USB Audio CODEC: USB Audio (hw:1,0)\". Left its rig control alone: \`radio configure --force\` replaces it"* ]]
[ "$(jq .useflrig "$(NOT1MM_JSON)")" = true ]
FAKE_RUNNING=not1mm run bash "$REPO/radio" configure --force
@@ -838,7 +856,7 @@ con = sqlite3.connect(sys.argv[1]); con.execute("INSERT INTO ptt_configs (channe
[[ "$output" == *"WSJT-X: rig control through rigctld, PTT by CAT, sound card \"USB Audio CODEC Analog Stereo\""* ]]
grep -qx "SoundInName=alsa_input.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.mono-fallback" "$(WSJTX_INI)"
grep -qx "SoundOutName=alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo" "$(WSJTX_INI)"
[[ "$output" == *"Choose the radio's sound card yourself in fldigi, not1mm and POTACAT, which name it in ways radio can't: it's \"USB Audio CODEC Analog Stereo\" (hw:CARD=CODEC)."* ]]
[[ "$output" == *"Choose the radio's sound card yourself in fldigi and POTACAT, which name it in ways radio can't: it's \"USB Audio CODEC Analog Stereo\" (hw:CARD=CODEC)."* ]]
run bash "$REPO/radio" configure
[[ "$output" == *"WSJT-X: already set up"* ]]
@@ -912,3 +930,51 @@ con = sqlite3.connect(sys.argv[1]); con.execute("INSERT INTO ptt_configs (channe
[[ "$output" == *"Graywolf: skipped: it has no channel that transmits yet"* ]]
[ "$(qlog_query "SELECT COUNT(*) FROM channels" "$(GRAYWOLF_DB)")" = 0 ]
}
@test "configure gives not1mm's voice keyer the radio's sound card by PipeWire's name, which doesn't change" {
configurable
pipewire_card 1
sd_outputs "USB Audio CODEC: USB Audio (hw:1,0)" "USB Audio CODEC Analog Stereo" pipewire default
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: rig control through rigctld, voice keyer on \"USB Audio CODEC Analog Stereo\""* ]]
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = "USB Audio CODEC Analog Stereo" ]
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: already set up"* ]]
}
@test "configure gives not1mm ALSA's name for the card without PipeWire, or when two cards share its name" {
configurable
run bash "$REPO/radio" configure
[[ "$output" == *"voice keyer on \"USB Audio CODEC: USB Audio (hw:1,0)\""* ]]
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = "USB Audio CODEC: USB Audio (hw:1,0)" ]
# Two radios with the same codec: PipeWire's name would match both
pipewire_card 1
sd_outputs "USB Audio CODEC: USB Audio (hw:1,0)" "USB Audio CODEC Analog Stereo" "USB Audio CODEC: USB Audio (hw:2,0)" "USB Audio CODEC Analog Stereo"
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: already set up"* ]]
}
@test "configure updates not1mm's card when its number changed, and leaves a card you chose unless --force" {
configurable
jq '.sounddevice = "USB Audio CODEC: USB Audio (hw:3,0)"' "$(NOT1MM_JSON)" > "$BATS_TEST_TMPDIR/n.json" && mv "$BATS_TEST_TMPDIR/n.json" "$(NOT1MM_JSON)"
run bash "$REPO/radio" configure
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = "USB Audio CODEC: USB Audio (hw:1,0)" ]
jq '.sounddevice = "HD-Audio Generic: ALC897 Analog (hw:0,0)"' "$(NOT1MM_JSON)" > "$BATS_TEST_TMPDIR/n.json" && mv "$BATS_TEST_TMPDIR/n.json" "$(NOT1MM_JSON)"
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: Left its sound card (HD-Audio Generic: ALC897 Analog (hw:0,0)) alone"* ]]
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = "HD-Audio Generic: ALC897 Analog (hw:0,0)" ]
run bash "$REPO/radio" configure --force
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = "USB Audio CODEC: USB Audio (hw:1,0)" ]
}
@test "configure says when not1mm's sounddevice doesn't list the radio's card" {
configurable
sd_outputs "HD-Audio Generic: ALC897 Analog (hw:0,0)" pipewire default
run bash "$REPO/radio" configure
[[ "$output" == *"not1mm: rig control through rigctld, choose its sound card yourself: its sounddevice library doesn't list the radio's"* ]]
[ "$(jq -r .sounddevice "$(NOT1MM_JSON)")" = default ]
}