feat(tci): key CW through the radio's own macro keyer

The sixth CW engine, and the one the TCI backend was left without. A SunSDR
keys from the WebSocket that already carries the CAT: no WinKeyer, no second
serial port, nothing to wire.

    CW_MACROS:0,<text>;     send
    CW_MACROS_SPEED:<wpm>;  speed
    CW_MACROS_STOP;         abort

Confirmed against the TCI command table in ars-ka0s/eesdr-tci — the source that
settled SPOT. CW_MACROS rather than TCI 2.0's CW_MSG: it exists from 1.6, and
OpsLog resolves its own variables, so the before/after callsign fields have
nothing to carry.

Commas and semicolons are stripped before sending. They are the protocol's own
separators: a comma would become another argument, a semicolon would end the
command with the message half keyed and the rest parsed as a command.

Only the MACRO speed is set, not the paddle keyer's — an operator who set their
paddle to 28 wpm did not ask for it to change because a macro went out at 25.
And there is no backspace: TCI can stop a message but cannot un-type one, so the
type-ahead correction the Flex engine offers is absent rather than faked.
This commit is contained in:
2026-08-28 13:01:55 +02:00
parent 8bc4ed68d4
commit 766b0f95a4
11 changed files with 200 additions and 10 deletions
+72
View File
@@ -0,0 +1,72 @@
package cat
import (
"fmt"
"strings"
)
// CW keying over TCI — a sixth CW engine, so a SunSDR needs no WinKeyer and no
// second serial port: the radio's own macro keyer is driven over the WebSocket
// that already carries the CAT.
//
// The commands, from the TCI command table (confirmed against ars-ka0s/eesdr-tci,
// the same source that settled SPOT):
//
// CW_MACROS:<trx>,<text>; send text through the radio's keyer
// CW_MACROS_SPEED:<wpm>; the speed those macros are keyed at
// CW_MACROS_STOP; abort what is being keyed
// CW_MACROS_EMPTY; the radio saying the buffer has run dry
//
// CW_MSG (TCI 2.0) does the same with separate before/after callsign fields.
// CW_MACROS is used instead because it exists from 1.6 and OpsLog resolves the
// variables itself — the text handed here is already what should go on the air.
//
// Notably absent: there is no backspace. The FlexRadio CWX keyer can un-type
// what has not been sent yet; TCI can only stop. So the type-ahead correction
// the Flex engine offers is not offered here rather than faked.
// tciCWTextLimit caps one macro. A runaway paste down a WebSocket that also
// carries audio is worth refusing, and no real CW message is this long.
const tciCWTextLimit = 512
// SendCW keys a message through the radio's macro keyer.
func (t *TCI) SendCW(text string) error {
msg := sanitiseTCICW(text)
if msg == "" {
return nil
}
return t.send(fmt.Sprintf("cw_macros:0,%s;", msg))
}
// StopCW aborts the message being keyed.
func (t *TCI) StopCW() error { return t.send("cw_macros_stop;") }
// SetCWSpeed sets the macro keyer speed in words per minute.
//
// Only the MACRO speed: the paddle keyer has its own (CW_KEYER_SPEED) and an
// operator who has set their paddle to 28 wpm did not ask the logger to change
// it because a macro went out at 25.
func (t *TCI) SetCWSpeed(wpm int) error {
if wpm < 5 {
wpm = 5
}
if wpm > 60 {
wpm = 60
}
return t.send(fmt.Sprintf("cw_macros_speed:%d;", wpm))
}
// sanitiseTCICW makes a message safe to put in a TCI command.
//
// Commas and semicolons are the protocol's own separators — a comma inside the
// text would be read as another argument and a semicolon would end the command
// early, keying half a message and leaving the rest to be parsed as a command of
// its own. Neither belongs in Morse anyway.
func sanitiseTCICW(text string) string {
s := strings.ToUpper(strings.TrimSpace(text))
s = strings.NewReplacer(",", " ", ";", " ", "\r", " ", "\n", " ").Replace(s)
if len(s) > tciCWTextLimit {
s = s[:tciCWTextLimit]
}
return strings.TrimSpace(s)
}
+23
View File
@@ -96,3 +96,26 @@ func (m *Manager) TCIPanelDo(fn func(TCIPanelController) error) error {
return fn(tc)
})
}
// TCICWController is the radio's CW keyer, as the CW engine uses it.
//
// Three methods, and no backspace: TCI can stop a message but cannot un-type one
// (see tci_cw.go). Kept as its own interface rather than folded into the console
// one so a CW engine does not have to depend on forty panel setters to key a
// message.
type TCICWController interface {
SendCW(text string) error
StopCW() error
SetCWSpeed(wpm int) error
}
// TCICWDo dispatches one keyer command onto the CAT goroutine.
func (m *Manager) TCICWDo(fn func(TCICWController) error) error {
return m.exec(func(b Backend) error {
tc, ok := b.(TCICWController)
if !ok {
return fmt.Errorf("the active CAT backend is not a TCI radio")
}
return fn(tc)
})
}
+17
View File
@@ -22,3 +22,20 @@ func TestTCISpotsUnsupported(t *testing.T) {
}
}
}
func TestSanitiseTCICW(t *testing.T) {
// The separators must never survive: a comma would become another argument
// and a semicolon would end the command with the message half sent.
for _, c := range []struct{ in, want string }{
{"cq cq de f4bpo", "CQ CQ DE F4BPO"},
{" tu 599 ", "TU 599"},
{"73, gl", "73 GL"},
{"test;cw_macros_stop", "TEST CW_MACROS_STOP"},
{"line\r\nbreak", "LINE BREAK"},
{" ", ""},
} {
if got := sanitiseTCICW(c.in); got != c.want {
t.Errorf("sanitiseTCICW(%q) = %q, want %q", c.in, got, c.want)
}
}
}