Implemented new C++ logic

This commit is contained in:
Martino Ferrari
2026-06-12 15:25:13 +02:00
parent 617b5bd712
commit f25bd7f08e
220 changed files with 39185 additions and 850 deletions
+47 -3
View File
@@ -82,6 +82,14 @@ type MarteController struct {
cmdPort int
udpPort int
logPort int
// rawSigs holds the most-recently received UDP CONFIG signals before
// translation. After DISCOVER populates m.signals, we re-translate and
// push a corrected config to the hub so that src.signals names match the
// s.Values keys used by ParseData (which also re-translates rawSigs).
rawSigsMu sync.RWMutex
rawSigs []udpsprotocol.SignalInfo
rawPm uint8
}
// NewMarteController creates a MarteController bound to the given hub.
@@ -483,8 +491,19 @@ func (m *MarteController) handleJSONResponse(tag, data string) {
all := append(m.discoverAcc, resp.Signals...)
m.discoverAcc = nil
m.parseDiscoverSignals(all)
// Synthesize SignalInfo for the hub so the plot system gets a config
m.synthesizeHubConfig(all)
// Update hub config now that m.signals is populated for name translation.
// If UDP CONFIG was already received (rawSigs non-empty), re-translate the
// real config so that src.signals uses the same names as s.Values produced
// by ParseData (which also re-translates rawSigs on every PktData).
// If UDP CONFIG has not arrived yet, fall back to synthesizing from DISCOVER.
m.rawSigsMu.RLock()
raw := m.rawSigs
m.rawSigsMu.RUnlock()
if len(raw) > 0 {
m.hub.UpdateConfigForSource("debug", m.translateSignalNames(raw))
} else {
m.synthesizeHubConfig(all)
}
// Re-marshal the merged list so the browser gets a single consistent blob.
merged, _ := json.Marshal(discoverResp{Signals: all})
broadcastHub(m.hub, map[string]any{
@@ -747,7 +766,15 @@ func (m *MarteController) synthesizeHubConfig(sigs []discoverSignalJSON) {
}
sigInfos = append(sigInfos, si)
}
m.hub.UpdateConfigForSource("debug", sigInfos)
// Translate to GAM-path names so the synthesised config matches the names
// that the real UDP CONFIG (and data frames) use. Without this translation,
// synthesizeHubConfig would overwrite the real config with DISCOVER-canonical
// names (e.g. "DDB1.Ch3"), causing buildBinaryDataMessageForSource to fail to
// find signals in s.Values (which uses translated names), starving the JS
// buffer and limiting live streaming to the fraction of a second that
// accumulated before the DISCOVER response arrived.
translated := m.translateSignalNames(sigInfos)
m.hub.UpdateConfigForSource("debug", translated)
}
// ---------------------------------------------------------------------------
@@ -829,6 +856,12 @@ func (m *MarteController) runDebugUDP(host string, port int) {
log.Printf("[debug-udp] parse config: %v", err)
continue
}
// Store raw (untranslated) sigs so that after DISCOVER populates
// m.signals we can re-translate and push a corrected config to the hub.
m.rawSigsMu.Lock()
m.rawSigs = sigs
m.rawPm = pm
m.rawSigsMu.Unlock()
sigs = m.translateSignalNames(sigs)
currentSigs = sigs
currentPublishMode = pm
@@ -839,6 +872,17 @@ func (m *MarteController) runDebugUDP(host string, port int) {
if len(currentSigs) == 0 {
continue
}
// Re-translate on every data packet: if DISCOVER ran since the last
// UDP CONFIG arrived (which is the common case — CONFIG is sent once
// at startup, before the browser connects and triggers DISCOVER),
// m.signals is now populated and we must use translated names so that
// s.Values keys match src.signals keys in buildBinaryDataMessageForSource.
m.rawSigsMu.RLock()
raw := m.rawSigs
m.rawSigsMu.RUnlock()
if len(raw) > 0 {
currentSigs = m.translateSignalNames(raw)
}
samples, err := udpsprotocol.ParseData(complete, currentSigs, currentPublishMode, arrivalTime)
if err != nil {
log.Printf("[debug-udp] parse data: %v", err)