Implemented and fixed many issues
This commit is contained in:
@@ -154,6 +154,37 @@ public:
|
||||
*/
|
||||
void SetRingCapacities(uint32 temporal, uint32 scalar);
|
||||
|
||||
/**
|
||||
* @brief Grow every ring so it can retain at least @p seconds of history.
|
||||
*
|
||||
* The required capacity is seconds × the rate measured from the ring
|
||||
* itself (count / time span), because most sources advertise
|
||||
* samplingRate = 0. Signals whose ring has not filled enough to measure a
|
||||
* rate are left alone; the caller is expected to retry.
|
||||
*
|
||||
* @param seconds Retention target.
|
||||
* @param maxPts Per-signal ceiling, so a multi-Msps source cannot be
|
||||
* asked to allocate an unbounded amount of memory.
|
||||
* @return true if at least one ring was enlarged.
|
||||
*/
|
||||
bool GrowRingsForSeconds(float64 seconds, uint32 maxPts);
|
||||
|
||||
/** @return Largest ring capacity currently allocated in this session. */
|
||||
uint32 GetMaxRingCapacity() const;
|
||||
|
||||
/**
|
||||
* @brief Newest timestamp this source has produced on its *own* clock, or
|
||||
* 0 when it publishes no producer-timed signal (or has no data yet).
|
||||
*
|
||||
* Only signals that reference a time signal count: PACKET-timed signals
|
||||
* are stamped on arrival and so live in the hub's wall-clock domain, not
|
||||
* the producer's, even when they come from the very same source. A source
|
||||
* free-running on its own clock sits seconds away from wall time and drifts,
|
||||
* so anything waiting for a capture window to fill must compare against
|
||||
* this, never clock_gettime().
|
||||
*/
|
||||
float64 ProducerNewestTime() const;
|
||||
|
||||
/**
|
||||
* @brief Attach the (shared) hub trigger engine.
|
||||
* Every decoded sample of the trigger's configured signal — resolved
|
||||
@@ -241,24 +272,42 @@ private:
|
||||
* signal @p tIdx given the first decoded timer value @p timer0S of the
|
||||
* current packet and the arrival wall time @p wallNowS.
|
||||
*
|
||||
* Re-anchors the offset (offset = wallNowS − timer0S) when (a) it is the
|
||||
* first packet, (b) the source clock jumped backward versus the previous
|
||||
* packet (a looping/rewinding producer), or (c) the computed wall time has
|
||||
* drifted past kRecalibThresholdS from the true arrival wall time.
|
||||
* Snaps the offset to wallNowS − timer0S only when there is a genuine
|
||||
* discontinuity in the source: the first packet, or a backward jump of the
|
||||
* source clock (a looping/rewinding producer).
|
||||
*
|
||||
* A source that free-runs on its own clock also *drifts* against wall time,
|
||||
* without any discontinuity. Snapping that away would shift the whole
|
||||
* published timeline in one step and so tear a hole of exactly the drift
|
||||
* into a stream that is in fact continuous, which is worse than the drift
|
||||
* itself. Past kRecalibThresholdS the offset is therefore slewed instead:
|
||||
* nudged towards wall time by at most kMaxSlewFraction of the packet's own
|
||||
* duration, so the seam can never exceed a fraction of one packet.
|
||||
*
|
||||
* @return the calibration offset to add to timer-seconds for this signal.
|
||||
*/
|
||||
inline float64 CalibrateTimeSignal(uint32 tIdx, float64 timer0S,
|
||||
float64 wallNowS) {
|
||||
static const float64 kRecalibThresholdS = 2.0;
|
||||
static const float64 kMaxSlewFraction = 0.1;
|
||||
const bool reset = timeSigLastValid_[tIdx] &&
|
||||
(timer0S < timeSigLastTimerS_[tIdx]);
|
||||
const float64 drift = (timeSigCalib_[tIdx] + timer0S) - wallNowS;
|
||||
const float64 absDrift = (drift < 0.0) ? -drift : drift;
|
||||
if ((!timeSigCalibValid_[tIdx]) || reset ||
|
||||
(absDrift > kRecalibThresholdS)) {
|
||||
if ((!timeSigCalibValid_[tIdx]) || reset) {
|
||||
timeSigCalib_[tIdx] = wallNowS - timer0S;
|
||||
timeSigCalibValid_[tIdx] = true;
|
||||
}
|
||||
else {
|
||||
const float64 drift = (timeSigCalib_[tIdx] + timer0S) - wallNowS;
|
||||
const float64 absDrift = (drift < 0.0) ? -drift : drift;
|
||||
if (absDrift > kRecalibThresholdS) {
|
||||
const float64 pktSpan = timer0S - timeSigLastTimerS_[tIdx];
|
||||
const float64 maxStep = pktSpan * kMaxSlewFraction;
|
||||
float64 step = -drift;
|
||||
if (step > maxStep) { step = maxStep; }
|
||||
if (step < -maxStep) { step = -maxStep; }
|
||||
timeSigCalib_[tIdx] += step;
|
||||
}
|
||||
}
|
||||
timeSigLastTimerS_[tIdx] = timer0S;
|
||||
timeSigLastValid_[tIdx] = true;
|
||||
return timeSigCalib_[tIdx];
|
||||
|
||||
Reference in New Issue
Block a user