56 lines
3.7 KiB
C#
56 lines
3.7 KiB
C#
using System.Collections.Frozen;
|
|
using Opc.Ua;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer;
|
|
|
|
/// <summary>
|
|
/// The one table between OPC UA Part 13 standard aggregate-function NodeIds (<c>ObjectIds.AggregateFunction_*</c>)
|
|
/// and <see cref="HistoryAggregateType"/>. HistoryRead-Processed maps a request's aggregate through it, and the
|
|
/// advertised <c>AggregateFunctions</c> folders map a backend's served set back through it — one table, so a
|
|
/// NodeId the server can dispatch is exactly a NodeId it can advertise.
|
|
/// </summary>
|
|
internal static class AggregateFunctionMap
|
|
{
|
|
/// <summary>NodeId ⇒ aggregate, for every aggregate the server can name to a backend.</summary>
|
|
public static readonly FrozenDictionary<NodeId, HistoryAggregateType> ByNodeId = new Dictionary<NodeId, HistoryAggregateType>
|
|
{
|
|
[ObjectIds.AggregateFunction_Average] = HistoryAggregateType.Average,
|
|
[ObjectIds.AggregateFunction_Minimum] = HistoryAggregateType.Minimum,
|
|
[ObjectIds.AggregateFunction_Maximum] = HistoryAggregateType.Maximum,
|
|
[ObjectIds.AggregateFunction_Total] = HistoryAggregateType.Total,
|
|
[ObjectIds.AggregateFunction_Count] = HistoryAggregateType.Count,
|
|
[ObjectIds.AggregateFunction_Interpolative] = HistoryAggregateType.Interpolative,
|
|
[ObjectIds.AggregateFunction_TimeAverage] = HistoryAggregateType.TimeAverage,
|
|
[ObjectIds.AggregateFunction_Start] = HistoryAggregateType.Start,
|
|
[ObjectIds.AggregateFunction_End] = HistoryAggregateType.End,
|
|
[ObjectIds.AggregateFunction_Delta] = HistoryAggregateType.Delta,
|
|
[ObjectIds.AggregateFunction_Range] = HistoryAggregateType.Range,
|
|
[ObjectIds.AggregateFunction_MinimumActualTime] = HistoryAggregateType.MinimumActualTime,
|
|
[ObjectIds.AggregateFunction_MaximumActualTime] = HistoryAggregateType.MaximumActualTime,
|
|
[ObjectIds.AggregateFunction_StartBound] = HistoryAggregateType.StartBound,
|
|
[ObjectIds.AggregateFunction_EndBound] = HistoryAggregateType.EndBound,
|
|
[ObjectIds.AggregateFunction_DeltaBounds] = HistoryAggregateType.DeltaBounds,
|
|
[ObjectIds.AggregateFunction_DurationGood] = HistoryAggregateType.DurationGood,
|
|
[ObjectIds.AggregateFunction_DurationBad] = HistoryAggregateType.DurationBad,
|
|
[ObjectIds.AggregateFunction_PercentGood] = HistoryAggregateType.PercentGood,
|
|
[ObjectIds.AggregateFunction_PercentBad] = HistoryAggregateType.PercentBad,
|
|
[ObjectIds.AggregateFunction_WorstQuality] = HistoryAggregateType.WorstQuality,
|
|
[ObjectIds.AggregateFunction_NumberOfTransitions] = HistoryAggregateType.NumberOfTransitions,
|
|
[ObjectIds.AggregateFunction_AnnotationCount] = HistoryAggregateType.AnnotationCount,
|
|
[ObjectIds.AggregateFunction_StandardDeviationPopulation] = HistoryAggregateType.StandardDeviationPopulation,
|
|
[ObjectIds.AggregateFunction_VariancePopulation] = HistoryAggregateType.VariancePopulation,
|
|
[ObjectIds.AggregateFunction_TimeAverage2] = HistoryAggregateType.TimeAverage2,
|
|
[ObjectIds.AggregateFunction_Total2] = HistoryAggregateType.Total2,
|
|
}.ToFrozenDictionary();
|
|
|
|
/// <summary>
|
|
/// Map a request's aggregate-function NodeId to <see cref="HistoryAggregateType"/>; <c>null</c> for one the server
|
|
/// cannot name to any backend (the caller answers <c>BadAggregateNotSupported</c>).
|
|
/// </summary>
|
|
/// <param name="aggregateNodeId">The per-node aggregate-function NodeId from the request.</param>
|
|
/// <returns>The mapped aggregate, or <c>null</c>.</returns>
|
|
public static HistoryAggregateType? Map(NodeId? aggregateNodeId) =>
|
|
aggregateNodeId is { } nodeId && ByNodeId.TryGetValue(nodeId, out var aggregate) ? aggregate : null;
|
|
}
|