OpcUaCanOpen
CANopen OPC-UA server
UaControlDeviceItem.cpp
Go to the documentation of this file.
1 #include "UaControlDeviceItem.h"
2 #include "CanPDOItem.h"
3 #include "NmBuildingAutomation.h"
4 #include "UaControlNode.h"
5 
6 using namespace UserDevice;
7 using namespace CanOpen;
8 
9 namespace AddressSpace
10 {
11  UaControlVariable::UaControlVariable (
12  const UaString& name,
13  const UaNodeId& newNodeId,
14  NmBuildingAutomation* pNodeManager,
15  UaVariant &dv,
16  UaMutexRefCounted* pSharedMutex
17  ) : OpcUa::BaseDataVariableType(newNodeId,name,pNodeManager->getNameSpaceIndex(),
18  dv, Ua_AccessLevel_CurrentRead | Ua_AccessLevel_CurrentWrite,
19  pNodeManager, pSharedMutex) { if (pSharedMutex) pSharedMutex->addReference(); }
20 
22  UaNode *cur,
23  NmBuildingAutomation* pNodeManager,
24  UaVariable *instance,
25  UaMutexRefCounted* pSharedMutex
26  ) : OpcUa::BaseDataVariableType(cur, instance, pNodeManager, pSharedMutex) { if (pSharedMutex) pSharedMutex->addReference(); }
27 
29  UaNode *cur,
30  NmBuildingAutomation* pNodeManager,
31  UaVariable *instance,
33  pUserDeviceStruct* interf,
34  UaMutexRefCounted* pSharedMutex
35  ) : UaControlVariable(cur, pNodeManager, instance, pSharedMutex)
36  {
37  UaStatus addStatus;
38  UaNodeId nodeTypeId = instance->nodeId();
39  pUserDeviceStruct* pCanInter = pNodeManager->m_pControlInterface->createInterfaceEntry(interf, nodeTypeId.identifierNumeric(), conf, this);
40  //if (pCanInter == interf) {
41  // UserDevice::AbstractHardware *newd = new DEVICE<CanOpen::CanOpenItem, ::xml_schema::type>();
42  // pCanInter = newd->createHardwareEntry(interf, conf, this, nodeTypeId.identifierNumeric());
43  // delete newd;
44  //}
45  //if (pCanInter)
46  // pCanInter->addReference();
47  setUserData(pCanInter); // Set interface for this Item
48 
49  addStatus = UaControlNode::UaControlNodeCreateByType<UaControlDeviceItem>(this, instance, pNodeManager, conf, pCanInter, pSharedMutex); // create object structure base on type
50  UA_ASSERT(addStatus.isGood());
51  }
52 
55  const UaString& name,
56  const UaNodeId& newNodeId,
57  NmBuildingAutomation* pNodeManager,
58  UaVariant &dv,
59  UaVariableType *instance,
61  pUserDeviceStruct* interf,
62  UaMutexRefCounted* pSharedMutex
63  ) : UaControlVariable (name,newNodeId,pNodeManager, dv,pSharedMutex)
64  {
65  UaStatus addStatus;
66  UaNodeId nodeTypeId = instance->nodeId();
67  setTypeDefinition(nodeTypeId);
68  pUserDeviceStruct* pCanInter = pNodeManager->m_pControlInterface->createInterfaceEntry(interf,nodeTypeId.identifierNumeric() ,conf,this);
69  setUserData(pCanInter); // Set interface for this Item
70 
71  // if (pCanInter)
72  // pCanInter->addReference();
73 
74  addStatus =UaControlNode::UaControlNodeCreateByType<UaControlDeviceItem>(this, instance, pNodeManager, conf, pCanInter,pSharedMutex); // create object structure base on type
75  UA_ASSERT(addStatus.isGood());
76  }
77 
78 /*
79  UaControlDeviceItem::
80  UaControlDeviceItem (
81  const UaString& name,
82  const UaNodeId& newNodeId,
83  NmBuildingAutomation* pNodeManager,
84  UaVariant &dv,
85  OpcUa_Int32 baTypeId,
86  ::xml_schema::type *conf,
87  UserDataBase* interf,
88  UaMutexRefCounted* pSharedMutex
89  ) : UaControlVariable (name,newNodeId,pNodeManager, dv,pSharedMutex)
90  {
91 
92  UserDataBase* pCanInter = pNodeManager->m_pControlInterface->createInterfaceEntry(interf,baTypeId,conf,this);
93  setUserData(pCanInter); // Set interface for this Item
94  setTypeDefinition(baTypeId);
95  }
96 */
97 
98  UaStatus UaControlDeviceItem::write(UaDataValue &udv)
99  {
100  pUserDeviceStruct* iubd = static_cast<pUserDeviceStruct *>(getUserData());
101  if (iubd) {
102 // cout << this->browseName().toString().toUtf8() << endl;
103  CanOpenItem * cpdoi = static_cast<CanOpenItem *>(iubd->getDevice());
104  UaStatus ret = cpdoi->write(udv);
105  return ret;
106  }
107  return OpcUa_False;
108  }
109 /*
110  UaNodeId UaControlDeviceItem::typeDefinitionId() const
111  {
112  UserDataBase * udb = getUserData();
113 // InterfaceUserDataBase* iubd = ((UserDataBase_ptr<InterfaceUserDataBase> *)udb)->getDevice();
114  InterfaceUserDataBase* iubd = (InterfaceUserDataBase *)udb;
115  UaNodeId ret(iubd->getCodeFunction(), browseName().namespaceIndex());
116  return ret;
117  }
118 */
120  UaStatus Status = OpcUa_Good;
121 
122  pUserDeviceStruct* iubd = static_cast<pUserDeviceStruct *>(getUserData());
123  if (iubd) {
124  UserDeviceItem * cpdoi = static_cast<UserDeviceItem *>(iubd->getDevice());
125  UaStatus ret = cpdoi->read();
126  return ret;
127 
128  }
129  return OpcUa_False;
130 
131  }
132  UaStatus UaControlDeviceItem::read(IOVariableCallback *iom) {
133  UaStatus Status;
134  UaDataValue dataValue;
135 
136  pUserDeviceStruct* iubd = static_cast<pUserDeviceStruct *>(getUserData());
137  Status = static_cast<UserDeviceItem*>(iubd->getDevice())->read();
138  if (Status.isGood()) {
139  dataValue = this->value(0);
140  iom->dataChange(dataValue);
141  }
142  return Status;
143  }
144 }