fix(focas): #985 refusals stay Healthy, protocol faults close the session, dead CNCs no longer stall others

- P-6: the wire adapter throws refused fixed-tree calls as FocasWireException carrying the rc
  (was InvalidOperationException, so a refusing control looked silent, degraded and was
  reconnect-looped by the #527 watchdog); a refused axis is per-node BadNoData and the tick continues.
- P-7: bootstrap capability probes latch only an ANSWER (rc, or session still up); a transport
  failure/timeout or a session dropped mid-pass retries the bootstrap.
- P-21: CoalesceRejected latches only range-shaped codes (not EW_BUSY/EW_SOCKET/EW_UNEXP/EW_HANDLE/unknown).
  Macro/param multi-block batching deferred (unproven on hardware).
- P-10: any fault once a request is on the wire closes the session (bad magic/version, unexpected
  PDU, malformed blocks); replies must echo the request's command ids in order (verified against
  every 31i-B capture). A refusal never closes the session.
- P-8: close handshake bounded to 1 s and run under the request gate (sync + async dispose).
- P-11: data-path callers check the backoff before ConnectGate and fail fast behind an in-flight
  reconnect to a device whose last connect failed.
- P-9: axes/spindles carry their wire slot (FocasAxisName/FocasSpindleName.Slot); cnc_rddynamic2 and
  the spindle-meter lookup use it.
- P-20: a truncated (>= 32) alarm list never clears/retriggers a told-active condition unless it
  shows a new key; unseen told keys are kept.
- P-25: a refused connect-time sysinfo is not cached; a short PARAM payload reads BadTypeMismatch.

Tests: loopback MockFocasWireServer drives the real wire client; every fix mutation-checked
(reverting it fails its test). FOCAS.Tests 619/619, FOCAS.IntegrationTests 19/19 vs the sim on
10.100.0.35, Runtime.Tests FOCAS 7/7, FOCAS.Cli.Tests 57/57.
This commit is contained in:
Joseph Doherty
2026-12-03 10:04:42 -05:00
parent 65fd71de7a
commit e68d856fcb
13 changed files with 1568 additions and 100 deletions
+66 -3
View File
@@ -213,6 +213,20 @@ Two caveats worth knowing before you browse:
stops answering, its fixed-tree values go `BadCommunicationError` rather than
continuing to serve the last snapshot as `Good`; the budget is eight poll
cadences, floored at 30 s.
- **A refusal is an answer, not silence (#985).** A `cnc_rddynamic2` the CNC
answers with a non-OK return code (e.g. `EW_FUNC`, a sustained `EW_BUSY`) reads
`BadNoData` on *that axis's* nodes (and, for the first axis, `FeedRate` /
`SpindleSpeed`) while the other axes, meters, program and status keep polling;
the driver stays `Healthy` with `LastSuccessfulRead` advancing, so the #527
comms-loss watchdog never reconnect-loops a control that merely declines a call.
Only a transport failure (no answer) degrades it. (Before #985 the wire adapter
threw a plain exception for every refused fixed-tree call, so a refusal read as
silence and degraded the driver.)
- **Axes and spindles are addressed by their wire slot (#985).** `cnc_rdaxisname`
reports each name in a 1-based slot and skips blank ones; that slot — not the
name's position in the blank-free list — is the axis number `cnc_rddynamic2` is
asked for, and the spindle meter record a `Spindle/<name>/…` node reads. A control
reporting names in slots 1, 2 and 4 used to poll its third axis as axis 3.
What gets populated (all under `FOCAS/{deviceHostAddress}/`, addressed as
`FIXED:{subtree}/{field}`):
@@ -265,6 +279,13 @@ covers `Spindle/`, `Program/` + `OperationMode/`, `Status/`, `Timers/`, and
per-axis `ServoLoad` independently. Identity + `Axes/*` position reads
(which every Fanuc CNC supports) are always emitted.
The probe result is latched for the life of the device, so only an **answer** is
recorded (#985): a refusal (a non-OK return code), or any failure that left the
session up. A transport failure or timeout during the probe pass — or a session
that dropped part-way through it — retries the whole bootstrap two seconds later
instead. (A single stalled `cnc_rdsvmeter` at startup used to close the session
and record every later capability "unsupported" until the driver was respawned.)
Position values (`AbsolutePosition`, `MachinePosition`, `RelativePosition`, `DistanceToGo`)
are published as `Float64` in engineering units. **Each `cnc_rddynamic2` position block carries
its own scale** — `[i32 raw][u16 base][u16 exponent]`, value = `raw / base^exponent` (a real
@@ -386,9 +407,13 @@ Rules worth knowing:
are separate). A multi-byte tag joins a range only when its offset from the range start is a multiple of its
width, because the CNC splits a range into width-sized slots from the start.
- **Spare gap bytes must be valid PMC addresses.** A gap that crosses a hole in the CNC's PMC map makes the CNC
refuse the whole range. That is handled, not fatal: a refused range is remembered per device and its tags are
read **individually**, each with its own true status (a refusal is never stamped onto healthy members). If
that happens routinely, lower `MaxGapBytes` (0 disables gap-spanning entirely) or set `Enabled` to `false`.
refuse the whole range. That is handled, not fatal: the range's tags are read **individually**, each with its
own true status (a refusal is never stamped onto healthy members), and a range refused with a **range-shaped**
code (`EW_NUMBER` / `EW_LENGTH` / `EW_OVRFLOW` / `EW_DATA` / `EW_ATTRIB` / `EW_FUNC` / `EW_NOOPT`) is
remembered per device so later polls skip the merged read. Any other code (`EW_BUSY`, `EW_SOCKET`,
`EW_UNEXP`, `EW_PARITY`, `EW_HANDLE`, unknown) says nothing about the range and is **not** remembered (#985 —
one blip used to disable coalescing for the device's lifetime). If refusals happen routinely, lower
`MaxGapBytes` (0 disables gap-spanning entirely) or set `Enabled` to `false`.
- A transport failure or timeout on the merged read fails every member with `BadCommunicationError` and does
**not** retry per tag — the link is down, so per-tag retries would only multiply timeouts.
- Read-only: this changes `pmc_rdpmcrng` reads only; nothing here can write.
@@ -447,6 +472,12 @@ it, then author `ALARM:T<code>`. Number ranges are series-independent.
CNC alarm is a statement the operator has not seen); the **displayed** alarm leaves while others remain =
`Retrigger` with the next one down (the MTConnect precedent); a **non-displayed** member leaves = nothing;
nothing matches = `Clear`.
- **A list cut off at the cap (32) cannot take anything away (#985).** Any alarm a truncated read does not show
may simply be past the cap, so a condition the server was told is active keeps its told state — no `Clear`, no
`Retrigger` for a displayed alarm that fell past the cap — unless the list shows it a genuinely new alarm (a
`Retrigger`, as above). The members it could not see stay in the told set, so their reappearance when the
storm subsides is not "new" either. (An active `ALARM:Servo/401` used to clear in an alarm storm and re-raise
un-acknowledged once the list shrank.)
- **Severity, explicitly.** An authored integer `alarm.severity` is the condition's exact Part 9 severity
(`OpcUaSeverity`; the host clamps 1..1000). Without one, the bucket comes from the displayed alarm's type:
Overtravel / Servo / PulseCode → Critical (900), Parameter / MacroAlarm → Medium (500), everything else
@@ -537,6 +568,38 @@ single-client deployment. Reads / writes during recycle simply wait for the
reconnect rather than failing — worst case, an operator sees a brief read
latency spike once per cadence.
The close PDU a recycle (or a shutdown / re-initialise) sends is a courtesy to the
CNC's handle pool, and its reply wait is **bounded to 1 s** and runs under the
session's request gate (#985): a CNC that lost power, or hung while TCP still
ACKs, used to block the dispose until TCP gave up — with the recycle holding the
device's connect gate, so every poll of that device parked behind it with no
result and no health change.
## Wire session integrity (#985)
- **A protocol fault closes the session.** Once a request is on the wire, *any*
failure — a socket error or timeout, but equally a bad PDU magic or version, an
unexpected PDU type, a malformed block list, or a reply whose blocks do not echo
the request's command ids in order (or carry more blocks than were asked for) —
tears both sockets down and fails the call as transient; the next call
reconnects. Replies are matched to requests by position, so a kept session would
hand request N's reply to request N+1 (a macro publishing another macro's value
at `Good`). A CNC **refusal** (a non-OK return code inside a well-formed reply)
is an answer and never closes the session. Every captured 31i-B reply
(`Fixtures/v3`, refused blocks included) and the focas-mock fixture echo command
ids in request order; a *shorter* reply is tolerated as before.
- **A refused connect-time `cnc_sysinfo` is not cached** — only an answer is, so a
transient `EW_BUSY` at connect no longer fails every later sysinfo (and with it
the fixed-tree bootstrap) for the life of the session.
- **A `PARAM:` payload shorter than the tag's type reads `BadTypeMismatch`** (a
per-tag refusal; no health impact) — it used to decode as a `Good 0`.
- **A dead CNC does not stall the others.** A data-path caller checks the device's
connect backoff *before* queueing on its connect gate, and fails fast while a
reconnect to a device whose last connect failed is already in flight (the probe
bypasses the backoff and can hold the gate for a whole connect timeout).
`ReadAsync` awaits every device, so before #985 one black-holed CNC delayed the
healthy CNCs' publishes by up to the connect timeout.
## Testing
- **Unit tests** — `tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Tests/` cover the