feat(grpc-data): A1 — AbCip signals per node at the end of each ALMD/ALMA poll tick

This commit is contained in:
Joseph Doherty
2026-11-24 10:18:29 -05:00
parent dbbc35e83d
commit 8f1be25673
3 changed files with 176 additions and 1 deletions
@@ -196,12 +196,16 @@ internal sealed class AbCipAlarmProjection : IAsyncDisposable
{
// results index layout: per sourceNode, ALMD = [InAlarm, Severity]; ALMA = the plan's member list.
var cursor = 0;
// grpc-data A1 (§5.1 AbCip row, G1): the nodes whose state this tick established — ALMD: InAlarm read Good;
// ALMA: every plan ref read Good. Signalled per node at the end of the tick, after every transition (F2).
var established = new List<string>(sub.SourceNodeIds.Count);
for (var i = 0; i < sub.SourceNodeIds.Count; i++)
{
var nodeId = sub.SourceNodeIds[i];
var plan = sub.Plans[i];
if (plan.Alma is not null)
{
if (AllGood(results, cursor, plan.Alma.RefCount)) established.Add(nodeId);
TickAlma(sub, nodeId, plan.Alma, results, cursor);
cursor += plan.Alma.RefCount;
continue;
@@ -210,6 +214,7 @@ internal sealed class AbCipAlarmProjection : IAsyncDisposable
var severityDv = results[cursor + 1];
cursor += 2;
if (inAlarmDv.StatusCode != AbCipStatusMapper.Good) continue;
established.Add(nodeId);
var nowFaulted = ToBool(inAlarmDv.Value);
// severityDv.StatusCode is not checked here. When the Severity read is Bad (value null),
@@ -246,6 +251,18 @@ internal sealed class AbCipAlarmProjection : IAsyncDisposable
Kind: AlarmTransitionKind.Clear));
}
}
// G5: only a subscription that is still live signals (an unsubscribe / supersede raises nothing).
bool live;
lock (_subsLock) live = _subs.TryGetValue(sub.Handle.Id, out var current) && ReferenceEquals(current, sub);
if (live && established.Count > 0) _driver.InvokeInitialAlarmState(new AlarmInitialStateEventArgs(established));
}
private static bool AllGood(IReadOnlyList<DataValueSnapshot> results, int at, int count)
{
for (var k = 0; k < count; k++)
if (results[at + k].StatusCode != AbCipStatusMapper.Good) return false;
return true;
}
private async Task RunPollLoopAsync(Subscription sub, CancellationToken ct)
@@ -27,7 +27,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip;
/// handles GC-collected tags.</para>
/// </remarks>
public sealed class AbCipDriver : IDriver, IReadable, IWritable, ITagDiscovery, IBatchSubscribable,
IHostConnectivityProbe, IPerCallHostResolver, IAlarmSource, ISkippedTagReporter, IAsyncDisposable, IDisposable
IHostConnectivityProbe, IPerCallHostResolver, IAlarmSource, IAlarmInitialStateSignal, ISkippedTagReporter, IAsyncDisposable, IDisposable
{
/// <summary>Authored tags this driver could not build into its poll table.</summary>
private readonly SkippedTagLedger _skippedTags = new();
@@ -183,6 +183,13 @@ public sealed class AbCipDriver : IDriver, IReadable, IWritable, ITagDiscovery,
/// <param name="args">The alarm event arguments.</param>
internal void InvokeAlarmEvent(AlarmEventArgs args) => OnAlarmEvent?.Invoke(this, args);
/// <inheritdoc />
/// <remarks>grpc-data A1 (§5.1 AbCip row): raised at the end of each alarm poll tick for the nodes whose
/// <c>InAlarm</c> (ALMA: every plan ref) read Good, after that tick's transitions.</remarks>
public event EventHandler<AlarmInitialStateEventArgs>? InitialAlarmStateDelivered;
internal void InvokeInitialAlarmState(AlarmInitialStateEventArgs args) => InitialAlarmStateDelivered?.Invoke(this, args);
/// <summary>Initializes a new instance of the <see cref="AbCipDriver"/> class.</summary>
/// <param name="options">The driver configuration options.</param>
/// <param name="driverInstanceId">A unique identifier for this driver instance.</param>