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:
co-authored by
Claude Opus 5.5
parent
4cb5ce25ff
commit
81c6e0b73f
@@ -309,7 +309,13 @@ for baud in sys.argv[2:]:
|
||||
unkey()
|
||||
found = re.search(rb"ID(\d{3,4});", ask(b"ID;"))
|
||||
if found:
|
||||
print(baud, "cat_id", found.group(1).decode())
|
||||
# Elecraft radios all answer ID017;. Their option modules (OM;) tell
|
||||
# them apart: twelve characters, which radio reads
|
||||
options = ""
|
||||
if found.group(1) == b"017":
|
||||
om = re.search(rb"OM ([A-Za-z0-9-]{12});", ask(b"OM;"))
|
||||
options = om.group(1).decode() if om else ""
|
||||
print(baud, "cat_id", found.group(1).decode(), options)
|
||||
break
|
||||
# To any address (00) from a computer (E0); the radio answers to E0 from its address
|
||||
found = re.search(rb"\xfe\xfe\xe0(.)\x19\x00.\xfd", ask(bytes.fromhex("fefe00e01900fd")), re.S)
|
||||
@@ -323,16 +329,50 @@ for baud in sys.argv[2:]:
|
||||
# answer, or PROBE_ERROR if the port couldn't be opened
|
||||
probe_port() {
|
||||
local reply
|
||||
ANSWER_BAUD="" ANSWER_FIELD="" ANSWER_VALUE="" PROBE_ERROR=""
|
||||
ANSWER_BAUD="" ANSWER_FIELD="" ANSWER_VALUE="" ANSWER_OPTIONS="" PROBE_ERROR=""
|
||||
if ! reply="$(ask_radio "$1")"; then
|
||||
PROBE_ERROR="${reply#error }"
|
||||
PROBE_ERROR="${PROBE_ERROR:-python3 failed}"
|
||||
return 1
|
||||
fi
|
||||
read -r ANSWER_BAUD ANSWER_FIELD ANSWER_VALUE <<< "$reply"
|
||||
read -r ANSWER_BAUD ANSWER_FIELD ANSWER_VALUE ANSWER_OPTIONS <<< "$reply"
|
||||
[ -n "$ANSWER_VALUE" ]
|
||||
}
|
||||
|
||||
# Which Elecraft radio's option modules these are (its reply to OM;, after
|
||||
# "OM "), as Hamlib 4.7's elecraft_open() reads them: a KX2 or KX3 has 0 and
|
||||
# its model number (1 or 2) last; a K4 has S and 4 among them; a K3S has R;
|
||||
# anything else is a K3. elecraft_model OPTIONS
|
||||
elecraft_model() {
|
||||
if [ "${1:10:1}" = 0 ]; then
|
||||
case "${1:11:1}" in
|
||||
1) echo KX2 ;;
|
||||
2) echo KX3 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
elif [[ "$1" == *S* && "$1" == *4* ]]; then
|
||||
echo K4
|
||||
elif [[ "$1" == *R* ]]; then
|
||||
echo K3S
|
||||
else
|
||||
echo K3
|
||||
fi
|
||||
}
|
||||
|
||||
# The radios that could have given the probe's answer, as matching prints
|
||||
# them: those with its ID, narrowed by an Elecraft radio's option modules
|
||||
answer_models() {
|
||||
local models model kind narrowed=""
|
||||
models="$(matching "$ANSWER_FIELD" "$ANSWER_VALUE")" || return 1
|
||||
if [ -n "${ANSWER_OPTIONS:-}" ] && kind="$(elecraft_model "$ANSWER_OPTIONS")"; then
|
||||
while IFS= read -r model; do
|
||||
[ "$(conf_field "${model%|*}" elecraft)" = "$kind" ] && narrowed+="$model"$'\n'
|
||||
done <<< "$models"
|
||||
[ -z "$narrowed" ] || models="${narrowed%$'\n'}"
|
||||
fi
|
||||
echo "$models"
|
||||
}
|
||||
|
||||
# Describe the radios matching prints, in one line
|
||||
models_text() {
|
||||
local line names=()
|
||||
@@ -360,7 +400,7 @@ unknown_answer_text() {
|
||||
# Describe the radio that answered
|
||||
describe_answer() {
|
||||
local models
|
||||
models="$(matching "$ANSWER_FIELD" "$ANSWER_VALUE")"
|
||||
models="$(answer_models)"
|
||||
if [ -n "$models" ]; then models_text "$models"; else unknown_answer_text; fi
|
||||
}
|
||||
|
||||
@@ -415,7 +455,7 @@ identify() {
|
||||
if probe_port "$DEVDIR/$port"; then
|
||||
ID_CAT_PORT="$port" ID_BAUD="$ANSWER_BAUD"
|
||||
if [ -z "$ID_MODELS" ]; then
|
||||
ID_MODELS="$(matching "$ANSWER_FIELD" "$ANSWER_VALUE")"
|
||||
ID_MODELS="$(answer_models)"
|
||||
[ -n "$ID_MODELS" ] || ID_ANSWER="$(unknown_answer_text)"
|
||||
ID_HOW="answered on $port at $ANSWER_BAUD baud"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user