ChimeraTK-ControlSystemAdapter-OPCUAAdapter  04.00.01
ua_adapter.h
Go to the documentation of this file.
1 /*
2  * This file is part of ChimeraTKs ControlSystem-OPC-UA-Adapter.
3  *
4  * ChimeraTKs ControlSystem-OPC-UA-Adapter is free software: you can
5  * redistribute it and/or modify it under the terms of the Lesser GNU
6  * General Public License as published by the Free Software Foundation,
7  * either version 3 of the License, or (at your option) any later version.
8  *
9  * ChimeraTKs ControlSystem-OPC-UA-Adapter is distributed in the hope
10  * that it will be useful, but WITHOUT ANY WARRANTY; without even the
11  * implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * See the Lesser GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Foobar. If not, see https://www.gnu.org/licenses/lgpl.html
16  *
17  * Copyright (c) 2016 Chris Iatrou <Chris_Paul.Iatrou@tu-dresden.de>
18  * Copyright (c) 2016 Julian Rahm <Julian.Rahm@tu-dresden.de>
19  * Copyright (c) 2019-2021 Andreas Ebner <Andreas.Ebner@iosb.fraunhofer.de>
20  */
21 
22 #pragma once
23 
24 #include "node_historizing.h"
25 #include <open62541/config.h>
26 #include <open62541/plugin/accesscontrol.h>
27 #include <open62541/plugin/accesscontrol_default.h>
28 #include <open62541/plugin/historydata/history_data_gathering.h>
29 #include <open62541/server_config_default.h>
30 
31 #include <memory>
32 
33 using namespace std;
34 
35 namespace ChimeraTK {
36  struct ServerConfig {
37  string rootFolder;
39  UA_Boolean UsernamePasswordLogin = UA_FALSE;
40  string password;
41  string username;
42  string applicationName = "OPCUA-Adapter";
43  uint16_t opcuaPort = 16664;
44  bool enableSecurity = false;
45  bool unsecure = false;
46  UA_LogLevel logLevel = UA_LOGLEVEL_INFO;
47  string certPath;
48  string keyPath;
52  vector<AdapterHistorySetup> history{};
53  vector<AdapterFolderHistorySetup> historyfolders{};
54  vector<AdapterPVHistorySetup> historyvariables{};
55  };
56 
65  struct FolderInfo {
69  string folderName;
71  UA_NodeId folderNodeId = UA_NODEID_NULL;
73  UA_NodeId nextFolderNodeId = UA_NODEID_NULL;
75  UA_NodeId prevFolderNodeId = UA_NODEID_NULL;
76  };
77 
101  private:
102  UA_ServerConfig* server_config{nullptr};
103 
104  UA_NodeId variablesListId;
105  UA_NodeId constantsListId;
106  std::shared_ptr<UA_DataTypeArray> customDataTypes;
107 
108  vector<FolderInfo> folderVector;
109  UA_NodeId ownNodeId;
110  UA_NodeId configNodeId;
111  string pvSeperator;
112  UA_Boolean mappingExceptions;
113 
114  ServerConfig serverConfig;
115  UA_Logger logger;
116 
117  vector<ua_processvariable*> variables;
118  vector<ua_additionalvariable*> additionalVariables;
119  vector<ua_processvariable*> mappedVariables;
120 
121  std::shared_ptr<xml_file_handler> fileHandler;
122 
125  void constructServer();
126 
131  UA_StatusCode mapSelfToNamespace();
132 
141  UA_NodeId createUAFolder(UA_NodeId basenodeId, const string& folderName, const string& description = "");
142 
155  void raiseError(std::string errorMesssage, std::string consequenceMessage, const int& line = -1);
156 
157  public:
158  bool running = false;
159  // TODO move this field to private and add getter and setter
160  vector<string> exclude;
161  vector<string> folder_with_history;
162 
171  ua_uaadapter(const string& configPath);
172 
178  virtual ~ua_uaadapter();
179 
184  UA_DateTime getSourceTimeStamp();
185 
190  UA_Server* getMappedServer();
191 
197  UA_NodeId createFolderPath(UA_NodeId basenodeid, vector<string> folderPathVector);
198 
205  UA_NodeId createFolder(UA_NodeId basenodeid, const string& folderName, const string& description = "");
206 
212  UA_NodeId existFolderPath(UA_NodeId basenodeid, const vector<string>& folderPath);
213 
219  UA_NodeId existFolder(UA_NodeId basenodeid, const string& folderName);
220 
228  UA_NodeId enrollFolderPathFromString(const string& path, const string& seperator);
229 
235  void implicitVarMapping(const std::string& varName, const boost::shared_ptr<ControlSystemPVManager>& csManager);
236 
243  void applyMapping(const boost::shared_ptr<ControlSystemPVManager>& csManager);
244 
250  void explicitVarMapping(const boost::shared_ptr<ControlSystemPVManager>& csManager);
251 
255  void addAdditionalVariables();
256 
262  void buildFolderStructure(const boost::shared_ptr<ControlSystemPVManager>& csManager);
263 
271  void deepCopyHierarchicalLayer(
272  const boost::shared_ptr<ControlSystemPVManager>& csManager, UA_NodeId layer, UA_NodeId target);
273 
278  UA_NodeId getOwnNodeId();
279 
284  vector<ua_processvariable*> getVariables();
285 
290  void workerThread();
291 
295  void readConfig();
296 
302  vector<string> getAllNotMappableVariablesNames();
303 
304  // ToDo documentation
305  vector<string> getAllMappedPvSourceNames();
306 
311  void fillBuildInfo(UA_ServerConfig* config) const;
312 
317  ServerConfig get_server_config();
318 
324  static UA_StatusCode readLogLevel(UA_Server* server, const UA_NodeId* sessionId, void* sessionContext,
325  const UA_NodeId* nodeId, void* nodeContext, UA_Boolean sourceTimeStamp, const UA_NumericRange* range,
326  UA_DataValue* dataValue);
327 
333  static UA_StatusCode writeLogLevel(UA_Server* server, const UA_NodeId* sessionId, void* sessionContext,
334  const UA_NodeId* nodeId, void* nodeContext, const UA_NumericRange* range, const UA_DataValue* data);
335  // friend class declaration
336  friend class csa_opcua_adapter;
337  };
338 } // namespace ChimeraTK
ChimeraTK::csa_opcua_adapter
This class provide the two parts of the OPCUA Adapter. First of all the OPCUA server starts with a po...
Definition: csa_opcua_adapter.h:44
ChimeraTK::ServerConfig::password
string password
Definition: ua_adapter.h:40
ChimeraTK::ServerConfig::rootFolder
string rootFolder
Definition: ua_adapter.h:37
ChimeraTK::ServerConfig::descriptionFolder
string descriptionFolder
Definition: ua_adapter.h:38
ChimeraTK::ua_uaadapter
This class provide the opcua server and manage the variable mapping.
Definition: ua_adapter.h:100
ChimeraTK::ServerConfig::allowListFolder
string allowListFolder
Definition: ua_adapter.h:49
ChimeraTK::ServerConfig::issuerListFolder
string issuerListFolder
Definition: ua_adapter.h:51
ChimeraTK::ua_mapped_class
This class mapped all inforamtion into the opca server.
Definition: ua_mapped_class.h:33
ChimeraTK::ServerConfig::username
string username
Definition: ua_adapter.h:41
ChimeraTK::ServerConfig::blockListFolder
string blockListFolder
Definition: ua_adapter.h:50
ChimeraTK::ServerConfig::keyPath
string keyPath
Definition: ua_adapter.h:48
ChimeraTK::FolderInfo
This struct represents a folder in OPCUA with its own node id and with his parent and child node id....
Definition: ua_adapter.h:65
ChimeraTK::ua_uaadapter::folder_with_history
vector< string > folder_with_history
Definition: ua_adapter.h:161
ChimeraTK::ServerConfig
This struct represents a server config. If the hole config file is prased, all information will be st...
Definition: ua_adapter.h:36
csManager
boost::shared_ptr< ChimeraTK::ControlSystemPVManager > csManager
Definition: csa_opcua_application.cpp:59
node_historizing.h
ChimeraTK::ua_uaadapter::exclude
vector< string > exclude
Definition: ua_adapter.h:160
generate_open62541CCode.line
line
Definition: generate_open62541CCode.py:126
ChimeraTK::FolderInfo::folderName
string folderName
Name of the folder.
Definition: ua_adapter.h:69
ChimeraTK
Definition: csa_additionalvariable.h:28
generate_open62541CCode.logger
logger
Definition: generate_open62541CCode.py:29
ChimeraTK::ServerConfig::certPath
string certPath
Definition: ua_adapter.h:47