|
@@ -81,6 +81,7 @@ type Device struct {
|
|
|
|
|
|
|
|
safeCh chan req
|
|
safeCh chan req
|
|
|
applyCh chan req
|
|
applyCh chan req
|
|
|
|
|
+ applyMu sync.Mutex
|
|
|
ctrlCh chan req
|
|
ctrlCh chan req
|
|
|
|
|
|
|
|
lastCont protocol.SetAll
|
|
lastCont protocol.SetAll
|
|
@@ -133,6 +134,7 @@ type Device struct {
|
|
|
safetyContract safety.EffectiveContract
|
|
safetyContract safety.EffectiveContract
|
|
|
safetyErr error
|
|
safetyErr error
|
|
|
workerCtx context.Context
|
|
workerCtx context.Context
|
|
|
|
|
+ actorHold atomic.Bool
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type applyJobState struct {
|
|
type applyJobState struct {
|
|
@@ -176,7 +178,7 @@ func New(p Params) *Device {
|
|
|
book: faults.NewBook(256),
|
|
book: faults.NewBook(256),
|
|
|
lease: control.NewManager(p.Config.DeviceID, p.Config.MinTTL(), p.Config.MaxTTL(), p.Config.CommandCacheSize),
|
|
lease: control.NewManager(p.Config.DeviceID, p.Config.MinTTL(), p.Config.MaxTTL(), p.Config.CommandCacheSize),
|
|
|
safeCh: make(chan req, 4),
|
|
safeCh: make(chan req, 4),
|
|
|
- applyCh: make(chan req, 32),
|
|
|
|
|
|
|
+ applyCh: make(chan req, 1),
|
|
|
ctrlCh: make(chan req, 16),
|
|
ctrlCh: make(chan req, 16),
|
|
|
jobs: make(chan serialJob, 1),
|
|
jobs: make(chan serialJob, 1),
|
|
|
results: make(chan serialResult, 1),
|
|
results: make(chan serialResult, 1),
|
|
@@ -216,6 +218,12 @@ func (d *Device) Start(parent context.Context) {
|
|
|
d.workerCancel = workerCancel
|
|
d.workerCancel = workerCancel
|
|
|
d.runCtx = actorCtx
|
|
d.runCtx = actorCtx
|
|
|
d.workerCtx = workerCtx
|
|
d.workerCtx = workerCtx
|
|
|
|
|
+ if d.safetyErr != nil {
|
|
|
|
|
+ d.store.SetLifecycle(hthv1.DeviceLifecycleState_DEVICE_LIFECYCLE_STATE_UNAVAILABLE)
|
|
|
|
|
+ d.book.Raise(d.clk.Now(), hthv1.FaultType_FAULT_TYPE_CONFIG_INVALID, d.id, "", "effective safety contract invalid: "+d.safetyErr.Error(), "", nil)
|
|
|
|
|
+ d.publishNow()
|
|
|
|
|
+ // Actor still runs so Stop/Doctor work, but UART is never opened.
|
|
|
|
|
+ }
|
|
|
d.wg.Add(2)
|
|
d.wg.Add(2)
|
|
|
go func() {
|
|
go func() {
|
|
|
defer d.wg.Done()
|
|
defer d.wg.Done()
|
|
@@ -289,6 +297,14 @@ func (d *Device) loop(ctx context.Context) {
|
|
|
applyBurst := 0
|
|
applyBurst := 0
|
|
|
for {
|
|
for {
|
|
|
d.markProgress()
|
|
d.markProgress()
|
|
|
|
|
+ for d.actorHold.Load() {
|
|
|
|
|
+ d.markProgress()
|
|
|
|
|
+ if ctx.Err() != nil {
|
|
|
|
|
+ d.runShutdown()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ time.Sleep(2 * time.Millisecond)
|
|
|
|
|
+ }
|
|
|
for {
|
|
for {
|
|
|
select {
|
|
select {
|
|
|
case r := <-d.safeCh:
|
|
case r := <-d.safeCh:
|
|
@@ -352,6 +368,9 @@ func (d *Device) loop(ctx context.Context) {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
d.recoverStuckSerial(ctx, &backoff, &nextTry)
|
|
d.recoverStuckSerial(ctx, &backoff, &nextTry)
|
|
|
|
|
+ if d.connected {
|
|
|
|
|
+ d.kickPendingSerial(ctx)
|
|
|
|
|
+ }
|
|
|
if !d.connected && (nextTry.IsZero() || !d.clk.Now().Before(nextTry)) {
|
|
if !d.connected && (nextTry.IsZero() || !d.clk.Now().Before(nextTry)) {
|
|
|
d.tryOpen(ctx, &backoff, &nextTry)
|
|
d.tryOpen(ctx, &backoff, &nextTry)
|
|
|
}
|
|
}
|
|
@@ -361,6 +380,9 @@ func (d *Device) loop(ctx context.Context) {
|
|
|
|
|
|
|
|
func (d *Device) tryOpen(ctx context.Context, backoff *time.Duration, next *time.Time) {
|
|
func (d *Device) tryOpen(ctx context.Context, backoff *time.Duration, next *time.Time) {
|
|
|
_ = ctx
|
|
_ = ctx
|
|
|
|
|
+ if d.safetyErr != nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
if d.connected || d.serialInflight() {
|
|
if d.connected || d.serialInflight() {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -521,32 +543,44 @@ func (d *Device) handle(ctx context.Context, r req) {
|
|
|
}
|
|
}
|
|
|
switch r.kind {
|
|
switch r.kind {
|
|
|
case opAcquire:
|
|
case opAcquire:
|
|
|
|
|
+ if r.rpcCtx != nil && r.rpcCtx.Err() != nil {
|
|
|
|
|
+ replyNonblock(r.reply, res{err: r.rpcCtx.Err(), action: cancelledResult(r.batch, r.rpcCtx.Err())})
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
l, err := d.lease.Acquire(d.clk.Now(), r.holder, r.ttl)
|
|
l, err := d.lease.Acquire(d.clk.Now(), r.holder, r.ttl)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- r.reply <- res{err: err}
|
|
|
|
|
|
|
+ replyNonblock(r.reply, res{err: err})
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
d.publishEvent(hthv1.EventKind_EVENT_KIND_LEASE_ACQUIRED, "acquired")
|
|
d.publishEvent(hthv1.EventKind_EVENT_KIND_LEASE_ACQUIRED, "acquired")
|
|
|
d.publishNow()
|
|
d.publishNow()
|
|
|
- r.reply <- res{lease: l.Proto()}
|
|
|
|
|
|
|
+ replyNonblock(r.reply, res{lease: l.Proto()})
|
|
|
case opRenew:
|
|
case opRenew:
|
|
|
|
|
+ if r.rpcCtx != nil && r.rpcCtx.Err() != nil {
|
|
|
|
|
+ replyNonblock(r.reply, res{err: r.rpcCtx.Err(), action: cancelledResult(r.batch, r.rpcCtx.Err())})
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
l, err := d.lease.Renew(d.clk.Now(), r.leaseID, r.leaseEpoch, r.ttl)
|
|
l, err := d.lease.Renew(d.clk.Now(), r.leaseID, r.leaseEpoch, r.ttl)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- r.reply <- res{err: err}
|
|
|
|
|
|
|
+ replyNonblock(r.reply, res{err: err})
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
d.publishEvent(hthv1.EventKind_EVENT_KIND_LEASE_RENEWED, "renewed")
|
|
d.publishEvent(hthv1.EventKind_EVENT_KIND_LEASE_RENEWED, "renewed")
|
|
|
d.publishNow()
|
|
d.publishNow()
|
|
|
- r.reply <- res{lease: l.Proto()}
|
|
|
|
|
|
|
+ replyNonblock(r.reply, res{lease: l.Proto()})
|
|
|
case opRelease:
|
|
case opRelease:
|
|
|
|
|
+ if r.rpcCtx != nil && r.rpcCtx.Err() != nil {
|
|
|
|
|
+ replyNonblock(r.reply, res{err: r.rpcCtx.Err(), action: cancelledResult(r.batch, r.rpcCtx.Err())})
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
err := d.lease.Release(d.clk.Now(), r.leaseID, r.leaseEpoch)
|
|
err := d.lease.Release(d.clk.Now(), r.leaseID, r.leaseEpoch)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- r.reply <- res{err: err}
|
|
|
|
|
|
|
+ replyNonblock(r.reply, res{err: err})
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
d.publishEvent(hthv1.EventKind_EVENT_KIND_LEASE_RELEASED, "released")
|
|
d.publishEvent(hthv1.EventKind_EVENT_KIND_LEASE_RELEASED, "released")
|
|
|
d.enterSafe(ctx, "lease_released")
|
|
d.enterSafe(ctx, "lease_released")
|
|
|
- r.reply <- res{}
|
|
|
|
|
|
|
+ replyNonblock(r.reply, res{})
|
|
|
case opValidate:
|
|
case opValidate:
|
|
|
r.reply <- res{action: d.validate(r.batch)}
|
|
r.reply <- res{action: d.validate(r.batch)}
|
|
|
case opApply:
|
|
case opApply:
|
|
@@ -758,7 +792,8 @@ func (d *Device) beginApply(ctx context.Context, r req) {
|
|
|
reply: r.reply, batch: r.batch, payload: control.PayloadHash(r.batch),
|
|
reply: r.reply, batch: r.batch, payload: control.PayloadHash(r.batch),
|
|
|
target: target, result: out, credit: credit,
|
|
target: target, result: out, credit: credit,
|
|
|
}
|
|
}
|
|
|
- if !d.enqueueSerial(serialJob{kind: jobSetAllApply, timeout: d.cfg.SetAllTimeout(), frame: target}) {
|
|
|
|
|
|
|
+ ax := d.newActionContext(r.batch.GetCommandId(), "apply", hthv1.ActionMode_ACTION_MODE_NORMAL, target, r.rpcCtx)
|
|
|
|
|
+ if !d.enqueueSerial(d.serialJobFromAction(jobSetAllApply, d.cfg.SetAllTimeout(), ax)) {
|
|
|
d.applyJob = nil
|
|
d.applyJob = nil
|
|
|
out.Accepted = false
|
|
out.Accepted = false
|
|
|
out.RejectReason = hthv1.RejectReason_REJECT_REASON_DEVICE_NOT_READY
|
|
out.RejectReason = hthv1.RejectReason_REJECT_REASON_DEVICE_NOT_READY
|
|
@@ -886,7 +921,7 @@ func (d *Device) recordAction(res *hthv1.ActionResult) {
|
|
|
if res.Dispatched != nil {
|
|
if res.Dispatched != nil {
|
|
|
s.LastDispatched = res.Dispatched
|
|
s.LastDispatched = res.Dispatched
|
|
|
}
|
|
}
|
|
|
- s.ContinuousTargets = d.commandedTargets()
|
|
|
|
|
|
|
+ s.ContinuousTargets = d.commandedTargetsAt(s.DeviceEpoch)
|
|
|
s.Lease = d.lease.Current().Summary(now)
|
|
s.Lease = d.lease.Current().Summary(now)
|
|
|
s.ActiveFaults = d.book.Active()
|
|
s.ActiveFaults = d.book.Active()
|
|
|
s.DeviceConfirmation = res.Confirmation
|
|
s.DeviceConfirmation = res.Confirmation
|
|
@@ -895,7 +930,7 @@ func (d *Device) recordAction(res *hthv1.ActionResult) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *Device) heartbeat(ctx context.Context) {
|
|
func (d *Device) heartbeat(ctx context.Context) {
|
|
|
- if d.draining || !d.connected || d.backend.PollMode() != backend.PollUART {
|
|
|
|
|
|
|
+ if d.safetyErr != nil || d.draining || !d.connected || d.backend.PollMode() != backend.PollUART {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
if !d.startupDone || !d.baselineReady || !d.haveCont {
|
|
if !d.startupDone || !d.baselineReady || !d.haveCont {
|
|
@@ -912,14 +947,15 @@ func (d *Device) heartbeat(ctx context.Context) {
|
|
|
frame = d.safeFrame()
|
|
frame = d.safeFrame()
|
|
|
origin = "watchdog_heartbeat_safe_policy_full_open_doors"
|
|
origin = "watchdog_heartbeat_safe_policy_full_open_doors"
|
|
|
}
|
|
}
|
|
|
- d.enqueueSerial(serialJob{kind: jobSetAllHB, timeout: d.cfg.SetAllTimeout(), frame: frame, origin: origin})
|
|
|
|
|
|
|
+ ax := d.newActionContext("", origin, hthv1.ActionMode_ACTION_MODE_HEARTBEAT, frame, nil)
|
|
|
|
|
+ d.enqueueSerial(d.serialJobFromAction(jobSetAllHB, d.cfg.SetAllTimeout(), ax))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *Device) safeFrame() protocol.SetAll {
|
|
func (d *Device) safeFrame() protocol.SetAll {
|
|
|
- if d.safetyErr == nil && (d.safetyContract.Frame != protocol.SetAll{} || d.safetyContract.ByID != nil) {
|
|
|
|
|
- return d.safetyContract.Frame
|
|
|
|
|
|
|
+ if d.safetyErr != nil {
|
|
|
|
|
+ return protocol.SetAll{}
|
|
|
}
|
|
}
|
|
|
- return safety.SafeSetAll(d.prof, d.cfg.Safety.Fan, d.cfg.Safety.PTC, d.cfg.Safety.DoorClosePercent)
|
|
|
|
|
|
|
+ return d.safetyContract.Frame
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *Device) checkLease(ctx context.Context) {
|
|
func (d *Device) checkLease(ctx context.Context) {
|
|
@@ -1027,7 +1063,7 @@ func (d *Device) applyTempMeas(rep *backend.TempReport) {
|
|
|
d.store.Commit(func(s *hthv1.Snapshot) {
|
|
d.store.Commit(func(s *hthv1.Snapshot) {
|
|
|
s.Measurements = mergeMeas(s.Measurements, meas)
|
|
s.Measurements = mergeMeas(s.Measurements, meas)
|
|
|
s.CaptureWindow = window(rep.Window)
|
|
s.CaptureWindow = window(rep.Window)
|
|
|
- s.ContinuousTargets = d.commandedTargets()
|
|
|
|
|
|
|
+ s.ContinuousTargets = d.commandedTargetsAt(s.DeviceEpoch)
|
|
|
s.Lease = d.lease.Current().Summary(now)
|
|
s.Lease = d.lease.Current().Summary(now)
|
|
|
s.ActiveFaults = d.book.Active()
|
|
s.ActiveFaults = d.book.Active()
|
|
|
})
|
|
})
|
|
@@ -1039,7 +1075,7 @@ func (d *Device) applyMotorMeas(rep *backend.MotorReport) {
|
|
|
meas := motorMeasurements(rep.Status, now)
|
|
meas := motorMeasurements(rep.Status, now)
|
|
|
d.store.Commit(func(s *hthv1.Snapshot) {
|
|
d.store.Commit(func(s *hthv1.Snapshot) {
|
|
|
s.Measurements = mergeMeas(s.Measurements, meas)
|
|
s.Measurements = mergeMeas(s.Measurements, meas)
|
|
|
- s.ContinuousTargets = d.commandedTargets()
|
|
|
|
|
|
|
+ s.ContinuousTargets = d.commandedTargetsAt(s.DeviceEpoch)
|
|
|
s.Lease = d.lease.Current().Summary(now)
|
|
s.Lease = d.lease.Current().Summary(now)
|
|
|
s.ActiveFaults = d.book.Active()
|
|
s.ActiveFaults = d.book.Active()
|
|
|
if !d.startupDone {
|
|
if !d.startupDone {
|
|
@@ -1161,10 +1197,15 @@ func (d *Device) replayAdvance(ctx context.Context, rp backend.Replayer) error {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *Device) replayCaptureID() string {
|
|
func (d *Device) replayCaptureID() string {
|
|
|
- if d.cfg != nil && d.cfg.Replay.Path != "" {
|
|
|
|
|
- return d.cfg.Replay.Path
|
|
|
|
|
|
|
+ if d.cfg == nil || d.cfg.Replay.Path == "" {
|
|
|
|
|
+ return ""
|
|
|
|
|
+ }
|
|
|
|
|
+ man, err := capture.ReadManifest(d.cfg.Replay.Path)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return ""
|
|
|
}
|
|
}
|
|
|
- return ""
|
|
|
|
|
|
|
+ man.Normalize()
|
|
|
|
|
+ return man.CaptureID
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *Device) publishNow() {
|
|
func (d *Device) publishNow() {
|
|
@@ -1177,7 +1218,7 @@ func (d *Device) publishNow() {
|
|
|
d.book.Clear(hthv1.FaultType_FAULT_TYPE_TELEMETRY_STALE, d.id, "", now)
|
|
d.book.Clear(hthv1.FaultType_FAULT_TYPE_TELEMETRY_STALE, d.id, "", now)
|
|
|
}
|
|
}
|
|
|
snap := d.store.Commit(func(s *hthv1.Snapshot) {
|
|
snap := d.store.Commit(func(s *hthv1.Snapshot) {
|
|
|
- s.ContinuousTargets = d.commandedTargets()
|
|
|
|
|
|
|
+ s.ContinuousTargets = d.commandedTargetsAt(s.DeviceEpoch)
|
|
|
s.Lease = d.lease.Current().Summary(now)
|
|
s.Lease = d.lease.Current().Summary(now)
|
|
|
s.ActiveFaults = d.book.Active()
|
|
s.ActiveFaults = d.book.Active()
|
|
|
d.refreshMeasurementAge(s, now, stale)
|
|
d.refreshMeasurementAge(s, now, stale)
|
|
@@ -1283,12 +1324,12 @@ func (d *Device) drainPending(err error) {
|
|
|
func (d *Device) submit(ctx context.Context, ch chan req, r req) res {
|
|
func (d *Device) submit(ctx context.Context, ch chan req, r req) res {
|
|
|
r.reply = make(chan res, 1)
|
|
r.reply = make(chan res, 1)
|
|
|
r.rpcCtx = ctx
|
|
r.rpcCtx = ctx
|
|
|
|
|
+ if r.kind == opApply {
|
|
|
|
|
+ return d.submitApply(ctx, r)
|
|
|
|
|
+ }
|
|
|
select {
|
|
select {
|
|
|
case ch <- r:
|
|
case ch <- r:
|
|
|
default:
|
|
default:
|
|
|
- if r.kind == opApply {
|
|
|
|
|
- return res{action: &hthv1.ActionResult{CommandId: r.batch.GetCommandId(), RejectReason: hthv1.RejectReason_REJECT_REASON_QUEUE_FULL, Confirmation: hthv1.ConfirmationStatus_CONFIRMATION_STATUS_REJECTED, Message: "apply queue full"}}
|
|
|
|
|
- }
|
|
|
|
|
select {
|
|
select {
|
|
|
case ch <- r:
|
|
case ch <- r:
|
|
|
case <-ctx.Done():
|
|
case <-ctx.Done():
|
|
@@ -1309,6 +1350,40 @@ func (d *Device) submit(ctx context.Context, ch chan req, r req) res {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (d *Device) submitApply(ctx context.Context, r req) res {
|
|
|
|
|
+ d.applyMu.Lock()
|
|
|
|
|
+ select {
|
|
|
|
|
+ case old := <-d.applyCh:
|
|
|
|
|
+ d.applyMu.Unlock()
|
|
|
|
|
+ d.replySuperseded(old, hthv1.RejectReason_REJECT_REASON_SUPERSEDED, "SUPERSEDED by later apply at ingress")
|
|
|
|
|
+ d.applyMu.Lock()
|
|
|
|
|
+ default:
|
|
|
|
|
+ }
|
|
|
|
|
+ select {
|
|
|
|
|
+ case d.applyCh <- r:
|
|
|
|
|
+ d.applyMu.Unlock()
|
|
|
|
|
+ default:
|
|
|
|
|
+ d.applyMu.Unlock()
|
|
|
|
|
+ select {
|
|
|
|
|
+ case d.applyCh <- r:
|
|
|
|
|
+ case <-ctx.Done():
|
|
|
|
|
+ return res{action: cancelledResult(r.batch, ctx.Err()), err: ctx.Err()}
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ var shutting <-chan struct{}
|
|
|
|
|
+ if d.runCtx != nil {
|
|
|
|
|
+ shutting = d.runCtx.Done()
|
|
|
|
|
+ }
|
|
|
|
|
+ select {
|
|
|
|
|
+ case out := <-r.reply:
|
|
|
|
|
+ return out
|
|
|
|
|
+ case <-ctx.Done():
|
|
|
|
|
+ return res{action: cancelledResult(r.batch, ctx.Err()), err: ctx.Err()}
|
|
|
|
|
+ case <-shutting:
|
|
|
|
|
+ return res{action: cancelledResult(r.batch, context.Canceled), err: context.Canceled}
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func cancelledResult(batch *hthv1.ActionBatch, err error) *hthv1.ActionResult {
|
|
func cancelledResult(batch *hthv1.ActionBatch, err error) *hthv1.ActionResult {
|
|
|
id := ""
|
|
id := ""
|
|
|
if batch != nil {
|
|
if batch != nil {
|
|
@@ -1517,7 +1592,20 @@ func (d *Device) commandedTargets() []*hthv1.CommandedActuator {
|
|
|
if !d.haveCont || !d.baselineReady {
|
|
if !d.haveCont || !d.baselineReady {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
- return commandedWithEpoch(d.lastCont, 0)
|
|
|
|
|
|
|
+ return d.commandedTargetsAt(d.store.Epoch())
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (d *Device) commandedTargetsAt(epoch uint64) []*hthv1.CommandedActuator {
|
|
|
|
|
+ if !d.haveCont || !d.baselineReady {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ return commandedWithEpoch(d.lastCont, epoch)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// TestingHoldActor blocks the actor loop so tests can enqueue then cancel RPCs
|
|
|
|
|
+// before handle() runs. Production code must not call this.
|
|
|
|
|
+func (d *Device) TestingHoldActor(hold bool) {
|
|
|
|
|
+ d.actorHold.Store(hold)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func commandedWithEpoch(s protocol.SetAll, epoch uint64) []*hthv1.CommandedActuator {
|
|
func commandedWithEpoch(s protocol.SetAll, epoch uint64) []*hthv1.CommandedActuator {
|
|
@@ -1527,13 +1615,26 @@ func commandedWithEpoch(s protocol.SetAll, epoch uint64) []*hthv1.CommandedActua
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
a.TargetEpoch = epoch
|
|
a.TargetEpoch = epoch
|
|
|
- a.TargetSource = "commanded"
|
|
|
|
|
- a.TargetQuality = hthv1.DataQuality_DATA_QUALITY_NOT_SUPPORTED
|
|
|
|
|
|
|
+ a.TargetSource = "HOST_DISPATCHED_COMMAND"
|
|
|
|
|
+ a.TargetQuality = hthv1.DataQuality_DATA_QUALITY_VALID
|
|
|
|
|
+ a.ActualQuality = hthv1.DataQuality_DATA_QUALITY_NOT_SUPPORTED
|
|
|
a.ActualReason = "COMMANDED_NOT_ACTUAL"
|
|
a.ActualReason = "COMMANDED_NOT_ACTUAL"
|
|
|
}
|
|
}
|
|
|
return out
|
|
return out
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (d *Device) makeInternalRecord(cmd, origin string, mode hthv1.ActionMode, now time.Time, conf hthv1.ConfirmationStatus, frame protocol.SetAll) *hthv1.ActionRecord {
|
|
|
|
|
+ rec := actionRecord(&hthv1.ActionBatch{CommandId: cmd, ClientId: "hthd"}, now, conf, frame)
|
|
|
|
|
+ ax := ActionExecutionContext{
|
|
|
|
|
+ CommandID: cmd, Origin: "daemon/internal", Mode: mode,
|
|
|
|
|
+ DeviceEpoch: d.store.Epoch(), PortGeneration: d.portGen,
|
|
|
|
|
+ }
|
|
|
|
|
+ if origin != "" {
|
|
|
|
|
+ ax.Origin = "daemon/internal:" + origin
|
|
|
|
|
+ }
|
|
|
|
|
+ return bindActionRecord(rec, ax, hthv1.ActionDispatchState_ACTION_DISPATCH_STATE_UNCONFIRMED)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (d *Device) publishActionResult(res *hthv1.ActionResult) {
|
|
func (d *Device) publishActionResult(res *hthv1.ActionResult) {
|
|
|
if res == nil {
|
|
if res == nil {
|
|
|
return
|
|
return
|
|
@@ -1719,7 +1820,7 @@ func buildCaps(cfg *config.Config, p *profile.Profile) *hthv1.Capabilities {
|
|
|
ProtocolContractHash: p.SourceContractSHA256,
|
|
ProtocolContractHash: p.SourceContractSHA256,
|
|
|
ApiVersion: p.APIVersion, FirmwareVersion: "", FirmwareVersionQuality: hthv1.DataQuality_DATA_QUALITY_NOT_SUPPORTED,
|
|
ApiVersion: p.APIVersion, FirmwareVersion: "", FirmwareVersionQuality: hthv1.DataQuality_DATA_QUALITY_NOT_SUPPORTED,
|
|
|
HoodCount: int32(p.Topology.HoodCount), ChamberCount: int32(p.Topology.ChamberCount),
|
|
HoodCount: int32(p.Topology.HoodCount), ChamberCount: int32(p.Topology.ChamberCount),
|
|
|
- RecommendedSamplePeriod: durationpb.New(p.RecommendedSamplePeriod()),
|
|
|
|
|
|
|
+ RecommendedSamplePeriod: durationpb.New(cfg.GetTempTimeout(p)),
|
|
|
AckSupported: false, StatusQuerySupported: p.Protocol.StatusQuery,
|
|
AckSupported: false, StatusQuerySupported: p.Protocol.StatusQuery,
|
|
|
PositionFeedbackSupported: false, RpmFeedbackSupported: false, DeviceFaultQuerySupported: false,
|
|
PositionFeedbackSupported: false, RpmFeedbackSupported: false, DeviceFaultQuerySupported: false,
|
|
|
HostFaultReportingSupported: true, DeviceNativeFaultQuerySupported: false,
|
|
HostFaultReportingSupported: true, DeviceNativeFaultQuerySupported: false,
|
|
@@ -1728,13 +1829,17 @@ func buildCaps(cfg *config.Config, p *profile.Profile) *hthv1.Capabilities {
|
|
|
Notes: "No encoder: door current_position is ESTIMATED open-loop STEP count; endpoints may be limit-confirmed. Fan RPM, PTC actual power, firmware version, DIMM map: NOT_SUPPORTED / UNKNOWN. Door 0 = full open. SET_ALL has no ACK. Axis faults come from MOTOR_STATUS_DATA, not a device fault queue. One hthd instance owns one serial controller.",
|
|
Notes: "No encoder: door current_position is ESTIMATED open-loop STEP count; endpoints may be limit-confirmed. Fan RPM, PTC actual power, firmware version, DIMM map: NOT_SUPPORTED / UNKNOWN. Door 0 = full open. SET_ALL has no ACK. Axis faults come from MOTOR_STATUS_DATA, not a device fault queue. One hthd instance owns one serial controller.",
|
|
|
}
|
|
}
|
|
|
for _, s := range p.Sensors {
|
|
for _, s := range p.Sensors {
|
|
|
- c.Sensors = append(c.Sensors, &hthv1.SensorCapability{
|
|
|
|
|
|
|
+ sc := &hthv1.SensorCapability{
|
|
|
Id: s.ID, Aliases: s.Aliases, DisplayName: s.DisplayName, Kind: sensorKind(s.Kind),
|
|
Id: s.ID, Aliases: s.Aliases, DisplayName: s.DisplayName, Kind: sensorKind(s.Kind),
|
|
|
Unit: s.Unit, ValidRange: &hthv1.Range{Min: s.ValidRange.Min, Max: s.ValidRange.Max},
|
|
Unit: s.Unit, ValidRange: &hthv1.Range{Min: s.ValidRange.Min, Max: s.ValidRange.Max},
|
|
|
Resolution: s.Resolution, SourceTimestamp: s.SourceTimestamp, MappingConfidence: s.MappingConfidence,
|
|
Resolution: s.Resolution, SourceTimestamp: s.SourceTimestamp, MappingConfidence: s.MappingConfidence,
|
|
|
HoodId: s.HoodID, ChamberId: s.ChamberID, DimmId: s.DIMMID, Connector: s.Connector,
|
|
HoodId: s.HoodID, ChamberId: s.ChamberID, DimmId: s.DIMMID, Connector: s.Connector,
|
|
|
SourceIndex: int32(s.SourceIndex), CalibrationVersion: s.CalibrationVersion, FeedbackMode: feedback(s.FeedbackMode),
|
|
SourceIndex: int32(s.SourceIndex), CalibrationVersion: s.CalibrationVersion, FeedbackMode: feedback(s.FeedbackMode),
|
|
|
- })
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ if s.Kind == "TEMPERATURE" {
|
|
|
|
|
+ sc.UpdatePeriod = durationpb.New(p.RecommendedSamplePeriod())
|
|
|
|
|
+ }
|
|
|
|
|
+ c.Sensors = append(c.Sensors, sc)
|
|
|
}
|
|
}
|
|
|
sort.Slice(c.Sensors, func(i, j int) bool { return c.Sensors[i].Id < c.Sensors[j].Id })
|
|
sort.Slice(c.Sensors, func(i, j int) bool { return c.Sensors[i].Id < c.Sensors[j].Id })
|
|
|
for _, a := range p.Actuators {
|
|
for _, a := range p.Actuators {
|
|
@@ -1767,22 +1872,37 @@ func buildCaps(cfg *config.Config, p *profile.Profile) *hthv1.Capabilities {
|
|
|
if recRPC < tempMS+3000 {
|
|
if recRPC < tempMS+3000 {
|
|
|
recRPC = tempMS + 3000
|
|
recRPC = tempMS + 3000
|
|
|
}
|
|
}
|
|
|
|
|
+ physTemp := uint32(p.RecommendedSamplePeriod() / time.Millisecond)
|
|
|
|
|
+ if physTemp < 1000 {
|
|
|
|
|
+ physTemp = tempMS
|
|
|
|
|
+ }
|
|
|
|
|
+ snapSub := uint32(cfg.TemperaturePoll() / time.Millisecond)
|
|
|
|
|
+ if snapSub < 1 {
|
|
|
|
|
+ snapSub = 50
|
|
|
|
|
+ }
|
|
|
|
|
+ c.Notes += fmt.Sprintf(" physical_temperature_update_period_ms=%d is the 27-channel GET_TEMPERATURE scan, not the %dms host poll tick (recommended_snapshot_subscription_period_ms). 50ms is a scheduler floor, not an ADC period.", physTemp, snapSub)
|
|
|
c.Timing = &hthv1.TimingCapabilities{
|
|
c.Timing = &hthv1.TimingCapabilities{
|
|
|
- TemperatureTransactionWorstCaseMs: tempMS,
|
|
|
|
|
- MotorStatusWorstCaseMs: motorMS,
|
|
|
|
|
- ControlDispatchWorstCaseMs: ctrlWorst,
|
|
|
|
|
- RecommendedRpcDeadlineMs: recRPC,
|
|
|
|
|
- RecommendedActionTtlMs: recRPC,
|
|
|
|
|
- MinimumControlPeriodMs: ctrlWindow,
|
|
|
|
|
- RecommendedSamplePeriodMs: uint32(p.RecommendedSamplePeriod() / time.Millisecond),
|
|
|
|
|
- MaxUnpreemptableTransactionMs: unpreempt,
|
|
|
|
|
- ControlWindowMs: ctrlWindow,
|
|
|
|
|
- SchedulerMarginMs: schedMargin,
|
|
|
|
|
- MaxPendingContinuousActions: 1,
|
|
|
|
|
- }
|
|
|
|
|
- if contract, err := safety.BuildEffectiveSafetyContract(p, cfg.Safety); err == nil {
|
|
|
|
|
- c = overlaySafetyDefaults(c, contract)
|
|
|
|
|
|
|
+ TemperatureTransactionWorstCaseMs: tempMS,
|
|
|
|
|
+ MotorStatusWorstCaseMs: motorMS,
|
|
|
|
|
+ ControlDispatchWorstCaseMs: ctrlWorst,
|
|
|
|
|
+ RecommendedRpcDeadlineMs: recRPC,
|
|
|
|
|
+ RecommendedActionTtlMs: recRPC,
|
|
|
|
|
+ MinimumControlPeriodMs: ctrlWindow,
|
|
|
|
|
+ RecommendedSamplePeriodMs: physTemp,
|
|
|
|
|
+ MaxUnpreemptableTransactionMs: unpreempt,
|
|
|
|
|
+ ControlWindowMs: ctrlWindow,
|
|
|
|
|
+ SchedulerMarginMs: schedMargin,
|
|
|
|
|
+ MaxPendingContinuousActions: 1,
|
|
|
|
|
+ PhysicalTemperatureUpdatePeriodMs: physTemp,
|
|
|
|
|
+ RecommendedSnapshotSubscriptionPeriodMs: snapSub,
|
|
|
|
|
+ }
|
|
|
|
|
+ contract, err := safety.BuildEffectiveSafetyContract(p, cfg.Safety)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ c.Notes += " CONFIG_INVALID: effective safety contract unavailable; no SafeSetAll fallback"
|
|
|
|
|
+ c.CapabilityHash = "CONFIG_INVALID"
|
|
|
|
|
+ return c
|
|
|
}
|
|
}
|
|
|
|
|
+ c = overlaySafetyDefaults(c, contract)
|
|
|
c.CapabilityHash = caphash.HashCanonicalCapabilities(c)
|
|
c.CapabilityHash = caphash.HashCanonicalCapabilities(c)
|
|
|
return c
|
|
return c
|
|
|
}
|
|
}
|