feat(communication): map enriched alarm fields across gRPC (server + client)

This commit is contained in:
Joseph Doherty
2026-05-31 02:16:43 -04:00
parent 50176765fe
commit 0c6f9a9cff
5 changed files with 132 additions and 10 deletions
@@ -67,7 +67,24 @@ public class StreamRelayActor : ReceiveActor
Priority = msg.Priority,
Timestamp = Timestamp.FromDateTimeOffset(msg.Timestamp),
Level = MapAlarmLevel(msg.Level),
Message = msg.Message ?? string.Empty
Message = msg.Message ?? string.Empty,
// Native alarm enrichment (additive — computed alarms map their default condition).
Kind = msg.Kind.ToString(),
Active = msg.Condition.Active,
Acknowledged = msg.Condition.Acknowledged,
Confirmed = msg.Condition.Confirmed ?? false,
ShelveState = AlarmShelveStateCodec.ToWire(msg.Condition.Shelve),
Suppressed = msg.Condition.Suppressed,
SourceReference = msg.SourceReference ?? string.Empty,
AlarmTypeName = msg.AlarmTypeName ?? string.Empty,
Category = msg.Category ?? string.Empty,
OperatorUser = msg.OperatorUser ?? string.Empty,
OperatorComment = msg.OperatorComment ?? string.Empty,
OriginalRaiseTime = msg.OriginalRaiseTime.HasValue
? Timestamp.FromDateTimeOffset(msg.OriginalRaiseTime.Value)
: null,
CurrentValue = msg.CurrentValue ?? string.Empty,
LimitValue = msg.LimitValue ?? string.Empty
}
};
@@ -0,0 +1,21 @@
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
namespace ZB.MOM.WW.ScadaBridge.Communication.Grpc;
/// <summary>
/// Maps <see cref="AlarmShelveState"/> to/from the wire string carried in the
/// <c>AlarmStateUpdate.shelve_state</c> proto field. The wire form is the enum
/// member name; an empty or unrecognized string parses back to
/// <see cref="AlarmShelveState.Unshelved"/> (the safe default).
/// </summary>
public static class AlarmShelveStateCodec
{
/// <summary>Returns the wire string for a shelve state (the enum member name).</summary>
public static string ToWire(AlarmShelveState state) => state.ToString();
/// <summary>Parses a wire string back to a shelve state; defaults to <see cref="AlarmShelveState.Unshelved"/>.</summary>
public static AlarmShelveState Parse(string? wire) =>
Enum.TryParse<AlarmShelveState>(wire, ignoreCase: true, out var state)
? state
: AlarmShelveState.Unshelved;
}
@@ -3,6 +3,7 @@ using Grpc.Core;
using Grpc.Net.Client;
using Microsoft.Extensions.Logging;
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Streaming;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Alarms;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
using Google.Protobuf.WellKnownTypes;
@@ -233,11 +234,32 @@ public class SiteStreamGrpcClient : IAsyncDisposable, IDisposable
evt.AlarmChanged.Timestamp.ToDateTimeOffset())
{
Level = MapAlarmLevel(evt.AlarmChanged.Level),
Message = evt.AlarmChanged.Message ?? string.Empty
Message = evt.AlarmChanged.Message ?? string.Empty,
// Native alarm enrichment (additive — computed alarms carry their default condition).
Kind = ParseAlarmKind(evt.AlarmChanged.Kind),
Condition = new AlarmConditionState(
Active: evt.AlarmChanged.Active,
Acknowledged: evt.AlarmChanged.Acknowledged,
Confirmed: evt.AlarmChanged.Confirmed,
Shelve: AlarmShelveStateCodec.Parse(evt.AlarmChanged.ShelveState),
Suppressed: evt.AlarmChanged.Suppressed,
Severity: evt.AlarmChanged.Priority),
SourceReference = evt.AlarmChanged.SourceReference ?? string.Empty,
AlarmTypeName = evt.AlarmChanged.AlarmTypeName ?? string.Empty,
Category = evt.AlarmChanged.Category ?? string.Empty,
OperatorUser = evt.AlarmChanged.OperatorUser ?? string.Empty,
OperatorComment = evt.AlarmChanged.OperatorComment ?? string.Empty,
OriginalRaiseTime = evt.AlarmChanged.OriginalRaiseTime?.ToDateTimeOffset(),
CurrentValue = evt.AlarmChanged.CurrentValue ?? string.Empty,
LimitValue = evt.AlarmChanged.LimitValue ?? string.Empty
},
_ => null
};
/// <summary>Parses the wire "kind" string back to <see cref="AlarmKind"/>; defaults to Computed.</summary>
internal static AlarmKind ParseAlarmKind(string? kind) =>
System.Enum.TryParse<AlarmKind>(kind, ignoreCase: true, out var k) ? k : AlarmKind.Computed;
/// <summary>
/// Maps proto Quality enum to domain string. Internal for testability.
/// </summary>