Files
OpsLog/internal/kpa/doc.go
T
rouggy 55a643d9a4 feat(kpa): the Elecraft KPA500 / KPA1500 protocol, decoded and pinned
One package for both amplifiers: they share the Elecraft command set — a
caret, letters, a semicolon, case-insensitive in and upper case out — the
same family as the K3/K4 panel. What differs is the transport and which
commands exist, not the grammar.

Everything here comes from the KPA1500 Programming Reference, and the
document's own examples ARE the test:

  ^WS1204 014;  1204 W and SWR 1.4:1 — power and SWR in one exchange
  ^VI513 061;   51.3 V and 61 A — volts in tenths, amps whole
  ^FL91;        HEX, and 0x91 is 'antenna not connected?'

That last one is why the parsing is pinned rather than eyeballed: read as
decimal, 90 and 91 become 144 and 145 and match nothing, so an amplifier
shut down by high reflected power would report a fault OpsLog could not
name. SWR in tenths is confirmed by the reference too — 'expressed in
tenths, 123 is 12.3:1' — where it had only been inferred from Hamlib.

The client is question-and-answer under one lock, never two questions in
flight: the reference states there is no flow control and that commands
are paced by waiting for the reply. Fast cycle four times a second for
power, SWR and the fault; the rest once a second.

Faults are named in the operator's terms — 'the ATU found no match', not
'fault 92' — and an unknown code from a newer firmware still says
something rather than nothing.

Not wired to the app yet, and two commands are deliberately absent: ^TX
makes the amplifier transmit from software, and ^ON0 cuts the main
supplies with Wake-on-LAN as the way back. Neither belongs on a poll loop
or behind a button that can be pressed by accident.
2026-08-26 17:43:32 +02:00

61 lines
2.8 KiB
Go

// Package kpa talks to the Elecraft KPA500 and KPA1500 amplifiers.
//
// One package for both: they share the Elecraft command set — ASCII, a caret
// prefix, a semicolon terminator, case-insensitive on the way in and upper case
// on the way back — which is the same family as the K3/K4 panel in
// internal/cat. What differs between the two models is the transport and which
// commands exist, not the grammar.
//
// # Transports
//
// KPA500: serial only.
//
// KPA1500: serial, and a network server. Four things may be connected AT ONCE,
// which is unusual enough to design around — the Host PC USB port, the XCVR
// SERIAL connector when repurposed as a second host, ONE TCP client, and any
// number of UDP clients:
//
// - TCP on port 1500 (changed with ^CP). Single client. If the operator
// already has the Elecraft utility or another program on TCP, OpsLog will
// not get in, and the failure is a refused connection rather than anything
// the amplifier says.
// - UDP on the same port. Many clients, one command per packet and at most
// one response, and packets may be dropped under congestion — so it is the
// right choice for sharing the amplifier and the wrong one for a command
// that must not be missed.
//
// # Pacing
//
// There is NO flow control. The reference is explicit: pace commands by waiting
// for the response to the previous one. So this client is strictly
// question-and-answer on one connection, like the ACOM and SPE clients, rather
// than firing a poll cycle and sorting out the replies afterwards.
//
// # Serial speed
//
// 4800 to 230400, 8N1, set on the amplifier (^BR / SERIAL SPEED HOST) and not
// negotiated. Elecraft's own utility finds it by sending bare semicolons at
// each speed until something answers — worth copying if operators turn up with
// amplifiers whose speed they do not know.
//
// # What is settled, and how
//
// From the KPA1500 Programming Reference:
//
// - ^SW is the SWR IN TENTHS. "123 is 12.3:1", so ^SW015 is 1.5:1. This was
// first taken from Hamlib's backend and is now confirmed by the document,
// which matters more than it sounds: a wrongly scaled SWR bar reports a
// good match on a bad antenna.
// - ^WS returns forward power AND SWR together, ^VI returns PA voltage AND
// current together. Two round trips instead of four on the link the display
// depends on while the operator is transmitting.
// - ^SF returns the fault log: index, fault code, a short name in quotes, a
// timestamp, and fault-specific values. ^FC describes the codes.
//
// # Not touched
//
// ^TX simulates a KEY IN — it makes the amplifier transmit from software — and
// ^ON0 switches the main supplies off. Neither belongs on a poll loop or behind
// a button that can be pressed by accident.
package kpa