构建与配置
1. 环境要求
| 依赖 |
版本 |
获取方式 |
| CMake |
≥ 3.16 |
系统安装 |
| C++ 编译器 |
C++17 |
GCC / Clang / MSVC |
| nlohmann_json |
v3.11.3 |
FetchContent 自动 |
| asio |
v1.30.2 |
FetchContent 自动 |
| open62541 |
v1.4.6 |
Vendor:third_party/open62541/(SOFTBUS_WITH_OPCUA=ON) |
| Python 3 |
— |
open62541 代码生成(构建时) |
| Threads |
— |
CMake 自动 |
| dbus-1 |
可选 |
系统安装(Linux) |
2. CMake 选项
| 选项 |
默认值 |
说明 |
SOFTBUS_WITH_OPCUA |
ON |
启用 open62541 与 softbus_opcua |
SOFTBUS_WITH_ZMQ |
OFF |
ZeroMQ 传输(未使用) |
3. 构建步骤
3.1 输出目录
| 类型 |
路径 |
| 可执行文件 |
build/bin/ |
| 静态库 |
build/lib/ |
| 插件动态库 |
build/lib/ |
3.2 构建目标一览
| Target |
类型 |
输出 |
softbus_core |
STATIC |
libsoftbus_core.a |
softbus_api |
STATIC |
libsoftbus_api.a |
softbus_transport |
STATIC |
libsoftbus_transport.a |
softbus_opcua |
STATIC |
libsoftbus_opcua.a |
protocol_modbus |
SHARED |
libprotocol_modbus.so |
protocol_canopen |
SHARED |
libprotocol_canopen.so |
softbus_edge |
EXECUTABLE |
softbus_edge |
softbus_daemon |
EXECUTABLE |
softbus_daemon |
4. CMake 模块
| 文件 |
职责 |
cmake/SoftbusPackage.cmake |
包宏:softbus_package、softbus_export_include、softbus_add_plugin |
cmake/SoftbusPlatform.cmake |
平台检测、线程、可选 DBus/UDEV/ZMQ、softbus_apply_* |
cmake/SoftbusThirdParty.cmake |
第三方依赖:open62541 vendor + FetchContent(json/asio) |
5. 配置文件
5.1 daemon_profile.json
守护进程运行时配置:
| 字段 |
类型 |
默认值 |
说明 |
opcua.port |
integer |
4840 |
OPC UA 监听端口 |
opcua.applicationName |
string |
SoftBusDaemon |
OPC UA 应用名称 |
uplink.listenHost |
string |
127.0.0.1 |
上行 TCP 监听地址 |
uplink.listenPort |
integer |
9000 |
上行 TCP 监听端口 |
plugins.modbus |
string |
protocol_modbus |
Modbus 插件库名 |
plugins.canopen |
string |
protocol_canopen |
CANopen 插件库名 |
security.tlsEnabled |
boolean |
false |
TLS 开关(Phase 1 未实现) |
security.certPath |
string |
"" |
证书路径 |
security.keyPath |
string |
"" |
私钥路径 |
5.2 softbus_model.json
对象模型与 OPC UA 地址空间定义:
| 字段 |
类型 |
说明 |
site |
string |
站点名(OPC UA Site 节点) |
system |
string |
系统名 |
asset |
string |
资产名 |
devices[].stableDeviceKey |
string |
设备稳定标识(OPC UA Device 节点) |
devices[].protocol |
string |
协议标签 |
devices[].points[].name |
string |
测点名(OPC UA Variable 节点) |
devices[].points[].register |
integer |
寄存器地址 |
devices[].points[].domain |
string |
数据域 |
5.3 ua_model.xml
Phase 2 静态 NodeSet2 XML 占位文件,Phase 1 不使用。守护进程通过 UaAddressSpaceBuilder 从 JSON 动态构建地址空间。
6. 运行指南
6.1 双进程启动
6.2 自测模式
启动后自动向边缘发送一次写命令,验证 OPC UA Method → TCP 下行链路。
6.3 OPC UA 客户端验证
- 使用 UaExpert 或其他 OPC UA 客户端
- 连接
opc.tcp://localhost:4840
- 浏览地址空间:
Objects → DemoSite → ... → Temperature(读 Variable 值)
Objects → SoftBusControl → ExecuteCommand(调用 Method)
6.4 CLI 参数汇总
softbus_daemon:
| 参数 |
默认值 |
--config |
config/daemon_profile.json |
--model |
config/softbus_model.json |
--self-test |
关闭 |
softbus_edge:
| 参数 |
默认值 |
--daemon |
127.0.0.1:9000 |
--object-ref |
DemoSite/DemoSystem/DemoAsset/SimModbusDevice/Temperature |
7. 平台支持
| 平台 |
状态 |
备注 |
| Linux |
支持 |
主要开发与测试平台 |
| Windows |
支持 |
插件扩展名 .dll,路径解析适配 |
| macOS |
未测试 |
理论可编译 |
平台检测由 cmake/SoftbusPlatform.cmake 完成,定义 SOFTBUS_PLATFORM_LINUX / SOFTBUS_PLATFORM_WINDOWS 等宏。
8. 故障排查
| 现象 |
可能原因 |
处理 |
| 守护进程启动失败:plugin load |
插件 .so 不在搜索路径 |
确认 config/lib/protocol_modbus.so 或 build/lib/libprotocol_modbus.so 存在 |
| OPC UA 连接拒绝 |
端口被占用或 OPC UA 未启用 |
检查 4840 端口;确认 SOFTBUS_WITH_OPCUA=ON |
| Variable 值不更新 |
边缘未连接或 objectRef 不匹配 |
确认 edge 运行且 sourceId 与模型路径一致 |
| Method 调用失败 |
JSON 格式错误或 objectRef 无效 |
检查入参 JSON 与五层路径 |
9. 项目目录结构