refactor(tci): remove the test bench now that choosing the device is the setup

The TCI section of the audio settings was an investigation: open the
stream, read what arrives, record ten seconds to listen to, key a tone.
It answered every question it was built for — the frame layout, the
sample width, that the radio asks rather than follows a clock, that the
transmit audio source decides — and confirmed 80 W on real hardware.

None of that belongs in front of an operator now. The radio is simply one
of the devices in the two dropdowns, and choosing it IS the configuration:
one control, in the place where the question is already being asked.
Keeping the tick box beside it would have been two switches for one
decision, with the second one where nobody looks.

Gone with it: the stream/record/probe bindings, the audio.tci_rx setting,
and twenty-four translation keys. The plumbing they proved out stays and
now carries the voice keyer.
This commit is contained in:
2026-08-26 00:13:04 +02:00
parent ec3e60e47b
commit ceb88d2e29
10 changed files with 24 additions and 601 deletions
+5 -158
View File
@@ -26,24 +26,20 @@ package cat
// used. Answering the request is what makes the difference, and it also means
// the radio sets the pace — no drift, no buffer to tune.
//
// What remains here is the probe: a tone, on demand, to prove the path end to
// end on real hardware. The voice keyer will use the same feed mechanism with
// WAV samples in place of the sine.
// All of it was established with a tone probe — key the radio, push a sine,
// watch — which is gone now that it has served its purpose: it answered the
// three questions above, confirmed 80 W out on a real SunSDR, and had no
// business in front of an operator once the voice keyer worked. What is left is
// the exchange it discovered, with tci_tx_play.go supplying the message.
import (
"encoding/binary"
"fmt"
"math"
"time"
"github.com/gorilla/websocket"
)
// tciTXProbeMaxSeconds caps the pass. Long enough to read a power meter, short
// enough that a carrier left running by a defect is a mistake and not an
// incident.
const tciTXProbeMaxSeconds = 10
// sendBinaryFrame writes one TCI binary frame: the 16-word header the radio's
// own frames carry, then the payload.
func (t *TCI) sendBinaryFrame(stype, rx, rate, length int, payload []byte) error {
@@ -116,152 +112,3 @@ func (t *TCI) setTXFeed(fn func(samples int) []byte) {
t.audio.txSent, t.audio.txShort = 0, 0
t.audio.mu.Unlock()
}
// ProbeTXStream keys the radio, answers its chrono requests with a tone for the
// given number of seconds, unkeys, and reports what happened.
//
// INTO A DUMMY LOAD. Confirmed on a SunSDR: 80 W out of a 1 kHz tone at 70% of
// full scale into 80% drive.
//
// If the radio's transmit audio source is the microphone rather than TCI it
// will not ask for anything, and this stops within a fifth of a second and says
// which setting to change.
func (t *TCI) ProbeTXStream(seconds int, toneHz float64) error {
if seconds <= 0 {
seconds = 5
}
if seconds > tciTXProbeMaxSeconds {
seconds = tciTXProbeMaxSeconds
}
if toneHz <= 0 {
toneHz = 1000
}
t.mu.Lock()
allowed, known, connected := t.txAllowed, t.txAllowedKnown, t.conn != nil
mode := t.mode
drive := t.drive
t.mu.Unlock()
if !connected {
return fmt.Errorf("not connected to the radio")
}
if known && !allowed {
return fmt.Errorf("the radio refuses transmitting (tx_enable is false)")
}
if !tciDigitalMode(mode) {
// A NOTE, not a refusal.
//
// The first experiments said "digital modes only": SSB produced nothing
// four times over, DIGU answered at once. That was a real observation
// and the wrong rule. ExpertSDR3 has a TRANSMIT AUDIO SOURCE — the
// microphone or TCI — and it was simply set to the microphone; the mode
// had nothing to do with it. Refusing SSB would have blocked the one
// thing a voice keyer exists for.
debugLog.Printf("TCI: TX PROBE — mode is %s, not a digital mode. That is fine IF ExpertSDR3's transmit audio source is set to TCI rather than the microphone; if it is not, the radio will not ask for audio and this stops straight away", mode)
}
t.audio.mu.Lock()
rate := t.audio.rate
t.audio.mu.Unlock()
if rate <= 0 {
rate = 48000
}
// The tone, generated on demand: the radio asks for a size and gets exactly
// that, at whatever pace it asks. Phase is carried across the calls, since a
// sine restarted every frame is a click 47 times a second.
phase := 0.0
step := 2 * math.Pi * toneHz / float64(rate)
// Near full scale.
//
// A quarter was the first choice, out of caution, and the first real test
// showed exactly what that produces: a clean signal on the panadapter and a
// wattmeter that never moves. In a digital mode the radio expects a line
// level it can drive to full output — the POWER is set by its own drive
// control, not by how loud we send — so sending quietly just wastes the
// range. Short of 1.0 to leave room for the sine's peaks.
const amp = 0.7
const chans = 2
le := binary.LittleEndian
t.setTXFeed(func(samples int) []byte {
payload := make([]byte, samples*4)
for s := 0; s+chans-1 < samples; s += chans {
v := float32(math.Sin(phase) * amp)
phase += step
if phase > 2*math.Pi {
phase -= 2 * math.Pi
}
bits := math.Float32bits(v)
le.PutUint32(payload[s*4:], bits) // left
le.PutUint32(payload[(s+1)*4:], bits) // right
}
return payload
})
defer t.setTXFeed(nil)
// The drive is in the line because it is half of "how much power came out".
// A tone at full scale into a drive of 15 is still 15% of the radio.
debugLog.Printf("TCI: TX PROBE starting — %d s of a %.0f Hz tone at %.0f%% of full scale, answered to the radio's own requests, mode %s, radio drive %d%%, INTO A DUMMY LOAD",
seconds, toneHz, amp*100, mode, drive)
if err := t.SetPTT(true); err != nil {
return fmt.Errorf("could not key the radio: %w", err)
}
// Every path out unkeys, including the panic that has not happened yet. A
// transmitter left keyed by a defect is the one fault here that would reach
// somebody else's band.
defer func() {
if err := t.SetPTT(false); err != nil {
debugLog.Printf("TCI: TX PROBE — UNKEY FAILED (%v) — stop the transmission at the radio", err)
}
}()
// Wait for the radio to ask, and give up quickly if it does not.
//
// The radio declares what it wants by requesting audio — 47 times a second
// when it wants any at all. So there is no need to decide in advance whether
// this mode or that setting will work: key, listen for one request, and if
// none comes in a fifth of a second, stop. That is a quarter of a second of
// carrier instead of five, and an answer that names the setting to change.
deadline := time.Now().Add(200 * time.Millisecond)
for time.Now().Before(deadline) {
t.audio.mu.Lock()
asked := t.audio.txSent > 0
t.audio.mu.Unlock()
if asked {
break
}
time.Sleep(10 * time.Millisecond)
}
t.audio.mu.Lock()
started := t.audio.txSent
t.audio.mu.Unlock()
if started == 0 {
debugLog.Printf("TCI: TX PROBE — the radio never asked for audio; set ExpertSDR3's transmit audio source to TCI (it is on the microphone)")
return fmt.Errorf("the radio did not ask for any audio — set ExpertSDR3's transmit audio source to TCI instead of the microphone, then try again")
}
time.Sleep(time.Duration(seconds)*time.Second - 200*time.Millisecond)
t.audio.mu.Lock()
sent, short := t.audio.txSent, t.audio.txShort
chrono := t.audio.countByType[tciStreamTXChrono] - t.audio.txMark[tciStreamTXChrono]
t.audio.mu.Unlock()
debugLog.Printf("TCI: TX PROBE finished — the radio asked %d times, %d frames sent, %d requests unanswered",
chrono, sent, short)
if sent == 0 {
debugLog.Printf("TCI: TX PROBE — the radio never asked for audio; in a digital mode it should, so check that ExpertSDR3 takes its transmit audio from TCI")
}
return nil
}
// tciDigitalMode says whether the radio's current mode is one where network
// audio reaches the modulator. Measured on a SunSDR: DIGU asks for audio, SSB
// never does.
func tciDigitalMode(mode string) bool {
switch mode {
case "digu", "digl", "DIGU", "DIGL", "FT8", "ft8", "FT4", "ft4", "DATA", "data", "RTTY", "rtty":
return true
}
return false
}