OpcUaCanOpen
CANopen OPC-UA server
UaProgramMethod.h
Go to the documentation of this file.
1 #ifndef __UAPROGRAMMETHOD_H__
2 #define __UAPROGRAMMETHOD_H__
3 
4 #include "Ids.h"
5 #include "UaDeviceMethod.h"
6 
7 namespace AddressSpace
8 {
13  template<class T>
14  class UaProgramMethod : public UaDeviceMethod<T>
15  {
17  public:
24  UaProgramMethod(T* cur , NmBuildingAutomation* pNodeManager,UaMethod* instance,UaMutexRefCounted *pSharedMutex)
25  :UaDeviceMethod<T>(cur,pNodeManager,instance,pSharedMutex)
26  {
27 // m_iCode = instance->nodeId().identifierNumeric();
28  }
29 
30  UaProgramMethod(T* cur, const UaNodeId& nodeId, const UaString& name, NmBuildingAutomation* pNodeManager, OpcUa_UInt32 icode, UaMutexRefCounted *pSharedMutex)
31  :UaDeviceMethod<T>(cur, nodeId, name, pNodeManager, icode, pSharedMutex)
32  {
33 // m_iCode = icode;
34  }
35 
37  virtual UaStatus execute()
38  {
39  UaStatus ret,rets;
40  UaControlDeviceItem *ptNode;
41  UaControlVariable *pValue;
42  OpcUa_UInt32 refType;
43 
44  UaReferenceLists *uaList = this->getUaReferenceLists(); // take the list children
45  for (UaReference *pRef = (UaReference *)uaList->pTargetNodes(); pRef != 0; pRef = pRef->pNextForwardReference()) {
46  refType = pRef->referenceTypeId().identifierNumeric();
47 
48  switch (refType) {
49  case BA_HASADDRESS:
50  ptNode = (UaControlDeviceItem *)pRef->pTargetNode(); // take address of operation
51  break;
52  case BA_HASVALUE:
53  pValue = (UaControlVariable *)pRef->pTargetNode();
54  break;
55 
56  default:
57 
58  break;
59  }
60  }
61 
62  OpcUa_UInt32 fCode = this->getFunctionCode();
63 
64  if (fCode == BA_SDOREAD)
65  {
66  ret = ptNode->read();
67  }
68  else
69  if (fCode == BA_SDOWRITE)
70  {
71  UaDataValue dataValue = pValue->value(0);
72  UaDateTime udt, sdt;
73  ret = ptNode->write(dataValue);
74  if (ret.isBad()) {
75  UaVariant val = *pValue->value(0).value();
76  udt = pValue->value(0).sourceTimestamp();
77  sdt = UaDateTime::now();
78  dataValue.setDataValue(val, OpcUa_False, ret.statusCode(), udt, sdt);
79  rets = pValue->setValue(0, dataValue, OpcUa_False);
80  }
81  }
82 
83 
84  return ret;
85  }
86 
88  virtual ~UaProgramMethod(void)
89  {
90  };
91 
92 
93  protected:
94  };
95 }
96 #endif
97