diff --git a/PLAN.md b/PLAN.md index e03e38d..afe7372 100644 --- a/PLAN.md +++ b/PLAN.md @@ -18,8 +18,6 @@ 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: - - [ ] 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 offer flrig as the controller instead - [ ] More than one radio at once: a rigctld for each, on its own port diff --git a/README.md b/README.md index 4b647c7..ae4f8d5 100644 --- a/README.md +++ b/README.md @@ -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, 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. diff --git a/TEST.md b/TEST.md index bb062e6..94760d1 100644 --- a/TEST.md +++ b/TEST.md @@ -92,7 +92,11 @@ Dire Wolf, not1mm, QLog and POTACAT quit: 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. + 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 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 diff --git a/radio b/radio index e1e42c9..7c76628 100755 --- a/radio +++ b/radio @@ -1059,27 +1059,61 @@ configure_potacat() { else state="empty" fi + local set_rig=0 set_sound=0 sound="" + SAID=() LEFT=() case "$state" in - already) report POTACAT "already set up"; return ;; + already) ;; 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 + if (( FORCE )); then + set_rig=1 + else + LEFT+=("its own radio") fi ;; + *) set_rig=1 ;; esac + (( ! set_rig )) || SAID+=("rig \"$1 (HamPack's rigctld)\" is rigctld, and active") - 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 + # The sound card goes on HamPack's rig only. POTACAT keeps Chromium's device + # ids, which only it can see, with the device's name (its label) beside + # each. When a saved id matches no device, POTACAT takes the one device + # whose name is the saved label (lib/audio-device-heal.js, at launch). So + # the rig gets PipeWire's names for the card as labels, which is how + # Chromium names PipeWire's devices, and ids that match nothing. + if [ -n "$PW_IN_NAME" ] && { (( set_rig )) || jq -e 'any(.rigs // [] | .[]; .id == "rig_hampack")' "$global" > /dev/null; }; then + sound="$(jq -r --arg in "$PW_IN_DESC" --arg out "$PW_OUT_DESC" ' + (first(.rigs // [] | .[] | select(.id == "rig_hampack")) // {}) as $r + | 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 - 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" mkdir -p "$(dirname "$cat_file")" && { [ -f "$cat_file" ] || echo '{}' > "$cat_file"; } || return 1 tmp="$(mktemp "$cat_file.XXXXXX")" || return 1 @@ -1089,7 +1123,7 @@ configure_potacat() { return 1 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 @@ -1337,7 +1371,7 @@ 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 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 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 diff --git a/tests/radio.bats b/tests/radio.bats index 4c6139e..e7e43cb 100644 --- a/tests/radio.bats +++ b/tests/radio.bats @@ -791,7 +791,7 @@ DIREWOLF_CONF() { echo "$HAMPACK_STATE/conf.d/direwolf.conf"; } 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"* ]] + [[ "$output" == *"POTACAT: Left its own radio alone: \`radio configure --force\` replaces it"* ]] [ "$(jq -r .activeRigId "$(POTACAT_JSON)")" = rig_1 ] 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\""* ]] 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 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 [[ "$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 ] [[ -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]' ] +}