opcua_options.cpp
Go to the documentation of this file.
1 
11 #include "opcua_options.h"
12 
14 
15 #include <boost/program_options/options_description.hpp>
16 #include <boost/program_options/parsers.hpp>
17 #include <boost/program_options/variables_map.hpp>
18 #include <iostream>
19 
20 #ifndef CONFIG_PATH
21 #define CONFIG_PATH "/etc/opcua/client"
22 #endif
23 
24 namespace
25 {
26 namespace po = boost::program_options;
27 using namespace OpcUa;
28 
29 const char * OPTION_HELP = "help";
30 const char * OPTION_GET_ENDPOINTS = "get-endpoints";
31 const char * OPTION_BROWSE = "browse";
32 const char * OPTION_READ = "read";
33 const char * OPTION_WRITE = "write";
34 const char * OPTION_CREATE_SUBSCRIPTION = "create-subscription";
35 const char * OPTION_FIND_ServerS = "find-servers";
36 const char * OPTION_REGISTER_MODULE = "register-module";
37 const char * OPTION_UNREGISTER_MODULE = "unregister-module";
38 
39 const char * OPTION_MODULE_Id = "id";
40 const char * OPTION_MODULE_PATH = "path";
41 const char * OPTION_CONFIG_DIR = "config-dir";
42 
43 const char * OPTION_Server_URI = "uri";
44 const char * OPTION_ATTRIBUTE = "attribute";
45 const char * OPTION_NODE_Id = "node-id";
46 
47 
48 const char * OPTION_VALUE_BYTE = "value-byte";
49 const char * OPTION_VALUE_SBYTE = "value-sbyte";
50 const char * OPTION_VALUE_UINT16 = "value-uint16";
51 const char * OPTION_VALUE_INT16 = "value-int16";
52 const char * OPTION_VALUE_UINT32 = "value-uint32";
53 const char * OPTION_VALUE_INT32 = "value-int32";
54 const char * OPTION_VALUE_UINT64 = "value-uint64";
55 const char * OPTION_VALUE_INT64 = "value-int64";
56 const char * OPTION_VALUE_FLOAT = "value-float";
57 const char * OPTION_VALUE_DOUBLE = "value-double";
58 const char * OPTION_VALUE_STRING = "value-string";
59 
60 // codegen
62 
63 NodeId GetNodeIdOptionValue(const po::variables_map & vm)
64 {
65  const std::string & value = vm[OPTION_NODE_Id].as<std::string>();
66  return OpcUa::ToNodeId(value);
67 }
68 
69 Variant GetOptionValue(const po::variables_map & vm)
70 {
71  if (vm.count(OPTION_VALUE_BYTE))
72  {
73  return Variant(vm[OPTION_VALUE_BYTE].as<uint8_t>());
74  }
75 
76  if (vm.count(OPTION_VALUE_SBYTE))
77  {
78  return Variant(vm[OPTION_VALUE_SBYTE].as<int8_t>());
79  }
80 
81  if (vm.count(OPTION_VALUE_UINT16))
82  {
83  return Variant(vm[OPTION_VALUE_UINT16].as<uint16_t>());
84  }
85 
86  if (vm.count(OPTION_VALUE_INT16))
87  {
88  return Variant(vm[OPTION_VALUE_INT16].as<int16_t>());
89  }
90 
91  if (vm.count(OPTION_VALUE_UINT32))
92  {
93  return Variant(vm[OPTION_VALUE_UINT32].as<uint32_t>());
94  }
95 
96  if (vm.count(OPTION_VALUE_INT32))
97  {
98  return Variant(vm[OPTION_VALUE_INT32].as<int32_t>());
99  }
100 
101  if (vm.count(OPTION_VALUE_UINT64))
102  {
103  return Variant(vm[OPTION_VALUE_UINT64].as<uint64_t>());
104  }
105 
106  if (vm.count(OPTION_VALUE_INT64))
107  {
108  return Variant(vm[OPTION_VALUE_INT64].as<int64_t>());
109  }
110 
111  if (vm.count(OPTION_VALUE_FLOAT))
112  {
113  return Variant(vm[OPTION_VALUE_FLOAT].as<float>());
114  }
115 
116  if (vm.count(OPTION_VALUE_DOUBLE))
117  {
118  return Variant(vm[OPTION_VALUE_DOUBLE].as<double>());
119  }
120 
121  if (vm.count(OPTION_VALUE_STRING))
122  {
123  return Variant(vm[OPTION_VALUE_STRING].as<std::string>());
124  }
125 
126  return Variant();
127 }
128 
129 }
130 
131 
132 namespace OpcUa
133 {
134 
135 CommandLine::CommandLine(int argc, char ** argv)
136  : NamespaceIndex(0)
138  , IsHelp(false)
139  , IsGetEndpoints(false)
140  , IsBrowse(false)
141  , IsRead(false)
142  , IsWrite(false)
143  , IsCreateSubscription(false)
144  , IsFindServers(false)
145  , IsAddModule(false)
146  , IsRemoveModule(false)
147 {
148  // Declare the supported options.
149  po::options_description desc("Parameters");
150  desc.add_options()
151  (OPTION_HELP, "produce help message")
152  (OPTION_GET_ENDPOINTS, "List endpoints endpoints.")
153  (OPTION_BROWSE, "browse command.")
154  (OPTION_READ, "read command.")
155  (OPTION_WRITE, "write command.")
156  (OPTION_CREATE_SUBSCRIPTION, "create subscription command.")
157  (OPTION_FIND_ServerS, "find servers command.")
158  (OPTION_REGISTER_MODULE, "Register new module.")
159  (OPTION_UNREGISTER_MODULE, "Unregister module.")
160 
161  (OPTION_Server_URI, po::value<std::string>(), "Uri of the server.")
162  (OPTION_ATTRIBUTE, po::value<std::string>(), "Name of attribute.")
163  (OPTION_NODE_Id, po::value<std::string>(), "NodeId in the form 'nsu=uri;srv=1;ns=0;i=84.")
164  (OPTION_VALUE_BYTE, po::value<uint8_t>(), "Byte value.")
165  (OPTION_VALUE_SBYTE, po::value<int8_t>(), "Signed byte value.")
166  (OPTION_VALUE_UINT16, po::value<uint16_t>(), "UInt16 value.")
167  (OPTION_VALUE_INT16, po::value<int16_t>(), "Int16 value.")
168  (OPTION_VALUE_UINT32, po::value<uint32_t>(), "UInt32 value.")
169  (OPTION_VALUE_INT32, po::value<int32_t>(), "Int32 value.")
170  (OPTION_VALUE_UINT64, po::value<uint64_t>(), "UInt64 value.")
171  (OPTION_VALUE_INT64, po::value<int64_t>(), "Int64 value.")
172  (OPTION_VALUE_FLOAT, po::value<float>(), "Float value.")
173  (OPTION_VALUE_DOUBLE, po::value<double>(), "Double value.")
174  (OPTION_VALUE_STRING, po::value<std::string>(), "String value.")
175  (OPTION_MODULE_Id, po::value<std::string>(), "Id of the new module.")
176  (OPTION_MODULE_PATH, po::value<std::string>(), "Path to the new module shared library.")
177  (OPTION_CONFIG_DIR, po::value<std::string>(), "Path to the directory with modules configuration files. By default '" CONFIG_PATH "'.");
178 
179 
180  po::variables_map vm;
181  po::store(po::parse_command_line(argc, argv, desc), vm);
182  po::notify(vm);
183 
184  if (vm.count(OPTION_HELP))
185  {
186  IsHelp = true;
187  desc.print(std::cout);
188  return;
189  }
190 
191  if (vm.count(OPTION_Server_URI))
192  {
193  ServerURI = vm[OPTION_Server_URI].as<std::string>();
194  }
195 
196 
197  if (vm.count(OPTION_NODE_Id))
198  {
199  Node = GetNodeIdOptionValue(vm);
200  }
201 
202  if (vm.count(OPTION_ATTRIBUTE))
203  {
205  }
206 
207  Value = GetOptionValue(vm);
208  IsGetEndpoints = vm.count(OPTION_GET_ENDPOINTS) != 0;
209  IsBrowse = vm.count(OPTION_BROWSE) != 0;
210  IsRead = vm.count(OPTION_READ) != 0;
211  IsWrite = vm.count(OPTION_WRITE) != 0;
212  IsCreateSubscription = vm.count(OPTION_CREATE_SUBSCRIPTION) != 0;
213  IsFindServers = vm.count(OPTION_FIND_ServerS) != 0;
214 
215  if (vm.count(OPTION_REGISTER_MODULE))
216  {
217  IsAddModule = true;
218  ModulePath = vm[OPTION_MODULE_PATH].as<std::string>();
219  ModuleId = vm[OPTION_MODULE_Id].as<std::string>();
220  }
221 
222  if (vm.count(OPTION_UNREGISTER_MODULE))
223  {
224  IsRemoveModule = true;
225  ModuleId = vm[OPTION_MODULE_Id].as<std::string>();
226  }
227 
228  if (vm.count(OPTION_CONFIG_DIR))
229  {
230  ConfigDir = vm[OPTION_CONFIG_DIR].as<std::string>();
231  }
232 
233  else
234  {
236  }
237 }
238 }
#define CONFIG_PATH
OpcUa client command line options parser. GNU LGPL.
CommandLine(int argc, char **argv)
OPC UA Address space part. GNU LGPL.
A Node object represent an OPC-UA node. It is high level object intended for developper who want to e...
Definition: node.h:42
NodeId ToNodeId(const std::string &str, uint32_t defaultNamespace=0)
std::string ModulePath
AttributeId GetAttributeIdOptionValue(const po::variables_map &vm)
std::string ModuleId
std::string ServerURI
std::string ConfigDir


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:07