OpcUaCanOpen
CANopen OPC-UA server
UaControlDeviceGeneric.cpp
Go to the documentation of this file.
2 #include "NmBuildingAutomation.h"
3 
4 #include "methodhandleuanode.h"
5 #include "UaDeviceMethod.h"
6 #include "UaControlNode.h"
7 
8 namespace AddressSpace
9 {
15  const UaString& name,
16  const UaNodeId& newNodeId,
17  NmBuildingAutomation* pNodeManager,
18  OpcUa_Int32 baTypeId,
20  pUserDeviceStruct* interf
21  )
22  : OpcUa::BaseObjectTypeGeneric(newNodeId,name, pNodeManager->getNameSpaceIndex(), pNodeManager )
23  {
24  UaObjectType* pInstanceDeclarationObject = NULL;
25  UaStatus addStatus;
26 
27  m_pSharedMutex->addReference();
28 
29  pUserDeviceStruct * pCanInter = pNodeManager->m_pControlInterface->createInterfaceEntry(interf,baTypeId,conf,this); // Open Device hardware channel
30  setUserData(pCanInter); // Set interface for this node
31  setTypeDefinitionId(baTypeId);
32 
33  pInstanceDeclarationObject = pNodeManager->getInstanceDeclarationObjectType(baTypeId); // take the type
34 
35 // cout << this->browseName().toString().toUtf8() << " " << pInstanceDeclarationObject->browseName().toString().toUtf8() << endl;
36 
37  addStatus = UaControlNode::UaControlNodeCreateByType<UaControlDeviceGeneric>(this,pInstanceDeclarationObject,pNodeManager,conf,pCanInter,getSharedMutex()); // create object structure base on type
38  UA_ASSERT(addStatus.isGood());
39 
40  }
41 
46  const UaString &name,
47  const UaNodeId& newNodeId,
48  NmBuildingAutomation* pNodeManager,
49  UaObjectType *instance,
51  pUserDeviceStruct* interf
52  )
53 // : OpcUa::BaseObjectTypeGeneric(UaNodeId(name,pNodeManager->getNameSpaceIndex()),instance, pNodeManager )
54  : OpcUa::BaseObjectTypeGeneric( newNodeId, name, pNodeManager->getNameSpaceIndex(), pNodeManager)
55  {
56  UaNodeId uaId;
57 
58  UaStatus addStatus;
59  m_pSharedMutex->addReference();
60 
61  setDisplayName(UaLocalizedText(pNodeManager->getDefaultLocale(),name));
62  uaId = instance->nodeId();
63  pUserDeviceStruct* pCanInter = pNodeManager->m_pControlInterface->createInterfaceEntry(interf,uaId.identifierNumeric(),conf,this); // Open Device hardware chennal
64  setUserData(pCanInter); // Set interface for this node
65  //if (pCanInter)
66  // pCanInter->addReference();
67 
68  setTypeDefinitionId(uaId);
69  /**************************************************************
70  * Create the Address Space components
71  **************************************************************/
72  addStatus = UaControlNode::UaControlNodeCreateByType<UaControlDeviceGeneric>(this,instance,pNodeManager,conf,pCanInter,getSharedMutex()); // create object structure base on type
73  UA_ASSERT(addStatus.isGood());
74  }
75 
80  const UaString &name,
81  const UaNodeId& newNodeId,
82  NmBuildingAutomation* pNodeManager,
83  UaObject *instance,
85  pUserDeviceStruct* interf
86  )
87  : OpcUa::BaseObjectTypeGeneric(newNodeId,instance, pNodeManager )
88  {
89  UaNodeId uaId;
90 
91  UaStatus addStatus;
92  m_pSharedMutex->addReference();
93 
94  setDisplayName(UaLocalizedText(pNodeManager->getDefaultLocale(), name));
95  uaId = instance->nodeId();
96  pUserDeviceStruct* pCanInter = pNodeManager->m_pControlInterface->createInterfaceEntry(interf, uaId.identifierNumeric(), conf, this); // Open Device hardware chennal
97  setUserData(pCanInter); // Set interface for this node
98 
99  setTypeDefinitionId(uaId);
100  /**************************************************************
101  * Create the Address Space components
102  **************************************************************/
103  addStatus = UaControlNode::UaControlNodeCreateByType<UaControlDeviceGeneric>(this, instance, pNodeManager, conf, pCanInter, getSharedMutex()); // create object structure base on type
104  UA_ASSERT(addStatus.isGood());
105  }
106 
108  {
109 // pUserDeviceStruct * iudb = (pUserDeviceStruct*)getUserData();
110 // cout << browseName().toString().toUtf8() << endl;
111 // if (iudb) {
112 // delete iudb;
113  // setUserData(0);
114 
115 // }
116 // OpcUa::BaseObjectTypeGeneric::~BaseObjectTypeGeneric();
117  }
118 
120  {
121  return Ua_EventNotifier_None;
122  }
123 
125  {
126  return this->typeDefinitionId().identifierNumeric();
127  }
128 
130  MethodManagerCallback* pCallback,
131  const ServiceContext& serviceContext,
132  OpcUa_UInt32 callbackHandle,
133  MethodHandle* pMethodHandle,
134  const UaVariantArray& inputArguments)
135  {
136  UaStatus ret;
137  UaVariantArray outputArguments;
138  UaStatusCodeArray inputArgumentResults;
139  UaDiagnosticInfos inputArgumentDiag;
140  MethodHandleUaNode* pMethodHandleUaNode = static_cast<MethodHandleUaNode*>(pMethodHandle);
142 
143  OpcUa_ReferenceParameter(serviceContext);
144 
145  if(pMethodHandleUaNode)
146  {
147  pMethod = (UaDeviceMethod<UaControlDeviceGeneric> *)pMethodHandleUaNode->pUaMethod();
148 
149  if(pMethod)
150  {
151  // Check if we have the calling method
152  for (OpcUa_UInt32 i = 0; i < m_pMethod.size(); i++) {
153  if ( pMethod->nodeId() == m_pMethod[i]->nodeId())
154  {
155 
156  if ( inputArguments.length() > 0 )
157  {
158  ret = OpcUa_BadInvalidArgument;
159  }
160  else
161  {
162  pMethod->execute();
163  break; //include call method
164  }
165  }
166  }
167 
168  pCallback->finishCall(
169  callbackHandle,
170  inputArgumentResults,
171  inputArgumentDiag,
172  outputArguments,
173  ret);
174 
175  ret = OpcUa_Good;
176  }
177  else
178  {
179  assert(false);
180  ret = OpcUa_BadInvalidArgument;
181  }
182  }
183  else
184  {
185  assert(false);
186  ret = OpcUa_BadInvalidArgument;
187  }
188 
189  return ret;
190  }
191 }