Search in sources :

Example 1 with UaNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaNode in project FAAAST-Service by FraunhoferIOSB.

the class ExampleNamespace method startBogusEventNotifier.

private void startBogusEventNotifier() {
    // Set the EventNotifier bit on Server Node for Events.
    UaNode serverNode = getServer().getAddressSpaceManager().getManagedNode(Identifiers.Server).orElse(null);
    if (serverNode instanceof ServerTypeNode) {
        ((ServerTypeNode) serverNode).setEventNotifier(ubyte(1));
        // Post a bogus Event every couple seconds
        eventThread = new Thread(() -> {
            while (keepPostingEvents) {
                try {
                    BaseEventTypeNode eventNode = getServer().getEventFactory().createEvent(newNodeId(UUID.randomUUID()), Identifiers.BaseEventType);
                    eventNode.setBrowseName(new QualifiedName(1, "foo"));
                    eventNode.setDisplayName(LocalizedText.english("foo"));
                    eventNode.setEventId(ByteString.of(new byte[] { 0, 1, 2, 3 }));
                    eventNode.setEventType(Identifiers.BaseEventType);
                    eventNode.setSourceNode(serverNode.getNodeId());
                    eventNode.setSourceName(serverNode.getDisplayName().getText());
                    eventNode.setTime(DateTime.now());
                    eventNode.setReceiveTime(DateTime.NULL_VALUE);
                    eventNode.setMessage(LocalizedText.english("event message!"));
                    eventNode.setSeverity(ushort(2));
                    // noinspection UnstableApiUsage
                    getServer().getEventBus().post(eventNode);
                    eventNode.delete();
                } catch (Throwable e) {
                    logger.error("Error creating EventNode: {}", e.getMessage(), e);
                }
                try {
                    // noinspection BusyWait
                    Thread.sleep(2_000);
                } catch (InterruptedException ignored) {
                // ignored
                }
            }
        }, "bogus-event-poster");
        eventThread.start();
    }
}
Also used : BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode)

Example 2 with UaNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaNode in project milo by eclipse.

the class ExampleNamespace method registerCustomEnumType.

private void registerCustomEnumType() throws Exception {
    NodeId dataTypeId = CustomEnumType.TYPE_ID.toNodeIdOrThrow(getServer().getNamespaceTable());
    dictionaryManager.registerEnumCodec(new CustomEnumType.Codec().asBinaryCodec(), "CustomEnumType", dataTypeId);
    UaNode node = getNodeManager().get(dataTypeId);
    if (node instanceof UaDataTypeNode) {
        UaDataTypeNode dataTypeNode = (UaDataTypeNode) node;
        dataTypeNode.setEnumStrings(new LocalizedText[] { LocalizedText.english("Field0"), LocalizedText.english("Field1"), LocalizedText.english("Field2") });
    }
    EnumField[] fields = new EnumField[] { new EnumField(0L, LocalizedText.english("Field0"), LocalizedText.NULL_VALUE, "Field0"), new EnumField(1L, LocalizedText.english("Field1"), LocalizedText.NULL_VALUE, "Field1"), new EnumField(2L, LocalizedText.english("Field2"), LocalizedText.NULL_VALUE, "Field2") };
    EnumDefinition definition = new EnumDefinition(fields);
    EnumDescription description = new EnumDescription(dataTypeId, new QualifiedName(getNamespaceIndex(), "CustomEnumType"), definition, ubyte(BuiltinDataType.Int32.getTypeId()));
    dictionaryManager.registerEnumDescription(description);
}
Also used : EnumField(org.eclipse.milo.opcua.stack.core.types.structured.EnumField) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) EnumDefinition(org.eclipse.milo.opcua.stack.core.types.structured.EnumDefinition) UaDataTypeNode(org.eclipse.milo.opcua.sdk.server.nodes.UaDataTypeNode) EnumDescription(org.eclipse.milo.opcua.stack.core.types.structured.EnumDescription)

Example 3 with UaNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaNode in project milo by eclipse.

the class TestNamespace method startBogusEventNotifier.

private void startBogusEventNotifier() {
    // Set the EventNotifier bit on Server Node for Events.
    UaNode serverNode = getServer().getAddressSpaceManager().getManagedNode(Identifiers.Server).orElse(null);
    if (serverNode instanceof ServerTypeNode) {
        ((ServerTypeNode) serverNode).setEventNotifier(ubyte(1));
        // Post a bogus Event every couple seconds
        eventThread = new Thread(() -> {
            try {
                Thread.sleep(2_000);
            } catch (InterruptedException ignored) {
            // ignored
            }
            while (keepPostingEvents) {
                try {
                    BaseEventTypeNode eventNode = getServer().getEventFactory().createEvent(newNodeId(UUID.randomUUID()), Identifiers.BaseEventType);
                    eventNode.setBrowseName(new QualifiedName(1, "foo"));
                    eventNode.setDisplayName(LocalizedText.english("foo"));
                    eventNode.setEventId(ByteString.of(new byte[] { 0, 1, 2, 3 }));
                    eventNode.setEventType(Identifiers.BaseEventType);
                    eventNode.setSourceNode(serverNode.getNodeId());
                    eventNode.setSourceName(serverNode.getDisplayName().getText());
                    eventNode.setTime(DateTime.now());
                    eventNode.setReceiveTime(DateTime.NULL_VALUE);
                    eventNode.setMessage(LocalizedText.english("event message!"));
                    eventNode.setSeverity(ushort(2));
                    // noinspection UnstableApiUsage
                    getServer().getEventBus().post(eventNode);
                    eventNode.delete();
                } catch (Throwable e) {
                    logger.error("Error creating EventNode: {}", e.getMessage(), e);
                }
                try {
                    // noinspection BusyWait
                    Thread.sleep(2_000);
                } catch (InterruptedException ignored) {
                // ignored
                }
            }
        }, "bogus-event-poster");
        eventThread.start();
    }
}
Also used : BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode)

Example 4 with UaNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaNode in project milo by eclipse.

the class InstanceDeclarationHierarchyTest method test.

@Test
public void test() throws Exception {
    NamespaceTable namespaceTable = new NamespaceTable();
    UaNodeManager nodeManager = new UaNodeManager();
    AddressSpaceManager addressSpaceManager = Mockito.mock(AddressSpaceManager.class);
    Mockito.when(addressSpaceManager.getManagedNode(Mockito.any(NodeId.class))).then((Answer<Optional<UaNode>>) invocationOnMock -> nodeManager.getNode(invocationOnMock.getArgument(0)));
    Mockito.when(addressSpaceManager.getManagedNode(Mockito.any(ExpandedNodeId.class))).then((Answer<Optional<UaNode>>) invocationOnMock -> nodeManager.getNode(invocationOnMock.getArgument(0), namespaceTable));
    Mockito.when(addressSpaceManager.getManagedReferences(Mockito.any(NodeId.class))).then((Answer<List<Reference>>) invocationOnMock -> nodeManager.getReferences(invocationOnMock.getArgument(0)));
    OpcUaServer server = Mockito.mock(OpcUaServer.class);
    Mockito.when(server.getAddressSpaceManager()).thenReturn(addressSpaceManager);
    Mockito.when(server.getNamespaceTable()).thenReturn(namespaceTable);
    UaNodeContext context = new UaNodeContext() {

        @Override
        public OpcUaServer getServer() {
            return server;
        }

        @Override
        public NodeManager<UaNode> getNodeManager() {
            return nodeManager;
        }
    };
    new NodeLoader(context, nodeManager).loadNodes();
    InstanceDeclarationHierarchy idh = InstanceDeclarationHierarchy.create(addressSpaceManager, namespaceTable, Identifiers.AnalogItemType);
    System.out.println(idh);
    assertNotNull(idh);
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) NodeManager(org.eclipse.milo.opcua.sdk.server.api.NodeManager) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) Test(org.testng.annotations.Test) Assert.assertNotNull(org.testng.Assert.assertNotNull) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) List(java.util.List) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) Optional(java.util.Optional) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) Reference(org.eclipse.milo.opcua.sdk.core.Reference) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Optional(java.util.Optional) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNodeManager(org.eclipse.milo.opcua.sdk.server.UaNodeManager) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) List(java.util.List) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) Test(org.testng.annotations.Test)

Example 5 with UaNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaNode in project milo by eclipse.

the class OpcUaNamespace method configureGetMonitoredItems.

private void configureGetMonitoredItems() {
    UaNode node = getNodeManager().get(Identifiers.Server_GetMonitoredItems);
    if (node instanceof UaMethodNode) {
        UaMethodNode methodNode = (UaMethodNode) node;
        configureMethodNode(methodNode, GetMonitoredItemsMethodImpl::new);
    } else {
        logger.warn("GetMonitoredItems UaMethodNode not found.");
    }
}
Also used : UaMethodNode(org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode)

Aggregations

UaNode (org.eclipse.milo.opcua.sdk.server.nodes.UaNode)18 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)11 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)9 BaseEventTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode)7 AddressSpaceManager (org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager)6 NamespaceTable (org.eclipse.milo.opcua.stack.core.NamespaceTable)6 Optional (java.util.Optional)5 Reference (org.eclipse.milo.opcua.sdk.core.Reference)5 VariableNode (org.eclipse.milo.opcua.sdk.core.nodes.VariableNode)5 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)5 ServerTypeNode (org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode)5 UaMethodNode (org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode)5 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)5 UaException (org.eclipse.milo.opcua.stack.core.UaException)5 List (java.util.List)4 AttributeContext (org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext)4 UaVariableNode (org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode)4 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)4 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)4 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)4