feat(mqtt): read Sparkplug B array metrics as 1-D OPC UA arrays (lmxopcua#754)
v2-ci / unit-tests (push) Has been cancelled
v2-ci / unit-tests (push) Has been cancelled
R06:M-5 made Sparkplug *Array leaves unbindable because the ingestor refused them. The ingestor now decodes the packed bytes_value of all 13 array types (new SparkplugArrayCodec: LE fixed widths, int64-ms DateTime, uint32-count + MSB-first BooleanArray, NUL-terminated UTF-8 StringArray; golden vectors are the spec's examples, reproduced byte-for-byte by SparkplugNet 1.3.10) and publishes a typed 1-D array through the scalar coercion, all-or-nothing. Shape uses the fleet's one array model: the tag's platform isArray/arrayLength keys (ValueRank=1, ArrayDimensions=[arrayLength] or [0] = variable length). The driver reads them with TagConfigIntent's exact semantics and never rejects on them, so composer, driver, authoring model and deploy inspector agree (MqttArrayShapeParityTests). Shape mismatch (array metric on a scalar tag, or the reverse) is BadTypeMismatch - a String tag no longer gets the packed buffer as base64; a malformed body or a length differing from a declared arrayLength is BadDecodingError (MTConnect #627 verdict). Template/DataSet members of an array type take the same path. Arrays stay read-only (encoder refuses them; MQTT is not in DriverArrayWriteSupport). Browser: array leaves are bindable again and state isArray in AddressFields; the commit mapper writes "isArray": true (no arrayLength). Discovery reports IsArray/ArrayDim. Docs: Mqtt.md "Array metrics", design table, drivers rule. Tests: codec (golden + malformed), ingest through the real codec + Dispatch (the project's MiniBroker never forwards a PUBLISH, so there is no in-process broker harness), browse, discovery, commit mapper, parity corpus. Mutating the fix back out fails 18 MQTT + 9 AdminUI tests. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -456,20 +456,22 @@ internal sealed class MqttBrowseSession : IRebirthCapableBrowseSession
|
||||
var descriptor = new StringBuilder(metric.BirthType.ToString()).Append(" · ").Append(sparkplugName);
|
||||
if (metric.Alias is { } alias) descriptor.Append(" · alias ").Append(alias);
|
||||
if (mapped is null) descriptor.Append(" · unsupported in v1 — not bindable");
|
||||
else if (isArray) descriptor.Append(" · array metrics are not read in v1 — not bindable");
|
||||
else if (isArray) descriptor.Append(" · 1-D array");
|
||||
|
||||
// Unbindable = the ingestor refuses it: an unmapped type, or ANY array variant (SparkplugIngestor
|
||||
// gates on the array bit and never feeds the tag). Such a leaf states NO address, so the
|
||||
// Unbindable = the ingestor refuses it: an unmapped type. Such a leaf states NO address, so the
|
||||
// browse-commit refuses it at commit instead of writing a tag that sits at
|
||||
// BadWaitingForInitialData forever (R06:M-5). Labelling it alone was not enough — it still bound.
|
||||
var bindable = mapped is not null && !isArray;
|
||||
// An *Array variant IS bindable since #754 (the ingestor decodes it into a 1-D array) — but only to
|
||||
// an ARRAY tag, so its address states the array bit too and the commit writes "isArray": true.
|
||||
// Without it the committed tag would be scalar and read BadTypeMismatch forever: R06:M-5 again.
|
||||
var bindable = mapped is not null;
|
||||
|
||||
return new AttributeInfo(
|
||||
metric.Name,
|
||||
mapped?.ToString() ?? sparkplugName,
|
||||
isArray,
|
||||
descriptor.ToString(),
|
||||
AddressFields: bindable ? BuildMetricAddressFields(metric.Name, scope) : null);
|
||||
AddressFields: bindable ? BuildMetricAddressFields(metric.Name, scope, isArray) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -477,13 +479,15 @@ internal sealed class MqttBrowseSession : IRebirthCapableBrowseSession
|
||||
/// </summary>
|
||||
/// <param name="metricName">The metric's birth-declared name.</param>
|
||||
/// <param name="scope">The metric node's stamped identity, or <see langword="null"/>.</param>
|
||||
/// <param name="isArray">Whether the metric is an <c>*Array</c> variant; stated as
|
||||
/// <see cref="MqttTagConfigKeys.IsArray"/> = <c>"true"</c> so the commit writes an array tag (#754).</param>
|
||||
/// <returns>
|
||||
/// The address fields, or <see langword="null"/> when the node carries no scope (which a
|
||||
/// Sparkplug metric node never does — every one is created with the scope its birth parsed —
|
||||
/// so a null here is "the producer cannot state the address", never "the address is empty").
|
||||
/// </returns>
|
||||
private static IReadOnlyDictionary<string, string>? BuildMetricAddressFields(
|
||||
string metricName, SparkplugScope? scope)
|
||||
string metricName, SparkplugScope? scope, bool isArray)
|
||||
{
|
||||
if (scope?.EdgeNodeId is not { } edgeNodeId) return null;
|
||||
|
||||
@@ -497,6 +501,9 @@ internal sealed class MqttBrowseSession : IRebirthCapableBrowseSession
|
||||
// Omitted, not blank, for a node-level metric: the factory normalises "" to absent anyway, but
|
||||
// an emitted empty device id would read as "a device whose id is empty" to anything else looking.
|
||||
if (scope.DeviceId is { } deviceId) fields[MqttTagConfigKeys.DeviceId] = deviceId;
|
||||
|
||||
// Omitted for a scalar metric, for the same reason: absence is the factory's scalar default.
|
||||
if (isArray) fields[MqttTagConfigKeys.IsArray] = "true";
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user