15 #include <boost/program_options/options_description.hpp> 16 #include <boost/program_options/parsers.hpp> 17 #include <boost/program_options/variables_map.hpp> 21 #define CONFIG_PATH "/etc/opcua/client" 26 namespace po = boost::program_options;
27 using namespace OpcUa;
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";
39 const char * OPTION_MODULE_Id =
"id";
40 const char * OPTION_MODULE_PATH =
"path";
41 const char * OPTION_CONFIG_DIR =
"config-dir";
43 const char * OPTION_Server_URI =
"uri";
44 const char * OPTION_ATTRIBUTE =
"attribute";
45 const char * OPTION_NODE_Id =
"node-id";
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";
63 NodeId GetNodeIdOptionValue(
const po::variables_map & vm)
69 Variant GetOptionValue(
const po::variables_map & vm)
71 if (vm.count(OPTION_VALUE_BYTE))
73 return Variant(vm[OPTION_VALUE_BYTE].as<uint8_t>());
76 if (vm.count(OPTION_VALUE_SBYTE))
78 return Variant(vm[OPTION_VALUE_SBYTE].as<int8_t>());
81 if (vm.count(OPTION_VALUE_UINT16))
83 return Variant(vm[OPTION_VALUE_UINT16].as<uint16_t>());
86 if (vm.count(OPTION_VALUE_INT16))
88 return Variant(vm[OPTION_VALUE_INT16].as<int16_t>());
91 if (vm.count(OPTION_VALUE_UINT32))
93 return Variant(vm[OPTION_VALUE_UINT32].as<uint32_t>());
96 if (vm.count(OPTION_VALUE_INT32))
98 return Variant(vm[OPTION_VALUE_INT32].as<int32_t>());
101 if (vm.count(OPTION_VALUE_UINT64))
103 return Variant(vm[OPTION_VALUE_UINT64].as<uint64_t>());
106 if (vm.count(OPTION_VALUE_INT64))
108 return Variant(vm[OPTION_VALUE_INT64].as<int64_t>());
111 if (vm.count(OPTION_VALUE_FLOAT))
113 return Variant(vm[OPTION_VALUE_FLOAT].as<float>());
116 if (vm.count(OPTION_VALUE_DOUBLE))
118 return Variant(vm[OPTION_VALUE_DOUBLE].as<double>());
121 if (vm.count(OPTION_VALUE_STRING))
123 return Variant(vm[OPTION_VALUE_STRING].as<std::string>());
139 , IsGetEndpoints(false)
143 , IsCreateSubscription(false)
144 , IsFindServers(false)
146 , IsRemoveModule(false)
149 po::options_description desc(
"Parameters");
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.")
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 "'.");
180 po::variables_map vm;
181 po::store(po::parse_command_line(argc, argv, desc), vm);
184 if (vm.count(OPTION_HELP))
187 desc.print(std::cout);
191 if (vm.count(OPTION_Server_URI))
197 if (vm.count(OPTION_NODE_Id))
199 Node = GetNodeIdOptionValue(vm);
202 if (vm.count(OPTION_ATTRIBUTE))
207 Value = GetOptionValue(vm);
209 IsBrowse = vm.count(OPTION_BROWSE) != 0;
210 IsRead = vm.count(OPTION_READ) != 0;
211 IsWrite = vm.count(OPTION_WRITE) != 0;
215 if (vm.count(OPTION_REGISTER_MODULE))
222 if (vm.count(OPTION_UNREGISTER_MODULE))
228 if (vm.count(OPTION_CONFIG_DIR))
bool IsCreateSubscription
#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...
NodeId ToNodeId(const std::string &str, uint32_t defaultNamespace=0)
AttributeId GetAttributeIdOptionValue(const po::variables_map &vm)