1- #include " opcuaClient.h"
21#include " opcua.h"
3- #include " variantAccess .h"
2+ #include " opcuaClient .h"
43
54#include < open62541/client_config_default.h>
65#include < open62541/client_highlevel.h>
7- #include < open62541/plugin/log_stdout.h>
8- #include < open62541/plugin/pki_default.h>
96#include < open62541/client_subscriptions.h>
107#include < open62541/client.h>
118#include < open62541/common.h>
12- #include < iostream>
9+ #include < open62541/plugin/log_stdout.h>
10+ #include < open62541/plugin/pki_default.h>
1311
14- #include < cover/coVRPluginSupport.h>
15- #include < cover/ui/VectorEditField.h>
1612#include < cover/coVRMSController.h>
13+ #include < cover/coVRPluginSupport.h>
1714#include < cover/ui/SelectionList.h>
15+ #include < cover/ui/VectorEditField.h>
1816
1917#include < algorithm>
18+ #include < iostream>
2019
2120using namespace opencover ::opcua;
2221using namespace opencover ::opcua::detail;
@@ -333,12 +332,6 @@ void Client::registerNode(const NodeRequest &nodeRequest)
333332
334333}
335334
336- void Client::queueUnregisterNode (size_t id)
337- {
338- Guard g (m_mutex);
339- m_nodesToUnregister.push_back (id);
340- }
341-
342335void Client::unregisterNode (size_t id)
343336{
344337 for (auto &node : m_availableNodes)
@@ -400,17 +393,65 @@ UA_Variant_ptr Client::getValue(ClientNode *node)
400393 return UA_Variant_ptr ();
401394}
402395
403- double Client::getNumericScalar ( const ObserverHandle &handle, UA_DateTime *timestamp )
396+ std::unique_ptr<opencover::dataclient::detail::MultiDimensionalArrayBase> Client::getArrayImpl (std::type_index type, const std::string &name )
404397{
405- return getNumericScalar (handle.m_node ->name , timestamp);
398+ auto node = findNode (name);
399+ if (!node)
400+ return nullptr ;
401+ return getArrayImpl (type, node);
402+
406403}
407404
408- double Client::getNumericScalar ( const std::string &nodeName, UA_DateTime *timestamp )
405+ std::unique_ptr<opencover::dataclient::detail::MultiDimensionalArrayBase> Client::getArrayImpl ( std::type_index type, ClientNode* node )
409406{
410- return getNumericScalar (findNode (nodeName), timestamp);
407+ if (!node)
408+ return nullptr ;
409+ std::lock_guard<std::mutex> g (m_mutex);
410+ auto variant = getValue (node);
411+
412+ if (!variant.get ())
413+ return nullptr ;
414+ for_<8 >([this , &node, &variant, &type] (auto i) {
415+ typedef typename detail::Type<numericalTypes[i.value ]>::type T;
416+ if (node->type == numericalTypes[i.value ])
417+ {
418+ if (type != std::type_index (typeid (T)))
419+ {
420+ std::cerr << " opcua type mismatch " << node->type << " requested " << type.name () << std::endl;
421+ return ;
422+ }
423+ auto array = std::make_unique<dataclient::MultiDimensionalArray<T>>();
424+ array->timestamp = variant.timestamp ;
425+ auto size = std::max (size_t (1 ), variant->arrayLength );
426+ array->dimensions .push_back (size);
427+ array->data .resize (size);
428+ std::memcpy (array->data .data (), variant->data , size * sizeof (T));
429+ if (variant.get ()->arrayDimensionsSize > 0 )
430+ {
431+ array->dimensions .resize (variant->arrayDimensionsSize );
432+ for (size_t i = 0 ; i < variant.get ()->arrayDimensionsSize ; i++)
433+ {
434+ array->dimensions .push_back (variant->arrayDimensions [i]);
435+ }
436+ }
437+ }
438+ });
439+ return nullptr ;
411440}
412441
413- double Client::getNumericScalar (ClientNode *node, UA_DateTime *timestamp)
442+
443+ double Client::getNumericScalar (const opencover::dataclient::ObserverHandle &handle, double *timestamp)
444+ {
445+ return 0 ;
446+ }
447+
448+ double Client::getNumericScalar (const std::string &nodeName, double *timestamp)
449+ {
450+ return 0 ;
451+ // return getNumericScalar(findNode(nodeName), timestamp);
452+ }
453+
454+ double Client::getNumericScalar (ClientNode *node, double *timestamp)
414455{
415456 double retval = 0 ;
416457 if (!node)
@@ -420,11 +461,12 @@ double Client::getNumericScalar(ClientNode *node, UA_DateTime *timestamp)
420461 typedef typename detail::Type<numericalTypes[i.value ]>::type T;
421462 if (node->type == numericalTypes[i.value ])
422463 {
423- auto v = getArray<T>(node);
424- if (v.isScalar ()){
464+ auto array = getArrayImpl (std::type_index (typeid (T)), node);
465+ auto v = dynamic_cast <dataclient::MultiDimensionalArray<T>*>(array.get ());
466+ if (v->isScalar ()){
425467 if (timestamp)
426- *timestamp = v. timestamp ;
427- retval = ( double )v. data [0 ];
468+ *timestamp = v-> timestamp ;
469+ retval = static_cast < double >(v-> data [0 ]) ;
428470 }
429471 }
430472 });
@@ -492,10 +534,10 @@ bool Client::connectCommunication()
492534 return true ;
493535}
494536
495- ObserverHandle Client::observeNode (const std::string &name)
537+ opencover::dataclient:: ObserverHandle Client::observeNode (const std::string &name)
496538{
497539 Guard g (m_mutex);
498- ObserverHandle id (m_requestId, this );
540+ dataclient:: ObserverHandle id (m_requestId, this );
499541 auto node = findNode (name);
500542 if (!node)
501543 {
@@ -504,8 +546,8 @@ ObserverHandle Client::observeNode(const std::string &name)
504546 return id;
505547
506548 }
507- m_nodesToObserve.push_back (NodeRequest{node, m_requestId, &id. m_deleter -> m_client });
508- id.m_node = node;
549+ m_nodesToObserve.push_back (NodeRequest{node, m_requestId, getClientReference (id) });
550+ // id.m_node = node;
509551 ++m_requestId;
510552 return id;
511553}
@@ -570,59 +612,36 @@ bool Client::isConnected() const
570612 return b;
571613}
572614
573- Client::StatusChange Client::statusChanged ( void * caller)
615+ std::vector<std::string> Client::getNodesWith (std::type_index type, bool isScalar) const
574616{
575- Guard g (m_mutex);
576- StatusChange retval = Unchanged;
577- if (msController->isMaster ())
617+ std::vector<std::string> vec{NoNodeName};
618+ for (const auto &node : m_availableNodes)
578619 {
579- auto obs = m_statusObservers.find (caller);
580- if (obs == m_statusObservers.end ())
581- {
582- obs = m_statusObservers.insert (obs, std::make_pair (caller, false ));
583- }
584- if (!obs->second )
585- {
586- obs->second = true ;
587- retval = client != nullptr ? Connected : Disconnected;
588- }
589- }
590- msController->syncData (&retval, sizeof (StatusChange));
591- return retval;
620+ if (node.isScalar () != isScalar)
621+ continue ;
622+ for_<8 >([this , &node, &type, &vec] (auto i) {
623+ typedef typename detail::Type<numericalTypes[i.value ]>::type T;
624+ if (type == std::type_index (typeid (T)))
625+ vec.push_back (node.name );
626+ });
627+ }
628+ return msController->syncVector (vec);
592629}
593630
594- std::vector<std::string> Client::findAvailableNodesWith ( const std::function< bool ( const ClientNode &)> &compare ) const
631+ std::vector<std::string> Client::getNodesWith ( bool isArithmetic, bool isScalar ) const
595632{
596633 std::vector<std::string> vec{NoNodeName};
597634 for (const auto &node : m_availableNodes)
598635 {
599- if (compare (node))
600- vec.push_back (node.name );
636+ if (node.isScalar () != isScalar)
637+ continue ;
638+ for_<8 >([this , &node, isArithmetic, &vec] (auto i) {
639+ typedef typename detail::Type<numericalTypes[i.value ]>::type T;
640+ if (std::is_arithmetic<T>::value == isArithmetic)
641+ vec.push_back (node.name );
642+ });
601643 }
602- return msController->syncVector (vec);
603- }
604-
605- std::vector<std::string> Client::allAvailableScalars () const
606- {
607- return findAvailableNodesWith ([](const ClientNode &n){return n.isScalar ();});
644+ return msController->syncVector (vec);
608645}
609646
610- std::vector<std::string> Client::availableNumericalScalars () const
611- {
612- return findAvailableNodesWith ([](const ClientNode &n){return n.isScalar () && std::find (numericalTypes.begin (), numericalTypes.end (), n.type ) != numericalTypes.end () ;});
613- }
614-
615- std::vector<std::string> Client::allAvailableArrays () const
616- {
617- return findAvailableNodesWith ([](const ClientNode &n){return !n.isScalar ();});
618-
619-
620- }
621- std::vector<std::string> Client::availableNumericalArrays () const
622- {
623- return findAvailableNodesWith ([](const ClientNode &n){return !n.isScalar () && std::find (numericalTypes.begin (), numericalTypes.end (), n.type ) != numericalTypes.end () ;});
624- }
625-
626-
627-
628647
0 commit comments