Tell Elecraft radios apart by their option modules

The K3, K3S, KX2, KX3 and K4 all answer ID; with ID017;, so radio listed
them all. When a radio answers ID017;, the probe now asks OM; too, and
radio reads the model from its option modules as Hamlib 4.7's
elecraft_open() does: 0 then 1 or 2 last for a KX2 or KX3, S and 4 for
a K4, R for a K3S, else a K3. radios.conf's new elecraft= field names
each, and narrows the radios the answer could be. A radio that doesn't
answer OM; (a TS-570) is still listed as one of several.

radios.conf gets the K3S (Hamlib 2043), which flrig drives with its K3
driver.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-28 14:15:02 -07:00
co-authored by Claude Opus 5.5
parent 4cb5ce25ff
commit 81c6e0b73f
6 changed files with 113 additions and 13 deletions
+2 -1
View File
@@ -117,7 +117,8 @@ EOF
}
check_radio() {
check_keys hamlib usb_serial cat_id civ flrig
check_keys hamlib usb_serial cat_id civ flrig elecraft
[[ "${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="
+43 -3
View File
@@ -183,12 +183,12 @@ answers() {
[ "${lines[2]}" = " Sound card: none found with it" ]
}
@test "lists every radio a reply could come from" {
@test "lists every radio a reply could come from, when nothing narrows it" {
usb 1-4 0403:6001 FTDI "FT232R USB UART" A12345
port 1-4 ttyUSB0
answers ttyUSB0 "38400 cat_id 017"
run bash "$REPO/radio" --probe
[ "${lines[0]}" = "1. One of: Elecraft K3 (Hamlib model 2029), Elecraft KX3 (Hamlib model 2045), Elecraft KX2 (Hamlib model 2044), Elecraft K4 (Hamlib model 2047), answered on ttyUSB0 at 38400 baud" ]
[ "${lines[0]}" = "1. One of: Elecraft K3 (Hamlib model 2029), Elecraft K3S (Hamlib model 2043), Elecraft KX3 (Hamlib model 2045), Elecraft KX2 (Hamlib model 2044), Elecraft K4 (Hamlib model 2047), answered on ttyUSB0 at 38400 baud" ]
}
@test "says what answered when it doesn't know the radio" {
@@ -330,6 +330,12 @@ while time.monotonic() < end:
if sys.argv[2] == "kenwood" and b"ID;" in heard:
os.write(master, b"ID0761;")
heard = b""
if sys.argv[2] == "elecraft" and b"ID;" in heard:
os.write(master, b"ID017;")
heard = b""
if sys.argv[2] == "elecraft" and b"OM;" in heard:
os.write(master, b"OM AP--------02;")
heard = b""
if sys.argv[2] == "icom" and civ_request in heard:
# With CI-V USB echo on, the radio echoes the request first
os.write(master, civ_request + bytes.fromhex("fefee0a41900a4fd"))
@@ -616,7 +622,7 @@ DIREWOLF_CONF() { echo "$HAMPACK_STATE/conf.d/direwolf.conf"; }
echo 0001 > "$ROOT_HUB/1-2/1-2.1/serial"
run bash "$REPO/radio" configure
[ "$status" -eq 1 ]
[[ "$output" == *"Couldn't tell which radio it is: it's one of: Elecraft K3 (Hamlib model 2029), Elecraft KX3"* ]]
[[ "$output" == *"Couldn't tell which radio it is: it's one of: Elecraft K3 (Hamlib model 2029), Elecraft K3S (Hamlib model 2043), Elecraft KX3"* ]]
[[ "$output" == *"radio configure --model 2045"* ]]
run bash "$REPO/radio" configure --model 2045
@@ -1332,3 +1338,37 @@ FLRIG_AUTOSTART() { echo "$HOME/.config/autostart/hampack-flrig.desktop"; }
[ "$in_radio" = "$in_rule" ] || { echo "$device: radio $in_radio, rule $in_rule"; return 1; }
done
}
# --- Elecraft ---
@test "tells Elecraft radios apart by their option modules" {
usb 1-4 0403:6001 FTDI "FT232R USB UART" A12345
port 1-4 ttyUSB0
touch "$RADIO_DEV/ttyUSB0"
local options expected
for options in "AP--------02:Elecraft KX3 (Hamlib model 2045)" "----------01:Elecraft KX2 (Hamlib model 2044)" \
"AP-S----4---:Elecraft K4 (Hamlib model 2047)" "AP-S-R------:Elecraft K3S (Hamlib model 2043)" \
"AP-S--------:Elecraft K3 (Hamlib model 2029)"; do
expected="${options#*:}"
answers ttyUSB0 "38400 cat_id 017 ${options%%:*}"
run bash "$REPO/radio" probe "$RADIO_DEV/ttyUSB0"
[ "$output" = "$expected, at 38400 baud" ] || { echo "${options%%:*}: $output"; return 1; }
done
}
@test "configure sets up an Elecraft without --model, once its option modules say which" {
configurable
echo 0001 > "$ROOT_HUB/1-2/1-2.1/serial"
answers ttyUSB0 "38400 cat_id 017 AP--------01"
run bash "$REPO/radio" configure
[ "$status" -eq 0 ]
[[ "${lines[0]}" == "Setting up the Elecraft KX2 (Hamlib model 2044), on "* ]]
grep -q -- "-m 2044 " "$HOME/.config/systemd/user/hampack-rigctld.service"
}
@test "probe asks a real Elecraft for its option modules" {
fake_radio elecraft
run bash "$REPO/radio" probe "$PTY"
[ "$status" -eq 0 ]
[ "$output" = "Elecraft KX3 (Hamlib model 2045), at 38400 baud" ]
}