soft_bus/
├── src/
│ ├── common/ # [公共定义] 所有层共用的数据结构、枚举、DOM模型
│ │ ├── dom/ # DOM模型定义 (ProcessData, ControlCommand...)
│ │ │ └── DomBase.h
│ │ └── types.h
│ │
│ ├── core/ # [核心逻辑] 没有任何 UI 代码,可以在无头模式运行
│ │ ├── pal/ # Layer 1: Protocol Adapter Layer (协议适配)
│ │ │ ├── interfaces/ # 协议插件接口
│ │ │ │ └── IProtocolAdapter.h
│ │ │ └── serial/ # 对应原 serial_manager
│ │ │ └── SerialProtocolAdapter.h/cpp
│ │ │
│ │ ├── dal/ # Layer 2: Data Abstraction Layer (数据抽象)
│ │ │ ├── mapper/ # 映射引擎 (Addr -> Name)
│ │ │ │ └── DataMapper.h/cpp
│ │ │ └── processor/ # 预处理 (Deadband, Scale)
│ │ │ └── DataProcessor.h/cpp
│ │ │
│ │ ├── sbl/ # Layer 3: Service Bus Layer (服务总线核心)
│ │ │ ├── dispatcher/ # 消息调度内核
│ │ │ │ └── MessageDispatcher.h/cpp
│ │ │ └── pubsub/ # 发布订阅引擎 (Topic Tree)
│ │ │ └── TopicTree.h/cpp
│ │ │
│ │ └── SoftBusCore.h/cpp # 核心单例/入口,管理上述模块的生命周期
│ │
│ ├── api/ # Layer 4: Unified Interface Layer (统一接口)
│ │ └── SoftBusAPI.h/cpp # UI 唯一调用的头文件
│ │
│ └── gui/ # [界面层] 纯粹的视图,只负责显示和发送指令
│ ├── main_window/
│ ├── view_serial/ # 移除内部逻辑,改为通过 API 获取数据
│ ├── view_can/
│ └── message_viewer/
│
└── main.cpp # 程序入口,负责组装 Core 和 GUI
物理设备
-> ProtocolAdapter (PAL层: 协议解析)
-> DataMapper (DAL层: 地址映射、工程量转换)
-> MessageDispatcher (SBL层: 优先级队列、路由)
-> SoftBusAPI (API层: 统一接口)
-> UI Widgets (GUI层: 显示)
UI Widgets (GUI层: 用户操作)
-> SoftBusAPI::sendCommand() (API层)
-> MessageDispatcher (SBL层: 高优先级队列)
-> ProtocolAdapter (PAL层: 协议封装)
-> 物理设备
定义在 src/common/dom/DomBase.h:
接口: IProtocolAdapter
实现:
SerialProtocolAdapter: 串口协议适配器CanProtocolAdapter, ModbusTcpAdapter等DataMapper:
DataProcessor:
MessageDispatcher:
TopicTree:
SoftBusAPI:
// 1. 初始化API
SoftBusAPI* api = SoftBusAPI::instance();
api->initialize();
// 2. 注册协议适配器
SerialProtocolAdapter* adapter = new SerialProtocolAdapter();
adapter->setSerialManager(serialManager);
SoftBusCore::instance()->registerProtocolAdapter(adapter);
// 3. 加载映射配置
SoftBusCore::instance()->getDataMapper()->loadProfile("config/tag_mapping.json");
// 订阅所有数据
api->subscribe("*");
// 连接信号
connect(api, &SoftBusAPI::dataChanged,
this, &MyWidget::onDataChanged);
void MyWidget::onDataChanged(QString tagName, QVariant value, int quality) {
if (tagName == "Tank.Level") {
ui->labelLevel->setText(value.toString());
}
}
// 发送控制指令
api->sendCommand("Pump.Main.Control", 1, true);
// 监听确认
connect(api, &SoftBusAPI::commandAcknowledged,
this, &MyWidget::onCommandAck);
IProtocolAdapter 接口SoftBusCorecore/sbl/transport/ 下实现传输适配器MessageDispatcher 使用新的传输方式核心层(core/)不依赖Qt Widgets,可以: