Set POTACAT's sound card in radio configure

POTACAT keeps Chromium's device ids, which only it can see, with each
device's name beside it, and when a saved id matches no device it takes
the one device of that name when it starts (lib/audio-device-heal.js).
So HamPack's rig gets PipeWire's names for the radio's card as those
names, which is how Chromium names PipeWire's devices, and placeholder
ids that match nothing. Only HamPack's rig gets a sound card; one you
chose on it is left alone unless --force, which now keeps the rig's
other settings.

Every program that uses the radio's sound card now gets it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 13:31:11 -07:00
co-authored by Claude Opus 5.5
parent 8020cdc061
commit b2ffaf9592
5 changed files with 104 additions and 24 deletions
-2
View File
@@ -18,8 +18,6 @@ control a radio.
- [ ] `radio configure`, the rest. It writes the rigctld user service and - [ ] `radio configure`, the rest. It writes the rigctld user service and
points WSJT-X, JS8Call, Pat, fldigi, Dire Wolf, not1mm, QLog, POTACAT points WSJT-X, JS8Call, Pat, fldigi, Dire Wolf, not1mm, QLog, POTACAT
and Graywolf at it. Still to do: and Graywolf at it. Still to do:
- [ ] POTACAT's sound card. It keeps browser (Chromium) device ids, which
only it can see; every other program's is done
- [ ] 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
+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. `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, fldigi, 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. fldigi and not1mm get PipeWire's name for it too where PortAudio lists it (through PipeWire's JACK support), 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. It also gives WSJT-X, JS8Call, fldigi, Dire Wolf, not1mm's voice keyer and POTACAT the radio's sound card. POTACAT finds it by name the next time it starts. WSJT-X and JS8Call get it as PipeWire names it, so PipeWire must be running. fldigi and not1mm get PipeWire's name for it too where PortAudio lists it (through PipeWire's JACK support), 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 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`. `radio configure` also says which sound card is the radio's.
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. 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.
+5 -1
View File
@@ -92,7 +92,11 @@ Dire Wolf, not1mm, QLog and POTACAT quit:
10. Open POTACAT (after running it once). My Rigs has "... (HamPack's 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, 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 and the frequency follows the radio. If you have an operator profile, check
POTACAT doesn't say the connection belongs to another rig. POTACAT doesn't say the connection belongs to another rig. The rig's audio
shows the radio's card for input and output: `radio configure` saved them
by name only, and POTACAT's log should say it followed each "by name" when
it started. If they're blank, note the names POTACAT lists for the card,
since radio assumed Chromium shows PipeWire's descriptions.
11. With no channels in Graywolf, run `radio configure` (it asks for sudo to 11. With no channels in Graywolf, run `radio configure` (it asks for sudo to
stop Graywolf). Graywolf's web UI shows a channel named after the radio, stop Graywolf). Graywolf's web UI shows a channel named after the radio,
on plughw:CARD=...,DEV=0 for input and output, 1200 baud APRS, with PTT on plughw:CARD=...,DEV=0 for input and output, 1200 baud APRS, with PTT
+51 -17
View File
@@ -1059,27 +1059,61 @@ configure_potacat() {
else else
state="empty" state="empty"
fi fi
local set_rig=0 set_sound=0 sound=""
SAID=() LEFT=()
case "$state" in case "$state" in
already) report POTACAT "already set up"; return ;; already) ;;
theirs) theirs)
if (( ! FORCE )); then 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" set_rig=1
return else
LEFT+=("its own radio")
fi ;; fi ;;
*) set_rig=1 ;;
esac esac
(( ! set_rig )) || SAID+=("rig \"$1 (HamPack's rigctld)\" is rigctld, and active")
back_up "$global" # The sound card goes on HamPack's rig only. POTACAT keeps Chromium's device
tmp="$(mktemp "$global.XXXXXX")" || return 1 # ids, which only it can see, with the device's name (its label) beside
if ! jq --argjson t "$target" --arg name "$1 (HamPack's rigctld)" --arg cat "$cat_file" --arg global "$global" ' # each. When a saved id matches no device, POTACAT takes the one device
.rigs = ([(.rigs // [])[] | select(.id != "rig_hampack")] + [{id: "rig_hampack", name: $name, catTarget: $t}]) # whose name is the saved label (lib/audio-device-heal.js, at launch). So
| .activeRigId = "rig_hampack" # the rig gets PipeWire's names for the card as labels, which is how
| if $cat == $global then .catTarget = $t else . end # Chromium names PipeWire's devices, and ids that match nothing.
' "$global" > "$tmp" || ! chmod --reference="$global" "$tmp" || ! mv -f "$tmp" "$global"; then if [ -n "$PW_IN_NAME" ] && { (( set_rig )) || jq -e 'any(.rigs // [] | .[]; .id == "rig_hampack")' "$global" > /dev/null; }; then
rm -f "$tmp" sound="$(jq -r --arg in "$PW_IN_DESC" --arg out "$PW_OUT_DESC" '
report POTACAT "couldn't change $global" (first(.rigs // [] | .[] | select(.id == "rig_hampack")) // {}) as $r
return 1 | def unset(id): (id // "") as $i | $i == "" or $i == "default" or $i == "communications" or ($i | startswith("hampack:"));
if $r.remoteAudioInputLabel == $in and $r.remoteAudioOutputLabel == $out then "already"
elif unset($r.remoteAudioInput) and unset($r.remoteAudioOutput) then "empty"
else "theirs" end' "$global")" || { report POTACAT "couldn't read $global"; return 1; }
if [ "$sound" = empty ] || { [ "$sound" = theirs ] && (( FORCE )); }; then
set_sound=1
SAID+=("sound card \"$PW_OUT_DESC\", which POTACAT finds by name when it starts")
elif [ "$sound" = theirs ]; then
LEFT+=("its sound card")
fi
fi fi
if [ "$cat_file" != "$global" ]; then
if (( set_rig || set_sound )); then
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" \
--argjson rig "$set_rig" --argjson sound "$set_sound" \
--arg in_id "hampack:$PW_IN_NAME" --arg in_label "$PW_IN_DESC" --arg out_id "hampack:$PW_OUT_NAME" --arg out_label "$PW_OUT_DESC" '
(first(.rigs // [] | .[] | select(.id == "rig_hampack")) // {}) as $old
| ($old
+ (if $rig == 1 then {id: "rig_hampack", name: $name, catTarget: $t} else {} end)
+ (if $sound == 1 then {remoteAudioInput: $in_id, remoteAudioInputLabel: $in_label,
remoteAudioOutput: $out_id, remoteAudioOutputLabel: $out_label} else {} end)) as $new
| .rigs = ([(.rigs // [])[] | select(.id != "rig_hampack")] + [$new])
| if $rig == 1 then .activeRigId = "rig_hampack" | (if $cat == $global then .catTarget = $t else . end) 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
fi
if (( set_rig )) && [ "$cat_file" != "$global" ]; then
back_up "$cat_file" back_up "$cat_file"
mkdir -p "$(dirname "$cat_file")" && { [ -f "$cat_file" ] || echo '{}' > "$cat_file"; } || return 1 mkdir -p "$(dirname "$cat_file")" && { [ -f "$cat_file" ] || echo '{}' > "$cat_file"; } || return 1
tmp="$(mktemp "$cat_file.XXXXXX")" || return 1 tmp="$(mktemp "$cat_file.XXXXXX")" || return 1
@@ -1089,7 +1123,7 @@ configure_potacat() {
return 1 return 1
fi fi
fi fi
report POTACAT "rig \"$1 (HamPack's rigctld)\" is rigctld, and active" say_changes POTACAT
} }
# Graywolf keeps its settings in graywolf.db. If it has no channels yet and # Graywolf keeps its settings in graywolf.db. If it has no channels yet and
@@ -1337,7 +1371,7 @@ configure() {
if [ -z "$card" ]; then if [ -z "$card" ]; then
echo "No sound card was found with the radio: choose the one it's connected to in each program yourself." echo "No sound card was found with the radio: choose the one it's connected to in each program yourself."
elif (( pipewire )); then elif (( pipewire )); then
echo "Choose the radio's sound card yourself in POTACAT, which names it in a way radio can't: it's \"$PW_OUT_DESC\" ($card)." echo "The radio's sound card is \"$PW_OUT_DESC\" ($card)."
else 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 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 and POTACAT."
fi fi
+46 -2
View File
@@ -791,7 +791,7 @@ DIREWOLF_CONF() { echo "$HAMPACK_STATE/conf.d/direwolf.conf"; }
configurable 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)" 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 run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: left alone: it has a radio set up already"* ]] [[ "$output" == *"POTACAT: Left its own radio alone: \`radio configure --force\` replaces it"* ]]
[ "$(jq -r .activeRigId "$(POTACAT_JSON)")" = rig_1 ] [ "$(jq -r .activeRigId "$(POTACAT_JSON)")" = rig_1 ]
FAKE_RUNNING=potacat run bash "$REPO/radio" configure --force FAKE_RUNNING=potacat run bash "$REPO/radio" configure --force
@@ -857,7 +857,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\""* ]] [[ "$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 "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)" 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 POTACAT, which names it in a way radio can't: it's \"USB Audio CODEC Analog Stereo\" (hw:CARD=CODEC)."* ]] [[ "$output" == *"The radio's sound card is \"USB Audio CODEC Analog Stereo\" (hw:CARD=CODEC)."* ]]
run bash "$REPO/radio" configure run bash "$REPO/radio" configure
[[ "$output" == *"WSJT-X: already set up"* ]] [[ "$output" == *"WSJT-X: already set up"* ]]
@@ -1027,3 +1027,47 @@ con = sqlite3.connect(sys.argv[1]); con.execute("INSERT INTO ptt_configs (channe
[ "$status" -eq 0 ] || [ "$status" -eq 1 ] [ "$status" -eq 0 ] || [ "$status" -eq 1 ]
[[ -z "$output" ]] || [[ "$(head -1 <<< "$output")" == *$'\t'*$'\t'*$'\t'* ]] [[ -z "$output" ]] || [[ "$(head -1 <<< "$output")" == *$'\t'*$'\t'*$'\t'* ]]
} }
@test "configure gives POTACAT's rig the sound card by name, for POTACAT to find when it starts" {
configurable
pipewire_card 1
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: rig \"Icom IC-7300 (HamPack's rigctld)\" is rigctld, and active, sound card \"USB Audio CODEC Analog Stereo\", which POTACAT finds by name when it starts"* ]]
[ "$(jq -c '.rigs[0] | [.remoteAudioInput, .remoteAudioInputLabel, .remoteAudioOutput, .remoteAudioOutputLabel]' "$(POTACAT_JSON)")" = '["hampack:alsa_input.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.mono-fallback","USB Audio CODEC Mono","hampack:alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo","USB Audio CODEC Analog Stereo"]' ]
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: already set up"* ]]
# POTACAT found the devices and stored their ids: still set up
jq '.rigs[0].remoteAudioInput = "4f3a9c" | .rigs[0].remoteAudioOutput = "9b21e0"' "$(POTACAT_JSON)" > "$BATS_TEST_TMPDIR/p.json" && mv "$BATS_TEST_TMPDIR/p.json" "$(POTACAT_JSON)"
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: already set up"* ]]
[ "$(jq -r '.rigs[0].remoteAudioInput' "$(POTACAT_JSON)")" = 4f3a9c ]
}
@test "configure leaves a sound card you chose on POTACAT's rig, unless --force" {
configurable
pipewire_card 1
bash "$REPO/radio" configure > /dev/null
jq '.rigs[0] += {remoteAudioInput: "77aa", remoteAudioInputLabel: "Other Mono", remoteAudioOutput: "88bb", remoteAudioOutputLabel: "Other Analog Stereo"}' "$(POTACAT_JSON)" > "$BATS_TEST_TMPDIR/p.json" && mv "$BATS_TEST_TMPDIR/p.json" "$(POTACAT_JSON)"
run bash "$REPO/radio" configure
[[ "$output" == *"POTACAT: Left its sound card alone"* ]]
[ "$(jq -r '.rigs[0].remoteAudioInput' "$(POTACAT_JSON)")" = 77aa ]
run bash "$REPO/radio" configure --force
[ "$(jq -r '.rigs[0].remoteAudioInputLabel' "$(POTACAT_JSON)")" = "USB Audio CODEC Mono" ]
[ "$(jq -r '.rigs[0].name' "$(POTACAT_JSON)")" = "Icom IC-7300 (HamPack's rigctld)" ]
}
@test "configure gives POTACAT no sound card for your own rig, or without PipeWire" {
configurable
pipewire_card 1
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 its own radio alone"* ]]
[ "$(jq -c '.rigs[0] | has("remoteAudioInput")' "$(POTACAT_JSON)")" = false ]
rm "$FAKE_RADIOS"/pw-*
run bash "$REPO/radio" configure --force
[ "$(jq -c '.rigs[1] | [.id, has("remoteAudioInput")]' "$(POTACAT_JSON)")" = '["rig_hampack",false]' ]
}