v3(focas): adopt Modbus RawTagEntry exemplar (multi-device)
- Rename FocasEquipmentTagParser -> FocasTagDefinitionFactory; TryParse ->
FromTagConfig(tagConfig, rawPath, out def). Drop leading-{ heuristic + the
deviceHostAddress blob key; def.Name = rawPath. Add inverse ToTagConfig.
writable: absent -> read-only, explicit true honoured (note preserved).
- FocasDriverOptions.Tags -> RawTags (IReadOnlyList<RawTagEntry>).
- FocasDriver: _tagsByRawPath (Ordinal); byName-only resolver; build table from
RawTags via FromTagConfig; multi-device routing threads RawTagEntry.DeviceName
-> ResolveDeviceHost match against options.Devices -> def.DeviceHostAddress
(TODO v3 WaveC: live host from Device row DeviceConfig). Tolerant per-tag
skip+log (mapper/address/matrix miss -> BadNodeIdUnknown); unknown device
fails init fast.
- Factory: bind List<RawTagEntry> RawTags; retire FocasTagDto/ParseDataType.
- CLI FocasCommandBase.BuildOptions -> RawTags via ToTagConfig + DeviceName.
- Tests: FocasRawTags helper; migrate Tags= -> RawTags=; rename parser tests to
FromTagConfig; rewrite retired blob-ref tests (equipment-tag/capability-gate/
resolve-host) onto authored RawPath. 272 driver + 52 CLI green.
This commit is contained in:
@@ -5,10 +5,9 @@ using ZB.MOM.WW.OtOpcUa.Driver.FOCAS;
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// CONV-4 — <see cref="FocasDriver.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. An address-less equipment ref (FOCAS coalesces a missing <c>deviceHostAddress</c> to
|
||||
/// <c>""</c>) must fall back rather than key an empty host.
|
||||
/// CONV-4 — <see cref="FocasDriver.ResolveHost"/> must resolve an authored raw tag (by its RawPath)
|
||||
/// to its OWN device host so per-host breaker keys are correct for multi-device drivers. A reference
|
||||
/// that resolves to no authored tag falls back to the first device rather than keying an empty host.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class FocasResolveHostTests
|
||||
@@ -16,15 +15,16 @@ public sealed class FocasResolveHostTests
|
||||
private const string DeviceA = "focas://10.0.0.5:8193";
|
||||
private const string DeviceB = "focas://10.0.0.6:8193";
|
||||
|
||||
// FOCAS's equipment-ref resolver validates against the initialized Devices map, so — unlike
|
||||
// the other drivers — the driver must be initialized (as it always is when ResolveHost runs at
|
||||
// runtime) before an equipment ref resolves. Probe off / no connect: init just parses devices.
|
||||
private static async Task<FocasDriver> NewDriverAsync()
|
||||
// The driver builds its RawPath → definition table (with each tag's resolved device host) at
|
||||
// InitializeAsync, so the driver must be initialized before ResolveHost can resolve a tag — as it
|
||||
// always is when ResolveHost runs at runtime. Probe off / no connect: init just parses devices + tags.
|
||||
private static async Task<FocasDriver> NewDriverAsync(params FocasTagDefinition[] tags)
|
||||
{
|
||||
var drv = new FocasDriver(
|
||||
new FocasDriverOptions
|
||||
{
|
||||
Devices = [new FocasDeviceOptions(DeviceA), new FocasDeviceOptions(DeviceB)],
|
||||
RawTags = FocasRawTags.Entries(tags),
|
||||
Probe = new FocasProbeOptions { Enabled = false },
|
||||
},
|
||||
"focas-1", new FakeFocasClientFactory());
|
||||
@@ -32,18 +32,17 @@ public sealed class FocasResolveHostTests
|
||||
return drv;
|
||||
}
|
||||
|
||||
/// <summary>An equipment-tag ref naming device B resolves to device B's host, not the first device.</summary>
|
||||
/// <summary>An authored tag routed to device B resolves to device B's host, not the first device.</summary>
|
||||
[Fact]
|
||||
public async Task ResolveHost_EquipmentTagRef_ReturnsItsOwnDeviceHost()
|
||||
public async Task ResolveHost_AuthoredTag_ReturnsItsOwnDeviceHost()
|
||||
{
|
||||
var drv = await NewDriverAsync();
|
||||
var json = $$"""{"deviceHostAddress":"{{DeviceB}}","address":"R100","dataType":"Byte"}""";
|
||||
drv.ResolveHost(json).ShouldBe(DeviceB);
|
||||
var drv = await NewDriverAsync(new FocasTagDefinition("eq/onB", DeviceB, "R100", FocasDataType.Byte));
|
||||
drv.ResolveHost("eq/onB").ShouldBe(DeviceB);
|
||||
}
|
||||
|
||||
/// <summary>An equipment ref with no deviceHostAddress falls back to the first device, not an empty host.</summary>
|
||||
/// <summary>A reference that resolves to no authored tag falls back to the first device, not an empty host.</summary>
|
||||
[Fact]
|
||||
public async Task ResolveHost_EquipmentTagRef_WithoutDeviceHost_FallsBack()
|
||||
public async Task ResolveHost_UnresolvedRef_FallsBack()
|
||||
{
|
||||
var drv = await NewDriverAsync();
|
||||
var json = """{"address":"R100","dataType":"Byte"}""";
|
||||
|
||||
Reference in New Issue
Block a user