fix(dcl): separator-aware alarm routing, typed reply for browse/search while disconnected, server-timestamp fallback (DCL-5, DCL-6, DCL-7, WP3 task 3.4)
This commit is contained in:
@@ -448,23 +448,33 @@ public class OpcUaDataConnection
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<BrowseChildrenResult> BrowseChildrenAsync(
|
||||
public async Task<BrowseChildrenResult> BrowseChildrenAsync(
|
||||
string? parentNodeId,
|
||||
string? continuationToken = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
=> _client!.BrowseChildrenAsync(parentNodeId, continuationToken, cancellationToken);
|
||||
{
|
||||
// async so a not-connected adapter FAULTS the task instead of throwing synchronously
|
||||
// (DCL-6): a freshly swapped failover adapter has no client until the reconnect timer
|
||||
// fires, and the old `_client!` dereference threw a NullReferenceException on the actor
|
||||
// thread, so the caller got no reply at all.
|
||||
var client = _client
|
||||
?? throw new ConnectionNotConnectedException("OPC UA client is not connected.");
|
||||
return await client.BrowseChildrenAsync(parentNodeId, continuationToken, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<AddressSpaceSearchResult> SearchAddressSpaceAsync(
|
||||
public async Task<AddressSpaceSearchResult> SearchAddressSpaceAsync(
|
||||
string query, int maxDepth, int maxResults, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// Guard connection state with the typed ConnectionNotConnectedException so
|
||||
// the site-side handler can map it uniformly (mirrors BrowseChildrenAsync,
|
||||
// whose underlying client throws the same type when the session is down).
|
||||
if (_client == null || !_client.IsConnected)
|
||||
// async so the guard faults the task rather than throwing synchronously (DCL-6).
|
||||
var client = _client;
|
||||
if (client == null || !client.IsConnected)
|
||||
throw new ConnectionNotConnectedException("OPC UA client is not connected.");
|
||||
|
||||
return _client.SearchAddressSpaceAsync(query, maxDepth, maxResults, cancellationToken);
|
||||
return await client.SearchAddressSpaceAsync(query, maxDepth, maxResults, cancellationToken);
|
||||
}
|
||||
|
||||
private void StopHeartbeatMonitor()
|
||||
|
||||
@@ -56,6 +56,26 @@ internal static class OpcUaValueBoundary
|
||||
internal static DateTime ToClrTimestamp(DateTimeUtc value) =>
|
||||
value == DateTimeUtc.MinValue ? DateTime.MinValue : value.ToDateTime();
|
||||
|
||||
/// <summary>
|
||||
/// The timestamp to stamp on a value read or notified from the server: the SOURCE timestamp
|
||||
/// when present, else the SERVER timestamp, else now (DCL-7). A connection configured for
|
||||
/// <c>TimestampsToReturn = Server</c> gets no source timestamp at all, and a server may omit it
|
||||
/// on notifications; taking <c>SourceTimestamp</c> unconditionally stamped such values
|
||||
/// <c>0001-01-01T00:00:00Z</c>, which was stored, streamed and shown until the tag next changed.
|
||||
/// One helper for both the read and the notification path.
|
||||
/// </summary>
|
||||
/// <param name="source">The DataValue's source timestamp.</param>
|
||||
/// <param name="server">The DataValue's server timestamp.</param>
|
||||
/// <returns>The effective UTC timestamp, never <see cref="DateTime.MinValue"/>.</returns>
|
||||
internal static DateTime EffectiveTimestamp(DateTimeUtc source, DateTimeUtc server)
|
||||
{
|
||||
var fromSource = ToClrTimestamp(source);
|
||||
if (fromSource != DateTime.MinValue)
|
||||
return fromSource;
|
||||
var fromServer = ToClrTimestamp(server);
|
||||
return fromServer != DateTime.MinValue ? fromServer : DateTime.UtcNow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The SDK value to write for a CLR payload, with SDK 1.5's <c>new Variant(object)</c>
|
||||
/// semantics: a <c>byte[]</c> is a ByteString scalar, other supported scalars and
|
||||
|
||||
@@ -772,7 +772,7 @@ public class RealOpcUaClient : IOpcUaClient
|
||||
// SDK 2: DataValue is a struct; restore the SDK 1.5 CLR payload shapes.
|
||||
var dataValue = notification.Value;
|
||||
var value = OpcUaValueBoundary.ToClr(dataValue.WrappedValue);
|
||||
var timestamp = OpcUaValueBoundary.ToClrTimestamp(dataValue.SourceTimestamp);
|
||||
var timestamp = OpcUaValueBoundary.EffectiveTimestamp(dataValue.SourceTimestamp, dataValue.ServerTimestamp);
|
||||
var statusCode = dataValue.StatusCode.Code;
|
||||
|
||||
if (_callbacks.TryGetValue(handle, out var cb))
|
||||
@@ -1609,7 +1609,8 @@ public class RealOpcUaClient : IOpcUaClient
|
||||
var result = results[i];
|
||||
outcomes[index] = new OpcUaReadOutcome(
|
||||
nodeId, OpcUaValueBoundary.ToClr(result.WrappedValue),
|
||||
OpcUaValueBoundary.ToClrTimestamp(result.SourceTimestamp), result.StatusCode.Code, null);
|
||||
OpcUaValueBoundary.EffectiveTimestamp(result.SourceTimestamp, result.ServerTimestamp),
|
||||
result.StatusCode.Code, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user