Implemented qt port + e2e

This commit is contained in:
Martino Ferrari
2026-06-26 09:11:10 +02:00
parent 0d7d8f396b
commit 4702d0a217
146 changed files with 57272 additions and 128 deletions
@@ -94,6 +94,8 @@ void UDPSourceSession::ResetCalibration() {
for (uint32 i = 0u; i < UDPSS_MAX_SIGNALS; i++) {
timeSigCalibValid_[i] = false;
timeSigCalib_[i] = 0.0;
timeSigLastValid_[i] = false;
timeSigLastTimerS_[i] = 0.0;
lastPktWallValid_[i] = false;
lastPktWallS_[i] = 0.0;
accScalarPrevN_[i] = 0u;
@@ -359,6 +361,28 @@ void UDPSourceSession::ParseDataPayload(const uint8 *payload, uint32 size) {
off += elemsToRead * wireElemBytes;
}
/* The decode scratch is sized at CONFIG time to the largest per-signal
* element count, but an Accumulate packet writes numSamples elements per
* accumulated scalar — for a lone scalar source that count is 1, so the
* batch decode would overrun valScratch_/tsBatchScratch_ (heap corruption
* that scrambled timestamps into the value stream). Grow the scratch to
* the largest element count actually present in THIS packet before pass 2.
* Runs on the receive thread (the only writer of these buffers) and only
* when the batch first exceeds the current capacity. */
uint32 maxNeeded = 1u;
for (uint32 s = 0u; s < nSigs; s++) {
if (sigElems[s] > maxNeeded) { maxNeeded = sigElems[s]; }
}
if (maxNeeded > timeScratchLen_) {
delete[] timeScratch_;
delete[] valScratch_;
delete[] tsBatchScratch_;
timeScratch_ = new float64[maxNeeded];
valScratch_ = new float64[maxNeeded];
tsBatchScratch_ = new float64[maxNeeded];
timeScratchLen_ = maxNeeded;
}
/* Pass 2: decode values and timestamps; write ring buffers.
* Timestamp logic mirrors Go buildBinaryDataMessageForSource (hub.go). */
static const float64 kRecalibThresholdS = 2.0;
@@ -390,12 +414,8 @@ void UDPSourceSession::ParseDataPayload(const uint8 *payload, uint32 size) {
float64 tv0 = 0.0;
DecodeElems(payload, sigOff[tIdx], descs[tIdx], 1u, &tv0);
const float64 timerS = tv0 * timerToSec;
if ((!timeSigCalibValid_[tIdx]) ||
(Fabs((timeSigCalib_[tIdx] + timerS) - wallNowS) > kRecalibThresholdS)) {
timeSigCalib_[tIdx] = wallNowS - timerS;
timeSigCalibValid_[tIdx] = true;
}
anchor = timeSigCalib_[tIdx] + timerS;
const float64 calib = CalibrateTimeSignal(tIdx, timerS, wallNowS);
anchor = calib + timerS;
} else {
anchorIsFirstSample = false;
}
@@ -416,12 +436,7 @@ void UDPSourceSession::ParseDataPayload(const uint8 *payload, uint32 size) {
(nElems <= timeScratchLen_)) {
DecodeElems(payload, sigOff[tIdx], descs[tIdx], nElems, timeScratch_);
const float64 timer0S = timeScratch_[0] * timerToSec;
if ((!timeSigCalibValid_[tIdx]) ||
(Fabs((timeSigCalib_[tIdx] + timer0S) - wallNowS) > kRecalibThresholdS)) {
timeSigCalib_[tIdx] = wallNowS - timer0S;
timeSigCalibValid_[tIdx] = true;
}
const float64 calib = timeSigCalib_[tIdx];
const float64 calib = CalibrateTimeSignal(tIdx, timer0S, wallNowS);
DecodeElems(payload, sigOff[s], desc, nElems, valScratch_);
for (uint32 e = 0u; e < nElems; e++) {
tsBatchScratch_[e] = calib + timeScratch_[e] * timerToSec;