fix(tci): one marker per callsign on the panorama, not one per spotter
Spot mirroring drew the same station two or three times, a few hertz apart. Not a loop in the spot pipeline — one cluster line produces exactly one SendSpot. It is that a popular DX station IS spotted two or three times, by different operators inside the same minute, and no two of them agree on the frequency to better than a few tens of hertz. This backend assumed ExpertSDR replaced a spot bearing a callsign it already held, and said so in a comment; it keys on the frequency too, so each of those became its own marker and stayed. The FlexRadio backend has always done this properly (spot remove before spot add, "one live spot per call"). TCI now does the same: the frequency drawn for each call is remembered, a re-spot within 500 Hz sends nothing at all, and one further away deletes the old marker before drawing the new one — so a station that really moves still moves, instead of collecting markers. SPOT_DELETE was not in the protocol document this backend was written from. Confirmed before use against ars-ka0s/eesdr-tci, an independent TCI library that lists SPOT with 5 arguments, SPOT_DELETE with 1 and SPOT_CLEAR with 0 — the other two matching exactly what already works here, which is what makes the third trustworthy. The memory is cleared where Connect sends spot_clear. Left standing, it would suppress the next spot for every remembered call as "already drawn" onto a panorama the radio had just emptied — spots would quietly stop appearing after a reconnect until each station changed frequency. Five tests on the decision, which is split out from SendSpot so it can be checked without a radio.
This commit is contained in:
+77
-2
@@ -48,6 +48,19 @@ type TCI struct {
|
||||
tx bool
|
||||
|
||||
lastSig string // last logged state signature (log only on change)
|
||||
|
||||
// spotFreq is the frequency of the marker currently on the panorama for each
|
||||
// callsign — the panadapter's own state, which TCI never reports back. It is
|
||||
// what makes one spot per call possible: without it there is no way to know
|
||||
// there is an older marker to delete.
|
||||
spotFreq map[string]int64
|
||||
}
|
||||
|
||||
func absInt64(v int64) int64 {
|
||||
if v < 0 {
|
||||
return -v
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
const tciDefaultPort = 40001
|
||||
@@ -100,14 +113,65 @@ func (t *TCI) Connect() error {
|
||||
debugLog.Printf("TCI: connected to %s", url)
|
||||
go t.reader(conn)
|
||||
if t.spotsEnabled {
|
||||
// Forget what we thought was on the panorama at the same moment the radio
|
||||
// is told to drop it. Kept, the memory would suppress the next spot for
|
||||
// each of those calls as "already drawn" onto a panorama now empty.
|
||||
t.mu.Lock()
|
||||
t.spotFreq = map[string]int64{}
|
||||
t.mu.Unlock()
|
||||
_ = t.send("spot_clear;") // drop any leftover spots from a previous session
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// spotFreqTolHz is how far a re-spot of the same callsign may sit from the one
|
||||
// already on the panorama before it is treated as a move rather than the same
|
||||
// spot said again.
|
||||
//
|
||||
// Two spotters hearing the same CW station rarely agree to better than a couple
|
||||
// of hundred hertz, and every one of them produces a cluster line. Below this
|
||||
// they are the same spot and nothing is sent at all; above it the marker is
|
||||
// deleted and redrawn where the station now is.
|
||||
const spotFreqTolHz = 500
|
||||
|
||||
// noteSpot records what the panorama is about to hold for a callsign and says
|
||||
// what has to be sent: whether to draw at all, and whether an older marker for
|
||||
// the same call must be deleted first.
|
||||
//
|
||||
// Separate from SendSpot so the rule can be tested without a radio — and
|
||||
// because the lock must be released before anything is sent: t.send takes t.mu
|
||||
// itself, Go mutexes are not reentrant, and sending while holding it would
|
||||
// deadlock the backend and take the rig offline.
|
||||
func (t *TCI) noteSpot(call string, freqHz int64) (draw, deletePrev bool) {
|
||||
key := strings.ToUpper(strings.TrimSpace(call))
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
prev, had := t.spotFreq[key]
|
||||
if had && absInt64(prev-freqHz) <= spotFreqTolHz {
|
||||
return false, false
|
||||
}
|
||||
if t.spotFreq == nil {
|
||||
t.spotFreq = map[string]int64{}
|
||||
}
|
||||
if len(t.spotFreq) > 4000 {
|
||||
t.spotFreq = map[string]int64{} // bound memory on a long session
|
||||
had = false // forgotten: nothing left to delete by name
|
||||
}
|
||||
t.spotFreq[key] = freqHz
|
||||
return true, had
|
||||
}
|
||||
|
||||
// SendSpot mirrors a cluster spot onto the TCI panorama (implements Spotter).
|
||||
// The radio replaces a spot that has the same callsign, so re-spotting updates
|
||||
// it in place. No-op when spot mirroring is disabled.
|
||||
// No-op when spot mirroring is disabled.
|
||||
//
|
||||
// ONE MARKER PER CALLSIGN. This code assumed the radio replaced a spot carrying
|
||||
// a callsign it already had; it does not. ExpertSDR keys a spot on its
|
||||
// frequency too, so a DX station spotted by three operators — 14025.00,
|
||||
// 14025.12, 14024.90, which is an ordinary minute on a cluster — was drawn
|
||||
// three times, a few pixels apart, and stayed that way.
|
||||
//
|
||||
// So the previous spot for the call is deleted before the new one is sent,
|
||||
// which is what the FlexRadio backend has always done (spot remove / spot add).
|
||||
func (t *TCI) SendSpot(s SpotInfo) error {
|
||||
if !t.spotsEnabled {
|
||||
return nil
|
||||
@@ -116,6 +180,17 @@ func (t *TCI) SendSpot(s SpotInfo) error {
|
||||
if call == "" || s.FreqHz <= 0 {
|
||||
return nil
|
||||
}
|
||||
draw, deletePrev := t.noteSpot(call, s.FreqHz)
|
||||
if !draw {
|
||||
return nil // the same station said again by another spotter
|
||||
}
|
||||
if deletePrev {
|
||||
// SPOT_DELETE takes the callsign alone. Not in the protocol PDF this
|
||||
// backend was written from; confirmed against ars-ka0s/eesdr-tci, which
|
||||
// lists SPOT (5 arguments), SPOT_DELETE (1) and SPOT_CLEAR (0) — the
|
||||
// other two matching what already works here.
|
||||
_ = t.send(fmt.Sprintf("spot_delete:%s;", call))
|
||||
}
|
||||
// TCI's SPOT command wants the colour as a signed 32-bit DECIMAL integer in
|
||||
// 0xAARRGGBB order — NOT a "0x…" hex string (e.g. "spot:UN7GK,cw,14025000,
|
||||
// -16776961,test;"). ExpertSDR silently drops a spot whose colour field it
|
||||
|
||||
Reference in New Issue
Block a user