Files
lmxopcua/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Shared/Drivers/Pickers/FocasAddressBuilder.cs
T
Joseph Doherty b61fe38823 fix(focas): browse-committed fixed-tree tags are readable (Gitea #540)
Authoring FOCAS tags through /raw -> Browse device... produced tags the driver
could never read. Every committed tag read BadNodeIdUnknown forever, and the
failure was silent end to end: the AdminUI accepted it, the deploy gate sealed
green, and the driver reported Healthy with 0 errors while ignoring the tags.
Net effect: the whole fixed-tree surface could not be published through any v3
authoring path. Found cutting wonder-app-vd03 over to v3 against a real Makino
Pro 5 / Fanuc 30i, where 0 of 20 committed tags read while two hand-authored
MACRO: tags on the same device read Good.

A captured browse leaf's id IS its DriverAttributeInfo.FullName, and the fixed
tree emitted "{deviceHost}/{path}" there -- an internal cache key, not an
address. Both authoring paths wrote it verbatim into TagConfig.address, and
FocasAddress.TryParse accepts no such form, so the driver skipped the tags at
init.

Fixed at the emitter rather than by stripping the host at commit, which fixes
the browse-commit flow and the manual picker's tree-select together and leaves
one canonical address form:

- FocasAddress gains a fourth kind, FIXED:<path>, and moves to Contracts so the
  AdminUI and ControlPlane can parse without referencing the runtime driver
  (#526). A FIXED: read is served from the fixed-tree snapshot the poll loop
  already maintains -- no area read, no connection. Writes refuse: nothing in
  that tree is a writable location on the CNC.
- The address carries no device. A tag's device comes from its Device row, and
  a second routing channel for one fact is what created this defect.
- An authored FIXED: tag arms the fixed-tree poll loop by itself. Enabled
  defaults false and the browser force-enables it only for a browse, so the
  operator would otherwise browse, commit, deploy, and land on a driver whose
  loop never starts -- every tag Bad with a correct address.
- Fixed-tree values are now dated from the last answered poll and go
  BadCommunicationError once it is stale (8 cadences, floored at 30s). The poll
  loop swallows a failed tick by design, so a dead CNC would otherwise serve its
  last snapshot as Good indefinitely -- harmless while nothing could bind to the
  tree, not harmless now.

Guardrails, so this class cannot recur silently:

- FocasTagConfigModel.Validate() runs the real parser instead of a non-empty
  check, and FocasTagDefinitionFactory.Inspect() warns at the deploy gate, which
  covers CSV/API config that never touches the modal.
- The manual picker offered axis/spindle/program/status "parameter groups" --
  none of which is a FOCAS addressing space -- and its own default value,
  axis:5, was unusable. It now composes PMC / PARAM: / MACRO: through
  FocasAddress, so what it emits is parseable by construction.

Tests assert addresses ROUND-TRIP through the parser rather than matching an
expected string: the previous FocasAddressBuilderTests pinned "axis:5" exactly,
which is how a green suite coexisted with a picker nobody could use. Verified
red-first against the old emitter. FOCAS 308, AdminUI 1095, ControlPlane 169,
Core 581 -- all pass, 0 warnings.

The remaining half of #540 -- a driver reporting Healthy/0 errors while
skipping tags at init -- is fleet-wide (eight drivers do this) and is filed
separately rather than patched per-driver.
2026-08-05 17:32:18 -04:00

77 lines
3.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using ZB.MOM.WW.OtOpcUa.Driver.FOCAS;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers.Pickers;
/// <summary>
/// The addressing spaces the manual FOCAS picker can compose. Mirrors the parseable subset of
/// <see cref="FocasAreaKind"/>: <see cref="FocasAreaKind.Fixed"/> is deliberately absent because a
/// fixed-tree path is discovered from the machine, not composed from parts — the picker's browse
/// tree supplies those.
/// </summary>
public enum FocasManualAddressKind
{
/// <summary>PMC area — letter + byte + optional bit.</summary>
Pmc,
/// <summary>CNC parameter number + optional bit.</summary>
Parameter,
/// <summary>Macro variable number.</summary>
Macro,
}
/// <summary>
/// Pure static helper that composes a canonical FOCAS address from the manual picker's parts.
/// Extracted so unit tests can call it without bUnit.
/// </summary>
/// <remarks>
/// <para>
/// <b>It builds through <see cref="FocasAddress"/> rather than formatting a string</b>, so what
/// it emits is parseable by construction and the two cannot drift.
/// </para>
/// <para>
/// It previously emitted <c>$"{group}:{parameterId}"</c> over a group list of
/// <c>axis/spindle/program/status</c> — none of which is a FOCAS addressing space — so the
/// picker's own default value, <c>axis:5</c>, was an address the driver rejects. Together with
/// the browse-commit defect this meant every UI-assisted authoring path produced unusable tags,
/// and only hand-typed addresses worked at all (Gitea #540).
/// </para>
/// </remarks>
public static class FocasAddressBuilder
{
/// <summary>The PMC area letters the driver accepts, in the order the picker offers them.</summary>
public static IReadOnlyList<string> PmcLetters { get; } =
["X", "Y", "F", "G", "R", "D", "C", "K", "A", "E", "T"];
/// <summary>
/// Composes the canonical FOCAS address string, or an empty string when the parts do not form a
/// valid address (an out-of-range bit, a negative number, an unknown PMC letter).
/// </summary>
/// <param name="kind">Which addressing space the address is in.</param>
/// <param name="pmcLetter">The PMC area letter; ignored unless <paramref name="kind"/> is
/// <see cref="FocasManualAddressKind.Pmc"/>.</param>
/// <param name="number">The PMC byte, parameter number or macro number.</param>
/// <param name="bitIndex">Optional bit index — 0–7 for PMC, 0–31 for a parameter. Null for a
/// whole-word address; always ignored for a macro, which has no bit form.</param>
/// <returns>The canonical address, or an empty string when the parts are not addressable.</returns>
public static string Build(
FocasManualAddressKind kind, string? pmcLetter, int number, int? bitIndex)
{
FocasAddress? candidate = kind switch
{
FocasManualAddressKind.Pmc => new FocasAddress(
FocasAreaKind.Pmc, (pmcLetter ?? "").Trim().ToUpperInvariant(), number, bitIndex),
FocasManualAddressKind.Parameter => new FocasAddress(
FocasAreaKind.Parameter, null, number, bitIndex),
FocasManualAddressKind.Macro => new FocasAddress(
FocasAreaKind.Macro, null, number, null),
_ => null,
};
// Round-trip rather than trust the parts: the record accepts any values, the parser is the
// authority on which of them address anything, and an empty result is what the picker shows
// as "no address yet" instead of a plausible-looking string the driver would silently skip.
return candidate?.Canonical is { } text && FocasAddress.TryParse(text) is not null ? text : "";
}
}