Merge B1-ablegacy: v3 RawPath read-path
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using CliFx.Attributes;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.PlcFamilies;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Cli.Common;
|
||||
|
||||
@@ -37,7 +38,12 @@ public abstract class AbLegacyCommandBase : DriverCommandBase
|
||||
|
||||
/// <summary>
|
||||
/// Build an <see cref="AbLegacyDriverOptions"/> with the device + tag list a subclass
|
||||
/// supplies. Probe disabled for CLI one-shot runs.
|
||||
/// supplies. The CLI authors typed <see cref="AbLegacyTagDefinition"/>s from operator flags;
|
||||
/// v3 delivers tags to the driver as <see cref="RawTagEntry"/> records, so each typed def is
|
||||
/// serialised back to its <c>TagConfig</c> blob via
|
||||
/// <see cref="AbLegacyTagDefinitionFactory.ToTagConfig"/> (RawPath = the def's <c>Name</c>,
|
||||
/// DeviceName = the def's <c>DeviceHostAddress</c> — the CLI's single device). Probe disabled
|
||||
/// for CLI one-shot runs.
|
||||
/// </summary>
|
||||
/// <param name="tags">The tag definitions to include in the options.</param>
|
||||
/// <returns>Configured AB Legacy driver options.</returns>
|
||||
@@ -47,7 +53,8 @@ public abstract class AbLegacyCommandBase : DriverCommandBase
|
||||
HostAddress: Gateway,
|
||||
PlcFamily: PlcType,
|
||||
DeviceName: $"cli-{PlcType}")],
|
||||
Tags = tags,
|
||||
RawTags = [.. tags.Select(t => new RawTagEntry(
|
||||
t.Name, AbLegacyTagDefinitionFactory.ToTagConfig(t), t.WriteIdempotent, DeviceName: t.DeviceHostAddress))],
|
||||
Timeout = Timeout,
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.PlcFamilies;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy;
|
||||
@@ -14,8 +15,15 @@ public sealed class AbLegacyDriverOptions
|
||||
/// <summary>Gets or sets the list of PCCC devices to connect to.</summary>
|
||||
public IReadOnlyList<AbLegacyDeviceOptions> Devices { get; init; } = [];
|
||||
|
||||
/// <summary>Gets or sets the list of PCCC tag definitions.</summary>
|
||||
public IReadOnlyList<AbLegacyTagDefinition> Tags { get; init; } = [];
|
||||
/// <summary>
|
||||
/// Authored raw tags this driver serves. The deploy artifact hands each authored raw
|
||||
/// <c>Tag</c> as a <see cref="RawTagEntry"/> (RawPath identity + driver <c>TagConfig</c> blob +
|
||||
/// WriteIdempotent flag + owning <see cref="RawTagEntry.DeviceName"/>); the driver maps each
|
||||
/// through <see cref="AbLegacyTagDefinitionFactory.FromTagConfig"/> into its RawPath → definition
|
||||
/// table, routing each to its device by <see cref="RawTagEntry.DeviceName"/>. AbLegacy has no
|
||||
/// discovery protocol — the driver serves exactly these.
|
||||
/// </summary>
|
||||
public IReadOnlyList<RawTagEntry> RawTags { get; init; } = [];
|
||||
|
||||
/// <summary>Gets or sets the probe (connectivity check) options.</summary>
|
||||
public AbLegacyProbeOptions Probe { get; init; } = new();
|
||||
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy;
|
||||
|
||||
/// <summary>Parses an equipment tag's <c>TagConfig</c> JSON (the shape authored by the AdminUI
|
||||
/// <c>AbLegacyTagConfigModel</c>) into a transient <see cref="AbLegacyTagDefinition"/> whose
|
||||
/// <see cref="AbLegacyTagDefinition.Name"/> equals the reference string itself, so a value the
|
||||
/// driver publishes back keys the runtime's forward router correctly.</summary>
|
||||
public static class AbLegacyEquipmentTagParser
|
||||
{
|
||||
/// <summary>Attempts to parse an equipment-tag reference into a transient definition.</summary>
|
||||
/// <param name="reference">The equipment tag's TagConfig JSON (also used as the def identity).</param>
|
||||
/// <param name="def">The transient definition when parsing succeeds.</param>
|
||||
/// <returns><see langword="true"/> when <paramref name="reference"/> is an AbLegacy address object.</returns>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// When <c>isArray</c> is the JSON literal <see langword="true"/> but <c>arrayLength</c> is
|
||||
/// absent, zero, or negative, the result is silently a <b>scalar</b>
|
||||
/// (<see cref="AbLegacyTagDefinition.ArrayLength"/> is <see langword="null"/>).
|
||||
/// A valid positive <c>arrayLength</c> is required to produce an array tag; <c>isArray:true</c>
|
||||
/// alone is not sufficient. This is intentional: a stale length behind a cleared or absent
|
||||
/// <c>isArray</c> flag must never produce an orphan array tag that mismatches its scalar OPC UA
|
||||
/// node (see in-source comment, review C-2).
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static bool TryParse(string reference, out AbLegacyTagDefinition def)
|
||||
{
|
||||
def = null!;
|
||||
// Authored tag names never start with '{' (AdminUI name validation), so a leading brace marks an equipment-tag TagConfig blob.
|
||||
if (string.IsNullOrWhiteSpace(reference) || reference[0] != '{') return false;
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(reference);
|
||||
var root = doc.RootElement;
|
||||
if (root.ValueKind != JsonValueKind.Object
|
||||
|| !root.TryGetProperty("address", out var addr)
|
||||
|| addr.ValueKind != JsonValueKind.String)
|
||||
return false;
|
||||
var address = addr.GetString();
|
||||
if (string.IsNullOrWhiteSpace(address)) return false;
|
||||
// Strict enum read (R2-11 Phase C): a typo'd dataType rejects the tag (→ BadNodeIdUnknown)
|
||||
// instead of silently defaulting to a wrong-width Good.
|
||||
if (!TagConfigJson.TryReadEnumStrict(root, "dataType", AbLegacyDataType.Int, out var dataType)) return false;
|
||||
var deviceHostAddress = ReadString(root, "deviceHostAddress");
|
||||
int? arrayLength = null;
|
||||
if (IsArrayFlag(root))
|
||||
{
|
||||
var rawLength = ReadInt(root, "arrayLength");
|
||||
if (rawLength >= 1)
|
||||
arrayLength = Math.Min(rawLength, AbLegacyArray.MaxElements);
|
||||
}
|
||||
// "writable" defaults to true when absent (today's value) — makes read-only equipment tags
|
||||
// authorable (UNDER-6).
|
||||
var writable = TagConfigJson.ReadWritable(root);
|
||||
def = new AbLegacyTagDefinition(
|
||||
Name: reference, DeviceHostAddress: deviceHostAddress, Address: address,
|
||||
DataType: dataType, Writable: writable, ArrayLength: arrayLength);
|
||||
return true;
|
||||
}
|
||||
catch (JsonException) { return false; }
|
||||
catch (FormatException) { return false; }
|
||||
catch (InvalidOperationException) { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deploy-time inspection (05/CONV-2): warns on a present-but-invalid <c>dataType</c> (silently
|
||||
/// defaulted by the lenient runtime) and on a structurally unparseable TagConfig. Empty when clean
|
||||
/// or not an equipment-tag object. Never throws.
|
||||
/// </summary>
|
||||
/// <param name="reference">The equipment tag's TagConfig JSON.</param>
|
||||
/// <returns>The warnings; empty when clean.</returns>
|
||||
public static IReadOnlyList<string> Inspect(string reference)
|
||||
{
|
||||
var warnings = new List<string>();
|
||||
if (string.IsNullOrWhiteSpace(reference) || reference[0] != '{') return warnings;
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(reference);
|
||||
var root = doc.RootElement;
|
||||
if (root.ValueKind != JsonValueKind.Object)
|
||||
{
|
||||
warnings.Add("AbLegacy TagConfig root is not a JSON object — the tag will not resolve (BadNodeIdUnknown).");
|
||||
return warnings;
|
||||
}
|
||||
var w = TagConfigJson.DescribeInvalidEnum<AbLegacyDataType>(root, "dataType");
|
||||
if (w is not null) warnings.Add(w);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
warnings.Add("AbLegacy TagConfig is not valid JSON — the tag will not resolve (BadNodeIdUnknown).");
|
||||
}
|
||||
return warnings;
|
||||
}
|
||||
|
||||
private static string ReadString(JsonElement o, string name)
|
||||
=> o.TryGetProperty(name, out var e) && e.ValueKind == JsonValueKind.String
|
||||
? e.GetString() ?? "" : "";
|
||||
|
||||
private static int ReadInt(JsonElement o, string name)
|
||||
=> o.TryGetProperty(name, out var e) && e.ValueKind == JsonValueKind.Number
|
||||
&& e.TryGetInt32(out var v) ? v : 0;
|
||||
|
||||
// True only when the `isArray` property is the JSON literal true. Absent or false → scalar.
|
||||
private static bool IsArrayFlag(JsonElement o)
|
||||
=> o.TryGetProperty("isArray", out var e) && e.ValueKind == JsonValueKind.True;
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy;
|
||||
|
||||
/// <summary>
|
||||
/// v3 pure mapper: turns an authored raw tag's <c>TagConfig</c> JSON (the shape produced by the
|
||||
/// AdminUI <c>AbLegacyTagConfigModel</c>) into an <see cref="AbLegacyTagDefinition"/>. Under v3 a
|
||||
/// tag's identity is its <b>RawPath</b> (a cluster-scoped slash path), not the address blob — so the
|
||||
/// produced definition's <see cref="AbLegacyTagDefinition.Name"/> is the RawPath the driver was
|
||||
/// handed, which is exactly the wire reference the driver's <c>RawPath → def</c> resolver keys on.
|
||||
/// The driver builds that table by mapping each <see cref="RawTagEntry"/> the deploy artifact
|
||||
/// delivers through <see cref="FromTagConfig"/>; <see cref="ToTagConfig"/> is the inverse, used by
|
||||
/// authoring paths (the Client CLI) that hold a typed definition and need to synthesise the
|
||||
/// <c>TagConfig</c> blob for a <see cref="RawTagEntry"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>Device routing is out of band.</b> The AB Legacy driver is multi-device, but a tag's
|
||||
/// device no longer travels inside the <c>TagConfig</c> blob — the <c>deviceHostAddress</c> key
|
||||
/// is DROPPED here. The deploy artifact carries the tag's device on the
|
||||
/// <see cref="RawTagEntry.DeviceName"/> segment instead; the driver threads that name onto the
|
||||
/// definition (resolving it to a configured device) at table-build time.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static class AbLegacyTagDefinitionFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps an authored <c>TagConfig</c> object to a typed definition keyed by <paramref name="rawPath"/>.
|
||||
/// The input is always an authored TagConfig JSON object (there is no name-vs-blob heuristic in v3).
|
||||
/// The <c>dataType</c> enum is read STRICTLY — a present-but-invalid (typo'd) value rejects the whole
|
||||
/// tag (returns <see langword="false"/> ⇒ the driver surfaces <c>BadNodeIdUnknown</c>) rather than
|
||||
/// silently defaulting to a wrong-width Good. <see cref="AbLegacyTagDefinition.WriteIdempotent"/> is
|
||||
/// NOT read from the blob — it is a platform flag the caller threads in from the tag's
|
||||
/// <see cref="RawTagEntry.WriteIdempotent"/>. <see cref="AbLegacyTagDefinition.DeviceHostAddress"/>
|
||||
/// is left empty here — device routing travels on <see cref="RawTagEntry.DeviceName"/> and the driver
|
||||
/// resolves it at table-build time.
|
||||
/// </summary>
|
||||
/// <param name="tagConfig">The authored equipment-tag TagConfig JSON.</param>
|
||||
/// <param name="rawPath">The tag's RawPath — becomes the definition's identity (<c>Name</c>).</param>
|
||||
/// <param name="def">The mapped definition when this returns <see langword="true"/>.</param>
|
||||
/// <returns><see langword="true"/> when <paramref name="tagConfig"/> is a valid AbLegacy address object.</returns>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// When <c>isArray</c> is the JSON literal <see langword="true"/> but <c>arrayLength</c> is
|
||||
/// absent, zero, or negative, the result is silently a <b>scalar</b>
|
||||
/// (<see cref="AbLegacyTagDefinition.ArrayLength"/> is <see langword="null"/>).
|
||||
/// A valid positive <c>arrayLength</c> is required to produce an array tag; <c>isArray:true</c>
|
||||
/// alone is not sufficient. This is intentional: a stale length behind a cleared or absent
|
||||
/// <c>isArray</c> flag must never produce an orphan array tag that mismatches its scalar OPC UA
|
||||
/// node (see in-source comment, review C-2).
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static bool FromTagConfig(string tagConfig, string rawPath, out AbLegacyTagDefinition def)
|
||||
{
|
||||
def = null!;
|
||||
if (string.IsNullOrWhiteSpace(tagConfig)) return false;
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(tagConfig);
|
||||
var root = doc.RootElement;
|
||||
if (root.ValueKind != JsonValueKind.Object
|
||||
|| !root.TryGetProperty("address", out var addr)
|
||||
|| addr.ValueKind != JsonValueKind.String)
|
||||
return false;
|
||||
var address = addr.GetString();
|
||||
if (string.IsNullOrWhiteSpace(address)) return false;
|
||||
// Strict enum read (R2-11 Phase C): a typo'd dataType rejects the tag (→ BadNodeIdUnknown)
|
||||
// instead of silently defaulting to a wrong-width Good.
|
||||
if (!TagConfigJson.TryReadEnumStrict(root, "dataType", AbLegacyDataType.Int, out var dataType)) return false;
|
||||
int? arrayLength = null;
|
||||
if (IsArrayFlag(root))
|
||||
{
|
||||
var rawLength = ReadInt(root, "arrayLength");
|
||||
if (rawLength >= 1)
|
||||
arrayLength = Math.Min(rawLength, AbLegacyArray.MaxElements);
|
||||
}
|
||||
// "writable" defaults to true when absent (today's value) — makes read-only equipment tags
|
||||
// authorable (UNDER-6).
|
||||
var writable = TagConfigJson.ReadWritable(root);
|
||||
def = new AbLegacyTagDefinition(
|
||||
Name: rawPath, DeviceHostAddress: "", Address: address,
|
||||
DataType: dataType, Writable: writable, WriteIdempotent: false, ArrayLength: arrayLength);
|
||||
return true;
|
||||
}
|
||||
catch (JsonException) { return false; }
|
||||
catch (FormatException) { return false; }
|
||||
catch (InvalidOperationException) { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inverse of <see cref="FromTagConfig"/>: serialises a typed definition back to the camelCase
|
||||
/// <c>TagConfig</c> JSON the mapper reads. Used by authoring paths (the Client CLI) that construct
|
||||
/// an <see cref="AbLegacyTagDefinition"/> from operator flags and need the <c>TagConfig</c> string
|
||||
/// to hand the driver as a <see cref="RawTagEntry"/>. The enum value is written as its name string;
|
||||
/// the optional array fields are emitted only for a real array tag. <c>WriteIdempotent</c> and
|
||||
/// <c>deviceHostAddress</c> are NOT emitted — they travel on the <see cref="RawTagEntry"/>
|
||||
/// (<see cref="RawTagEntry.WriteIdempotent"/> / <see cref="RawTagEntry.DeviceName"/>), not inside
|
||||
/// the blob.
|
||||
/// </summary>
|
||||
/// <param name="def">The definition to serialise.</param>
|
||||
/// <returns>The camelCase TagConfig JSON string.</returns>
|
||||
public static string ToTagConfig(AbLegacyTagDefinition def)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(def);
|
||||
var o = new JsonObject
|
||||
{
|
||||
["address"] = def.Address,
|
||||
["dataType"] = def.DataType.ToString(),
|
||||
["writable"] = def.Writable,
|
||||
};
|
||||
if (def.ArrayLength is { } len)
|
||||
{
|
||||
o["isArray"] = true;
|
||||
o["arrayLength"] = len;
|
||||
}
|
||||
return o.ToJsonString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deploy-time inspection (05/CONV-2): warns on a present-but-invalid <c>dataType</c> (silently
|
||||
/// defaulted by the lenient runtime) and on a structurally unparseable TagConfig. Empty when clean
|
||||
/// or not an equipment-tag object. Never throws.
|
||||
/// </summary>
|
||||
/// <param name="reference">The equipment tag's TagConfig JSON.</param>
|
||||
/// <returns>The warnings; empty when clean.</returns>
|
||||
public static IReadOnlyList<string> Inspect(string reference)
|
||||
{
|
||||
var warnings = new List<string>();
|
||||
if (string.IsNullOrWhiteSpace(reference) || reference[0] != '{') return warnings;
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(reference);
|
||||
var root = doc.RootElement;
|
||||
if (root.ValueKind != JsonValueKind.Object)
|
||||
{
|
||||
warnings.Add("AbLegacy TagConfig root is not a JSON object — the tag will not resolve (BadNodeIdUnknown).");
|
||||
return warnings;
|
||||
}
|
||||
var w = TagConfigJson.DescribeInvalidEnum<AbLegacyDataType>(root, "dataType");
|
||||
if (w is not null) warnings.Add(w);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
warnings.Add("AbLegacy TagConfig is not valid JSON — the tag will not resolve (BadNodeIdUnknown).");
|
||||
}
|
||||
return warnings;
|
||||
}
|
||||
|
||||
private static int ReadInt(JsonElement o, string name)
|
||||
=> o.TryGetProperty(name, out var e) && e.ValueKind == JsonValueKind.Number
|
||||
&& e.TryGetInt32(out var v) ? v : 0;
|
||||
|
||||
// True only when the `isArray` property is the JSON literal true. Absent or false → scalar.
|
||||
private static bool IsArrayFlag(JsonElement o)
|
||||
=> o.TryGetProperty("isArray", out var e) && e.ValueKind == JsonValueKind.True;
|
||||
}
|
||||
@@ -19,11 +19,13 @@ public sealed class AbLegacyDriver : IDriver, IReadable, IWritable, ITagDiscover
|
||||
private readonly ILogger<AbLegacyDriver> _logger;
|
||||
private readonly PollGroupEngine _poll;
|
||||
private readonly Dictionary<string, DeviceState> _devices = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, AbLegacyTagDefinition> _tagsByName = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// Resolves a read/write/subscribe fullReference to a tag definition, bridging the two
|
||||
// authoring models: an authored tag-table entry (by name) OR an equipment tag whose
|
||||
// reference is its raw TagConfig JSON (parsed once via AbLegacyEquipmentTagParser, cached).
|
||||
// v3 authored-tag table, keyed by RawPath (the tag identity + driver wire reference). RawPath is
|
||||
// case-sensitive ordinal. Built in InitializeAsync from _options.RawTags via the pure mapper.
|
||||
private readonly Dictionary<string, AbLegacyTagDefinition> _tagsByRawPath = new(StringComparer.Ordinal);
|
||||
|
||||
// Resolves a read/write/subscribe RawPath reference to its tag definition via a single hit on the
|
||||
// authored _tagsByRawPath table (v3: the reference is always a RawPath; a miss is a miss).
|
||||
private readonly EquipmentTagRefResolver<AbLegacyTagDefinition> _resolver;
|
||||
|
||||
// volatile: _health is read by GetHealth() on any thread while ReadAsync / WriteAsync /
|
||||
@@ -60,8 +62,7 @@ public sealed class AbLegacyDriver : IDriver, IReadable, IWritable, ITagDiscover
|
||||
_tagFactory = tagFactory ?? new LibplctagLegacyTagFactory();
|
||||
_logger = logger ?? NullLogger<AbLegacyDriver>.Instance;
|
||||
_resolver = new EquipmentTagRefResolver<AbLegacyTagDefinition>(
|
||||
r => _tagsByName.TryGetValue(r, out var t) ? t : null,
|
||||
r => AbLegacyEquipmentTagParser.TryParse(r, out var d) ? d : null);
|
||||
r => _tagsByRawPath.TryGetValue(r, out var t) ? t : null);
|
||||
_poll = new PollGroupEngine(
|
||||
reader: ReadAsync,
|
||||
onChange: (handle, tagRef, snapshot) =>
|
||||
@@ -107,13 +108,32 @@ public sealed class AbLegacyDriver : IDriver, IReadable, IWritable, ITagDiscover
|
||||
var profile = AbLegacyPlcFamilyProfile.ForFamily(device.PlcFamily);
|
||||
_devices[device.HostAddress] = new DeviceState(addr, device, profile);
|
||||
}
|
||||
foreach (var tag in _options.Tags) _tagsByName[tag.Name] = tag;
|
||||
// Build the RawPath → definition table from the authored raw tags. Each entry's TagConfig
|
||||
// blob is mapped by the pure factory; the entry's WriteIdempotent flag is threaded onto the
|
||||
// def (it lives on the RawTagEntry, not inside the blob), and its DeviceName is resolved to
|
||||
// the owning device's host so the existing DeviceHostAddress-keyed routing continues to work.
|
||||
// A mapper miss is skipped (logged), never thrown — a bad tag must not fail the whole init.
|
||||
foreach (var entry in _options.RawTags)
|
||||
{
|
||||
if (!AbLegacyTagDefinitionFactory.FromTagConfig(entry.TagConfig, entry.RawPath, out var def))
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"AbLegacy tag config did not map to a definition; skipping. Driver={DriverInstanceId} RawPath={RawPath}",
|
||||
_driverInstanceId, entry.RawPath);
|
||||
continue;
|
||||
}
|
||||
_tagsByRawPath[entry.RawPath] = def with
|
||||
{
|
||||
WriteIdempotent = entry.WriteIdempotent,
|
||||
DeviceHostAddress = ResolveDeviceHost(entry.DeviceName),
|
||||
};
|
||||
}
|
||||
|
||||
// Validate tag types against their device's family profile. Long (32-bit integer)
|
||||
// and String (ST-file) are not supported by all PCCC families; reject them early
|
||||
// so a misconfigured tag fails at init time with a clear message rather than
|
||||
// surfacing an opaque comms error at runtime.
|
||||
foreach (var tag in _options.Tags)
|
||||
foreach (var tag in _tagsByRawPath.Values)
|
||||
{
|
||||
if (!_devices.TryGetValue(tag.DeviceHostAddress, out var deviceForTag)) continue;
|
||||
var profile = deviceForTag.Profile;
|
||||
@@ -157,7 +177,7 @@ public sealed class AbLegacyDriver : IDriver, IReadable, IWritable, ITagDiscover
|
||||
state.DisposeRuntimes();
|
||||
}
|
||||
_devices.Clear();
|
||||
_tagsByName.Clear();
|
||||
_tagsByRawPath.Clear();
|
||||
_resolver.Clear(); // drop transient equipment-tag parses so a config change re-parses
|
||||
throw;
|
||||
}
|
||||
@@ -183,7 +203,7 @@ public sealed class AbLegacyDriver : IDriver, IReadable, IWritable, ITagDiscover
|
||||
state.DisposeRuntimes();
|
||||
}
|
||||
_devices.Clear();
|
||||
_tagsByName.Clear();
|
||||
_tagsByRawPath.Clear();
|
||||
_resolver.Clear(); // drop transient equipment-tag parses so a config change re-parses
|
||||
_health = new DriverHealth(DriverState.Unknown, _health.LastSuccessfulRead, null);
|
||||
}
|
||||
@@ -415,7 +435,7 @@ public sealed class AbLegacyDriver : IDriver, IReadable, IWritable, ITagDiscover
|
||||
{
|
||||
var label = device.DeviceName ?? device.HostAddress;
|
||||
var deviceFolder = root.Folder(device.HostAddress, label);
|
||||
var tagsForDevice = _options.Tags.Where(t =>
|
||||
var tagsForDevice = _tagsByRawPath.Values.Where(t =>
|
||||
string.Equals(t.DeviceHostAddress, device.HostAddress, StringComparison.OrdinalIgnoreCase));
|
||||
foreach (var tag in tagsForDevice)
|
||||
{
|
||||
@@ -522,6 +542,42 @@ public sealed class AbLegacyDriver : IDriver, IReadable, IWritable, ITagDiscover
|
||||
new HostStatusChangedEventArgs(state.Options.HostAddress, old, newState));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolve the <see cref="RawTagEntry.DeviceName"/> a raw tag carries to the host-address key of
|
||||
/// the device it should route to. The AB Legacy driver is multi-device and keys its
|
||||
/// <c>_devices</c> table by <c>HostAddress</c>, so this maps the tag's owning device name to that
|
||||
/// key: it matches the name against each configured <see cref="AbLegacyDeviceOptions"/> by its
|
||||
/// <see cref="AbLegacyDeviceOptions.DeviceName"/> first, then by <c>HostAddress</c> as a fallback,
|
||||
/// and returns the matched device's <c>HostAddress</c>. When the name matches nothing but the
|
||||
/// driver has exactly one device, that sole device is used (single-device deployments never need
|
||||
/// to name their tag's device). Otherwise returns empty — the tag is unroutable and its
|
||||
/// read/write surfaces <c>BadNodeIdUnknown</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// TODO(v3 WaveC): the live device host address must ultimately come from the owning
|
||||
/// <c>Device</c> row's <c>DeviceConfig</c> (resolved by the deploy artifact / bootstrapper) rather
|
||||
/// than from a configured <see cref="AbLegacyDriverOptions.Devices"/> entry. Until Wave C threads
|
||||
/// the Device row through, the best available option is to route by matching the delivered
|
||||
/// <see cref="RawTagEntry.DeviceName"/> against <c>_options.Devices</c> and reusing that entry's
|
||||
/// <c>HostAddress</c> as the connection key.
|
||||
/// </remarks>
|
||||
/// <param name="deviceName">The owning device name delivered on the <see cref="RawTagEntry"/>.</param>
|
||||
/// <returns>The matched device's <c>HostAddress</c>; empty when unroutable.</returns>
|
||||
private string ResolveDeviceHost(string deviceName)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(deviceName))
|
||||
{
|
||||
foreach (var d in _options.Devices)
|
||||
if (string.Equals(d.DeviceName, deviceName, StringComparison.OrdinalIgnoreCase))
|
||||
return d.HostAddress;
|
||||
foreach (var d in _options.Devices)
|
||||
if (string.Equals(d.HostAddress, deviceName, StringComparison.OrdinalIgnoreCase))
|
||||
return d.HostAddress;
|
||||
}
|
||||
// Best-available fallback: a single-device driver routes every tag to its sole device.
|
||||
return _options.Devices.Count == 1 ? _options.Devices[0].HostAddress : "";
|
||||
}
|
||||
|
||||
// ---- IPerCallHostResolver ----
|
||||
|
||||
/// <summary>
|
||||
@@ -744,7 +800,7 @@ public sealed class AbLegacyDriver : IDriver, IReadable, IWritable, ITagDiscover
|
||||
state.DisposeRuntimes();
|
||||
}
|
||||
_devices.Clear();
|
||||
_tagsByName.Clear();
|
||||
_tagsByRawPath.Clear();
|
||||
_resolver.Clear(); // drop transient equipment-tag parses so a config change re-parses
|
||||
_health = new DriverHealth(DriverState.Unknown, _health.LastSuccessfulRead, null);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Hosting;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.PlcFamilies;
|
||||
|
||||
@@ -66,19 +67,11 @@ public static class AbLegacyDriverFactoryExtensions
|
||||
fallback: AbLegacyPlcFamily.Slc500),
|
||||
DeviceName: d.DeviceName))]
|
||||
: [],
|
||||
Tags = dto.Tags is { Count: > 0 }
|
||||
? [.. dto.Tags.Select(t => new AbLegacyTagDefinition(
|
||||
Name: t.Name ?? throw new InvalidOperationException(
|
||||
$"AB Legacy config for '{driverInstanceId}' has a tag missing Name"),
|
||||
DeviceHostAddress: t.DeviceHostAddress ?? throw new InvalidOperationException(
|
||||
$"AB Legacy tag '{t.Name}' in '{driverInstanceId}' missing DeviceHostAddress"),
|
||||
Address: t.Address ?? throw new InvalidOperationException(
|
||||
$"AB Legacy tag '{t.Name}' in '{driverInstanceId}' missing Address"),
|
||||
DataType: ParseEnum<AbLegacyDataType>(t.DataType, driverInstanceId, "DataType",
|
||||
tagName: t.Name),
|
||||
Writable: t.Writable ?? true,
|
||||
WriteIdempotent: t.WriteIdempotent ?? false))]
|
||||
: [],
|
||||
// v3: the deploy artifact (Wave C) populates rawTags with the cluster's authored raw AbLegacy
|
||||
// tags (RawPath + TagConfig blob + WriteIdempotent + owning DeviceName). The driver maps each
|
||||
// RawTagEntry's TagConfig blob through AbLegacyTagDefinitionFactory at Initialize and routes it
|
||||
// to its device by DeviceName; the legacy pre-declared DTO tag path is retired.
|
||||
RawTags = dto.RawTags is { Count: > 0 } ? [.. dto.RawTags] : [],
|
||||
Probe = new AbLegacyProbeOptions
|
||||
{
|
||||
Enabled = dto.Probe?.Enabled ?? true,
|
||||
@@ -145,9 +138,11 @@ public static class AbLegacyDriverFactoryExtensions
|
||||
public List<AbLegacyDeviceDto>? Devices { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of tags to monitor.
|
||||
/// Gets or sets the authored raw tags (RawPath + TagConfig blob + WriteIdempotent + owning
|
||||
/// DeviceName) the deploy artifact delivers. The driver maps each through
|
||||
/// <see cref="AbLegacyTagDefinitionFactory.FromTagConfig"/> at Initialize.
|
||||
/// </summary>
|
||||
public List<AbLegacyTagDto>? Tags { get; init; }
|
||||
public List<RawTagEntry>? RawTags { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the probe configuration.
|
||||
@@ -173,39 +168,6 @@ public static class AbLegacyDriverFactoryExtensions
|
||||
public string? DeviceName { get; init; }
|
||||
}
|
||||
|
||||
internal sealed class AbLegacyTagDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the tag name.
|
||||
/// </summary>
|
||||
public string? Name { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the device host address.
|
||||
/// </summary>
|
||||
public string? DeviceHostAddress { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the tag address.
|
||||
/// </summary>
|
||||
public string? Address { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the data type.
|
||||
/// </summary>
|
||||
public string? DataType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the tag is writable.
|
||||
/// </summary>
|
||||
public bool? Writable { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether write is idempotent.
|
||||
/// </summary>
|
||||
public bool? WriteIdempotent { get; init; }
|
||||
}
|
||||
|
||||
internal sealed class AbLegacyProbeDto
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -93,10 +93,7 @@ public sealed class AbLegacyDriverProbe : IDriverProbe
|
||||
// S:0 is present on all PCCC PLCs that support the status file, so a "not found" response
|
||||
// still proves PCCC connectivity; a successful read is the happy path.
|
||||
var tagName = opts.Probe.ProbeAddress
|
||||
?? opts.Tags.FirstOrDefault(
|
||||
t => string.Equals(t.DeviceHostAddress, firstDevice?.HostAddress, StringComparison.OrdinalIgnoreCase))
|
||||
?.Address
|
||||
?? opts.Tags.FirstOrDefault()?.Address
|
||||
?? FirstProbeableTagAddress(opts, firstDevice)
|
||||
?? "S:0";
|
||||
|
||||
var p = new AbLegacyTagCreateParams(
|
||||
@@ -187,4 +184,30 @@ public sealed class AbLegacyDriverProbe : IDriverProbe
|
||||
var parsed = AbLegacyHostAddress.TryParse(firstDevice.HostAddress);
|
||||
return (parsed, firstDevice);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pick a PCCC address to probe from the authored raw tags: prefer a tag owned by the device
|
||||
/// being probed, else any authored tag. v3 tags carry no typed address — the RawTagEntry's
|
||||
/// <c>TagConfig</c> blob is mapped through <see cref="AbLegacyTagDefinitionFactory.FromTagConfig"/>
|
||||
/// to recover the PCCC address. Returns <see langword="null"/> when no tag maps, so the caller
|
||||
/// falls back to the status file (<c>S:0</c>).
|
||||
/// </summary>
|
||||
/// <param name="opts">The deserialised driver options.</param>
|
||||
/// <param name="firstDevice">The device being probed (matched by DeviceName / HostAddress).</param>
|
||||
/// <returns>A probeable PCCC address, or <see langword="null"/>.</returns>
|
||||
private static string? FirstProbeableTagAddress(AbLegacyDriverOptions opts, AbLegacyDeviceOptions? firstDevice)
|
||||
{
|
||||
static string? Address(RawTagEntry e) =>
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(e.TagConfig, e.RawPath, out var d) ? d.Address : null;
|
||||
|
||||
foreach (var e in opts.RawTags)
|
||||
if ((string.Equals(e.DeviceName, firstDevice?.DeviceName, StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(e.DeviceName, firstDevice?.HostAddress, StringComparison.OrdinalIgnoreCase))
|
||||
&& Address(e) is { } matched)
|
||||
return matched;
|
||||
foreach (var e in opts.RawTags)
|
||||
if (Address(e) is { } any)
|
||||
return any;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,9 +94,13 @@ public sealed class BuildOptionsTests
|
||||
options.Devices[0].DeviceName.ShouldBe("cli-MicroLogix");
|
||||
}
|
||||
|
||||
/// <summary>Verifies that tag list is forwarded verbatim to the options.</summary>
|
||||
/// <summary>
|
||||
/// Verifies that the typed tag list is delivered as v3 <see cref="RawTagEntry"/> records: RawPath =
|
||||
/// the def's Name, DeviceName = the def's DeviceHostAddress, and the TagConfig blob round-trips the
|
||||
/// def's address / dataType / writable through the real mapper.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void BuildOptions_forwards_tag_list_verbatim()
|
||||
public void BuildOptions_delivers_tags_as_rawtag_entries()
|
||||
{
|
||||
var cmd = new TestCommand
|
||||
{
|
||||
@@ -107,7 +111,18 @@ public sealed class BuildOptionsTests
|
||||
|
||||
var options = cmd.Build(SampleTags);
|
||||
|
||||
options.Tags.ShouldBe(SampleTags);
|
||||
options.RawTags.Count.ShouldBe(SampleTags.Count);
|
||||
for (var i = 0; i < SampleTags.Count; i++)
|
||||
{
|
||||
var def = SampleTags[i];
|
||||
var entry = options.RawTags[i];
|
||||
entry.RawPath.ShouldBe(def.Name);
|
||||
entry.DeviceName.ShouldBe(def.DeviceHostAddress);
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(entry.TagConfig, entry.RawPath, out var round).ShouldBeTrue();
|
||||
round.Address.ShouldBe(def.Address);
|
||||
round.DataType.ShouldBe(def.DataType);
|
||||
round.Writable.ShouldBe(def.Writable);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Verifies that timeout-ms option is propagated to the driver options.</summary>
|
||||
@@ -139,7 +154,7 @@ public sealed class BuildOptionsTests
|
||||
|
||||
var options = cmd.Build([]);
|
||||
|
||||
options.Tags.ShouldBeEmpty();
|
||||
options.RawTags.ShouldBeEmpty();
|
||||
options.Devices.Count.ShouldBe(1);
|
||||
options.Devices[0].PlcFamily.ShouldBe(AbLegacyPlcFamily.Plc5);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public sealed class AbLegacyArrayTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = tags,
|
||||
RawTags = AbLegacyRawTags.Entries(tags),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "ablegacy-array", factory);
|
||||
return (drv, factory);
|
||||
@@ -169,7 +169,7 @@ public sealed class AbLegacyArrayTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("Vector", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int, ArrayLength: 8)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("Vector", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int, ArrayLength: 8)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "ablegacy-array", new FakeAbLegacyTagFactory());
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -231,30 +231,30 @@ public sealed class AbLegacyArrayTests
|
||||
|
||||
// ---- Equipment-tag resolver threads arrayLength ----
|
||||
|
||||
/// <summary>The equipment-tag parser threads <c>arrayLength</c> into the transient definition.</summary>
|
||||
/// <summary>The tag-definition factory threads <c>arrayLength</c> into the definition.</summary>
|
||||
[Fact]
|
||||
public void EquipmentTagParser_threads_arrayLength()
|
||||
public void TagDefinitionFactory_threads_arrayLength()
|
||||
{
|
||||
var json = """{"deviceHostAddress":"ab://10.0.0.5/1,0","address":"N7:0","dataType":"Int","isArray":true,"arrayLength":10}""";
|
||||
AbLegacyEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
|
||||
var json = """{"address":"N7:0","dataType":"Int","isArray":true,"arrayLength":10}""";
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(json, "eq/a", out var def).ShouldBeTrue();
|
||||
def!.ArrayLength.ShouldBe(10);
|
||||
}
|
||||
|
||||
/// <summary>The parser caps <c>arrayLength</c> at the PCCC 256-word file maximum (isArray:true).</summary>
|
||||
/// <summary>The factory caps <c>arrayLength</c> at the PCCC 256-word file maximum (isArray:true).</summary>
|
||||
[Fact]
|
||||
public void EquipmentTagParser_caps_arrayLength_at_256()
|
||||
public void TagDefinitionFactory_caps_arrayLength_at_256()
|
||||
{
|
||||
var json = """{"deviceHostAddress":"ab://10.0.0.5/1,0","address":"N7:0","dataType":"Int","isArray":true,"arrayLength":99999}""";
|
||||
AbLegacyEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
|
||||
var json = """{"address":"N7:0","dataType":"Int","isArray":true,"arrayLength":99999}""";
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(json, "eq/a", out var def).ShouldBeTrue();
|
||||
def!.ArrayLength.ShouldBe(256);
|
||||
}
|
||||
|
||||
/// <summary>A scalar equipment tag (no arrayLength) leaves ArrayLength null.</summary>
|
||||
/// <summary>A scalar tag (no arrayLength) leaves ArrayLength null.</summary>
|
||||
[Fact]
|
||||
public void EquipmentTagParser_scalar_leaves_arrayLength_null()
|
||||
public void TagDefinitionFactory_scalar_leaves_arrayLength_null()
|
||||
{
|
||||
var json = """{"deviceHostAddress":"ab://10.0.0.5/1,0","address":"N7:0","dataType":"Int"}""";
|
||||
AbLegacyEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
|
||||
var json = """{"address":"N7:0","dataType":"Int"}""";
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(json, "eq/a", out var def).ShouldBeTrue();
|
||||
def!.ArrayLength.ShouldBeNull();
|
||||
}
|
||||
|
||||
@@ -264,19 +264,19 @@ public sealed class AbLegacyArrayTests
|
||||
/// cleared / absent isArray must leave ArrayLength null and never produce an orphan array.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EquipmentTagParser_arrayLength_without_isArray_is_scalar()
|
||||
public void TagDefinitionFactory_arrayLength_without_isArray_is_scalar()
|
||||
{
|
||||
var json = """{"deviceHostAddress":"ab://10.0.0.5/1,0","address":"N7:0","dataType":"Int","arrayLength":8}""";
|
||||
AbLegacyEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
|
||||
var json = """{"address":"N7:0","dataType":"Int","arrayLength":8}""";
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(json, "eq/a", out var def).ShouldBeTrue();
|
||||
def!.ArrayLength.ShouldBeNull();
|
||||
}
|
||||
|
||||
/// <summary>C-2 regression: <c>isArray:false</c> with a positive arrayLength is a SCALAR.</summary>
|
||||
[Fact]
|
||||
public void EquipmentTagParser_isArray_false_with_arrayLength_is_scalar()
|
||||
public void TagDefinitionFactory_isArray_false_with_arrayLength_is_scalar()
|
||||
{
|
||||
var json = """{"deviceHostAddress":"ab://10.0.0.5/1,0","address":"N7:0","dataType":"Int","isArray":false,"arrayLength":8}""";
|
||||
AbLegacyEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
|
||||
var json = """{"address":"N7:0","dataType":"Int","isArray":false,"arrayLength":8}""";
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(json, "eq/a", out var def).ShouldBeTrue();
|
||||
def!.ArrayLength.ShouldBeNull();
|
||||
}
|
||||
|
||||
@@ -286,32 +286,33 @@ public sealed class AbLegacyArrayTests
|
||||
/// as a 1-element array.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EquipmentTagParser_isArray_true_arrayLength_one_is_one_element_array()
|
||||
public void TagDefinitionFactory_isArray_true_arrayLength_one_is_one_element_array()
|
||||
{
|
||||
var json = """{"deviceHostAddress":"ab://10.0.0.5/1,0","address":"N7:0","dataType":"Int","isArray":true,"arrayLength":1}""";
|
||||
AbLegacyEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
|
||||
var json = """{"address":"N7:0","dataType":"Int","isArray":true,"arrayLength":1}""";
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(json, "eq/a", out var def).ShouldBeTrue();
|
||||
def!.ArrayLength.ShouldBe(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// End-to-end: an AbLegacy driver with NO authored tags reads an equipment-tag ref whose
|
||||
/// TagConfig carries <c>isArray:true</c> + <c>arrayLength</c> — the resolver threads the
|
||||
/// count and the read surfaces a typed array, capping the libplctag element count at 256.
|
||||
/// End-to-end: an AbLegacy driver reads a raw tag authored as a <see cref="RawTagEntry"/> whose
|
||||
/// TagConfig carries <c>isArray:true</c> + <c>arrayLength</c> — the mapper threads the count and
|
||||
/// the read surfaces a typed array, capping the libplctag element count at 256.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Driver_reads_equipment_array_ref_as_typed_array()
|
||||
public async Task Driver_reads_array_rawtag_as_typed_array()
|
||||
{
|
||||
var json = """{"deviceHostAddress":"ab://10.0.0.5/1,0","address":"N7:0","dataType":"Int","isArray":true,"arrayLength":3}""";
|
||||
const string rawPath = "cell/ablegacy/dev1/Vec";
|
||||
var tagConfig = """{"address":"N7:0","dataType":"Int","isArray":true,"arrayLength":3}""";
|
||||
var factory = new FakeAbLegacyTagFactory { Customise = p => new FakeAbLegacyTag(p) { ArrayValue = new short[] { 11, 22, 33 } } };
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [],
|
||||
RawTags = [new RawTagEntry(rawPath, tagConfig, WriteIdempotent: false, DeviceName: "ab://10.0.0.5/1,0")],
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "ablegacy-eq-array", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
var r = await drv.ReadAsync([json], CancellationToken.None);
|
||||
var r = await drv.ReadAsync([rawPath], CancellationToken.None);
|
||||
|
||||
r[0].StatusCode.ShouldBe(AbLegacyStatusMapper.Good);
|
||||
var arr = r[0].Value.ShouldBeOfType<short[]>();
|
||||
@@ -320,24 +321,25 @@ public sealed class AbLegacyArrayTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// C-2 end-to-end: an equipment-tag ref carrying <c>isArray:false, arrayLength:8</c> reads
|
||||
/// a single SCALAR value (the parser drops the orphan length), so the read never decodes a
|
||||
/// C-2 end-to-end: a raw tag whose TagConfig carries <c>isArray:false, arrayLength:8</c> reads
|
||||
/// a single SCALAR value (the mapper drops the orphan length), so the read never decodes a
|
||||
/// phantom 8-element array against a scalar node. ElementCount stays 1.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Driver_reads_isArray_false_with_arrayLength_as_scalar()
|
||||
{
|
||||
var json = """{"deviceHostAddress":"ab://10.0.0.5/1,0","address":"N7:0","dataType":"Int","isArray":false,"arrayLength":8}""";
|
||||
const string rawPath = "cell/ablegacy/dev1/Scl";
|
||||
var tagConfig = """{"address":"N7:0","dataType":"Int","isArray":false,"arrayLength":8}""";
|
||||
var factory = new FakeAbLegacyTagFactory { Customise = p => new FakeAbLegacyTag(p) { Value = 99 } };
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [],
|
||||
RawTags = [new RawTagEntry(rawPath, tagConfig, WriteIdempotent: false, DeviceName: "ab://10.0.0.5/1,0")],
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "ablegacy-eq-scalar", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
var r = await drv.ReadAsync([json], CancellationToken.None);
|
||||
var r = await drv.ReadAsync([rawPath], CancellationToken.None);
|
||||
|
||||
r[0].StatusCode.ShouldBe(AbLegacyStatusMapper.Good);
|
||||
r[0].Value.ShouldBe(99);
|
||||
|
||||
@@ -80,7 +80,7 @@ public sealed class AbLegacyBitIndexRangeTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("LBit20", "ab://10.0.0.5/1,0", "L9:0/20", AbLegacyDataType.Bit)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("LBit20", "ab://10.0.0.5/1,0", "L9:0/20", AbLegacyDataType.Bit)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -105,7 +105,7 @@ public sealed class AbLegacyBitIndexRangeTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("Bit0", "ab://10.0.0.5/1,0", "N7:0/0", AbLegacyDataType.Bit)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("Bit0", "ab://10.0.0.5/1,0", "N7:0/0", AbLegacyDataType.Bit)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
@@ -19,7 +19,7 @@ public sealed class AbLegacyBitRmwTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("Flag3", "ab://10.0.0.5/1,0", "N7:0/3", AbLegacyDataType.Bit)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("Flag3", "ab://10.0.0.5/1,0", "N7:0/3", AbLegacyDataType.Bit)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -43,7 +43,7 @@ public sealed class AbLegacyBitRmwTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("F", "ab://10.0.0.5/1,0", "N7:0/3", AbLegacyDataType.Bit)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("F", "ab://10.0.0.5/1,0", "N7:0/3", AbLegacyDataType.Bit)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -67,7 +67,7 @@ public sealed class AbLegacyBitRmwTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = tags,
|
||||
RawTags = AbLegacyRawTags.Entries(tags),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -89,11 +89,11 @@ public sealed class AbLegacyBitRmwTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags =
|
||||
RawTags = AbLegacyRawTags.Entries(
|
||||
[
|
||||
new AbLegacyTagDefinition("Bit0", "ab://10.0.0.5/1,0", "N7:0/0", AbLegacyDataType.Bit),
|
||||
new AbLegacyTagDefinition("Bit5", "ab://10.0.0.5/1,0", "N7:0/5", AbLegacyDataType.Bit),
|
||||
],
|
||||
]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -120,7 +120,7 @@ public sealed class AbLegacyBitRmwTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("F", "ab://10.0.0.5/1,0", bitAddr, AbLegacyDataType.Bit)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("F", "ab://10.0.0.5/1,0", bitAddr, AbLegacyDataType.Bit)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -143,7 +143,7 @@ public sealed class AbLegacyBitRmwTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("F", "ab://10.0.0.5/1,0", "B3:0/3", AbLegacyDataType.Bit)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("F", "ab://10.0.0.5/1,0", "B3:0/3", AbLegacyDataType.Bit)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -167,7 +167,7 @@ public sealed class AbLegacyBitRmwTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = tags,
|
||||
RawTags = AbLegacyRawTags.Entries(tags),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -195,7 +195,7 @@ public sealed class AbLegacyBitRmwTests
|
||||
var opts = new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("Bit2", "ab://10.0.0.5/1,0", "N7:0/2", AbLegacyDataType.Bit)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("Bit2", "ab://10.0.0.5/1,0", "N7:0/2", AbLegacyDataType.Bit)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
};
|
||||
|
||||
@@ -241,7 +241,7 @@ public sealed class AbLegacyBitRmwTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("F", "ab://10.0.0.5/1,0", "I:0/3", AbLegacyDataType.Bit)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("F", "ab://10.0.0.5/1,0", "I:0/3", AbLegacyDataType.Bit)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
@@ -19,11 +19,11 @@ public sealed class AbLegacyCapabilityTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0", DeviceName: "Press-SLC-1")],
|
||||
Tags =
|
||||
RawTags = AbLegacyRawTags.Entries(
|
||||
[
|
||||
new AbLegacyTagDefinition("Speed", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int),
|
||||
new AbLegacyTagDefinition("Temperature", "ab://10.0.0.5/1,0", "F8:0", AbLegacyDataType.Float, Writable: false),
|
||||
],
|
||||
]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1");
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -50,7 +50,7 @@ public sealed class AbLegacyCapabilityTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -75,7 +75,7 @@ public sealed class AbLegacyCapabilityTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -190,11 +190,11 @@ public sealed class AbLegacyCapabilityTests
|
||||
new AbLegacyDeviceOptions("ab://10.0.0.5/1,0"),
|
||||
new AbLegacyDeviceOptions("ab://10.0.0.6/1,0"),
|
||||
],
|
||||
Tags =
|
||||
RawTags = AbLegacyRawTags.Entries(
|
||||
[
|
||||
new AbLegacyTagDefinition("A", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int),
|
||||
new AbLegacyTagDefinition("B", "ab://10.0.0.6/1,0", "N7:0", AbLegacyDataType.Int),
|
||||
],
|
||||
]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1");
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ public sealed class AbLegacyDisposeAndResolveHostTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0", AbLegacyPlcFamily.Slc500)],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-dispose", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -72,7 +72,7 @@ public sealed class AbLegacyDisposeAndResolveHostTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -135,7 +135,7 @@ public sealed class AbLegacyDisposeAndResolveHostTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)]),
|
||||
}, "drv-1");
|
||||
drv.ResolveHost("X").ShouldBe("ab://10.0.0.5/1,0");
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public sealed class AbLegacyDriverTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/", AbLegacyPlcFamily.Slc500)],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/", "N7:0", AbLegacyDataType.Int)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/", "N7:0", AbLegacyDataType.Int)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -154,7 +154,7 @@ public sealed class AbLegacyDriverTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,2", AbLegacyPlcFamily.Slc500)],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,2", "N7:0", AbLegacyDataType.Int)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,2", "N7:0", AbLegacyDataType.Int)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -171,7 +171,7 @@ public sealed class AbLegacyDriverTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/", AbLegacyPlcFamily.MicroLogix)],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/", "L9:0", AbLegacyDataType.Long)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/", "L9:0", AbLegacyDataType.Long)]),
|
||||
}, "drv-1");
|
||||
|
||||
var ex = await Should.ThrowAsync<InvalidOperationException>(
|
||||
@@ -188,7 +188,7 @@ public sealed class AbLegacyDriverTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0", AbLegacyPlcFamily.Slc500)],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "L9:0", AbLegacyDataType.Long)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "L9:0", AbLegacyDataType.Long)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1");
|
||||
|
||||
@@ -209,7 +209,7 @@ public sealed class AbLegacyDriverTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0", AbLegacyPlcFamily.Plc5)],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "L9:0", AbLegacyDataType.Long)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "L9:0", AbLegacyDataType.Long)]),
|
||||
}, "drv-1");
|
||||
|
||||
var ex = await Should.ThrowAsync<InvalidOperationException>(
|
||||
|
||||
+13
-9
@@ -4,30 +4,34 @@ using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Tests;
|
||||
|
||||
/// <summary>R2-11 Phase C strictness surface for the AbLegacy equipment-tag parser: the runtime is now STRICT —
|
||||
/// a typo'd <c>dataType</c> rejects the tag (<c>TryParse</c> ⇒ <see langword="false"/> ⇒ <c>BadNodeIdUnknown</c>),
|
||||
/// <c>Inspect</c> reports the typo, and the <c>writable</c> key is honoured (default true).</summary>
|
||||
/// <summary>R2-11 Phase C strictness surface for the AbLegacy tag-definition factory: the runtime is now STRICT —
|
||||
/// a typo'd <c>dataType</c> rejects the tag (<c>FromTagConfig</c> ⇒ <see langword="false"/> ⇒ <c>BadNodeIdUnknown</c>),
|
||||
/// <c>Inspect</c> reports the typo, and the <c>writable</c> key is honoured (default true). Under v3 the mapped
|
||||
/// definition's <c>Name</c> is the RawPath the factory was handed, not the blob.</summary>
|
||||
public sealed class AbLegacyEquipmentTagParserStrictnessTests
|
||||
{
|
||||
private const string RawPath = "cell/ablegacy/dev1/T1";
|
||||
|
||||
[Fact]
|
||||
public void Typo_dataType_rejects_the_tag()
|
||||
{
|
||||
AbLegacyEquipmentTagParser.TryParse("{\"address\":\"N7:0\",\"dataType\":\"Intt\"}", out _)
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig("{\"address\":\"N7:0\",\"dataType\":\"Intt\"}", RawPath, out _)
|
||||
.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Valid_dataType_still_parses()
|
||||
{
|
||||
AbLegacyEquipmentTagParser.TryParse("{\"address\":\"N7:0\",\"dataType\":\"Int\"}", out var def)
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig("{\"address\":\"N7:0\",\"dataType\":\"Int\"}", RawPath, out var def)
|
||||
.ShouldBeTrue();
|
||||
def.DataType.ShouldBe(AbLegacyDataType.Int);
|
||||
def.Name.ShouldBe(RawPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inspect_reports_typo_dataType()
|
||||
{
|
||||
var warnings = AbLegacyEquipmentTagParser.Inspect("{\"address\":\"N7:0\",\"dataType\":\"Intt\"}");
|
||||
var warnings = AbLegacyTagDefinitionFactory.Inspect("{\"address\":\"N7:0\",\"dataType\":\"Intt\"}");
|
||||
warnings.ShouldHaveSingleItem();
|
||||
warnings[0].ShouldContain("Intt");
|
||||
warnings[0].ShouldContain("dataType");
|
||||
@@ -36,13 +40,13 @@ public sealed class AbLegacyEquipmentTagParserStrictnessTests
|
||||
[Fact]
|
||||
public void Inspect_clean_config_has_no_warnings()
|
||||
{
|
||||
AbLegacyEquipmentTagParser.Inspect("{\"address\":\"N7:0\",\"dataType\":\"Int\"}").ShouldBeEmpty();
|
||||
AbLegacyTagDefinitionFactory.Inspect("{\"address\":\"N7:0\",\"dataType\":\"Int\"}").ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Writable_false_is_honoured()
|
||||
{
|
||||
AbLegacyEquipmentTagParser.TryParse("{\"address\":\"N7:0\",\"dataType\":\"Int\",\"writable\":false}", out var def)
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig("{\"address\":\"N7:0\",\"dataType\":\"Int\",\"writable\":false}", RawPath, out var def)
|
||||
.ShouldBeTrue();
|
||||
def.Writable.ShouldBeFalse();
|
||||
}
|
||||
@@ -50,7 +54,7 @@ public sealed class AbLegacyEquipmentTagParserStrictnessTests
|
||||
[Fact]
|
||||
public void Writable_absent_defaults_to_true()
|
||||
{
|
||||
AbLegacyEquipmentTagParser.TryParse("{\"address\":\"N7:0\",\"dataType\":\"Int\"}", out var def)
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig("{\"address\":\"N7:0\",\"dataType\":\"Int\"}", RawPath, out var def)
|
||||
.ShouldBeTrue();
|
||||
def.Writable.ShouldBeTrue();
|
||||
}
|
||||
|
||||
+26
-20
@@ -8,34 +8,38 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Tests;
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class AbLegacyEquipmentTagTests
|
||||
{
|
||||
private const string RawPath = "cell/ablegacy/dev1/Counter";
|
||||
|
||||
[Fact]
|
||||
public void Parses_equipment_tagconfig_into_a_transient_definition()
|
||||
public void Maps_tagconfig_into_a_definition_keyed_by_rawpath()
|
||||
{
|
||||
// v3: the deviceHostAddress key is dropped by the mapper (device routing travels on the
|
||||
// RawTagEntry's DeviceName). The mapped definition is keyed by the RawPath, not the blob.
|
||||
var json = """{"deviceHostAddress":"ab://10.0.0.5/1,0","address":"N7:0","dataType":"Int"}""";
|
||||
AbLegacyEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
|
||||
def!.Name.ShouldBe(json);
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(json, RawPath, out var def).ShouldBeTrue();
|
||||
def!.Name.ShouldBe(RawPath);
|
||||
def.Address.ShouldBe("N7:0");
|
||||
def.DataType.ShouldBe(AbLegacyDataType.Int);
|
||||
def.DeviceHostAddress.ShouldBe("ab://10.0.0.5/1,0");
|
||||
def.DeviceHostAddress.ShouldBe(""); // dropped — resolved from RawTagEntry.DeviceName at table-build time
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Rejects_a_non_address_blob()
|
||||
=> AbLegacyEquipmentTagParser.TryParse("""{"FullName":"x"}""", out _).ShouldBeFalse();
|
||||
=> AbLegacyTagDefinitionFactory.FromTagConfig("""{"FullName":"x"}""", RawPath, out _).ShouldBeFalse();
|
||||
|
||||
[Fact]
|
||||
public void Rejects_garbage()
|
||||
=> AbLegacyEquipmentTagParser.TryParse("not json", out _).ShouldBeFalse();
|
||||
=> AbLegacyTagDefinitionFactory.FromTagConfig("not json", RawPath, out _).ShouldBeFalse();
|
||||
|
||||
[Fact]
|
||||
public void Rejects_address_as_a_json_number()
|
||||
=> AbLegacyEquipmentTagParser.TryParse(
|
||||
"""{"address":7,"dataType":"Int"}""", out _).ShouldBeFalse();
|
||||
=> AbLegacyTagDefinitionFactory.FromTagConfig(
|
||||
"""{"address":7,"dataType":"Int"}""", RawPath, out _).ShouldBeFalse();
|
||||
|
||||
[Fact]
|
||||
public void Rejects_empty_address()
|
||||
=> AbLegacyEquipmentTagParser.TryParse(
|
||||
"""{"address":"","dataType":"Int"}""", out _).ShouldBeFalse();
|
||||
=> AbLegacyTagDefinitionFactory.FromTagConfig(
|
||||
"""{"address":"","dataType":"Int"}""", RawPath, out _).ShouldBeFalse();
|
||||
|
||||
// -002 regression: isArray:true without a valid positive arrayLength → scalar (null ArrayLength).
|
||||
|
||||
@@ -43,7 +47,7 @@ public sealed class AbLegacyEquipmentTagTests
|
||||
public void IsArray_true_with_arrayLength_zero_produces_scalar()
|
||||
{
|
||||
var json = """{"address":"N7:0","dataType":"Int","isArray":true,"arrayLength":0}""";
|
||||
AbLegacyEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(json, RawPath, out var def).ShouldBeTrue();
|
||||
def!.ArrayLength.ShouldBeNull();
|
||||
}
|
||||
|
||||
@@ -51,7 +55,7 @@ public sealed class AbLegacyEquipmentTagTests
|
||||
public void IsArray_true_with_no_arrayLength_produces_scalar()
|
||||
{
|
||||
var json = """{"address":"N7:0","dataType":"Int","isArray":true}""";
|
||||
AbLegacyEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(json, RawPath, out var def).ShouldBeTrue();
|
||||
def!.ArrayLength.ShouldBeNull();
|
||||
}
|
||||
|
||||
@@ -59,28 +63,30 @@ public sealed class AbLegacyEquipmentTagTests
|
||||
public void IsArray_true_with_negative_arrayLength_produces_scalar()
|
||||
{
|
||||
var json = """{"address":"N7:0","dataType":"Int","isArray":true,"arrayLength":-5}""";
|
||||
AbLegacyEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(json, RawPath, out var def).ShouldBeTrue();
|
||||
def!.ArrayLength.ShouldBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// End-to-end driver-level proof: an AbLegacy driver with NO authored tags can still read an
|
||||
/// equipment-tag ref (the raw TagConfig JSON) — the resolver parses it into a transient
|
||||
/// definition and the read goes to the fake runtime instead of returning BadNodeIdUnknown.
|
||||
/// End-to-end driver-level proof: a raw tag authored as a <see cref="RawTagEntry"/> (RawPath
|
||||
/// identity + TagConfig blob) is resolved by the driver's RawPath → def table and read against the
|
||||
/// fake runtime, returning Good instead of BadNodeIdUnknown. Under v3 the read reference is always
|
||||
/// a RawPath — the driver no longer parses a raw TagConfig blob handed as the reference.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Driver_resolves_an_equipment_ref_and_reads_instead_of_BadNodeIdUnknown()
|
||||
public async Task Driver_resolves_a_rawpath_ref_and_reads_instead_of_BadNodeIdUnknown()
|
||||
{
|
||||
var json = """{"deviceHostAddress":"ab://10.0.0.5/1,0","address":"N7:0","dataType":"Int"}""";
|
||||
var tagConfig = """{"address":"N7:0","dataType":"Int"}""";
|
||||
var factory = new FakeAbLegacyTagFactory { Customise = p => new FakeAbLegacyTag(p) { Value = 4242 } };
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [],
|
||||
RawTags = [new RawTagEntry(RawPath, tagConfig, WriteIdempotent: false, DeviceName: "ab://10.0.0.5/1,0")],
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "ablegacy-eq", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
var r = await drv.ReadAsync([json], CancellationToken.None);
|
||||
var r = await drv.ReadAsync([RawPath], CancellationToken.None);
|
||||
|
||||
r[0].StatusCode.ShouldBe(AbLegacyStatusMapper.Good);
|
||||
r[0].StatusCode.ShouldNotBe(AbLegacyStatusMapper.BadNodeIdUnknown);
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public sealed class AbLegacyEvictOnFailureTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions(Device)],
|
||||
Tags = tags,
|
||||
RawTags = AbLegacyRawTags.Entries(tags),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
return (drv, factory);
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ public sealed class AbLegacyLoggerInjectionTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-logged", factory, logger);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Test helper bridging the v2 authoring shape (a typed <see cref="AbLegacyTagDefinition"/>) to the v3
|
||||
/// delivery shape (<see cref="RawTagEntry"/>). Under v3 the driver no longer takes pre-declared
|
||||
/// definitions — the deploy artifact hands it authored raw tags (RawPath + TagConfig blob + owning
|
||||
/// DeviceName), and the driver rebuilds the typed definitions via
|
||||
/// <see cref="AbLegacyTagDefinitionFactory"/>. These tests keep expressing their intent as typed
|
||||
/// definitions; this helper serialises each back to its TagConfig blob (via
|
||||
/// <see cref="AbLegacyTagDefinitionFactory.ToTagConfig"/>) and packages it as a <see cref="RawTagEntry"/>
|
||||
/// whose RawPath is the def's <c>Name</c> and whose <see cref="RawTagEntry.DeviceName"/> is the def's
|
||||
/// <c>DeviceHostAddress</c> — so the round-trip through the real mapper reproduces the same definition
|
||||
/// the test authored, keyed by the same name the read/write/subscribe call sites use and routed to the
|
||||
/// same device (the driver matches DeviceName against a configured device's Name or HostAddress).
|
||||
/// </summary>
|
||||
internal static class AbLegacyRawTags
|
||||
{
|
||||
/// <summary>Serialises one typed definition into its <see cref="RawTagEntry"/> (RawPath = def.Name, DeviceName = def.DeviceHostAddress).</summary>
|
||||
/// <param name="def">The typed definition to convert.</param>
|
||||
/// <returns>The equivalent <see cref="RawTagEntry"/>.</returns>
|
||||
public static RawTagEntry Entry(AbLegacyTagDefinition def)
|
||||
=> new(def.Name, AbLegacyTagDefinitionFactory.ToTagConfig(def), def.WriteIdempotent, DeviceName: def.DeviceHostAddress);
|
||||
|
||||
/// <summary>Serialises typed definitions into <see cref="RawTagEntry"/> records.</summary>
|
||||
/// <param name="defs">The typed definitions to convert (array, params, or a collection expression).</param>
|
||||
/// <returns>The equivalent raw-tag entries.</returns>
|
||||
public static IReadOnlyList<RawTagEntry> Entries(params AbLegacyTagDefinition[] defs)
|
||||
=> [.. defs.Select(Entry)];
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public sealed class AbLegacyReadWriteTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = tags,
|
||||
RawTags = AbLegacyRawTags.Entries(tags),
|
||||
}, "drv-1", factory);
|
||||
return (drv, factory);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ public sealed class AbLegacyReadWriteTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("Bit3", "ab://10.0.0.5/1,0", "N7:0/3", AbLegacyDataType.Bit)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("Bit3", "ab://10.0.0.5/1,0", "N7:0/3", AbLegacyDataType.Bit)]),
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
@@ -206,7 +206,7 @@ public sealed class AbLegacyReadWriteTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("Flag", "ab://10.0.0.5/1,0", "B3:0", AbLegacyDataType.Bit)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("Flag", "ab://10.0.0.5/1,0", "B3:0", AbLegacyDataType.Bit)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -245,11 +245,11 @@ public sealed class AbLegacyReadWriteTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags =
|
||||
RawTags = AbLegacyRawTags.Entries(
|
||||
[
|
||||
new AbLegacyTagDefinition("A", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int),
|
||||
new AbLegacyTagDefinition("B", "ab://10.0.0.5/1,0", "N7:1", AbLegacyDataType.Int, Writable: false),
|
||||
],
|
||||
]),
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// CONV-4 — <see cref="AbLegacyDriver.ResolveHost"/> must resolve an equipment-tag reference
|
||||
/// (raw TagConfig JSON) to its OWN device host so per-host breaker keys are correct for
|
||||
/// equipment tags, not the first-device fallback.
|
||||
/// CONV-4 — <see cref="AbLegacyDriver.ResolveHost"/> must resolve a RawPath reference to its OWN
|
||||
/// device host so per-host breaker keys are correct for multi-device tags, not the first-device
|
||||
/// fallback. v3: the tag's device travels on the <see cref="RawTagEntry.DeviceName"/> the deploy
|
||||
/// artifact delivers; the driver resolves it to that device's host at table-build time.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class AbLegacyResolveHostTests
|
||||
@@ -15,21 +17,25 @@ public sealed class AbLegacyResolveHostTests
|
||||
private const string DeviceA = "ab://10.0.0.5/1,0";
|
||||
private const string DeviceB = "ab://10.0.0.6/1,0";
|
||||
|
||||
private static AbLegacyDriver NewDriver() => new(
|
||||
private static AbLegacyDriver NewDriver(params RawTagEntry[] rawTags) => new(
|
||||
new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions(DeviceA), new AbLegacyDeviceOptions(DeviceB)],
|
||||
RawTags = rawTags,
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
},
|
||||
"ablegacy-1", new FakeAbLegacyTagFactory());
|
||||
|
||||
/// <summary>An equipment-tag ref naming device B resolves to device B's host, not the first device.</summary>
|
||||
/// <summary>A raw tag owned by device B resolves to device B's host, not the first device.</summary>
|
||||
[Fact]
|
||||
public void ResolveHost_EquipmentTagRef_ReturnsItsOwnDeviceHost()
|
||||
public async Task ResolveHost_RawTagRef_ReturnsItsOwnDeviceHost()
|
||||
{
|
||||
var drv = NewDriver();
|
||||
var json = $$"""{"deviceHostAddress":"{{DeviceB}}","address":"N7:0","dataType":"Int"}""";
|
||||
drv.ResolveHost(json).ShouldBe(DeviceB);
|
||||
const string rawPath = "cell/ablegacy/devB/T1";
|
||||
var drv = NewDriver(new RawTagEntry(
|
||||
rawPath, """{"address":"N7:0","dataType":"Int"}""", WriteIdempotent: false, DeviceName: DeviceB));
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
drv.ResolveHost(rawPath).ShouldBe(DeviceB);
|
||||
}
|
||||
|
||||
/// <summary>An unresolvable ref keeps the current first-device fallback.</summary>
|
||||
|
||||
+2
-2
@@ -84,7 +84,7 @@ public sealed class AbLegacyRuntimeConcurrencyTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
@@ -117,7 +117,7 @@ public sealed class AbLegacyRuntimeConcurrencyTests
|
||||
var drv = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
{
|
||||
Devices = [new AbLegacyDeviceOptions("ab://10.0.0.5/1,0")],
|
||||
Tags = [new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)],
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("X", "ab://10.0.0.5/1,0", "N7:0", AbLegacyDataType.Int)]),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-1", factory);
|
||||
await drv.InitializeAsync("{}", CancellationToken.None);
|
||||
|
||||
Reference in New Issue
Block a user