fix(udps): publish the producer's HRT frequency so timestamps survive the hop
DATA packets timestamp with the raw value of the producer's high-resolution counter, and the wire never said how fast that counter runs. The hub divided by its own timer's frequency instead, which is only the same number while producer and hub share a machine — on x86 it is the TSC frequency and differs from model to model. Off-box, every accumulated batch was therefore laid out over the wrong span of time: the samples in it drift away from where they belong and start colliding with the next packet's, which is the "same" symptom as a stale time base even though nothing is out of order. CONFIG now carries the rate as a trailing uint64, alongside the publish-mode byte and read the same tolerant way: absent or zero means the producer did not say, and the hub falls back to its own timer as before. Anything below 1 kHz is not a high-resolution timer and is refused, so a mis-parsed payload cannot stretch a millisecond batch across seconds. The Accumulate DATA payload is unchanged, so this costs nothing per packet and the period *within* a batch is still estimated from the gap between packets. The Go, C and browser parsers already ignore trailer bytes they do not know, so they read the new CONFIG unchanged; none of them uses the HRT timestamp. Also corrects the Accumulate DATA layout in all three protocol documents: they described it as one snapshot per array signal, where it has always been one per accumulated cycle. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
092fd3c775
commit
5562877c99
@@ -102,6 +102,41 @@ inline float64 UDPSEstimateAccumDt(const float64 gap, const uint32 prevN,
|
||||
return dtEMA;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pick the tick rate to divide a producer's DATA timestamps by.
|
||||
*
|
||||
* DATA packets carry the raw value of the producer's high-resolution counter,
|
||||
* which is meaningless without the rate it runs at. The rate is published in
|
||||
* the CONFIG trailer, after the descriptors and the publish-mode byte. When it
|
||||
* is missing — an older producer, or one that could not determine it — the
|
||||
* only remaining option is this host's own timer, which is right only while
|
||||
* the two machines agree; on x86 that is the TSC frequency, so it is a
|
||||
* different number on every model.
|
||||
*
|
||||
* @param payload Reassembled CONFIG payload.
|
||||
* @param size Bytes in @p payload.
|
||||
* @param numSigs Signal count already read from the payload, capped to what
|
||||
* the receiver will store.
|
||||
* @param localFreq This host's HRT frequency, used as the fallback.
|
||||
* @return Ticks per second to convert DATA timestamps with; never 0.
|
||||
*/
|
||||
inline float64 UDPSConfigHrtFrequency(const uint8 *payload, const uint32 size,
|
||||
const uint32 numSigs,
|
||||
const float64 localFreq) {
|
||||
const uint32 offset = 4u + (numSigs * MARTe::UDPS_SIGNAL_DESC_SIZE) + 1u;
|
||||
if ((payload != NULL_PTR(const uint8 *)) && (size >= (offset + 8u))) {
|
||||
uint64 wireFreq = 0u;
|
||||
memcpy(&wireFreq, payload + offset, 8u);
|
||||
/* Anything below 1 kHz is not a high-resolution timer; the field is
|
||||
* either absent, unset, or the payload was mis-parsed, and adopting it
|
||||
* would stretch every timestamp far enough to make the trace useless. */
|
||||
if (wireFreq >= 1000u) {
|
||||
return static_cast<float64>(wireFreq);
|
||||
}
|
||||
}
|
||||
return localFreq;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief One connected UDPStreamer source.
|
||||
*
|
||||
@@ -463,10 +498,11 @@ private:
|
||||
float64 lastPktWallS_[UDPSS_MAX_SIGNALS];
|
||||
bool lastPktWallValid_[UDPSS_MAX_SIGNALS];
|
||||
|
||||
/* Accumulated-scalar timing: HRT counter frequency (local == sender on the
|
||||
* same host) and the previous packet's sample count, used to reconstruct
|
||||
* per-sample timestamps from the embedded sender HRT instead of the (UDP
|
||||
* burst-sensitive) packet arrival time. */
|
||||
/* Accumulated-scalar timing: the producer's HRT counter frequency and the
|
||||
* previous packet's sample count, used to reconstruct per-sample timestamps
|
||||
* from the embedded sender HRT instead of the (UDP burst-sensitive) packet
|
||||
* arrival time. Seeded from this host's timer and replaced by the rate the
|
||||
* producer publishes in CONFIG; see UDPSConfigHrtFrequency. */
|
||||
float64 hrtFreq_;
|
||||
uint32 accScalarPrevN_[UDPSS_MAX_SIGNALS];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user