1 package de.dlr.bt.stc.bridge.uas; 2 3 import org.eclipse.milo.opcua.sdk.server.nodes.UaObjectTypeNode; 4 import org.eclipse.milo.opcua.stack.core.Identifiers; 5 import org.eclipse.milo.opcua.stack.core.UaException; 6 import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; 7 8 import de.dlr.bt.stc.bridge.BridgeCfg; 9 import de.dlr.bt.stc.init.Register; 10 import de.dlr.bt.stc.opcuaserver.ANodeCreator; 11 import de.dlr.bt.stc.opcuaserver.NodeFactory; 12 import de.dlr.bt.stc.opcuaserver.STCNamespace; 13 import de.dlr.bt.stc.opcuaserver.STCNamespace.Folders; 14 import lombok.extern.slf4j.Slf4j; 15 16 @Slf4j 17 public class BridgeCfgNode extends ANodeCreator { 18 @Register 19 public static void register() { 20 NodeFactory.getInstance().registerCreator(BridgeCfg.class, BridgeCfgNode::new); 21 } 22 23 private BridgeCfgNode(STCNamespace namespace) { 24 super(namespace, "stc", "bridgecfg"); 25 } 26 27 private UaObjectTypeNode typeNode; 28 29 private static final String BRIDGECFG_TYPE = "BridgeCfgType"; 30 private static final String MAPPING_TYPE = "MappingType"; 31 32 private static final String MEASUREMENT = "Measurement"; 33 private static final String DEVICE = "Device"; 34 private static final String LOCATION = "Location"; 35 private static final String SYMBOLIC_NAME = "SymbolicName"; 36 private static final String FIELD = "Field"; 37 38 private static final String SOURCE_ID = "SourceID"; 39 private static final String SINK_ID = "SinkID"; 40 private static final String QUEUE_SIZE = "QueueSize"; 41 private static final String QUEUE_DURATION = "QueueDuration"; 42 private static final String VALUE_TEMPLATE = "ValueTemplate"; 43 private static final String MAPPING = "Mapping"; 44 45 @Override 46 public void createObjectType() { 47 try { 48 var measurement = namespace.createObjectTypeComponent(MEASUREMENT, 49 namespace.newNodeId(nodePathType(MEASUREMENT)), Identifiers.String); 50 var device = namespace.createObjectTypeComponent(DEVICE, namespace.newNodeId(nodePathType(DEVICE)), 51 Identifiers.String); 52 var location = namespace.createObjectTypeComponent(LOCATION, namespace.newNodeId(nodePathType(LOCATION)), 53 Identifiers.String); 54 var symbolicname = namespace.createObjectTypeComponent(SYMBOLIC_NAME, 55 namespace.newNodeId(nodePathType(SYMBOLIC_NAME)), Identifiers.String); 56 var field = namespace.createObjectTypeComponent(FIELD, namespace.newNodeId(nodePathType(FIELD)), 57 Identifiers.String); 58 59 var mappingType = namespace.createObjectTypeNode(MAPPING_TYPE, 60 namespace.newNodeId(nodePathType(MAPPING_TYPE)), measurement, device, location, symbolicname, 61 field); 62 63 var sourceid = namespace.createObjectTypeComponent(SOURCE_ID, namespace.newNodeId(nodePathType(SOURCE_ID)), 64 Identifiers.String); 65 var sinkid = namespace.createObjectTypeComponent(SINK_ID, namespace.newNodeId(nodePathType(SINK_ID)), 66 Identifiers.String); 67 var queuesize = namespace.createObjectTypeComponent(QUEUE_SIZE, 68 namespace.newNodeId(nodePathType(QUEUE_SIZE)), Identifiers.Integer); 69 var queueduration = namespace.createObjectTypeComponent(QUEUE_DURATION, 70 namespace.newNodeId(nodePathType(QUEUE_DURATION)), Identifiers.Integer); 71 var valuetemplate = namespace.createObjectTypeComponent(VALUE_TEMPLATE, 72 namespace.newNodeId(nodePathType(VALUE_TEMPLATE)), Identifiers.String); 73 74 var mappingt = namespace.createObjectTypeComponent(MAPPING, namespace.newNodeId(nodePathType(MAPPING)), 75 mappingType, Identifiers.ModellingRule_Mandatory); 76 77 typeNode = namespace.createObjectTypeNode(BRIDGECFG_TYPE, namespace.newNodeId(nodePathType(BRIDGECFG_TYPE)), 78 sourceid, sinkid, queuesize, queueduration, valuetemplate, mappingt); 79 } catch (UaException uae) { 80 log.info("Exception creating ObjectType for BridgeCfg: {}", uae); 81 } 82 83 } 84 85 @Override 86 public void createInstance(Object forNode, Folders folders) { 87 if (!(forNode instanceof BridgeCfg bridgeCfg)) 88 return; 89 90 try { 91 String id = bridgeCfg.getId(); 92 var uon = namespace.createObjectNode(typeNode, id, namespace.newNodeId(nodePathInst(id)), 93 folders.getConfigFolder()); 94 95 namespace.setObjectNodeComponent(uon, SOURCE_ID, new Variant(bridgeCfg.getSourceId())); 96 namespace.setObjectNodeComponent(uon, SINK_ID, new Variant(bridgeCfg.getSinkId())); 97 namespace.setObjectNodeComponent(uon, QUEUE_SIZE, new Variant(bridgeCfg.getQueueSize())); 98 namespace.setObjectNodeComponent(uon, QUEUE_DURATION, new Variant(bridgeCfg.getQueueDuration())); 99 namespace.setObjectNodeComponent(uon, VALUE_TEMPLATE, new Variant(bridgeCfg.getValueTemplate())); 100 101 var mn = namespace.getObjectNodeInstance(uon, MAPPING); 102 if (mn != null && bridgeCfg.getMapping() != null) { 103 namespace.setObjectNodeComponent(mn, DEVICE, new Variant(bridgeCfg.getMapping().getDevice())); 104 namespace.setObjectNodeComponent(mn, LOCATION, new Variant(bridgeCfg.getMapping().getLocation())); 105 namespace.setObjectNodeComponent(mn, MEASUREMENT, new Variant(bridgeCfg.getMapping().getMeasurement())); 106 namespace.setObjectNodeComponent(mn, SYMBOLIC_NAME, 107 new Variant(bridgeCfg.getMapping().getSymbolicName())); 108 namespace.setObjectNodeComponent(mn, FIELD, new Variant(bridgeCfg.getMapping().getField())); 109 } 110 111 addRootNode(forNode, uon); 112 } catch (UaException e) { 113 log.info("Exception during creation of NodeInstance {}: {}", bridgeCfg.getId(), e); 114 } 115 116 } 117 118 }