Skip to content

Commit

Permalink
OPC UA 服务器对象析构时会停止并自动阻塞run线程
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoxi-scut committed Jun 22, 2024
1 parent 14c0fdf commit 5ea3cb6
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 31 deletions.
1 change: 1 addition & 0 deletions 3rdparty/open62541/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ project(

option(UA_ENABLE_PUBSUB "Enable the PubSub protocol" ON)
rmvl_download(${OPEN62541_PKG} GIT "https://github.com/open62541/open62541.git : v1.3.8")
set(open62541_VERSION "1.3.8" CACHE INTERNAL "open62541 version")

if(NOT BUILD_SHARED_LIBS)
install(
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

**机器人控制与视觉库**

| 构建配置 | 编译器/环境 | Github Actions 工作流状态 |
| :------: | :----------------------------------------------------------: | :----------------------------------------------------------: |
| CMake | GCC 7.5.0 x86_64-linux-gnu<br />GCC 9.4.0 x86_64-linux-gnu<br />GCC 12.3.0 x86_64-linux-gnu<br />GCC 14.0.1 x86_64-linux-gnu | [![1.x in Linux](https://github.com/cv-rmvl/rmvl/actions/workflows/linux-1.x.yml/badge.svg)](https://github.com/cv-rmvl/rmvl/actions/workflows/linux-1.x.yml) |
| 编译器 | OpenCV | onnxruntime | open62541 | 工作流状态 |
| :------------------------------------------------------: | :------------------------------------: | :-----------------------------: | :------------------------------------: | :----------------------------------------------------------: |
| GCC 7.5.0<br />GCC 9.4.0<br />GCC 12.3.0<br />GCC 14.0.1 | 4.7.0<br />4.7.0<br />4.8.0<br />4.9.0 | 1.12<br />1.10<br />1.12<br />— | 1.3.8<br />1.3.8<br />1.3.8<br />1.4.0 | [![1.x in Linux](https://github.com/cv-rmvl/rmvl/actions/workflows/linux-1.x.yml/badge.svg)](https://github.com/cv-rmvl/rmvl/actions/workflows/linux-1.x.yml) |

RMVL 最初是面向 RoboMaster 赛事的视觉库,现在此之上逐步完善有关基础算法、机器视觉、通信的功能,旨在打造适用范围广、使用简洁、架构统一、功能强大的视觉控制一体库。

### 项目资源

* 用户手册: <https://cv-rmvl.github.io>

* 问题: <https://github.com/cv-rmvl/rmvl/issues>
* Issues: <https://github.com/cv-rmvl/rmvl/issues>

* VSCode 扩展插件

Expand Down
4 changes: 0 additions & 4 deletions modules/opcua/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
if(NOT BUILD_OPEN62541 AND WITH_OPEN62541)
find_package(open62541 REQUIRED)
endif()

set(BUILD_rmvl_opcua_INIT ${WITH_OPEN62541})
# generate parameters module
rmvl_generate_para(opcua)
Expand Down
7 changes: 2 additions & 5 deletions modules/opcua/include/rmvl/opcua/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,11 @@ class Client
* @param[out] outputs 输出参数列表
* @return 是否成功完成当前操作
*/
inline bool call(const std::string &name, const std::vector<Variable> &inputs, std::vector<Variable> &outputs)
{
return call(nodeObjectsFolder, name, inputs, outputs);
}
inline bool call(const std::string &name, const std::vector<Variable> &inputs, std::vector<Variable> &outputs) { return call(nodeObjectsFolder, name, inputs, outputs); }

/**
* @brief 添加视图节点 ViewNode 至 `ViewsFolder` 中
*
*
* @param[in] view `rm::View` 表示的视图
* @return 添加至服务器后,对应视图节点的唯一标识 `NodeId`
*/
Expand Down
7 changes: 1 addition & 6 deletions modules/opcua/include/rmvl/opcua/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ class Server
*/
inline void join() { _run.join(); }

//! 释放服务器资源
inline ~Server() { deleteServer(); }
~Server();

/****************************** 路径搜索 ******************************/

Expand Down Expand Up @@ -234,10 +233,6 @@ class Server
* @return 是否创建并触发成功?
*/
bool triggerEvent(const NodeId &node_id, const Event &event);

protected:
//! 释放服务器资源
void deleteServer();
};

//! @} opcua
Expand Down
8 changes: 2 additions & 6 deletions modules/opcua/src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Client::~Client()
return;
auto status = UA_Client_disconnect(_client);
if (status != UA_STATUSCODE_GOOD)
UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, "Failed to disconnect the client");
WARNING_("Failed to disconnect the client");
UA_Client_delete(_client);
_client = nullptr;
}
Expand All @@ -74,8 +74,7 @@ void Client::spin()
auto status = UA_Client_run_iterate(_client, para::opcua_param.SPIN_TIMEOUT);
if (!warning && status != UA_STATUSCODE_GOOD)
{
UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_CLIENT,
"No events and message received, spinning indefinitely, error status: %s", UA_StatusCode_name(status));
WARNING_("No events and message received, spinning indefinitely, error status: %s", UA_StatusCode_name(status));
warning = true;
}
warning = (status == UA_STATUSCODE_GOOD) ? false : warning;
Expand Down Expand Up @@ -256,10 +255,7 @@ bool Client::monitor(NodeId node, const std::vector<std::string> &names, UA_Clie
return false;
}
else
{
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, "Created event monitor, monitor id: %d", monitor_id);
return true;
}
}

////////////////////////// Private //////////////////////////
Expand Down
12 changes: 6 additions & 6 deletions modules/opcua/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ void Server::start()
});
}

void Server::deleteServer()
Server::~Server()
{
_running = false;
if (_run.joinable())
_run.join();
UA_Server_delete(_server);
}

Expand Down Expand Up @@ -349,9 +352,7 @@ NodeId Server::addObjectTypeNode(const ObjectType &otype)
UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_MODELLINGRULE_MANDATORY), true);
if (status != UA_STATUSCODE_GOOD)
{
UA_LOG_ERROR(
UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Failed to add reference during adding object type node, browse name: %s, error code: %s",
browse_name.c_str(), UA_StatusCode_name(status));
ERROR_("Failed to add reference during adding object type node, browse name: %s, error code: %s", browse_name.c_str(), UA_StatusCode_name(status));
return UA_NODEID_NULL;
}
}
Expand Down Expand Up @@ -384,8 +385,7 @@ NodeId Server::addObjectNode(const Object &obj, NodeId parent_id)
}
if (type_id.empty())
{
UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
"The object node \"%s\" does not belong to any object type node", obj.browse_name.c_str());
WARNING_("The object node \"%s\" does not belong to any object type node", obj.browse_name.c_str());
type_id = nodeBaseObjectType;
}
// 添加至服务器
Expand Down

0 comments on commit 5ea3cb6

Please sign in to comment.