v3(ablegacy): apply Modbus exemplar — RawTags delivery + RawPath mapper
- Rename AbLegacyEquipmentTagParser → AbLegacyTagDefinitionFactory; TryParse →
FromTagConfig(tagConfig, rawPath, out def). Drop the leading-{ heuristic and the
deviceHostAddress key; def.Name = rawPath. Add inverse ToTagConfig. Keep strict-enum
guards + Inspect.
- Options: Tags(IReadOnlyList<AbLegacyTagDefinition>) → RawTags(IReadOnlyList<RawTagEntry>).
- Driver: _tagsByRawPath (Ordinal); byName-only resolver; build table from _options.RawTags
via FromTagConfig, threading WriteIdempotent + resolving RawTagEntry.DeviceName to the
owning device host (ResolveDeviceHost; TODO(v3 WaveC) for the live Device-row host).
DiscoverAsync + family-profile validation iterate the built table. Probe picks its address
from RawTags via the mapper.
- Factory: retire the pre-declared tag DTO path; bind List<RawTagEntry>? RawTags; keep Devices.
- Cli BuildOptions: deliver typed defs as RawTagEntry via ToTagConfig.
- Tests: AbLegacyRawTags helper; migrate Tags= → RawTags; parser tests → FromTagConfig;
equipment-ref driver/ResolveHost tests re-authored as RawTagEntry + read by RawPath.
Driver+Contracts+Cli green; 213 driver + 36 Cli tests pass.
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user