From d910982ea7a695466cd2460cf5a96ee77727afb6 Mon Sep 17 00:00:00 2001 From: David Young Date: Sun, 29 Nov 2026 13:06:27 -0700 Subject: [PATCH] Set up older Yaesus with `radio configure --model`, without asking them The FT-817, FT-818, FT-857 and FT-897 have no ID command, and take every five bytes they're sent as a command, so radio doesn't probe them: --model sets one up on its only serial port, at the CAT rate it comes with (baud= in radios.conf), or --baud's. Where nothing answered, radio says so. Co-Authored-By: Claude Opus 5.5 --- PLAN.md | 4 ---- README.md | 4 ++-- TEST.md | 5 ++++ radio | 46 +++++++++++++++++++++++++++++++++--- radios.conf | 35 ++++++++++++++++++++++++++- tests/conf.bats | 8 ++++--- tests/radio.bats | 61 +++++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 149 insertions(+), 14 deletions(-) diff --git a/PLAN.md b/PLAN.md index bb2109a..5bca397 100644 --- a/PLAN.md +++ b/PLAN.md @@ -14,10 +14,6 @@ unconfigure` to undo it. - [ ] Run `TEST.md` against real radios, and mark the `radios.conf` values they confirm `# verified`. Fix or remove the ones they don't -- [ ] Radios with older Yaesu CAT that doesn't answer `ID;` (FT-817, FT-818, - FT-857, FT-897): find out what `radio probe` could safely send them - to tell what they are, or have `radio configure --model` set them up - without asking - [ ] Two interfaces of the same kind with no serial number (two AIOCs, two CM108 cables): `radio` names their PTT devices by USB socket (`/dev/input/by-path`), and their sound cards by ALSA card id, so they diff --git a/README.md b/README.md index ad438ca..2548be0 100644 --- a/README.md +++ b/README.md @@ -63,13 +63,13 @@ Graywolf's web UI is at http://localhost:8080 and, by default, can only be reach Controlling a radio means opening its serial port, and on Arch only members of the `uucp` group can. Keying a radio through the PTT line on a CM108-family sound card (a Digirig, an AIOC) means opening the card's `hidraw` device, which normally only root can; HamPack installs a udev rule, `/etc/udev/rules.d/70-hampack-cm108.rules`, that lets whoever is logged in at the desktop use it, as they can the sound card. HamPack adds you to it when it installs. Log out and back in once afterwards for it to take effect. `hampackremove` takes you out of the group again, unless you were already in it before HamPack. -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. Don't probe an older Yaesu (FT-817, FT-818, FT-857, FT-897): it has no command to say what it is, and takes every five bytes it's sent as a command, so `radio`'s questions could reach it as stray ones, which may key it or change its settings. Set one up with `radio configure --model` instead, as below. `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, which systemd starts whenever the radio is plugged in and switched on, and stops when it isn't, 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, 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`. +`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`. An FT-817, FT-818, FT-857 or FT-897 is set up without asking it anything: `radio configure --model 1020` (for an FT-817; `rigctl -l` lists the others) uses its serial port, at the CAT rate it comes with, 4800 baud. If you've changed its CAT RATE menu, give that too: `radio configure --model 1020 --baud 38400`. A radio with no CAT can be set up too, on an interface that keys it: rigctld then runs Hamlib's Dummy radio, which only keys the radio, and the programs reach it as before. A sound card with no serial port (an AIOC, a CM108 cable, a SignaLink) is numbered after the radios in `radio`'s list: `radio configure 2` keys the radio through its CM108 PTT pin if it has one, or leaves it to the radio's VOX. For an interface with a serial port, such as a Digirig on a handheld, say how it keys the radio: `radio configure --no-cat --ptt rts` (or `dtr`, `cm108` or `vox`). diff --git a/TEST.md b/TEST.md index be4f908..79b6980 100644 --- a/TEST.md +++ b/TEST.md @@ -50,6 +50,11 @@ rate): the G90's address is 88 by flrig and A4 by Hamlib. The IC-7851, IC-7600 and IC-9100 have USB serial chips: note the serial number `radio` lists, and whether it names the radio, as the IC-7300's does. +An FT-817, FT-818, FT-857 or FT-897 isn't probed. Run `radio configure --model +1020` (or 1041, 1022, 1023, 1043) with its CAT RATE menu at 4800, and check +`rigctl -m 2 -r 127.0.0.1:4532 f` prints its frequency. Then set CAT RATE to +38400 and run it again with `--baud 38400`. + Interfaces to try, as well as radios with built-in USB: a Digirig (CP2102 and CM108 behind its own hub, RTS keys PTT), an FTDI CAT cable, and an Icom CI-V cable. diff --git a/radio b/radio index 2b2a4b7..14325af 100755 --- a/radio +++ b/radio @@ -6,7 +6,7 @@ # # Usage : radio [detect] [--probe] # radio probe PORT -# radio configure [--force] [--model N] [--flrig] [--no-cat --ptt HOW] [NUMBER] +# radio configure [--force] [--model N [--baud RATE]] [--flrig] [--no-cat --ptt HOW] [NUMBER] # radio configure --auto # radio unconfigure # radio help @@ -25,6 +25,8 @@ LOCKDIR="${RADIO_LOCKDIR:-/run/lock}" # plugged in, in seconds AUTO_WAIT="${RADIO_AUTO_WAIT:-10}" AUTO=0 +# What to say where nothing answered, for the radios that can't be asked +UNASKABLE_HINT="An FT-817, FT-818, FT-857 or FT-897 can't be asked what it is: give its Hamlib model, as in \`radio configure --model 1020\` for an FT-817 (\`rigctl -l\` lists them)." # CAT baud rates to try, most likely first BAUDS=(38400 115200 19200 9600 4800) @@ -76,7 +78,10 @@ Usage: radio [detect] [--probe] Quit those programs first --force Replace rig settings you've set yourself --model N Use Hamlib model N (\`rigctl -l\`), for a radio that radio - can't tell apart from others, or doesn't know + can't tell apart from others, or doesn't know. Radios it + can't ask (an FT-817, FT-818, FT-857 or FT-897) are set up + without asking them, at the CAT rate they come with + --baud RATE The CAT rate of a radio radio can't ask, if you've changed it --flrig Put flrig in charge of the radio, with rigctld passing the other programs through it. flrig then has to be running for them to reach the radio @@ -578,6 +583,7 @@ detect() { echo " Run \`radio detect --probe\` to ask it what it is" elif (( ID_ASKED )); then echo " Nothing answered. If it's a radio, check it's switched on and its CAT rate is one of ${BAUDS[*]} baud. Interfaces like the Digirig answer only for a radio behind them" + echo " $UNASKABLE_HINT" fi fi done @@ -608,6 +614,7 @@ probe() { return 1 else echo "Nothing answered on $port at ${BAUDS[*]} baud" + echo "$UNASKABLE_HINT" return 1 fi } @@ -1610,6 +1617,7 @@ hamlib_name() { configure() { local number="" model="" radio="" sound_card="" sound_dev="" was_running=0 name port="" baud="" card card_sys local flrig_name="" flrig_port=12345 no_cat=0 ptt="" ptt_type="" ptt_device="" ptt_text="" sound_only total + local want_baud="" unaskable="" FORCE=0 BACKUPS=() USE_FLRIG=0 if [ "${1:-}" = --auto ]; then [ $# -eq 1 ] || { usage >&2; return 2; } @@ -1629,6 +1637,10 @@ configure() { [[ "${2:-}" =~ ^[0-9]+$ ]] || { usage >&2; return 2; } model="$2" shift ;; + --baud) + [[ "${2:-}" =~ ^[0-9]+$ ]] || { usage >&2; return 2; } + want_baud="$2" + shift ;; [1-9]*) [[ "$1" =~ ^[0-9]+$ ]] || { usage >&2; return 2; } number="$1" ;; @@ -1673,6 +1685,22 @@ configure() { echo "With no CAT, rigctld doesn't talk to the radio, so --model doesn't apply." return 2 fi + # A radio radio can't ask what it is, nor at what rate it answers + if [ -n "$model" ] && (( ! no_cat )); then + unaskable="$(hamlib_name "$model")" + [ -n "$unaskable" ] && [ -n "$(conf_field "$unaskable" baud)" ] || unaskable="" + fi + if [ -n "$want_baud" ] && [ -z "$unaskable" ]; then + echo "--baud is for a radio radio can't ask, such as an FT-817 (\`radio configure --model 1020 --baud 9600\`): it finds other radios' rate by asking them." + return 2 + fi + if [ -n "$unaskable" ] && [ -n "$radio" ]; then + read -ra ID_PORTS <<< "${RADIO_PORTS[$radio]}" + if [ ${#ID_PORTS[@]} -ne 1 ]; then + echo "The $unaskable can't be asked which of ${ID_PORTS[*]} it's on, and radio won't guess. Set it up in each program yourself." + return 2 + fi + fi if [ -n "$ptt" ] && (( ! no_cat )); then echo "--ptt is for a radio with no CAT: with CAT, the radio is keyed through it. Add --no-cat if this radio has none." return 2 @@ -1735,12 +1763,23 @@ configure() { vox) ptt_text="PTT by VOX: the radio keys itself on the audio" ;; esac + elif [ -n "$unaskable" ]; then + # Its only port, at the rate it comes with: it can't be asked either + name="$unaskable" + port="$(port_path "${ID_PORTS[0]}")" + baud="${want_baud:-$(conf_field "$name" baud)}" + card_sys="$(card_of "$radio")" + if (( USE_FLRIG )); then + flrig_name="$(conf_field "$name" flrig)" + flrig_port="$(fltk_get "$FLRIG_DIR/$flrig_name.prefs" xmlport)" + flrig_port="${flrig_port:-12345}" + fi else identify "$radio" always if [ -z "$ID_CAT_PORT" ]; then echo "Couldn't set it up: nothing answered on ${ID_PORTS[*]}." [ ${#ID_NOTES[@]} -eq 0 ] || printf ' %s\n' "${ID_NOTES[@]}" - (( ! ID_ASKED )) || echo "Check it's switched on and its CAT rate is one of ${BAUDS[*]} baud. If the radio has no CAT, \`radio configure --no-cat --ptt HOW\` sets it up to be keyed." + (( ! ID_ASKED )) || echo "Check it's switched on and its CAT rate is one of ${BAUDS[*]} baud. If the radio has no CAT, \`radio configure --no-cat --ptt HOW\` sets it up to be keyed. $UNASKABLE_HINT" (( ! was_running )) || systemctl --user start hampack-rigctld return 1 fi @@ -1785,6 +1824,7 @@ configure() { echo "Setting up the $name, with no CAT: $ptt_text" else echo "Setting up the $name (Hamlib model $model), on $port at $baud baud$( (( USE_FLRIG )) && echo ", through flrig")" + [ -z "$unaskable" ] || echo "It can't be asked what it is, so check it's a $name, and that its CAT RATE menu says $baud (or give --baud)." fi echo local rigctld="" diff --git a/radios.conf b/radios.conf index 6a497a6..23826f2 100644 --- a/radios.conf +++ b/radios.conf @@ -14,11 +14,14 @@ # modules) says: K3, K3S, KX2, KX3 or K4. They all answer ID; # alike, so radio asks OM; too, and reads the model from it # as Hamlib 4.7's elecraft.c does +# baud= - the radio's CAT rate as it comes, for a radio `radio` can't +# ask what it is, set up with `radio configure --model` # flrig= - flrig's name for the radio, for `radio configure --flrig` # (flrig 2.0.12's rigs/ sources). Left out where flrig has # no driver for it, or several (the TS-480's HX and SAT) # -# A radio needs usb_serial=, cat_id= or civ=, or `radio` can't recognise it. +# A radio needs usb_serial=, cat_id= or civ=, or `radio` can't recognise it; +# one with none of them needs baud=, and is set up with --model alone. # The Hamlib model numbers were checked against Hamlib 4.6 (the IC-7851, # IC-7600, IC-9100, Xiegus and Lab599 against 4.7.2). The other values # come from the radios' CAT manuals and Hamlib's tables; mark one "# verified" @@ -162,6 +165,36 @@ hamlib=1046 flrig=FT-450D cat_id=0241 +# Older Yaesus, whose CAT has no ID command: every five bytes they're sent is +# a command, keying the transmitter or writing to their EEPROM among them, so +# radio doesn't ask them anything. `radio configure --model 1020` sets one +# up, at the CAT rate (menu CAT RATE) they come with, or --baud's + +[Yaesu FT-817] +hamlib=1020 +flrig=FT-817 +baud=4800 + +[Yaesu FT-818] +hamlib=1041 +flrig=FT-818ND +baud=4800 + +[Yaesu FT-857] +hamlib=1022 +flrig=FT-857D +baud=4800 + +[Yaesu FT-897] +hamlib=1023 +flrig=FT-897D +baud=4800 + +[Yaesu FT-897D] +hamlib=1043 +flrig=FT-897D +baud=4800 + # Kenwood [Kenwood TS-2000] diff --git a/tests/conf.bats b/tests/conf.bats index e8d8965..054c5e3 100644 --- a/tests/conf.bats +++ b/tests/conf.bats @@ -117,16 +117,18 @@ EOF } check_radio() { - check_keys hamlib usb_serial cat_id civ flrig elecraft + check_keys hamlib usb_serial cat_id civ flrig elecraft baud [[ "${CONF[elecraft]:-K3}" =~ ^(K3|K3S|KX2|KX3|K4)$ ]] || problem "elecraft= should be K3, K3S, KX2, KX3 or K4" check_required hamlib [[ "${CONF[hamlib]}" =~ ^[0-9]+$ ]] || problem "hamlib= should be a Hamlib model number" - [ -n "${CONF[usb_serial]}${CONF[cat_id]}${CONF[civ]}" ] || problem "needs usb_serial=, cat_id= or civ=" + [ -n "${CONF[usb_serial]}${CONF[cat_id]}${CONF[civ]}${CONF[baud]}" ] || problem "needs usb_serial=, cat_id=, civ= or baud=" + [ -z "${CONF[baud]}" ] || [ -z "${CONF[usb_serial]}${CONF[cat_id]}${CONF[civ]}" ] || problem "baud= is only for a radio radio can't recognise" + [[ "${CONF[baud]:-4800}" =~ ^(4800|9600|19200|38400|57600|115200)$ ]] || problem "baud= should be a serial rate" [ -z "${CONF[cat_id]}" ] || [[ "${CONF[cat_id]}" =~ ^[0-9]{3,4}$ ]] || problem "cat_id= should be 3 or 4 digits" [ -z "${CONF[civ]}" ] || [[ "${CONF[civ]}" =~ ^[0-9A-F]{2}$ ]] || problem "civ= should be two hex digits, in capitals" } -@test "radios.conf: every radio has a Hamlib model and a way to recognise it" { +@test "radios.conf: every radio has a Hamlib model, and a way to recognise it or its CAT rate" { parse_conf "$REPO/radios.conf" check_radio check_unique_sections "$REPO/radios.conf" no_problems diff --git a/tests/radio.bats b/tests/radio.bats index 2bc53e4..7bc37c3 100644 --- a/tests/radio.bats +++ b/tests/radio.bats @@ -397,7 +397,7 @@ teardown() { fake_radio silent run bash "$REPO/radio" probe "$PTY" [ "$status" -eq 1 ] - [ "$output" = "Nothing answered on $PTY at 38400 115200 19200 9600 4800 baud" ] + [ "${lines[0]}" = "Nothing answered on $PTY at 38400 115200 19200 9600 4800 baud" ] } # --- radio configure --- @@ -1711,3 +1711,62 @@ auto() { run bash "$REPO/radio" unconfigure --force [ "$status" -eq 2 ] } + +# --- radios that can't be asked --- + +# An FT-817 on an FTDI CAT cable: one serial port, and no sound card +ft817() { + usb 1-4 0403:6001 FTDI "FT232R USB UART" A12345 + port 1-4 ttyUSB0 usb-FTDI_FT232R_USB_UART_A12345-if00-port0 + stub pgrep 'exit 1' + stub systemctl '[ "$*" != "--user is-active --quiet hampack-rigctld" ]' + answers ttyUSB0 "" +} + +@test "configure --model sets up a radio that can't be asked, without asking it" { + ft817 + : > "$STUB_LOG" + run bash "$REPO/radio" configure --model 1020 + [ "$status" -eq 0 ] + [ "${lines[0]}" = "Setting up the Yaesu FT-817 (Hamlib model 1020), on /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A12345-if00-port0 at 4800 baud" ] + [ "${lines[1]}" = "It can't be asked what it is, so check it's a Yaesu FT-817, and that its CAT RATE menu says 4800 (or give --baud)." ] + ! grep -q "TIOCMBIC" "$STUB_LOG" + grep -qx "ExecStart=/usr/bin/rigctld -m 1020 -r /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A12345-if00-port0 -s 4800 -T 127.0.0.1 -t 4532" "$HOME/.config/systemd/user/hampack-rigctld.service" + grep -qx "name=Yaesu FT-817" "$HAMPACK_STATE/radio" + + run bash "$REPO/radio" configure --model 1022 --baud 38400 + [ "$status" -eq 0 ] + grep -q "^ExecStart=/usr/bin/rigctld -m 1022 .* -s 38400 " "$HOME/.config/systemd/user/hampack-rigctld.service" +} + +@test "configure --model --flrig gives flrig a radio that can't be asked" { + ft817 + stub flrig 'exit 0' + run bash "$REPO/radio" configure --model 1041 --flrig + [ "$status" -eq 0 ] + [[ "$output" == *"flrig: controls the FT-818ND on /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A12345-if00-port0 at 4800 baud"* ]] + grep -qx "xcvr_name:FT-818ND" "$(FLRIG_PREFS)" +} + +@test "configure only takes --baud for a radio that can't be asked, and won't guess its port" { + ft817 + run bash "$REPO/radio" configure --baud 9600 + [ "$status" -eq 2 ] + [[ "$output" == "--baud is for a radio radio can't ask"* ]] + run bash "$REPO/radio" configure --model 3073 --baud 9600 + [ "$status" -eq 2 ] + + port 1-4 ttyUSB1 "" 1 + run bash "$REPO/radio" configure --model 1020 + [ "$status" -eq 2 ] + [[ "$output" == "The Yaesu FT-817 can't be asked which of ttyUSB0 ttyUSB1 it's on"* ]] +} + +@test "says how to set up a radio that can't be asked, when nothing answers" { + ft817 + run bash "$REPO/radio" --probe + [[ "$output" == *"An FT-817, FT-818, FT-857 or FT-897 can't be asked what it is: give its Hamlib model, as in \`radio configure --model 1020\`"* ]] + run bash "$REPO/radio" probe "$RADIO_DEV/ttyUSB0" + [ "$status" -eq 1 ] + [[ "$output" == *"radio configure --model 1020"* ]] +}