OpcUaCanOpen
CANopen OPC-UA server
CanBusInterface.h
Go to the documentation of this file.
1 #ifndef __CANBUSINTERFACE_H__
2 #define __CANBUSINTERFACE_H__
3 
4 #include "UaCalcItem.h"
5 #include "CANOpenServerConfig.h"
6 #include "CanBusAccess.h"
7 #include "CanBusObject.h"
8 #include "ControlInterface.h"
9 #include "UaCanBusObject.h"
10 #include "UaDeviceMethod.h"
11 
12 #include "NmBuildingAutomation.h"
13 #include "UaCanTrace.h"
14 
15 #include <list>
16 #include <map>
17 #include <vector>
18 #include <string>
19 
113 extern bool noExit;
114 namespace CanOpen {
115 
117  typedef std::map<string, vector<UaControlVariable *> > mapDataVariable;
118 
119 
124  {
125  public:
126 
128  {
129  public:
130  predCanBus(string s)
131  {
132  nport = s;
133  }
135  {
136  string bname = cbo->getCanBusAddress();
137  int n = bname.find(':');
138  int l = bname.length() - (n+1);
139  bool b = bname.compare(n+1,l, nport) == 0;
140  return b;
141  }
142  private:
143  string nport;
144  };
145 
146  CanBusInterface();
147  virtual ~CanBusInterface();
148  virtual void closeInterface();
149 
151  virtual UaStatus initialize(); // initialize interface and devices
152 
153  virtual UaStatus CreateXmlParser(UaString &sXmlFileName/*,UaString &sLogFileName*/);
161  virtual pUserDeviceStruct *createInterfaceEntry(pUserDeviceStruct* parent, int code, ::xml_schema::type* conf , UaNode* pAS);
162 
163  virtual IOManager* getIOManager(UaNode* pUaNode, OpcUa_Int32 attributeId);
164 
165  virtual VariableHandle* getVariableHandler(Session* session, VariableHandle::ServiceType serviceType, OpcUa_NodeId *nodeid, OpcUa_Int32 attributeId);
166 
167 
168 // bool isCanObject(int code) { return (find(m_CanObjects.begin(),m_CanObjects.end(),code) != m_CanObjects.end()); }
169 
170 // bool isCanItem(int code) {
171 // return (find(m_CanItems.begin(),m_CanItems.end(),code) != m_CanItems.end());
172 // }
173 // bool isCanMethod(int code) { return (find(m_CanMethods.begin(),m_CanMethods.end(),code) != m_CanMethods.end()); }
174 
175  virtual bool isTraceVariable(UaNodeId uaTraceId)
176  {
177  return (uaTraceId == UaNodeId("TraceLevel", getNodeManager()->getNameSpaceIndex()));
178  }
179  virtual void putTraceFunctions(OpcUa_DataValue *mvar)
180  {
181  OpcUa_Variant vdata;
182  vdata = mvar->Value;
183  UaCanTrace::putTraceFunctions(vdata.Value.Int32);
184  }
185 
186  virtual bool isDeviceVariable(UaNodeId uaDevVar)
187  {
188  bool ret = true;
189  OpcUa_UInt32 nn = uaDevVar.identifierNumeric();
190  if (nn == BA_STARTPROGRAM || nn == BA_CALCITEM)
191  ret = false ;
192  return ret;
193  }
194 
195  static void initCalculation();
196 
198 
203 // virtual UaStatus CreateAddressSpace(NmBuildingAutomation *nManager);
204  virtual UaStatus CreateAddressSpace(AddressSpace::NmBuildingAutomation *nManager, NodeManagerNodeSetXml* pXmlNodeManager, NodeManagerConfig *pDefaultNodeManager);
205 
209  virtual UaStatus getCanTraceSettings(
210  OpcUa_UInt32& uMaxTraceEntries, // Maximum number of trace entries in one trace file
211  OpcUa_UInt32& uMaxBackupFiles, // Maximum number of backup files
212  UaString& sTraceFile // Name and path of the trace file
213  )
214  {
215  uMaxTraceEntries = m_uCanMaxTraceEntries;
216  uMaxBackupFiles = m_uCanMaxBackupFiles;
217  sTraceFile = m_sLogFileName;
218  return OpcUa_Good;
219  }
220 
221  UaNodeId getCanNodeNodeId(UaNode *pNode);
222 
223 // UaStatus createTypeNodes(); //! create of ua node types
224  UaStatus createNodeTypes();
225  UaStatus createCanbuses();
226 
228 
229  static UaStatus CompileItems(OpcUa::BaseObjectType *pParent, CanOpenOpcServerConfig::ITEM_sequence &itnd, CanOpenOpcServerConfig::REGEXPR_sequence &regex, NmBuildingAutomation * nManager);
230 
232 
234 
235  static UaStatus executeInitMethod();
236  static UaStatus variableInitSet();
237 
238  static UaStatus createRegVariable(ITEM &itemvar, CanOpenOpcServerConfig::REGEXPR_sequence &regex, mapDataVariable& pvariables, OpcUa::BaseObjectType *pcn, OpcUa_Int32 &minVar, NmBuildingAutomation *nManager);
239 
240  static unique_ptr<CanBusAccess> g_pCanaccess ;
241 // static UaCalcCompiler *g_pCompiler;
242  static list<UaDeviceMethod<UaControlDeviceGeneric> *> m_listInitMethod;
243  struct InitSet {
244  OpcUa::BaseDataVariableType *setVar;
245  UaString value;
246  };
247  static list<struct InitSet> m_listInitSet;
248  static vector< AddressSpace::UaCalcItem *> m_vCCI;
250  private:
251 
252  list<CanBusObject *> m_CanBusList; // the list of CanBus in the system
253  map<OpcUa_UInt32,UserDevice::AbstractHardware *> factory; // map name of class to provide an object
254 
255 // vector<OpcUa_UInt32> m_CanObjects; // map code functions of objects
256 // vector<OpcUa_UInt32> m_CanMethods; // map code functions of methods
257 // vector<OpcUa_UInt32> m_CanItems; // map code functions of items
258 
267 
268  UaString m_sLocale;
269  UaString m_sLogFileName;
270  OpcUa_UInt32 m_uCanMaxTraceEntries; // Maximum number of trace entries in one trace file
271  OpcUa_UInt32 m_uCanMaxBackupFiles; // Maximum number of backup files
272  };
273 }
274 
275 #endif