ADR 0002: Protocol DSL
- Status: Accepted
- Date: 2026-10-10
Context
HamBench talks to radios over serial using a shared driver. Each radio describes its clone or CAT workflow as JSON steps beside serialConfig and memoryConfig in the module config. The desktop app and tests load that JSON; modules do not ship executable driver code.
The step vocabulary, schema, and interpreter already exist across ham-radio-api (RadioProtocolStep in src/radio/protocol.ts), ham-radio-utils (radio-protocol-schema.json), and ham-radio-driver (protocol-interpreter.ts and src/executors/). Shipped configs include Baofeng UV-5R, Kenwood TH-F6, TH-D74, and TM-D710A.
ham-radio-ui#60 (Icom IC-2730A) needs behavior the current step union cannot express: an unsolicited frame stream after clone-out, per-frame checksums, and high-bit encoding. Mid-session baud changes are already covered by setBaudRate on exchange steps. That work is not implemented yet; this ADR records the DSL we use today and how to extend it.
Authoritative operator and field reference: Protocol DSL and Protocols overview.
Decision
Protocol DSL. Radio I/O is a JSON array of typed steps (readMemory / writeMemory). There is no text grammar and no per-radio TypeScript driver. The interpreter dispatches each step to a built-in executor.
Step types in use. Top-level steps are: exchange (send / expect / setBaudRate / delay / timeout), chunked read, chunked write, catRead, and catWrite. Shape of expect is inferred (token, array, { bytes: N }, { until: token }). Byte tokens, placeholders ($address, $block, $chunkSize, $length, $data), inclusive endAddress, and addressSize / addressEndianness are defined in the types and schema; see the linked spec.
Extending the DSL (convention from this date forward). A new wire behavior that does not fit an existing step requires a new step type shipped together in:
ham-radio-api— extendRadioProtocolStepand related types.ham-radio-utils— extendradio-protocol-schema.jsonand tests.ham-radio-driver— add an executor and register it inStepExecutorRegistry(cat read/write before read/write before exchange).- Documentation in ham-radio-docs and tests in the driver and affected modules.
ProtocolInterpreter.registerExecutor and custom-step-example.ts are for in-process experiments only. JSON modules cannot register custom executors.
Packers (named code exception). Live CAT memory loops may set pack on catRead / catWrite. Only kenwood-th-f6 is implemented today. Packers turn CAT line replies into a fixed memory-map record; they are not a substitute for a new clone step type (for example Icom streamed frames).
Error cleanup (not a step type). Optional per-operation onError exchange lists run after failure or cancel; see ADR 0011.
Options considered
Text grammar or per-radio driver code. Rejected. Every new radio would fork serial logic instead of editing JSON.
Per-module TypeScript executors. Rejected for distribution. Modules are JSON-only (ADR 0004).
Model new protocols only as another packer. Rejected when the wire shape is not “one CAT command → one line.” Streamed clone protocols need a dedicated step type.
Shared JSON interpreter plus coordinated library releases for new step types. Accepted.
Consequences
- New radios extend existing step types where possible; otherwise the org ships a library release with the new step before a module can use it.
- Documentation and the protocol editor stay aligned with
radio-protocol-schema.json, not with ad hoc executor names. - Icom IC-2730A and similar radios are tracked as new step work (issue #60), not as module-only changes.
- Exchange step timeout defaults to 5000 ms, documented in Protocol DSL; implementation is in
protocol-operations.ts. CAT memory loops default to 2000 ms viacatTimeoutMsincat-packers.ts, not on the Protocol DSL page.