feat(grpc-data): A1 — FOCAS signals per device after each successful alarm read

This commit is contained in:
Joseph Doherty
2026-11-24 10:16:39 -05:00
parent 4e984b160e
commit dbbc35e83d
3 changed files with 183 additions and 1 deletions
@@ -311,8 +311,10 @@ internal sealed class FocasAlarmProjection : IAsyncDisposable
if (_failingDevices.Remove(deviceHostAddress, out _))
_logger.LogInformation("FOCAS alarm read for {Host} recovered", deviceHostAddress);
List<string>? established = null;
foreach (var tag in deviceTags.Where(t => sub.References.Contains(t.RawPath)))
{
(established ??= new List<string>()).Add(tag.RawPath);
// Lift a Bad this projection put there BEFORE the normal diff, so a recovery that also changed the
// alarm state (cleared during the outage) lands as Good then Clear.
if (_qualityBadTold.Remove(tag.RawPath, out _))
@@ -325,6 +327,26 @@ internal sealed class FocasAlarmProjection : IAsyncDisposable
if (evt is null) continue;
Deliver(handlers, evt, tag.RawPath);
}
// grpc-data A1 (§5.1, G1): this device's read succeeded and its transitions were emitted — its conditions'
// state is established. Per device, under the same lock and gate as the events (G5), after them (F2).
if (established is not null) SignalEstablished(established);
}
}
/// <summary>Raises the driver's <c>InitialAlarmStateDelivered</c> for <paramref name="conditionIds"/>. Caller holds the lock.</summary>
/// <param name="conditionIds">The RawPaths the completed read established.</param>
private void SignalEstablished(IReadOnlyList<string> conditionIds)
{
if (_driver.InitialStateHandlers is not { } signal) return;
var args = new AlarmInitialStateEventArgs(conditionIds);
foreach (var registration in signal.GetInvocationList())
{
try { ((EventHandler<AlarmInitialStateEventArgs>)registration).Invoke(_driver, args); }
catch (Exception ex)
{
_logger.LogWarning(ex, "FOCAS driver caught a fault from an initial-alarm-state subscriber; delivery continues.");
}
}
}
@@ -20,7 +20,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.FOCAS;
/// fail fast.
/// </remarks>
public sealed class FocasDriver : IDriver, IReadable, IWritable, ITagDiscovery, IBatchSubscribable,
IHostConnectivityProbe, IPerCallHostResolver, IAlarmSource, ISkippedTagReporter, IDisposable, IAsyncDisposable
IHostConnectivityProbe, IPerCallHostResolver, IAlarmSource, IAlarmInitialStateSignal, ISkippedTagReporter, IDisposable, IAsyncDisposable
{
/// <summary>Authored tags this driver could not build into its poll table. FOCAS has three
/// skip paths — an unmappable TagConfig, an unparseable address, and a capability-matrix rejection — and the second of them once went unreported while the driver read Healthy.</summary>
@@ -141,6 +141,11 @@ public sealed class FocasDriver : IDriver, IReadable, IWritable, ITagDiscovery,
/// <summary>Occurs when an alarm event is raised.</summary>
public event EventHandler<AlarmEventArgs>? OnAlarmEvent;
/// <inheritdoc />
/// <remarks>grpc-data A1 (§5.1 FOCAS row): raised per device at the end of each SUCCESSFUL alarm read's tick, after
/// that device's transitions, covering its subscribed <c>ALARM:</c> conditions. A failed read raises nothing.</remarks>
public event EventHandler<AlarmInitialStateEventArgs>? InitialAlarmStateDelivered;
/// <summary>Initializes a new instance of the <see cref="FocasDriver"/> class with the provided options and dependencies.</summary>
/// <param name="options">The driver configuration options.</param>
/// <param name="driverInstanceId">The unique identifier for this driver instance.</param>
@@ -1993,6 +1998,9 @@ public sealed class FocasDriver : IDriver, IReadable, IWritable, ITagDiscovery,
/// <summary>Gets the attached alarm handlers, or <see langword="null"/> when nobody is listening.</summary>
internal EventHandler<AlarmEventArgs>? AlarmHandlers => OnAlarmEvent;
/// <summary>Gets the attached initial-state signal handlers (grpc-data A1), or <see langword="null"/>.</summary>
internal EventHandler<AlarmInitialStateEventArgs>? InitialStateHandlers => InitialAlarmStateDelivered;
/// <summary>Gets the authored <c>ALARM:</c> tags (RawPath → tag). Test seam + projection input.</summary>
internal IReadOnlyDictionary<string, FocasAlarmTag> AlarmTags => Volatile.Read(ref _alarmTags);