OpcUaCanOpen
CANopen OPC-UA server
UaControlNode.cpp
Go to the documentation of this file.
2 #include "UaControlDeviceItem.h"
3 #include "NmBuildingAutomation.h"
5 #include "methodhandleuanode.h"
6 #include "UaDeviceMethod.h"
7 
8 namespace AddressSpace
9 {
10  template<class T>
11  UaStatus UaControlNode<T>::UaControlNodeCreateByType(T *cur, UaNode* instance, NmBuildingAutomation* pNodeManager,::xml_schema::type *conf, UserDataBase* interf)
12  {
13  OpcUa::BaseObjectTypeGeneric* pDeclarationObject = NULL;
14  OpcUa::BaseMethod* pMethodDeclaration = NULL;
15  OpcUa::BaseDataVariableType* pDataVariable = NULL;
16  UaControlDeviceProperty * pProperty;
17  UaStatus addStatus;
18  UaNodeId nTypeId; // ID of node type
19  UaNodeId uaId; //new id
20  UaVariant defaultValue;
21  defaultValue.clear();
22  /**************************************************************
23  * Create the Device components
24  **************************************************************/
25 
26  UaReferenceLists *uaList = instance->getUaReferenceLists(); // take the list children
27  for ( UaReference *pRef = (UaReference *)uaList->pTargetNodes(); pRef != 0; pRef = pRef->pNextForwardReference() ) {
28  OpcUa_UInt32 refType = pRef->referenceTypeId().identifierNumeric();
29 
30  UaNode *ptNode = pRef->pTargetNode(); // take child node
31 
32 // nTypeId = ptNode->nodeId();
33  UaString newName(ptNode->browseName().name());
34  uaId = pNodeManager->getNewNodeId(cur,newName);
35 // printf("Node Class %d %s %d %s\n", ptNode->nodeClass(), ptNode->displayName(0).toString().toUtf8(),refType, cur->displayName(0).toString().toUtf8());
36  switch (refType) {
37  case OpcUaId_HasComponent:
38  switch (ptNode->nodeClass()) {
39  case OpcUa_NodeClass_Variable:
40  pDataVariable = new UaControlDeviceItem(newName,uaId,pNodeManager,defaultValue,(UaVariableType*)ptNode,conf,interf,getObjectMutex());
41  addStatus = pNodeManager->addNodeAndReference(cur,pDataVariable,OpcUaId_HasComponent);
42  UA_ASSERT(addStatus.isGood());
43  break;
44  case OpcUa_NodeClass_ObjectType:
45  pDeclarationObject = new UaControlDeviceGeneric(newName,uaId,pNodeManager,(UaObject *)ptNode,conf,interf);
46  addStatus = pNodeManager->addNodeAndReference(cur,pDeclarationObject,OpcUaId_HasComponent);
47  UA_ASSERT(addStatus.isGood());
48  break;
49  case OpcUa_NodeClass_Method:
50  pMethodDeclaration = new UaDeviceMethod(cur,pNodeManager,(UaMethod *)ptNode,getObjectMutex());
51  addStatus = pNodeManager->addNodeAndReference(cur,pMethodDeclaration,OpcUaId_HasComponent);
52  UA_ASSERT(addStatus.isGood());
53  m_pMethod.push_back(pMethodDeclaration);
54  break;
55  }
56  break;
57  case OpcUaId_HasSubtype:
58 // printf("Node Class subtype %d %s\n", ptNode->nodeClass(), ptNode->displayName(0).toString().toUtf8());
59  addStatus = UaControlNodeCreateByType(cur,ptNode,pNodeManager,conf,interf);
60  UA_ASSERT(addStatus.isGood());
61  break;
62  case OpcUaId_HasProperty:
63  pProperty = new UaControlDeviceProperty(cur, pNodeManager, (UaVariable*)ptNode, conf, interf, getObjectMutex());
64  addStatus = pNodeManager->addNodeAndReference(cur, pProperty, OpcUaId_HasProperty);
65 // addStatus = pNodeManager->addNodeAndReference(cur->getUaReferenceLists(), pProperty, OpcUaId_HasProperty);
66  if (!addStatus.isGood())
67  {
68  std::cout << "While creating a property: " << pProperty->browseName().toString().toUtf8() << endl;
69  UA_ASSERT(addStatus.isGood());
70  return addStatus;
71  }
72  break;
73  }
74  }
75  return addStatus;
76  }
77 }