30 using namespace OpcUa;
34 Tabs(
unsigned num = 0)
43 for (
unsigned i = 0; i < tabs.
Num; ++i)
63 return "sign and encrypt";
81 return "client and server";
84 return "discovery server";
102 return "x509v3 certificate";
105 return "WS_Security token";
129 result +=
"variable";
149 result +=
"object type";
159 result +=
"variable type";
169 result +=
"reference type";
179 result +=
"data type";
202 const Tabs dataTabs(tabs.
Num + 2);
208 std::cout << tabs <<
"Two byte:" << std::endl;
215 std::cout << tabs <<
"Four byte:" << std::endl;
223 std::cout << tabs <<
"Numeric:" << std::endl;
231 std::cout << tabs <<
"String: " << std::endl;
239 std::cout << tabs <<
"Binary: " << std::endl;
241 std::cout << dataTabs <<
"Identifier: ";
245 std::cout << std::endl;
251 std::cout << tabs <<
"Guid: " << std::endl;
254 std::cout << dataTabs <<
"Identifier: " <<
std::hex << guid.Data1 <<
"-" << guid.Data2 <<
"-" << guid.Data3;
256 for (
auto val : guid.Data4) {std::cout << (unsigned)val; }
263 std::cout << tabs <<
"unknown id type:" << (unsigned)encoding << std::endl;
270 std::cout << tabs <<
"Namespace URI: " << nodeId.
NamespaceURI << std::endl;
275 std::cout << tabs <<
"Server index: " << nodeId.
ServerIndex << std::endl;
281 std::cout << tabs <<
"Id: " << policy.
PolicyId << std::endl;
282 std::cout << tabs <<
"TokenType: " << GetName(policy.
TokenType) << std::endl;
283 std::cout << tabs <<
"IssuedTokenType: " << policy.
IssuedTokenType << std::endl;
284 std::cout << tabs <<
"IssuerEndpointUrl: " << policy.
IssuerEndpointUrl << std::endl;
285 std::cout << tabs <<
"SecurityPolicyUri: " << policy.
SecurityPolicyUri << std::endl;
292 std::cout << tab <<
"Type: " << GetName(desc.
ApplicationType) << std::endl;
294 std::cout << tab <<
"ProductURI: " << desc.
ProductUri << std::endl;
295 std::cout << tab <<
"GatewayServerURI: " << desc.
GatewayServerUri << std::endl;
300 std::cout << tab <<
"DiscoveryProfileURLs: ";
304 std::cout <<
"'" << *it <<
"' ";
307 std::cout << std::endl;
313 std::cout << tab <<
"URL: " << desc.
EndpointUrl << std::endl;
314 std::cout << tab <<
"SecurityPolicyUri: " << desc.
SecurityPolicyUri << std::endl;
315 std::cout << tab <<
"SecurityLevel: " << GetName(desc.
SecurityMode) <<
" (" << (int)desc.
SecurityMode <<
")" << std::endl;
317 std::cout << tab <<
"SecurityLevel: " << (
int)desc.
SecurityLevel << std::endl;
318 std::cout << tab <<
"Server description: " << std::endl;
323 std::cout << tab <<
"User identify tokens: " << std::endl;
327 std::cout <<
Tabs(tab.
Num + 2) <<
"token: " << std::endl;
331 std::cout << std::endl;
340 std::shared_ptr<OpcUa::EndpointServices> service = computer.
Endpoints();
342 std::vector<OpcUa::EndpointDescription> endpoints = service->GetEndpoints(filter);
344 for (
auto it = endpoints.begin(); it != endpoints.end(); ++it)
346 std::cout <<
"endpoint:" << std::endl;
353 std::shared_ptr<OpcUa::EndpointServices> service = computer.
Endpoints();
355 std::vector<OpcUa::ApplicationDescription> applications = service->FindServers(filter);
359 std::cout <<
"Application:" << std::endl;
366 const Tabs tabs1(tabs.
Num + 2);
367 std::cout << tabs <<
"DisplayName: " << desc.
DisplayName.
Text << std::endl;
369 std::cout << tabs <<
"Is Forward: " << desc.
IsForward << std::endl;
371 std::cout << tabs <<
"Target Node class: " << GetNodeClassName(static_cast<unsigned>(desc.
TargetNodeClass)) << std::endl;
372 std::cout << tabs <<
"Target NodeId:" << std::endl;
375 std::cout << tabs <<
"TypeId:" << std::endl;
378 std::cout << tabs <<
"Type definition Id:" << std::endl;
396 std::vector<OpcUa::BrowseResult> results = view.
Browse(query);
405 if (results[0].Referencies.empty())
410 for (
auto refIt : results[0].Referencies)
412 std::cout <<
"reference:" << std::endl;
413 PrintReference(refIt,
Tabs(2));
414 std::cout << std::endl;
422 struct VariantPrinter
424 template <
typename T>
425 void PrintValue(
const T & val)
432 std::cout <<
"!!!TODO!!!";
437 std::cout <<
"!!!TODO!!!";
442 std::cout << text.
Text << std::endl;
450 template <
typename T>
451 void OnScalar(
const T & val)
454 std::cout << std::endl;
457 template <
typename T>
458 void OnContainer(
const std::vector<T> & vals)
460 typedef typename std::vector<T>::const_iterator Iterator;
462 for (Iterator it = vals.begin(); it != vals.end(); ++it)
468 std::cout << std::endl;
474 VariantPrinter printer;
481 std::cout << tabs <<
"boolean: ";
487 std::cout << tabs <<
"signed byte: ";
493 std::cout << tabs <<
"byte: ";
499 std::cout << tabs <<
"int16: ";
505 std::cout << tabs <<
"unsigned int16: ";
511 std::cout << tabs <<
"int32: ";
517 std::cout << tabs <<
"unsigned int32: ";
523 std::cout << tabs <<
"int64: ";
530 std::cout << tabs <<
"unsigned int64: ";
537 std::cout << tabs <<
"float: ";
544 std::cout << tabs <<
"double: ";
551 std::cout << tabs <<
"string: ";
559 std::cout << tabs <<
"NodeId: " << std::endl;
565 std::cout << tabs <<
"Name: ";
571 std::cout << tabs <<
"Text: ";
594 throw std::logic_error(
"Unknown variant type.");
598 std::cout << std::endl;
603 const Tabs tabs1(tabs.
Num + 2);
607 std::cout << tabs <<
"Status code:" << std::endl;
608 std::cout << tabs1 <<
"0x" << std::hex << static_cast<uint32_t>(value.
Status) << std::endl;
613 std::cout << tabs <<
"Value:" << std::endl;
623 attribute.
NodeId = nodeId;
626 const std::vector<DataValue> values = attributes.
Read(params);
628 if (values.size() != 1)
630 std::cout <<
"Server returned " << values.size() <<
" instead of 1." << std::endl;
634 std::cout <<
"data value:" << std::endl;
641 attribute.
NodeId = nodeId;
643 attribute.
Value = value;
644 std::vector<StatusCode> statuses = attributes.
Write(std::vector<OpcUa::WriteValue>(1, attribute));
648 std::cout <<
"Status code: 0x" << std::hex << static_cast<uint32_t>(status) << std::endl;
673 std::shared_ptr<OpcUa::Services> computer = addon->Connect(serverURI);
677 PrintEndpoints(*computer);
683 PrintServers(*computer);
697 computer->ActivateSession(session_parameters);
703 Browse(*computer->Views(), nodeId);
710 Read(*computer->Attributes(), nodeId, attributeId);
718 Write(*computer->Attributes(), nodeId, attributeId, value);
723 CreateSubscription(*computer->Subscriptions());
728 std::cout <<
"nothing to do" << std::endl;
732 computer->CloseSession();
737 std::cout <<
"Registering new module." << std::endl;
742 std::cout <<
"Id: " << addonId << std::endl;
743 std::cout <<
"Path: " << modulePath << std::endl;
744 std::cout <<
"Configuration file: " << configDir << std::endl;
747 const Common::ModulesConfiguration::const_iterator moduleIt = std::find_if(config.
Modules.begin(), config.
Modules.end(), [&addonId](
const Common::ModuleConfiguration & config) {
return config.Id == addonId;});
749 if (moduleIt != config.
Modules.end())
751 std::cerr <<
"Module already registered." << std::endl;
759 config.
Modules.push_back(module);
761 std::cout <<
"Successfully registered." << std::endl;
769 std::cout <<
"Unregistering module." << std::endl;
770 std::cout <<
"Id: " << addonId << std::endl;
771 std::cout <<
"Configuration file: " << configDir << std::endl;
776 if (moduleIt == config.
Modules.end())
778 std::cerr <<
"Module not found" << std::endl;
782 config.
Modules.erase(moduleIt);
785 std::cout <<
"Successfully unregistered." << std::endl;
790 int main(
int argc,
char ** argv)
806 return RegisterNewModule(cmd);
811 return UnregisterModule(cmd);
817 std::vector<Common::AddonInformation> infos(config.
Modules.size());
823 manager->Register(addon);
826 Process(cmd, *manager);
831 catch (
const std::exception & exc)
833 std::cout << exc.what() << std::endl;
838 std::cout <<
"Unknown error." << std::endl;
Configuration ParseConfigurationFiles(const std::string &directory)
void SaveConfiguration(const ModulesConfiguration &configuration, const std::string &configPath)
std::vector< OpcUa::ReadValueId > AttributesToRead
struct OpcUa::NodeId::NumericDataType NumericData
std::vector< OpcUa::UserTokenPolicy > UserIdentityTokens
std::string SecurityPolicyUri
Common::AddonInformation GetAddonInfomation(const ModuleConfiguration &config)
bool IsFindServersOperation() const
OpcUa::CreateSubscriptionParameters Parameters
virtual SubscriptionData CreateSubscription(const CreateSubscriptionRequest &, std::function< void(PublishResult)> callbackPublish)=0
ApplicationDescription ClientDescription
IntFormatSpec< int, TypeSpec<'x'> > hex(int value)
std::string GatewayServerUri
virtual std::shared_ptr< Addon > GetAddon(const AddonId &id) const =0
getting addon by id
bool IsGetEndpointsOperation() const
std::vector< BrowseDescription > NodesToBrowse
const uint8_t DATA_VALUE_STATUS_CODE
double RequestedPublishingInterval
uint32_t MaxNotificationsPerPublish
std::string SecurityPolicyUri
std::string IssuedTokenType
std::string GetModuleId() const
std::vector< T > Browse(const NodeId &node, NodeClass nodeClassMask, Services::SharedPtr services)
LocalizedText DisplayName
uint32_t RevisedLifetimeCount
uint32_t RequestedMaxKeepAliveCount
struct OpcUa::NodeId::GuidDataType GuidData
bool IsHelpOperation() const
struct OpcUa::NodeId::TwoByteDataType TwoByteData
bool IsBrowseOperation() const
double RevisedPublishingInterval
uint32_t RequestedLifetimeCount
bool IsUnregisterModuleOperation() const
OpcUa::ApplicationDescription Server
std::string TransportProfileUri
AttributeId GetAttribute() const
void Visit(VariantVisitor &visitor) const
string Print(const T &value)
struct OpcUa::NodeId::BinaryDataType BinaryData
OpcUa::ApplicationType ApplicationType
bool IsReadOperation() const
virtual EndpointServices::SharedPtr Endpoints()=0
AddonsManager::UniquePtr CreateAddonsManager(const Common::Logger::SharedPtr &logger)
Get instance of addons core.
virtual std::vector< BrowseResult > Browse(const OpcUa::NodesQuery &query) const =0
std::string DiscoveryProfileUri
struct OpcUa::NodeId::FourByteDataType FourByteData
NodeClass TargetNodeClass
OpcUa::MessageSecurityMode SecurityMode
OPC UA Address space part. GNU LGPL.
uint32_t RevisedMaxKeepAliveCount
std::string ApplicationUri
NodeId TargetNodeTypeDefinition
std::vector< uint8_t > Identifier
virtual std::vector< StatusCode > Write(const std::vector< OpcUa::WriteValue > &filter)=0
int main(int argc, char **argv)
struct OpcUa::NodeId::StringDataType StringData
std::string GetModulePath() const
OpcUa::LocalizedText ApplicationName
virtual std::vector< DataValue > Read(const OpcUa::ReadParameters &filter) const =0
BrowseResultMask ResultMask
uint32_t MaxReferenciesPerNode
std::string ToString(const AttributeId &value)
bool IsCreateSubscriptionOperation() const
static DateTime Current()
OpcUa::UserTokenType TokenType
std::vector< std::string > DiscoveryUrls
BrowseDirection Direction
std::ostream & operator<<(std::ostream &os, const Node &node)
OpcUa::AttributeId AttributeId
bool IsRegisterModuleOperation() const
bool IsWriteOperation() const
virtual std::vector< BrowseResult > BrowseNext() const =0
std::string GetServerURI() const
std::vector< ModuleConfiguration > Modules
std::string IssuerEndpointUrl
std::shared_ptr< logger > stderr_color_mt(const std::string &logger_name)
OpcUa::AttributeId AttributeId
std::string GetConfigDir() const