Files
softbus_OPC/README.md
flower_linux 0cf0713dc5 phase 2
2026-06-11 19:00:49 +08:00

157 lines
5.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# SoftBus OPC
SoftBus OPC 是 SoftBus 工业数据总线的 **Phase 1 原型**:边缘代理采集现场数据,守护进程经协议插件解析后映射到 OPC UA 地址空间,供北向客户端读写与控制。
更完整的架构与模块说明见 [docs/README.md](docs/README.md)。
## 环境要求
| 依赖 | 说明 |
|------|------|
| CMake ≥ 3.16 | 构建系统 |
| C++17 编译器 | GCC / Clang / MSVC |
| Git | 首次配置时通过 FetchContent 拉取 nlohmann_json、asio |
| Python 3 | open62541 构建时代码生成(系统自带即可) |
| pkg-configLinux可选 | 用于检测 libdbus-1 |
| libdbus-1Linux可选 | 未安装时 DBus IPC 自动禁用 |
| libudevLinux可选 | 未安装时 udev 设备监控使用 stub |
| libzmq可选 | 仅当开启 `SOFTBUS_WITH_ZMQ=ON` 时需要 |
- **open62541 v1.4.6**:已 vendor 至 `third_party/open62541/`,离线可直接构建 OPC UA
- **nlohmann_json、standalone asio**:首次配置时由 CMake FetchContent 自动下载
## 构建
在项目根目录执行:
```bash
cmake -B build -DSOFTBUS_WITH_OPCUA=ON
cmake --build build -j$(nproc)
```
常用 CMake 选项:
| 选项 | 默认值 | 说明 |
|------|--------|------|
| `SOFTBUS_WITH_OPCUA` | `ON` | 启用 OPC UA 服务端open62541 |
| `SOFTBUS_WITH_ZMQ` | `OFF` | 启用 ZeroMQ 传输 |
构建产物位于:
```
build/bin/softbus_daemon # 守护进程(编排 + OPC UA
build/bin/softbus_edge # 边缘代理Mock Modbus 采集)
build/lib/protocol_modbus.so # Modbus 协议插件
build/lib/protocol_canopen.so # CANopen 协议插件
```
### 使用 Qt Creator
项目已包含 `CMakeLists.txt.user`,可直接用 Qt Creator 打开根目录 `CMakeLists.txt`,选择 **Desktop Qt 6.9.2**(或其他已配置的 Kit进行构建。构建目录默认为 `build/Desktop_Qt_6_9_2-Debug/`,可执行文件在其中的 `bin/` 子目录。
## 运行
**请在项目根目录下启动**,以便正确加载 `config/` 下的配置文件与 `config/lib/` 中的协议插件(亦兼容 `build/lib/`)。
### 1. 启动守护进程
```bash
./build/bin/softbus_daemon \
--config config/daemon_profile.json \
--point-table config/point_table.json
```
命令行参数:
| 参数 | 默认值 | 说明 |
|------|--------|------|
| `--config <path>` | `config/daemon_profile.json` | 守护进程运行配置 |
| `--point-table <path>` | `config/point_table.json` | 点表(含 ValveOpening 等) |
| `--model <path>` | 同 `--point-table` | 兼容旧参数名 |
| `--self-test` | — | 启动后自动下发一条 ExecuteCommand 写值测试 |
守护进程启动后会:
-**TCP 9000**`config/daemon_profile.json``uplink.listenPort`)监听边缘上行连接
-**OPC UA 4840**`opcua.port`)暴露地址空间
### 2. 启动边缘代理(另开终端)
```bash
./build/bin/softbus_edge --daemon 127.0.0.1:9000
```
命令行参数:
| 参数 | 默认值 | 说明 |
|------|--------|------|
| `--daemon <host:port>` | `127.0.0.1:9000` | 守护进程 uplink 地址 |
| `--object-ref <ref>` | `DemoSite/DemoSystem/DemoAsset/SimModbusDevice/Temperature` | Mock 采集点位对象引用 |
边缘代理会周期性产生模拟 Modbus 温度数据,经 TCP JSONUplinkWire发送至守护进程最终更新 OPC UA Variable。
### 3. 连接 OPC UA 客户端
使用 UaExpert、opcua-client 等工具连接:
```
opc.tcp://localhost:4840
```
应用名称默认为 `SoftBusDaemon`(可在配置文件中修改)。
## 配置说明
`config/daemon_profile.json` 控制守护进程行为:
```json
{
"opcua": { "port": 4840, "applicationName": "SoftBusDaemon" },
"uplink": { "listenHost": "127.0.0.1", "listenPort": 9000 },
"plugins": { "modbus": "protocol_modbus", "canopen": "protocol_canopen" }
}
```
`config/point_table.json` 定义设备/点位/主题/OPC UA 映射,由 `softbus_registry` 加载并驱动 OPC UA 地址空间与控制闭环。
## 典型联调流程
```bash
# 终端 1守护进程
./build/bin/softbus_daemon
# 终端 2边缘代理
./build/bin/softbus_edge
# 终端 3可选自检模式自动触发写命令
./build/bin/softbus_daemon --self-test
```
`Ctrl+C` 停止各进程。
## 项目结构
```
softbus_OPC/
├── CMakeLists.txt # 顶层 CMake
├── cmake/ # 平台检测、第三方依赖、打包辅助
├── third_party/ # 固定版本第三方源码open62541
├── config/ # 运行时配置与对象模型
├── docs/ # 详细架构与模块文档
└── src/
├── softbus_core/ # 共享内核(模型、插件 ABI、日志
├── softbus_api/ # ExecuteCommand 控制面契约
├── softbus_transport/ # TCP 上行传输
├── softbus_opcua/ # OPC UA 服务端
├── softbus_daemon/ # 守护进程
├── softbus_edge/ # 边缘代理
└── plugins/ # Modbus / CANopen 协议插件
```
## 文档
| 文档 | 内容 |
|------|------|
| [docs/README.md](docs/README.md) | 文档索引与快速开始 |
| [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | 分层架构与模块依赖 |