@@ -149,15 +149,22 @@ protected override async Task OnMessageReceived(SparkplugMessageTopic topic, byt
149
149
/// <exception cref="Exception">Thrown if the metric is unknown.</exception>
150
150
private async Task HandleMessagesForVersionB ( SparkplugMessageTopic topic , Payload payload )
151
151
{
152
- // Filter out settion number metric.
152
+ // Filter out session number metric.
153
+ var sessionNumberMetric = payload . Metrics . FirstOrDefault ( m => m . Name != Constants . SessionNumberMetricName ) ;
153
154
var metricsWithoutSequenceMetric = payload . Metrics . Where ( m => m . Name != Constants . SessionNumberMetricName ) ;
154
- this . KnownMetricsStorage . FilterMetrics ( metricsWithoutSequenceMetric , topic . MessageType ) ;
155
+ var filteredMetrics = this . KnownMetricsStorage . FilterMetrics ( metricsWithoutSequenceMetric , topic . MessageType ) . ToList ( ) ;
155
156
157
+ if ( sessionNumberMetric is not null )
158
+ {
159
+ filteredMetrics . Add ( sessionNumberMetric ) ;
160
+ }
161
+
162
+ // Handle messages.
156
163
switch ( topic . MessageType )
157
164
{
158
165
case SparkplugMessageType . NodeBirth :
159
166
await this . FireNodeBirthReceived ( topic . GroupIdentifier , topic . EdgeNodeIdentifier ,
160
- this . ProcessPayload ( topic , payload , SparkplugMetricStatus . Online ) ) ;
167
+ this . ProcessPayload ( topic , filteredMetrics , SparkplugMetricStatus . Online ) ) ;
161
168
break ;
162
169
case SparkplugMessageType . DeviceBirth :
163
170
if ( string . IsNullOrWhiteSpace ( topic . DeviceIdentifier ) )
@@ -166,10 +173,10 @@ await this.FireNodeBirthReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifier
166
173
}
167
174
168
175
await this . FireDeviceBirthReceived ( topic . GroupIdentifier , topic . EdgeNodeIdentifier , topic . DeviceIdentifier ,
169
- this . ProcessPayload ( topic , payload , SparkplugMetricStatus . Online ) ) ;
176
+ this . ProcessPayload ( topic , filteredMetrics , SparkplugMetricStatus . Online ) ) ;
170
177
break ;
171
178
case SparkplugMessageType . NodeData :
172
- var nodeDataMetrics = this . ProcessPayload ( topic , payload , SparkplugMetricStatus . Online ) ;
179
+ var nodeDataMetrics = this . ProcessPayload ( topic , filteredMetrics , SparkplugMetricStatus . Online ) ;
173
180
await this . FireNodeDataReceived ( topic . GroupIdentifier , topic . EdgeNodeIdentifier , nodeDataMetrics ) ;
174
181
break ;
175
182
case SparkplugMessageType . DeviceData :
@@ -178,11 +185,11 @@ await this.FireDeviceBirthReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifi
178
185
throw new InvalidOperationException ( $ "Topic { topic } is invalid!") ;
179
186
}
180
187
181
- var deviceDataMetrics = this . ProcessPayload ( topic , payload , SparkplugMetricStatus . Online ) ;
188
+ var deviceDataMetrics = this . ProcessPayload ( topic , filteredMetrics , SparkplugMetricStatus . Online ) ;
182
189
await this . FireDeviceDataReceived ( topic . GroupIdentifier , topic . EdgeNodeIdentifier , topic . DeviceIdentifier , deviceDataMetrics ) ;
183
190
break ;
184
191
case SparkplugMessageType . NodeDeath :
185
- this . ProcessPayload ( topic , payload , SparkplugMetricStatus . Offline ) ;
192
+ this . ProcessPayload ( topic , filteredMetrics , SparkplugMetricStatus . Offline ) ;
186
193
await this . FireNodeDeathReceived ( topic . GroupIdentifier , topic . EdgeNodeIdentifier ) ;
187
194
break ;
188
195
case SparkplugMessageType . DeviceDeath :
@@ -191,7 +198,7 @@ await this.FireDeviceBirthReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifi
191
198
throw new InvalidOperationException ( $ "Topic { topic } is invalid!") ;
192
199
}
193
200
194
- this . ProcessPayload ( topic , payload , SparkplugMetricStatus . Offline ) ;
201
+ this . ProcessPayload ( topic , filteredMetrics , SparkplugMetricStatus . Offline ) ;
195
202
await this . FireDeviceDeathReceived ( topic . GroupIdentifier , topic . EdgeNodeIdentifier , topic . DeviceIdentifier ) ;
196
203
break ;
197
204
}
@@ -201,10 +208,10 @@ await this.FireDeviceBirthReceived(topic.GroupIdentifier, topic.EdgeNodeIdentifi
201
208
/// Handles the device message.
202
209
/// </summary>
203
210
/// <param name="topic">The topic.</param>
204
- /// <param name="payload ">The payload .</param>
211
+ /// <param name="metrics ">The metrics .</param>
205
212
/// <param name="metricStatus">The metric status.</param>
206
213
/// <exception cref="InvalidCastException">Thrown if the metric cast is invalid.</exception>
207
- private IEnumerable < Metric > ProcessPayload ( SparkplugMessageTopic topic , Payload payload , SparkplugMetricStatus metricStatus )
214
+ private IEnumerable < Metric > ProcessPayload ( SparkplugMessageTopic topic , List < Metric > metrics , SparkplugMetricStatus metricStatus )
208
215
{
209
216
var metricState = new MetricState < Metric >
210
217
{
@@ -225,7 +232,7 @@ private IEnumerable<Metric> ProcessPayload(SparkplugMessageTopic topic, Payload
225
232
this . NodeStates [ topic . EdgeNodeIdentifier ] = metricState ;
226
233
}
227
234
228
- foreach ( var payloadMetric in payload . Metrics )
235
+ foreach ( var payloadMetric in metrics )
229
236
{
230
237
if ( payloadMetric is not Metric convertedMetric )
231
238
{
0 commit comments