ChimeraTK-ControlSystemAdapter-OPCUAAdapter 04.00.05
Loading...
Searching...
No Matches
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
26#include <open62541/config.h>
27#include <open62541/plugin/accesscontrol.h>
28#include <open62541/plugin/accesscontrol_default.h>
29#include <open62541/plugin/historydata/history_data_gathering.h>
30#include <open62541/server_config_default.h>
31
32#include <memory>
33
34using namespace std;
35
36namespace ChimeraTK {
37 struct ServerConfig {
38 string rootFolder;
40 UA_Boolean UsernamePasswordLogin = UA_FALSE;
41 string password;
42 string username;
43 string applicationName = "OPCUA-Adapter";
44 uint16_t opcuaPort = 16664;
45 bool enableSecurity = false;
46 bool unsecure = false;
47 UA_LogLevel logLevel = UA_LOGLEVEL_INFO;
48 string certPath;
49 string keyPath;
53 vector<AdapterHistorySetup> history{};
54 vector<AdapterFolderHistorySetup> historyfolders{};
55 vector<AdapterPVHistorySetup> historyvariables{};
56 };
57
66 struct FolderInfo {
70 string folderName;
72 UA_NodeId folderNodeId = UA_NODEID_NULL;
74 UA_NodeId nextFolderNodeId = UA_NODEID_NULL;
76 UA_NodeId prevFolderNodeId = UA_NODEID_NULL;
77 };
78
102 private:
103 UA_ServerConfig* server_config{nullptr};
104
105 UA_NodeId variablesListId;
106 UA_NodeId constantsListId;
107 std::shared_ptr<UA_DataTypeArray> customDataTypes;
108 UA_DataType customType[1];
109
110 vector<FolderInfo> folderVector;
111 UA_NodeId ownNodeId;
112 UA_NodeId configNodeId;
113 string pvSeperator;
114 UA_Boolean mappingExceptions;
115
116 ServerConfig serverConfig;
117 UA_Logger logger;
118
119 vector<ua_processvariable*> variables;
120 vector<ua_additionalvariable*> additionalVariables;
121 vector<ua_processvariable*> mappedVariables;
122
123 std::shared_ptr<xml_file_handler> fileHandler;
124
127 void constructServer();
128
133 UA_StatusCode mapSelfToNamespace();
134
143 UA_NodeId createUAFolder(UA_NodeId basenodeId, const string& folderName, const string& description = "");
144
157 void raiseError(std::string errorMesssage, std::string consequenceMessage, const int& line = -1);
158
159 public:
160 bool running = false;
161 // TODO move this field to private and add getter and setter
162 vector<string> exclude;
163 vector<string> folder_with_history;
164
173 ua_uaadapter(const string& configPath);
174
180 virtual ~ua_uaadapter();
181
186 UA_DateTime getSourceTimeStamp();
187
192 UA_Server* getMappedServer();
193
199 UA_NodeId createFolderPath(UA_NodeId basenodeid, vector<string> folderPathVector);
200
207 UA_NodeId createFolder(UA_NodeId basenodeid, const string& folderName, const string& description = "");
208
214 UA_NodeId existFolderPath(UA_NodeId basenodeid, const vector<string>& folderPath);
215
221 UA_NodeId existFolder(UA_NodeId basenodeid, const string& folderName);
222
230 UA_NodeId enrollFolderPathFromString(const string& path, const string& seperator);
231
237 void implicitVarMapping(const std::string& varName, const boost::shared_ptr<ControlSystemPVManager>& csManager);
238
245 void applyMapping(const boost::shared_ptr<ControlSystemPVManager>& csManager);
246
252 void explicitVarMapping(const boost::shared_ptr<ControlSystemPVManager>& csManager);
253
258
264 void buildFolderStructure(const boost::shared_ptr<ControlSystemPVManager>& csManager);
265
274 const boost::shared_ptr<ControlSystemPVManager>& csManager, UA_NodeId layer, UA_NodeId target);
275
280 UA_NodeId getOwnNodeId();
281
286 vector<ua_processvariable*> getVariables();
287
292 void workerThread();
293
297 void readConfig();
298
304 vector<string> getAllNotMappableVariablesNames();
305
306 // ToDo documentation
307 vector<string> getAllMappedPvSourceNames();
308
313 void fillBuildInfo(UA_ServerConfig* config) const;
314
320
326 static UA_StatusCode readLogLevel(UA_Server* server, const UA_NodeId* sessionId, void* sessionContext,
327 const UA_NodeId* nodeId, void* nodeContext, UA_Boolean sourceTimeStamp, const UA_NumericRange* range,
328 UA_DataValue* dataValue);
329
335 static UA_StatusCode writeLogLevel(UA_Server* server, const UA_NodeId* sessionId, void* sessionContext,
336 const UA_NodeId* nodeId, void* nodeContext, const UA_NumericRange* range, const UA_DataValue* data);
337 // friend class declaration
338 friend class csa_opcua_adapter;
339 };
340} // namespace ChimeraTK
This class provide the two parts of the OPCUA Adapter.
This class mapped all inforamtion into the opca server.
This class provide the opcua server and manage the variable mapping.
Definition ua_adapter.h:101
void fillBuildInfo(UA_ServerConfig *config) const
Fill server build information.
void workerThread()
Create and start a thread for the opcua server instance.
void implicitVarMapping(const std::string &varName, const boost::shared_ptr< ControlSystemPVManager > &csManager)
Start implicit mapping process.
UA_NodeId createFolder(UA_NodeId basenodeid, const string &folderName, const string &description="")
Creates a folder in the given parent node.
static UA_StatusCode writeLogLevel(UA_Server *server, const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *nodeId, void *nodeContext, const UA_NumericRange *range, const UA_DataValue *data)
callback function used to change the servers logging level.
vector< ua_processvariable * > getVariables()
Methode that returns all <ua_processvariable> of the class.
UA_NodeId existFolder(UA_NodeId basenodeid, const string &folderName)
Check if a folder exist in opcua server.
void buildFolderStructure(const boost::shared_ptr< ControlSystemPVManager > &csManager)
Read mapping file and and add contained folders to the server.
void addAdditionalVariables()
Read mapping file and add contained additional variables to the server.
UA_NodeId getOwnNodeId()
Methode that returns the node id of the instanced class.
UA_DateTime getSourceTimeStamp()
Return the timestamp of the node.
void deepCopyHierarchicalLayer(const boost::shared_ptr< ControlSystemPVManager > &csManager, UA_NodeId layer, UA_NodeId target)
Copy (recursively) the content of a folder to a new location.
UA_Server * getMappedServer()
Return the OPC UA Server instance.
void explicitVarMapping(const boost::shared_ptr< ControlSystemPVManager > &csManager)
Read mapping file and apply contained PV mappings.
UA_NodeId existFolderPath(UA_NodeId basenodeid, const vector< string > &folderPath)
Check if a folder path exist in opcua server.
void readConfig()
This Methode reads the config-tag form the given <variableMap.xml>.
UA_NodeId createFolderPath(UA_NodeId basenodeid, vector< string > folderPathVector)
Create a path of folders in the given parent node.
vector< string > getAllMappedPvSourceNames()
UA_NodeId enrollFolderPathFromString(const string &path, const string &seperator)
Create folder structure based on the given path.
void applyMapping(const boost::shared_ptr< ControlSystemPVManager > &csManager)
Read mapping file and apply the contained folders, additional variables and pv mappings.
vector< string > folder_with_history
Definition ua_adapter.h:163
vector< string > exclude
Definition ua_adapter.h:162
virtual ~ua_uaadapter()
Destrructor of the class.
vector< string > getAllNotMappableVariablesNames()
Methode to get all names from all potential VarableNodes from XML-Mappingfile which could not allocat...
static UA_StatusCode readLogLevel(UA_Server *server, const UA_NodeId *sessionId, void *sessionContext, const UA_NodeId *nodeId, void *nodeContext, UA_Boolean sourceTimeStamp, const UA_NumericRange *range, UA_DataValue *dataValue)
callback function used to read the servers logging level.
ServerConfig get_server_config()
get ServerConfig.
boost::shared_ptr< ChimeraTK::ControlSystemPVManager > csManager
This struct represents a folder in OPCUA with its own node id and with his parent and child node id.
Definition ua_adapter.h:66
string folderName
Name of the folder.
Definition ua_adapter.h:70
UA_NodeId nextFolderNodeId
NodeId from the child folder.
Definition ua_adapter.h:74
UA_NodeId folderNodeId
NodeId from the folder from opcua server.
Definition ua_adapter.h:72
UA_NodeId prevFolderNodeId
NodeId from the parent folder.
Definition ua_adapter.h:76
This struct represents a server config.
Definition ua_adapter.h:37
UA_Boolean UsernamePasswordLogin
Definition ua_adapter.h:40
vector< AdapterPVHistorySetup > historyvariables
Definition ua_adapter.h:55
vector< AdapterHistorySetup > history
Definition ua_adapter.h:53
vector< AdapterFolderHistorySetup > historyfolders
Definition ua_adapter.h:54