Files
lmxopcua/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Heidenhain/HeidenhainDriverFactoryExtensions.cs
T
Joseph Doherty d50ee809e3 feat(heidenhain): native read-only LSV2 driver + in-process simulator (#803)
Native LSV2 TCP transport (default port 19000; no Java/Python/vendor SDK), ported from
the ignitionoee v0.20.3 reference driver:

- Lsv2ReadOnlyPolicy: payload-aware outbound allowlist (A_LG INSPECT/DNC/DATA, R_VR, R_PR,
  R_RI 22-28/30-34/51, bounded R_MB, R_DP), applied in Lsv2Codec.Frame before any byte is
  written; no public raw-command API.
- Lsv2Client: serialized transactions, one monotonic deadline per transaction, EOF/oversize/
  unexpected/trickle close the client; Close never waits on the gate.
- Lsv2Data / HeidenhainBindingCodec: reference decoders, R_PR byte-capacity + element-index
  rules, next-area cap, DATA Boolean 00/01/FF, strict non-truncating coercion.
- HeidenhainSession: per-batch wire cache, refusal suppression, provisional DNC denial retry,
  alarm cursor (57 = end, overflow = BadOutOfRange), capability strings.
- HeidenhainDeviceRuntime: one loop per control, generation-guarded publication, all-node
  BadNoCommunication on comms loss, bounded exponential reconnect.
- HeidenhainDriver: cached ReadAsync, push subscriptions deduped on (value,status), static
  catalog discovery (no connect), host status, diagnostics, skipped-tag report. No IWritable.
- Probe (INSPECT login + version) and factory registered in DriverFactoryBootstrap (probe on
  admin nodes too); DriverTypeNames.Heidenhain.

Tests: 159 unit tests against an in-process LSV2 simulator incl. the Java fixtures' captured
iTNC 530 replies as golden vectors; env-gated LiveIntegration category for real hardware.
2026-11-10 23:08:30 -05:00

45 lines
2.3 KiB
C#

using Microsoft.Extensions.Logging;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Core.Hosting;
using ZB.MOM.WW.Secrets.Abstractions;
namespace ZB.MOM.WW.OtOpcUa.Driver.Heidenhain;
/// <summary>
/// Factory registration for <see cref="HeidenhainDriver"/>. Construction opens nothing (the discovery browser
/// builds throwaway instances), there is exactly one config parser (<see cref="HeidenhainDriver.ParseOptions"/>),
/// and the instance is returned as its concrete type so every optional capability is dispatched — and,
/// because it implements no <see cref="IWritable"/>, no write is.
/// </summary>
public static class HeidenhainDriverFactoryExtensions
{
/// <summary>The <c>DriverInstance.DriverType</c> this factory answers to.</summary>
public const string DriverTypeName = DriverTypeNames.Heidenhain;
/// <summary>Registers the factory.</summary>
/// <param name="registry">The registry.</param>
/// <param name="loggerFactory">Optional logger factory.</param>
/// <param name="secretResolver">Resolver for <c>secret:</c> password references.</param>
public static void Register(DriverFactoryRegistry registry, ILoggerFactory? loggerFactory = null, ISecretResolver? secretResolver = null)
{
ArgumentNullException.ThrowIfNull(registry);
registry.Register(DriverTypeName, (id, json) => CreateInstance(id, json, loggerFactory, secretResolver));
}
/// <summary>Creates an instance from a config document.</summary>
/// <param name="driverInstanceId">The instance id.</param>
/// <param name="driverConfigJson">The config JSON.</param>
/// <param name="loggerFactory">Optional logger factory.</param>
/// <param name="secretResolver">Optional secret resolver.</param>
/// <returns>The driver.</returns>
public static HeidenhainDriver CreateInstance(string driverInstanceId, string driverConfigJson,
ILoggerFactory? loggerFactory = null, ISecretResolver? secretResolver = null)
{
ArgumentException.ThrowIfNullOrWhiteSpace(driverInstanceId);
ArgumentException.ThrowIfNullOrWhiteSpace(driverConfigJson);
var options = HeidenhainDriver.ParseOptions(driverConfigJson);
return new HeidenhainDriver(options, driverInstanceId,
logger: loggerFactory?.CreateLogger<HeidenhainDriver>(), secretResolver: secretResolver);
}
}