|
|
|
@@ -0,0 +1,105 @@
|
|
|
|
|
using ZB.MOM.WW.OtOpcUa.Commons.Types;
|
|
|
|
|
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
|
|
|
|
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
|
|
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
|
|
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Heidenhain;
|
|
|
|
|
|
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Configuration.Validation;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Heidenhain LSV2 deploy gates (lmxopcua#803). All reuse the driver's own Contracts parser, so the gate and
|
|
|
|
|
/// the runtime cannot disagree.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// <list type="bullet">
|
|
|
|
|
/// <item><b><see cref="WritableCode"/></b> — the driver is read-only (no <c>IWritable</c>), so a ReadWrite
|
|
|
|
|
/// access level would advertise a writable OPC node that can never be written. Refused, so no Heidenhain
|
|
|
|
|
/// node is ever writable.</item>
|
|
|
|
|
/// <item><b><see cref="CredentialCode"/></b> — a password field that is not blank / <c>secret:</c> /
|
|
|
|
|
/// <c>env:</c> would store a controller password in the config database (replicated to every node). The
|
|
|
|
|
/// message never echoes the value.</item>
|
|
|
|
|
/// <item><b><see cref="ConfigCode"/></b> — out-of-range driver settings, or an invalid endpoint on a device
|
|
|
|
|
/// that carries tags (the driver would fail to start).</item>
|
|
|
|
|
/// </list>
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public static class HeidenhainDeployChecks
|
|
|
|
|
{
|
|
|
|
|
/// <summary>A Heidenhain tag authored ReadWrite.</summary>
|
|
|
|
|
public const string WritableCode = "HeidenhainTagWritable";
|
|
|
|
|
|
|
|
|
|
/// <summary>A literal password in a Heidenhain DriverConfig/DeviceConfig.</summary>
|
|
|
|
|
public const string CredentialCode = "HeidenhainCredentialPersisted";
|
|
|
|
|
|
|
|
|
|
/// <summary>A Heidenhain tag whose <c>Tag.DataType</c> disagrees with the type the driver publishes.</summary>
|
|
|
|
|
public const string DataTypeCode = "HeidenhainTagDataTypeMismatch";
|
|
|
|
|
|
|
|
|
|
/// <summary>Invalid Heidenhain settings or endpoint.</summary>
|
|
|
|
|
public const string ConfigCode = "HeidenhainConfigInvalid";
|
|
|
|
|
|
|
|
|
|
/// <summary>Runs every Heidenhain gate.</summary>
|
|
|
|
|
/// <param name="draft">The draft.</param>
|
|
|
|
|
/// <returns>The errors.</returns>
|
|
|
|
|
public static IReadOnlyList<ValidationError> Errors(DraftSnapshot draft)
|
|
|
|
|
{
|
|
|
|
|
var errors = new List<ValidationError>();
|
|
|
|
|
foreach (var driver in draft.DriverInstances)
|
|
|
|
|
{
|
|
|
|
|
if (!string.Equals(driver.DriverType, DriverTypeNames.Heidenhain, StringComparison.Ordinal)) continue;
|
|
|
|
|
var devices = draft.Devices
|
|
|
|
|
.Where(d => string.Equals(d.DriverInstanceId, driver.DriverInstanceId, StringComparison.Ordinal))
|
|
|
|
|
.ToList();
|
|
|
|
|
var deviceIds = devices.Select(d => d.DeviceId).ToHashSet(StringComparer.Ordinal);
|
|
|
|
|
var tags = draft.Tags.Where(t => t.DeviceId is not null && deviceIds.Contains(t.DeviceId)).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var tag in tags.Where(t => t.AccessLevel == TagAccessLevel.ReadWrite))
|
|
|
|
|
{
|
|
|
|
|
errors.Add(new(WritableCode,
|
|
|
|
|
$"Tag '{tag.Name}' on Heidenhain driver '{driver.Name}' is ReadWrite. The Heidenhain LSV2 driver is " +
|
|
|
|
|
"read-only (only logins and read requests are ever sent); set the tag's access level to Read.",
|
|
|
|
|
tag.TagId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var tag in tags)
|
|
|
|
|
{
|
|
|
|
|
var expected = HeidenhainTagRules.ExpectedTagDataType(tag.TagConfig);
|
|
|
|
|
if (expected is null || string.Equals(expected, tag.DataType, StringComparison.OrdinalIgnoreCase)) continue;
|
|
|
|
|
errors.Add(new(DataTypeCode,
|
|
|
|
|
$"Tag '{tag.Name}' on Heidenhain driver '{driver.Name}' has data type {tag.DataType}, but the driver " +
|
|
|
|
|
$"publishes {expected} for its address — the node would advertise a type its values never carry.",
|
|
|
|
|
tag.TagId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HeidenhainDriverOptions options;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var merged = DriverDeviceConfigMerger.Merge(
|
|
|
|
|
driver.DriverConfig,
|
|
|
|
|
devices.Select(d => new DriverDeviceConfigMerger.DeviceRow(d.Name, d.DeviceConfig)).ToList(),
|
|
|
|
|
[]);
|
|
|
|
|
options = HeidenhainOptionsParser.Parse(merged);
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidOperationException ex)
|
|
|
|
|
{
|
|
|
|
|
errors.Add(new(ConfigCode, $"Heidenhain driver '{driver.Name}': {ex.Message}", driver.DriverInstanceId));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var problem in HeidenhainOptionsParser.Validate(options))
|
|
|
|
|
{
|
|
|
|
|
var code = problem.Contains("password", StringComparison.OrdinalIgnoreCase) ? CredentialCode : ConfigCode;
|
|
|
|
|
errors.Add(new(code, $"Heidenhain driver '{driver.Name}': {problem}", driver.DriverInstanceId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var device in devices)
|
|
|
|
|
{
|
|
|
|
|
if (!tags.Any(t => string.Equals(t.DeviceId, device.DeviceId, StringComparison.Ordinal))) continue;
|
|
|
|
|
var opts = options.Devices.FirstOrDefault(o => string.Equals(o.DeviceName, device.Name, StringComparison.Ordinal));
|
|
|
|
|
var problems = opts is null ? ["Device has no endpoint."] : HeidenhainOptionsParser.ValidateDevice(opts);
|
|
|
|
|
foreach (var p in problems)
|
|
|
|
|
errors.Add(new(ConfigCode, $"Heidenhain device '{device.Name}': {p}", device.DeviceId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
|
}
|
|
|
|
|
}
|