diff --git a/README.md b/README.md index 037491bf..f8805a12 100644 --- a/README.md +++ b/README.md @@ -606,14 +606,6 @@ Options: --nf, --nodesfile=VALUE the filename that contains the list of nodes to be created in the OPC UA address space. - --vf1k, --veryfast1knodes=VALUE - number of very fast 1 kB nodes (Deprecated: Use - veryfastbsnodes). - Default: 1 - --vf1kr, --veryfast1krate=VALUE - rate in ms to change very fast 1 kB nodes ( - Deprecated: Use veryfastbsrate). - Default: 1000 --vfbs, --veryfastbsnodes=VALUE number of very fast ByteString nodes. Default: 1 diff --git a/src/PluginNodes/SlowFastCommon.cs b/src/PluginNodes/SlowFastCommon.cs index 3f7d57d9..6c55d0cc 100644 --- a/src/PluginNodes/SlowFastCommon.cs +++ b/src/PluginNodes/SlowFastCommon.cs @@ -86,6 +86,7 @@ private BaseDataVariableState CreateNumberOfUpdatesVariable(string baseName, Fol variable.BrowseName = name; variable.DisplayName = name; variable.Description = new LocalizedText("The number of times to update the {name} nodes. Set to -1 to update indefinitely."); + variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType; simulatorFolder.AddChild(variable); return variable; diff --git a/src/PluginNodes/VeryFast1KBPluginNodes.cs b/src/PluginNodes/VeryFast1KBPluginNodes.cs deleted file mode 100644 index d0758e63..00000000 --- a/src/PluginNodes/VeryFast1KBPluginNodes.cs +++ /dev/null @@ -1,141 +0,0 @@ -namespace OpcPlc.PluginNodes; - -using Microsoft.Extensions.Logging; -using Opc.Ua; -using OpcPlc.Helpers; -using OpcPlc.PluginNodes.Models; -using System.Collections.Generic; -using System.Diagnostics; -using System.Text; - -/// -/// Nodes with 1 kB (ByteString) values. -/// The first byte cycles from 0 to 255 in a configurable rate in ms. -/// The values are deterministic but scrambled to ensure that they are not efficiently compressed. -/// -public class VeryFast1KBPluginNodes(TimeService timeService, ILogger logger) : PluginNodeBase(timeService, logger), IPluginNodes -{ - private uint NodeCount { get; set; } = 1; - private uint NodeRate { get; set; } = 1000; // ms. - - private readonly DeterministicGuid _deterministicGuid = new(); - private PlcNodeManager _plcNodeManager; - private BaseDataVariableState[] _veryFast1KBNodes; - private ITimer _nodeGenerator; - - public void AddOptions(Mono.Options.OptionSet optionSet) - { - optionSet.Add( - "vf1k|veryfast1knodes=", - $"number of very fast 1 kB nodes (Deprecated: Use veryfastbsnodes).\nDefault: {NodeCount}", - (uint i) => NodeCount = i); - - optionSet.Add( - "vf1kr|veryfast1krate=", - $"rate in ms to change very fast 1 kB nodes (Deprecated: Use veryfastbsrate).\nDefault: {NodeRate}", - (uint i) => NodeRate = i); - } - - public void AddToAddressSpace(FolderState telemetryFolder, FolderState methodsFolder, PlcNodeManager plcNodeManager) - { - _plcNodeManager = plcNodeManager; - - if (NodeCount == 0) - { - return; - } - - FolderState folder = _plcNodeManager.CreateFolder( - telemetryFolder, - path: "VeryFast1kB", - name: "VeryFast1kB", - NamespaceType.OpcPlcApplications); - - AddNodes(folder); - } - - public void StartSimulation() - { - // Only use the fast timers when we need to go really fast, - // since they consume more resources and create an own thread. - _nodeGenerator = NodeRate >= 50 || !Stopwatch.IsHighResolution - ? _timeService.NewTimer((s, e) => UpdateNodes(), intervalInMilliseconds: NodeRate) - : _timeService.NewFastTimer((s, e) => UpdateNodes(), intervalInMilliseconds: NodeRate); - } - - public void StopSimulation() - { - if (_nodeGenerator != null) - { - _nodeGenerator.Enabled = false; - } - } - - private void AddNodes(FolderState folder) - { - var nodes = new List(); - _veryFast1KBNodes = new BaseDataVariableState[NodeCount]; - - for (int i = 0; i < NodeCount; i++) - { - string oneKbGuid = GetLongDeterministicGuid(maxLength: 1024); - var initialByteArray = Encoding.UTF8.GetBytes(oneKbGuid); - - string name = $"VeryFast1kB{(i + 1)}"; - - _veryFast1KBNodes[i] = _plcNodeManager.CreateBaseVariable( - folder, - path: name, - name: name, - new NodeId((uint)BuiltInType.ByteString), - ValueRanks.Scalar, - AccessLevels.CurrentReadOrWrite, - "Very fast changing 1 kB node", - NamespaceType.OpcPlcApplications, - initialByteArray); - - // Update pn.json output. - nodes.Add(new NodeWithIntervals { - NodeId = name, - Namespace = OpcPlc.Namespaces.OpcPlcApplications, - PublishingInterval = NodeRate, - }); - - Nodes = nodes; - } - } - - private void UpdateNodes() - { - for (int i = 0; i < _veryFast1KBNodes.Length; i++) - { - byte[] arrayValue = (byte[])_veryFast1KBNodes[i].Value; - - // Update first byte in the range 0 to 255. - arrayValue[0] = arrayValue[0] == 255 - ? (byte)0 - : (byte)(arrayValue[0] + 1); - - SetValue(_veryFast1KBNodes[i], arrayValue); - } - } - - private void SetValue(BaseVariableState variable, T value) - { - variable.Value = value; - variable.Timestamp = _timeService.Now(); - variable.ClearChangeMasks(_plcNodeManager.SystemContext, includeChildren: false); - } - - private string GetLongDeterministicGuid(int maxLength) - { - var sb = new StringBuilder(); - - while (sb.Length < maxLength) - { - sb.Append(_deterministicGuid.NewGuid().ToString()); - } - - return sb.ToString()[..maxLength]; - } -} diff --git a/src/opc-plc.csproj b/src/opc-plc.csproj index 8c3981da..f0bb95ba 100644 --- a/src/opc-plc.csproj +++ b/src/opc-plc.csproj @@ -23,7 +23,7 @@ - + @@ -36,7 +36,7 @@ - + diff --git a/tests/opc-plc-tests.csproj b/tests/opc-plc-tests.csproj index 58bbac9b..81371008 100644 --- a/tests/opc-plc-tests.csproj +++ b/tests/opc-plc-tests.csproj @@ -8,12 +8,12 @@ - - - - + + + + - + diff --git a/version.json b/version.json index 32fd5ac0..14451c2b 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "2.12.24", + "version": "2.12.25", "versionHeightOffset": -1, "publicReleaseRefSpec": [ "^refs/heads/main$",