OpcUaCanOpen
CANopen OPC-UA server
NmBuildingAutomation.h
Go to the documentation of this file.
1 #ifndef __NMBUILDINGAUTOMATION_H__
2 #define __NMBUILDINGAUTOMATION_H__
3 
4 #include "nodemanagerbase.h"
5 #include "variablehandle.h"
6 #include "opcua_baseobjecttype.h"
7 #include "iomanager.h"
8 #include "CANOpenServerConfig.h"
9 #include "ControlInterface.h"
10 
11 
12 namespace AddressSpace
13 {
15 
16  typedef std::vector<UaControlVariable *> UaControlVariableSet ;
17  typedef std::map<string, UaControlVariable *> UaControlVariableMap;
18 
27 // class UaCanBusObject;
28 // class UaCanNodeObject;
29  class UaCalcCompiler;
30 
52  class NmBuildingAutomation : public NodeManagerBase
53  {
55  public:
56 
62  NmBuildingAutomation(shared_ptr<UserDevice::ControlInterface> conInterf, const UaString nameOfSerevr);
63 
64  virtual ~NmBuildingAutomation();
65 
66  virtual UaStatus afterStartUp();
67  virtual UaStatus beforeShutDown();
68 
70  virtual UaStatus readValues(const UaVariableArray &arrUaVariables, UaDataValueArray &arrDataValues);
71 
73  virtual UaStatus writeValues(const UaVariableArray &arrUaVariables, const PDataValueArray &arrpDataValues, UaStatusCodeArray &arrStatusCodes);
74 
80  virtual IOManager* getIOManager(UaNode* pUaNode, OpcUa_Int32 attributeId) const;
81 
89  virtual VariableHandle* getVariableHandler(Session* session, VariableHandle::ServiceType serviceType, OpcUa_NodeId *nodeId, OpcUa_Int32 attributeId);
90 
91  UaNodeId getNewNodeId(const UaNode *,const UaString );
92  UaNodeId getTopNodeId(const UaNode *pNode) const;
93 // UaNodeId getCanNodeNodeId(const UaNode *pNode) const; //! get node id of can node
94  UaNode* getUpNode(const UaNode *pNode) const;
95  UaString getDefaultLocale() const { return m_defaultLocaleId; }
96 
97 
104  OpcUa_Int32 findUaVariables(const OpcUa::BaseObjectType *pParObj,string& pattern, UaControlVariableSet& storage);
105 
113  OpcUa_Int32 findUaNodeVariables(UaNode *pNode,string& pattern,UaControlVariableSet &storage);
114 
115  shared_ptr<UserDevice::ControlInterface> m_pControlInterface;
116 // UaStatusCode createNodeManagerAliasNode(const UaNodeId &sourceNodeId);
117  UaObject* getInstanceDeclarationObject(OpcUa_UInt32 numericIdentifier,NodeManagerUaNode *nm)
118  {
119  return getInstanceDeclaration<UaObject>(numericIdentifier,nm);
120  }
121  // UaObject* getInstanceDeclarationObjectType(OpcUa_UInt32 numericIdentifier); //! get an object type based on numerical id ( if not return null)
122  // UaMethod* getInstanceDeclarationMethod(OpcUa_UInt32 numericIdentifier); //! get a method based on numerical id ( if not return null)
123  UaVariable* getInstanceDeclarationVariable(const UaNodeId &n)
124  {
125  return getInstanceDeclaration<UaVariable>(n);
126  }
127  // UaVariable* getInstanceDeclarationVariable(const UaString ); //! get a variable based on string ( if not return null)
128 
129  UaObjectType* getInstanceDeclarationObjectType(OpcUa_UInt32 numericIdentifier)
130  {
131 
132  return getInstanceDeclaration<UaObjectType>(numericIdentifier, m_pControlInterface->getNodeTypeManager());
133  // Try to find the instance declaration node with the numeric identifier
134  // and the namespace index of this node manager
135  //UaNode* pNode = m_pTypeNodeManager->getNode(UaNodeId(numericIdentifier, m_pTypeNodeManager->getNameSpaceIndex()));
136 
137  //if (pNode != NULL) {
138  // int t = pNode->nodeClass();
139  // if (t == OpcUa_NodeClass_ObjectType)
140  // {
141  // // Return the node if valid and a variable
142  // return (UaObject*)pNode;
143  // }
144  //}
145  return NULL;
146  }
147 
148  UaVariableType* getInstanceDeclarationVariableType(OpcUa_UInt32 numericIdentifier)
149  {
150  return getInstanceDeclaration<UaVariableType>(numericIdentifier, m_pControlInterface->getNodeTypeManager());
151 
152  // Try to find the instance declaration node with the numeric identifier
153  // and the namespace index of this node manager
154  //UaNode* pNode = m_pTypeNodeManager->getNode(UaNodeId(numericIdentifier, m_pTypeNodeManager->getNameSpaceIndex()));
155 
156  //if (pNode != NULL) {
157  // int t = pNode->nodeClass();
158  // if (t == OpcUa_NodeClass_VariableType)
159  // {
160  // // Return the node if valid and a variable
161  // return (UaVariableType*)pNode;
162  // }
163  //}
164  //return NULL;
165  }
166 
167  UaNode* findNode(const UaNodeId &NodeId) const { return NodeManagerBase::findNode(NodeId); }
168 
169  private:
170  template<typename X>
171  X* getInstanceDeclaration(OpcUa_UInt32 numericIdentifier, NodeManagerUaNode *nm)
172  {
175  X* pNode = dynamic_cast<X *>(nm->getNode(UaNodeId(numericIdentifier, nm->getNameSpaceIndex())));
176  //X* pNode = dynamic_cast<X *>(findNode(UaNodeId(numericIdentifier, nm->getNameSpaceIndex())));
177  return pNode;
178  };
179 
180  template<typename X>
181  X* getInstanceDeclaration(const UaNodeId &n)
182  {
185  X* pNode = dynamic_cast<X *>(getNode(n));
186  // X* pNode = dynamic_cast<X *>(findNode(n));
187  return pNode;
188  };
189 
190 
191 
192  UaStatus createTypeNodes();
193  UaStatus createNodeTypes();
194  UaStatus createCanbuses();
195 // UaStatus createItems(); //! create calculated items
196 
197  UaString m_sNameNodeId;
198  OpcUa_Int32 m_iNumNameNodeId;
199 
205 
206  };
207 }
208 #endif // __NMBUILDINGAUTOMATION_H__