fix(modbus): equipment tags carry unitId; ResolveHost keys per-unit via the resolver (CONV-4)

This commit is contained in:
Joseph Doherty
2026-07-13 12:29:13 -04:00
parent 9262dd25b7
commit e69d3b3b0f
4 changed files with 84 additions and 4 deletions
@@ -55,10 +55,14 @@ public static class ModbusEquipmentTagParser
// "writable" defaults to true when absent (today's value) — makes read-only equipment tags
// authorable (UNDER-6). Node-level authz remains the effective write gate.
var writable = TagConfigJson.ReadWritable(root);
// CONV-4: optional per-tag unitId (0255). Absent ⇒ null ⇒ the driver-level UnitId via
// ModbusDriver.ResolveUnitId, so multi-unit equipment tags key their own per-host breaker.
// Scope: unitId ONLY — the remaining parser-strictness gaps are R2-11's.
var unitId = ReadOptionalByte(root, "unitId");
def = new ModbusTagDefinition(
Name: reference, Region: region, Address: (ushort)address, DataType: dataType,
Writable: writable, ByteOrder: byteOrder, BitIndex: bitIndex, StringLength: stringLength,
ArrayCount: arrayCount);
ArrayCount: arrayCount, UnitId: unitId);
return true;
}
catch (JsonException) { return false; }
@@ -109,6 +113,10 @@ public static class ModbusEquipmentTagParser
=> o.TryGetProperty(name, out var e) && e.ValueKind == JsonValueKind.Number
&& e.TryGetInt32(out var v) ? v : 0;
private static byte? ReadOptionalByte(JsonElement o, string name)
=> o.TryGetProperty(name, out var e) && e.ValueKind == JsonValueKind.Number
&& e.TryGetInt32(out var v) && v is >= 0 and <= 255 ? (byte)v : null;
private static bool ReadBool(JsonElement o, string name)
=> o.TryGetProperty(name, out var e) && e.ValueKind == JsonValueKind.True;
}