Skip to content

Commit 80c5d73

Browse files
authored
Use a round-robin data generator for alarms and events (#429)
* Simplify * Use deterministic source for events
1 parent 1f2686d commit 80c5d73

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/AlarmCondition/AlarmConditionNodeManager.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
using Opc.Ua;
3434
using Opc.Ua.Server;
3535
using Opc.Ua.Test;
36+
using OpcPlc.AlarmCondition;
3637

3738
namespace AlarmCondition
3839
{
@@ -461,8 +462,7 @@ protected override NodeState ValidateNode(
461462

462463
private void ResetRandomGenerator(int seed, int boundaryValueFrequency = 0)
463464
{
464-
m_randomSource = new RandomSource(seed);
465-
m_generator = new DataGenerator(m_randomSource);
465+
m_generator = new DataGenerator(new RoundRobinSource(seed));
466466
m_generator.BoundaryValueFrequency = boundaryValueFrequency;
467467
}
468468

@@ -473,7 +473,6 @@ private void ResetRandomGenerator(int seed, int boundaryValueFrequency = 0)
473473
private readonly Dictionary<string, AreaState> m_areas;
474474
private readonly Dictionary<string, SourceState> m_sources;
475475
private Timer m_simulationTimer;
476-
private RandomSource m_randomSource;
477476
private DataGenerator m_generator;
478477
#endregion
479478
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace OpcPlc.AlarmCondition;
2+
3+
using Opc.Ua.Test;
4+
5+
/// <summary>
6+
/// Returns sequential numbers in a round-robin fashion.
7+
/// </summary>
8+
public class RoundRobinSource : IRandomSource
9+
{
10+
int _seed;
11+
12+
/// <summary>
13+
/// Initializes the source with a seed.
14+
/// </summary>
15+
public RoundRobinSource(int seed)
16+
{
17+
_seed = seed;
18+
}
19+
20+
public void NextBytes(byte[] bytes, int offset, int count)
21+
{
22+
// Not used.
23+
}
24+
25+
public int NextInt32(int max)
26+
{
27+
return _seed++ % max;
28+
}
29+
}

src/PlcServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace OpcPlc;
22

3-
using AlarmCondition;
3+
using global::AlarmCondition;
44
using Microsoft.Extensions.Logging;
55
using Opc.Ua;
66
using Opc.Ua.Bindings;

0 commit comments

Comments
 (0)