Skip to content

Commit

Permalink
Extract opaque node to own plugin file (#155)
Browse files Browse the repository at this point in the history
* Extract opaque nodes to own plugin file

* Update doc

* Remove unused var

* Cosmetic

* Bump version
  • Loading branch information
luiscantero authored Jul 21, 2022
1 parent 65ddfb0 commit e101ff2
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 23 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,16 @@ More information about this feature can be found [here](deterministic-alarms.md)

## Other features

- Node with special characters in name and Id as well as a node with of opaque type: `--scn`
- Node with special characters in name and NodeId: `--scn`
- Node with long ID (3950 bytes): `--lid`
- Nodes with large values (10/50 kB string, 100 kB StringArray, 200 kB ByteArray): `--lsn`
- Nodes for testing all datatypes, arrays, methods, permissions, etc `--ref`. The ReferenceNodeManager of the [OPC UA .NET reference stack](https://github.com/OPCFoundation/UA-.NETStandard) is used for this purpose.
- Limit the number of updates of Slow and Fast nodes. Update the values of the `SlowNumberOfUpdates` and `FastNumberOfUpdates` configuration nodes in the `OpcPlc/SimulatorConfiguration` folder to:
- `< 0` (default): Slow and Fast nodes are updated indefinitely
- `0`: Slow and Fast nodes are not updated
- `> 0`: Slow and Fast nodes are updated the given number of times, then they stop being updated (the value of the configuration node is decremented at every update).
- Nodes with deterministic random GUIDs as node IDs: `--gn=<number_of_nodes>`
- Nodes with deterministic random GUIDs as node IDs: `--gn=<number_of_nodes>`
- Node with opaque identifier (free-format byte string): `--on`

## OPC UA Methods

Expand Down
81 changes: 81 additions & 0 deletions src/PluginNodes/OpaquePluginNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
namespace OpcPlc.PluginNodes;

using Opc.Ua;
using OpcPlc.PluginNodes.Models;
using System.Collections.Generic;

/// <summary>
/// Node with an opaque identifier (free-format byte string that might or might not be human interpretable).
/// </summary>
public class OpaquePluginNode : IPluginNodes
{
public IReadOnlyCollection<NodeWithIntervals> Nodes { get; private set; } = new List<NodeWithIntervals>();

private static bool _isEnabled;
private PlcNodeManager _plcNodeManager;
private SimulatedVariableNode<uint> _node;

public void AddOptions(Mono.Options.OptionSet optionSet)
{
optionSet.Add(
"on|opaquenode",
$"add node with an opaque identifier.\nDefault: {_isEnabled}",
(string s) => _isEnabled = s != null);
}

public void AddToAddressSpace(FolderState telemetryFolder, FolderState methodsFolder, PlcNodeManager plcNodeManager)
{
_plcNodeManager = plcNodeManager;

if (_isEnabled)
{
FolderState folder = _plcNodeManager.CreateFolder(
telemetryFolder,
path: "Special",
name: "Special",
NamespaceType.OpcPlcApplications);

AddNodes(folder);
}
}

public void StartSimulation()
{
if (_isEnabled)
{
_node.Start(value => value + 1, periodMs: 1000);
}
}

public void StopSimulation()
{
if (_isEnabled)
{
_node.Stop();
}
}

private void AddNodes(FolderState folder)
{
_node = _plcNodeManager.CreateVariableNode<uint>(
_plcNodeManager.CreateBaseVariable(
folder,
path: new byte[] { (byte)'a', (byte)'b', (byte)'c' },
name: "Opaque_abc",
new NodeId((uint)BuiltInType.UInt32),
ValueRanks.Scalar,
AccessLevels.CurrentReadOrWrite,
"Constantly increasing value",
NamespaceType.OpcPlcApplications,
defaultValue: (uint)0));

Nodes = new List<NodeWithIntervals>
{
new NodeWithIntervals
{
NodeId = "Opaque_abc",
Namespace = OpcPlc.Namespaces.OpcPlcApplications,
},
};
}
}
20 changes: 0 additions & 20 deletions src/PluginNodes/SpecialCharNamePluginNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class SpecialCharNamePluginNode : IPluginNodes
private static bool _isEnabled;
private PlcNodeManager _plcNodeManager;
private SimulatedVariableNode<uint> _node;
private SimulatedVariableNode<uint> _opaqueNode;

public void AddOptions(Mono.Options.OptionSet optionSet)
{
Expand Down Expand Up @@ -46,7 +45,6 @@ public void StartSimulation()
if (_isEnabled)
{
_node.Start(value => value + 1, periodMs: 1000);
_opaqueNode.Start(value => value + 1, periodMs: 1000);
}
}

Expand All @@ -55,7 +53,6 @@ public void StopSimulation()
if (_isEnabled)
{
_node.Stop();
_opaqueNode.Stop();
}
}

Expand All @@ -75,30 +72,13 @@ private void AddNodes(FolderState folder)
NamespaceType.OpcPlcApplications,
defaultValue: (uint)0));

_opaqueNode = _plcNodeManager.CreateVariableNode<uint>(
_plcNodeManager.CreateBaseVariable(
folder,
path: new byte[] { (byte)'a', (byte)'b', (byte)'c' },
name: "Opaque_abc",
new NodeId((uint)BuiltInType.UInt32),
ValueRanks.Scalar,
AccessLevels.CurrentReadOrWrite,
"Constantly increasing value",
NamespaceType.OpcPlcApplications,
defaultValue: (uint)0));

Nodes = new List<NodeWithIntervals>
{
new NodeWithIntervals
{
NodeId = "Special_" + SpecialChars,
Namespace = OpcPlc.Namespaces.OpcPlcApplications,
},
new NodeWithIntervals
{
NodeId = "Opaque_abc",
Namespace = OpcPlc.Namespaces.OpcPlcApplications,
}
};
}
}
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.3.0",
"version": "2.4.0",
"versionHeightOffset": -1,
"publicReleaseRefSpec": [
"^refs/heads/master$",
Expand Down

0 comments on commit e101ff2

Please sign in to comment.