Files
softbus_OPC/docs/ARCHITECTURE.md
2026-06-09 17:27:24 +08:00

6.2 KiB
Raw Blame History

整体架构

1. 设计目标

SoftBus OPC 将工业现场总线数据通过统一对象模型暴露为 OPC UA 地址空间,实现:

  • 南向:边缘代理采集原始总线帧,经协议插件解析为语义消息
  • 北向OPC UA 客户端读写 Variable、调用 Method 下发控制命令
  • 中间层:守护进程编排 Pipeline保持模型与传输协议中立

2. 分层依赖

L3  可执行层
    softbus_daemon ─────────────────────────────┐
    softbus_edge                                │
                                                │
L2  服务/协议层                                  │
    softbus_opcua · softbus_transport           │
    plugins/protocol_modbus · protocol_canopen  │
                                                │
L1  契约层                                       │
    softbus_api (ExecuteCommand)                │
                                                │
L0  内核层                                       │
    softbus_core ◄──────────────────────────────┘

2.1 链接依赖表

模块 类型 直接依赖
softbus_core STATIC nlohmann_json, Threads
softbus_api STATIC softbus_core
softbus_transport STATIC softbus_core, softbus_api, asio
softbus_opcua STATIC softbus_core, softbus_api, open62541
protocol_modbus SHARED softbus_core
protocol_canopen SHARED softbus_core
softbus_edge EXECUTABLE core, transport, api, asio
softbus_daemon EXECUTABLE core, transport, api, opcu, asio, dbus(可选)

3. 模块职责

分区 路径 职责
softbus_core src/softbus_core 数据模型、身份标识、配置加载、插件 ABI、日志
softbus_api src/softbus_api 跨模块控制面契约ExecuteCommand
softbus_transport src/softbus_transport 边缘↔守护进程 TCP 传输与 UplinkWire 编解码
softbus_opcua src/softbus_opcua open62541 封装:地址空间、模型绑定、方法、事件
softbus_edge src/softbus_edge 边缘代理ingress 采集、上行发送、命令接收
softbus_daemon src/softbus_daemon 编排中心uplink 监听、Pipeline、OPC UA 服务
plugins src/plugins 协议分帧/解析动态库Modbus、CANopen

4. 运行时拓扑

                    ┌──────────────────────────────────┐
                    │         softbus_daemon           │
                    │  ┌─────────┐    ┌─────────────┐  │
  OPC UA Client ───►│  │UaServer │◄───│UaModelBinder│  │
  opc.tcp://:4840   │  │ Engine  │    └──────▲──────┘  │
                    │  └────┬────┘           │         │
                    │       │ ExecuteCommand  │         │
                    │  ┌────▼────┐    ┌──────┴──────┐  │
                    │  │UaMethod │    │ Pipeline    │  │
                    │  │ Binder  │    │ Engine      │  │
                    │  └────┬────┘    └──────▲──────┘  │
                    │       │         ┌──────┴──────┐  │
                    │  ┌────▼────┐    │protocol_    │  │
                    │  │Command  │    │modbus.so    │  │
                    │  │Dispatch │    └─────────────┘  │
                    │  └────┬────┘                     │
                    │  ┌────▼────────────┐             │
                    │  │TcpUplinkServer  │ :9000       │
                    │  └────┬────────────┘             │
                    └───────┼──────────────────────────┘
                            │ TCP JSON (UplinkWire)
                    ┌───────▼────────────┐
                    │    softbus_edge    │
                    │ MockModbusIngress  │
                    │ UplinkClient       │
                    └────────────────────┘

5. 对象模型五层结构

对象寻址路径格式:Site/System/Asset/Device/Point

DemoSite
└── DemoSystem
    └── DemoAsset
        └── SimModbusDevice
            └── Temperature   ← OPC UA Variable (Double)

定义来源:config/softbus_model.json,由 ObjectModelTree 加载,驱动 OPC UA 地址空间动态构建。

6. 约束原则

各模块须遵守以下全局约束(详见各分区文档 CONSTRAINTS 节):

  1. 传输中立softbus_core 模型字段不得编码 D-Bus、HTTP、OPC UA 特定语义
  2. 单向依赖:上层可依赖下层,下层不得反向引用 daemon/edge/opcua
  3. 插件 ABI 稳定:通过 C ABI 导出 create_framer / create_parser,避免破坏已有插件
  4. traceId 贯穿:上行 RawPacket 至 DOMMessage 至 OPC UA 写值,全程携带 traceId 便于追踪
  5. Phase 标注:未实现功能以 stub 标注,文档与代码同步标明 Phase 范围

7. 构建目标速查

Target 类型 输出路径
softbus_core STATIC build/lib/libsoftbus_core.a
softbus_api STATIC build/lib/libsoftbus_api.a
softbus_transport STATIC build/lib/libsoftbus_transport.a
softbus_opcua STATIC build/lib/libsoftbus_opcua.a
protocol_modbus SHARED build/lib/libprotocol_modbus.so
protocol_canopen SHARED build/lib/libprotocol_canopen.so
softbus_edge EXECUTABLE build/bin/softbus_edge
softbus_daemon EXECUTABLE build/bin/softbus_daemon