fixed issue on udpstreamer trigger logic
This commit is contained in:
@@ -108,6 +108,22 @@ type triggerEngine struct {
|
||||
firedPost float64
|
||||
firedValid bool
|
||||
|
||||
// The edge to fire on as soon as the FSM rearms, in sample time. Recorded
|
||||
// while a capture is still being collected or handed out, for edges late
|
||||
// enough that a capture of them would not overlap the one in flight.
|
||||
//
|
||||
// Without this the trigger is deaf from its own trigger point until the
|
||||
// capture has been harvested — a post-window plus captureMarginSec — and
|
||||
// then for the holdoff on top of that, and afterwards waits for a FRESH
|
||||
// edge. On a sparse pulse train that rounds the capture spacing up to a
|
||||
// whole pulse period: at the default 1 s window the blind stretch comes to
|
||||
// 1.15 s, so a 1 Hz train was caught at 0.5 Hz and a wider window lost whole
|
||||
// multiples. Remembering the edge instead makes the blind stretch exactly
|
||||
// the post-window it has to be, since the capture is built from the edge's
|
||||
// own timestamp and the ring still holds everything around it.
|
||||
pendingT float64
|
||||
pendingValid bool
|
||||
|
||||
rearmAt float64 // wall-clock seconds; 0 when no rearm is pending
|
||||
}
|
||||
|
||||
@@ -167,6 +183,9 @@ func (te *triggerEngine) SetConfig(cfg trigConfig) {
|
||||
te.baseKey, te.elemIdx = base, idx
|
||||
te.prevValid = false
|
||||
te.prevValue = 0
|
||||
// An edge held over from the old configuration would be latched against the
|
||||
// new window, whose fill the gate has not vouched for.
|
||||
te.pendingValid = false
|
||||
}
|
||||
|
||||
func (te *triggerEngine) Config() trigConfig {
|
||||
@@ -175,15 +194,37 @@ func (te *triggerEngine) Config() trigConfig {
|
||||
return te.cfg
|
||||
}
|
||||
|
||||
// Arm starts a fresh acquisition. It is the user's own arm, so it discards any
|
||||
// edge remembered during the previous capture: the user asked for the next
|
||||
// event, not for one that has already been and gone.
|
||||
func (te *triggerEngine) Arm() {
|
||||
te.mu.Lock()
|
||||
te.state = trigArmed
|
||||
te.prevValid = false
|
||||
te.prevValue = 0
|
||||
te.pendingValid = false
|
||||
te.rearmAt = 0
|
||||
te.mu.Unlock()
|
||||
}
|
||||
|
||||
// rearm is the automatic arm at the end of a capture. Unlike Arm it honours an
|
||||
// edge that arrived while the capture was being collected, firing on it at once
|
||||
// rather than waiting for the next one — see pendingT. It also keeps the level
|
||||
// tracked through the dead time, so the first sample after rearming is compared
|
||||
// against its real predecessor instead of being spent seeding one.
|
||||
func (te *triggerEngine) rearm() {
|
||||
te.mu.Lock()
|
||||
te.rearmAt = 0
|
||||
if te.pendingValid {
|
||||
t := te.pendingT
|
||||
te.pendingValid = false
|
||||
te.latchWindowLocked(t)
|
||||
} else {
|
||||
te.state = trigArmed
|
||||
}
|
||||
te.mu.Unlock()
|
||||
}
|
||||
|
||||
func (te *triggerEngine) Disarm() {
|
||||
te.mu.Lock()
|
||||
te.state = trigIdle
|
||||
@@ -191,6 +232,7 @@ func (te *triggerEngine) Disarm() {
|
||||
te.prevValid = false
|
||||
te.prevValue = 0
|
||||
te.firedValid = false
|
||||
te.pendingValid = false
|
||||
te.rearmAt = 0
|
||||
te.mu.Unlock()
|
||||
}
|
||||
@@ -366,7 +408,11 @@ func (te *triggerEngine) feed(key string, nElem int, t, v []float64) {
|
||||
te.lastT = t[len(t)-1]
|
||||
te.lastTOK = true
|
||||
te.lastFeedWall = float64(time.Now().UnixNano()) / 1e9
|
||||
if te.state != trigArmed {
|
||||
|
||||
// A capture in flight does not stop the comparator; it only changes what an
|
||||
// edge does. See pendingT.
|
||||
inFlight := te.state == trigCollecting || te.state == trigTriggered
|
||||
if te.state != trigArmed && !inFlight {
|
||||
return
|
||||
}
|
||||
step, start := 1, 0
|
||||
@@ -381,12 +427,20 @@ func (te *triggerEngine) feed(key string, nElem int, t, v []float64) {
|
||||
// which is what made the first shot after a window change come back short.
|
||||
// Track the level meanwhile, so the first edge once the buffer is deep
|
||||
// enough is still measured against the right previous sample.
|
||||
if te.fillLocked() < 1 {
|
||||
if !inFlight && te.fillLocked() < 1 {
|
||||
for i := start; i < len(v); i += step {
|
||||
te.prevValue, te.prevValid = v[i], true
|
||||
}
|
||||
return
|
||||
}
|
||||
// The earliest trigger point a new capture may take. The one in flight owns
|
||||
// everything up to the end of its own post-window, and the holdoff — a guard
|
||||
// against re-triggering on the ringing of the SAME event — is measured from
|
||||
// its trigger point too, so the two overlap rather than add.
|
||||
notBefore := math.Inf(1)
|
||||
if inFlight && te.firedValid {
|
||||
notBefore = te.trigTime + math.Max(te.firedPost, te.cfg.holdoffSec)
|
||||
}
|
||||
thr := te.cfg.threshold
|
||||
for i := start; i < len(t); i += step {
|
||||
if !te.prevValid {
|
||||
@@ -406,10 +460,19 @@ func (te *triggerEngine) feed(key string, nElem int, t, v []float64) {
|
||||
default:
|
||||
fired = up
|
||||
}
|
||||
if fired {
|
||||
if !fired {
|
||||
continue
|
||||
}
|
||||
if !inFlight {
|
||||
te.latchWindowLocked(t[i])
|
||||
return
|
||||
}
|
||||
// Keep the FIRST qualifying edge and go on tracking the level: a later
|
||||
// one would be no more use, and stopping here would leave prevValue
|
||||
// stale by the time the FSM rearms.
|
||||
if !te.pendingValid && t[i] >= notBefore {
|
||||
te.pendingT, te.pendingValid = t[i], true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -640,7 +703,7 @@ func (h *Hub) triggerTick() {
|
||||
// file of its own, where nothing overwrites it until the next trigger.
|
||||
h.hist.captureRange(trigTime-pre, trigTime+post)
|
||||
} else if h.trigger.dueRearm(nowSec) {
|
||||
h.trigger.Arm()
|
||||
h.trigger.rearm()
|
||||
}
|
||||
|
||||
if h.trigger.stateUnsent() {
|
||||
|
||||
Reference in New Issue
Block a user