private bool IsAckConfirm(NodeId methodId)
        {
            bool isAckConfirm = false;

            if (methodId.Equals(Opc.Ua.MethodIds.AcknowledgeableConditionType_Acknowledge) ||
                methodId.Equals(Opc.Ua.MethodIds.AcknowledgeableConditionType_Confirm))
            {
                isAckConfirm = true;
            }
            return(isAckConfirm);
        }
Beispiel #2
0
        public bool Equals(DestinyActivityGraphNodeDefinition input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     NodeId == input.NodeId ||
                     (NodeId.Equals(input.NodeId))
                     ) &&
                 (
                     OverrideDisplay == input.OverrideDisplay ||
                     (OverrideDisplay != null && OverrideDisplay.Equals(input.OverrideDisplay))
                 ) &&
                 (
                     Position == input.Position ||
                     (Position != null && Position.Equals(input.Position))
                 ) &&
                 (
                     FeaturingStates == input.FeaturingStates ||
                     (FeaturingStates != null && FeaturingStates.SequenceEqual(input.FeaturingStates))
                 ) &&
                 (
                     Activities == input.Activities ||
                     (Activities != null && Activities.SequenceEqual(input.Activities))
                 ) &&
                 (
                     States == input.States ||
                     (States != null && States.SequenceEqual(input.States))
                 ));
        }
Beispiel #3
0
        public void NodeIdOperatorTestMethod1()
        {
            NodeId _property = new NodeId(VariableTypes.PropertyType);

            Assert.AreNotSame(_property, VariableTypeIds.PropertyType);
            Assert.IsTrue(_property == VariableTypeIds.PropertyType);
            Assert.IsTrue(_property.Equals(VariableTypeIds.PropertyType));
        }
Beispiel #4
0
        // AL40 impl ported from java.
        public List <Vector3> findPath(NodeId start, NodeId goal, Vector3 exactEnd)
        {
            var graph = AStar(start, goal);

            if (graph == null)
            {
                return(null);
            }

            var path = new List <Vector3>();

            // gather the steps. these are reversed...
            NodeId currentNode = goal;

            while (true)
            {
                NodeId next = graph[currentNode]; // walks backwards from goal, so really 'prev'
                if (next.blockIndex < 0)
                {
                    Debug.WriteLine("NavMesh.FindPath - node not found??");
                    break;
                }

                path.Add(WorldPointFromNode(currentNode));

                // done if on start. the start point must be added to the list
                // to properly reduce later.
                if (next.Equals(start))
                {
                    break;
                }

                currentNode = next;
            }

            // reverse the list so points go from start to goal.

            // TODO - could reducePath here, and just traverse the path in
            // reverse and build the smoothed path in the correct order.

            var result = new List <Vector3>(path.Count);

            for (int i = path.Count() - 1; i >= 0; i--)
            {
                result.Add(path[i]);
            }

            result = reducePath(result);

            // replace last point with exact end point
            if (result.Count > 0)
            {
                result.RemoveAt(result.Count - 1);
            }
            result.Add(exactEnd);

            return(result);
        }
Beispiel #5
0
        public virtual void TestNodeId()
        {
            NodeId nodeId1 = NodeId.NewInstance("10.18.52.124", 8041);
            NodeId nodeId2 = NodeId.NewInstance("10.18.52.125", 8038);
            NodeId nodeId3 = NodeId.NewInstance("10.18.52.124", 8041);
            NodeId nodeId4 = NodeId.NewInstance("10.18.52.124", 8039);

            NUnit.Framework.Assert.IsTrue(nodeId1.Equals(nodeId3));
            NUnit.Framework.Assert.IsFalse(nodeId1.Equals(nodeId2));
            NUnit.Framework.Assert.IsFalse(nodeId3.Equals(nodeId4));
            NUnit.Framework.Assert.IsTrue(nodeId1.CompareTo(nodeId3) == 0);
            NUnit.Framework.Assert.IsTrue(nodeId1.CompareTo(nodeId2) < 0);
            NUnit.Framework.Assert.IsTrue(nodeId3.CompareTo(nodeId4) > 0);
            NUnit.Framework.Assert.IsTrue(nodeId1.GetHashCode() == nodeId3.GetHashCode());
            NUnit.Framework.Assert.IsFalse(nodeId1.GetHashCode() == nodeId2.GetHashCode());
            NUnit.Framework.Assert.IsFalse(nodeId3.GetHashCode() == nodeId4.GetHashCode());
            NUnit.Framework.Assert.AreEqual("10.18.52.124:8041", nodeId1.ToString());
        }
Beispiel #6
0
        public async Task LoadAllServerDataTypeSystems(NodeId dataTypeSystem)
        {
            // find the dictionary for the description.
            Browser browser = new Browser(Session)
            {
                BrowseDirection = BrowseDirection.Forward,
                ReferenceTypeId = ReferenceTypeIds.HasComponent,
                IncludeSubtypes = false,
                NodeClassMask   = 0
            };

            ReferenceDescriptionCollection references = browser.Browse(dataTypeSystem);

            Assert.NotNull(references);

            TestContext.Out.WriteLine("  Found {0} references", references.Count);

            // read all type dictionaries in the type system
            foreach (var r in references)
            {
                NodeId dictionaryId = ExpandedNodeId.ToNodeId(r.NodeId, Session.NamespaceUris);
                TestContext.Out.WriteLine("  ReadDictionary {0} {1}", r.BrowseName.Name, dictionaryId);
                var dictionaryToLoad = new DataDictionary(Session);
                await dictionaryToLoad.Load(dictionaryId, r.BrowseName.Name).ConfigureAwait(false);

                // internal API for testing only
                var dictionary = dictionaryToLoad.ReadDictionary(dictionaryId);
                // TODO: workaround known issues in the Xml type system.
                // https://mantis.opcfoundation.org/view.php?id=7393
                if (dataTypeSystem.Equals(ObjectIds.XmlSchema_TypeSystem))
                {
                    try
                    {
                        await dictionaryToLoad.Validate(dictionary, true).ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        Assert.Inconclusive(ex.Message);
                    }
                }
                else
                {
                    await dictionaryToLoad.Validate(dictionary, true).ConfigureAwait(false);
                }
            }
        }
        /// <summary>
        /// Gets the tree node from a node identifier
        /// </summary>
        /// <param name="nodeId">Node identifier</param>
        /// <returns>A Tree node</returns>
        public TreeNodeController GetNodeById(string nodeId)
        {
            if (NodeId.Equals(nodeId))
            {
                return(this);
            }

            foreach (TreeNodeController node in SubNodes)
            {
                TreeNodeController lNode = node.GetNodeById(nodeId);
                if (lNode != null)
                {
                    return(lNode);
                }
            }

            return(null);
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="id"></param>
        /// <param name="nsTable"></param>
        /// <returns></returns>
        private QualifiedName[] FindBrowsePath(Session connection, NodeId id, NodeId rootId, Opc.Ua.QualifiedName browseName, NamespaceTable nsTable)
        {
            HashSet <NodeId> set = new HashSet <NodeId>();
            var browsePath       = new List <QualifiedName>();

            set.Add(id);
            browsePath.Add(Converter.GetQualifiedName(browseName, nsTable));
            bool moreParents = true;

            while (moreParents)
            {
                connection.Browse(null, null, id, 1,
                                  BrowseDirection.Inverse,
                                  ReferenceTypeIds.HierarchicalReferences,
                                  true,
                                  0xFF,
                                  out byte[] contpoint,
                                  out ReferenceDescriptionCollection referenceDescriptions);

                moreParents = referenceDescriptions.Count > 0;
                if (moreParents)
                {
                    var refDesc = referenceDescriptions[0];
                    var nodeId  = ExpandedNodeId.ToNodeId(refDesc.NodeId, nsTable);
                    if (!rootId.Equals(nodeId))
                    {
                        id = nodeId;
                        if (set.Contains(nodeId))
                        {
                            _log.LogError("Loop detected");
                            throw new ArgumentException("Loop detected!");
                        }
                        set.Add(id);
                        browsePath.Add(Converter.GetQualifiedName(refDesc.BrowseName, nsTable));
                    }
                    else
                    {
                        moreParents = false;
                    }
                }
            }
            return(browsePath.Reverse <QualifiedName>().ToArray());
        }
Beispiel #9
0
        public bool IsSubtypeOrEqual(NodeId target, NodeId parent)
        {
            if (target.Equals(parent) || parent.EqualsNumeric(0, 0U))
            {
                return(true);
            }

            if (!this.AddressSpaceTable.TryGetValue(parent, out Node node))
            {
                return(false);
            }

            for (int index = 0; index < node.References.Count; ++index)
            {
                ReferenceNode reference = node.References[index];
                if (!reference.IsInverse && reference.ReferenceType.EqualsNumeric(0, 45U) && this.IsSubtypeOrEqual(target, reference.Target))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #10
0
        // https://www.redblobgames.com/pathfinding/a-star/introduction.html
        public Dictionary <NodeId, NodeId> AStar(NodeId start, NodeId goal)
        {
            var frontier = new PriorityQueue <NodeId>();

            frontier.Push(start, 0);
            var came_from   = new Dictionary <NodeId, NodeId>();
            var cost_so_far = new Dictionary <NodeId, float>();

            came_from[start]   = default(NodeId);
            cost_so_far[start] = 0;

            float heuristic(NodeId a, NodeId b)
            {
                Point p0 = BlockXYFromIndex(a.blockIndex);
                Point p1 = BlockXYFromIndex(b.blockIndex);

                float edist = Vector2.Distance(new Vector2(p0.X, p0.Y), new Vector2(p1.X, p1.Y));
                //float manhattanDist = Math.Abs(p0.X - p1.X) + Math.Abs(p0.Y - p1.Y);

                // Number of bits - favor nodes with more connections.
                float dirWeight = NumberOfSetBits(b.directionFlags);

                return(edist + dirWeight);
            }

            void test(NodeId current, int direction)
            {
                NodeId next = GetNeighbor(current, direction);

                if (next.blockIndex == -1)
                {
                    return;
                }
                float dirCost = (direction & 0xAA) != 0 ? 1.4142f : 1f;

                dirCost += NumberOfSetBits(next.directionFlags) / 2f;

                float new_cost = cost_so_far[current] + dirCost; //heuristic(current, next);

                if (!cost_so_far.ContainsKey(next) || new_cost < cost_so_far[next])
                {
                    cost_so_far[next] = new_cost;
                    // *10 seems to give better routes, reduce iterations...
                    int priority = (int)((new_cost + heuristic(goal, next)) * 10);
                    frontier.Push(next, priority);
                    came_from[next] = current;
                }
            }

            int iterationCount = 0;

            while (!frontier.Empty())
            {
                NodeId current = frontier.Pop();
                if (current.Equals(goal))
                {
                    break;
                }

                test(current, NavMeshUtil.DIRECTION_TOP);
                test(current, NavMeshUtil.DIRECTION_TL);
                test(current, NavMeshUtil.DIRECTION_RIGHT);
                test(current, NavMeshUtil.DIRECTION_BR);
                test(current, NavMeshUtil.DIRECTION_BOTTOM);
                test(current, NavMeshUtil.DIRECTION_BL);
                test(current, NavMeshUtil.DIRECTION_LEFT);
                test(current, NavMeshUtil.DIRECTION_TR);

                iterationCount++;
            }

            Debug.WriteLine("AStar iteration count: " + iterationCount);

            return(came_from);
        }
Beispiel #11
0
 public bool Equals(Node other)
 {
     return(NodeId.Equals(other.NodeId));
 }
Beispiel #12
0
 public void NodeIdOperatorTestMethod1()
 {
     NodeId _property = new NodeId(VariableTypes.PropertyType);
       Assert.AreNotSame(_property, VariableTypeIds.PropertyType);
       Assert.IsTrue(_property == VariableTypeIds.PropertyType);
       Assert.IsTrue(_property.Equals(VariableTypeIds.PropertyType));
 }
 private bool IsInNodeList(NodeId id, IEnumerable<ITreeNode> nodes)
 {
     foreach (ITreeNode node in nodes) {
         if (id.Equals(node.Id))
             return true;
     }
     return false;
 }