RTU/mimo/plan/libcom_decode合并计划.md

139 lines
4.0 KiB
Markdown
Raw Permalink 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.

# libcom_decode 模块合并计划
> **目标**: 将 libcom_channel(488行) + libcom_scan(192行) 合并为 libcom_decode按功能拆分文件整合为一个 app 线程
**涉及文件**: ~15个
---
## 新模块结构
```
src/system/libcom_decode/
├── inc/
│ └── .gitkeep
└── src/
├── decode_channel_mgr.cpp # 通道管理:参数配置、创建、启动、状态回调
├── decode_frame_codec.cpp # ICP66 帧解码:协议转换、环形缓冲
├── decode_data_router.cpp # 数据路由recv 分发、send 转发
└── decode_main.cpp # app 线程入口:事件循环
```
---
## 文件功能划分
### decode_channel_mgr.cpp (~150行)
- g_tcp_para[3] / g_uart_para[1] / g_channel_para[4] 参数配置
- com_channel_create() → comm_create + register callbacks
- com_channel_start() → pthread_create per channel
- com_start() → comm_connect 入口
- com_channel_state_cb() → 状态回调,通知 self_ptl
- com_channel_interface_get() → 供外部查询接口标识符
### decode_frame_codec.cpp (~120行)
- g_rx 环形缓冲区 + put_rx_data / get_rx_data
- crc_check_sum()
- icp66_search_frame() → 帧头+CRC+帧尾检测
- icp66_to_icp67() → 协议头转换
- icp66_search_first_head()
- icp66_frame_decode() → 帧解码主循环
### decode_data_router.cpp (~130行)
- com_recv_data() → 协议识别 + 路由到 iec/self_ptl
- com_scan_send_data_to_app() → 消息入队 + 事件通知
- com_channel_recv_cb() → 接收回调:透传/协议解析/直接投递
- com_send_data() → 下行发送
### decode_main.cpp (~80行)
- app_com_decode_init1() → com_channel_create + com_channel_start
- app_com_decode_init2() → return 0
- app_com_decode() → 事件循环:
```
wait EV_TIMER1|TIMER2|TIMER3|EV_COM_RX_IEC|EV_COM_RX_SELF_PTL
→ TIMER1/2: 空操作
→ TIMER3: run_cnt++
→ EV_COM_RX_IEC/EV_COM_RX_SELF_PTL: com_send_data()
```
---
## 外部接口变更
### mySystem.h 枚举
```c
// 旧
ENUM_APP_COMM = 2, // 删除
ENUM_APP_COM_SCAN = 3, // 删除
ENUM_APP_IEC = 4, // → 3
ENUM_APP_SELF_PTL = 5, // → 4
ENUM_APP_WEB_SERVER = 6, // → 5
ENUM_APP_IEC61850M = 7, // → 6
ENUM_APP_IEC61850S = 8, // → 7
ENUM_APP_MAX = 9 // → 8
// 新
ENUM_APP_COM_DECODE = 2, // 新增
ENUM_APP_IEC = 3,
...
ENUM_APP_MAX = 8
```
### mySystem.h extern 声明
- 删除: `app_com_channel_init1/2`, `app_com_channel`
- 删除: `app_com_scan_init1/2`, `app_com_scan`
- 删除: `com_recv_data`(不再对外暴露)
- 新增: `app_com_decode_init1`, `app_com_decode_init2`, `app_com_decode`
- 保留: `com_channel_interface_get`
### 所有引用 ENUM_APP_* 的文件需要更新
影响:
- `self_ptl.cpp`: ENUM_APP_COM_SCAN → ENUM_APP_COM_DECODE
- `iec.cpp`: ENUM_APP_COM_SCAN → ENUM_APP_COM_DECODE
- `app_sys.cpp`: g_vec_app 替换两个条目为一个
---
## 编译系统变更
### Makefile
- 删除: `release/src/system/libcom_channel/makefile`
- 删除: `release/src/system/libcom_scan/makefile`
- 新增: `release/src/system/libcom_decode/makefile`
- 更新: `release/src/system/makefile`(子目录列表)
- 更新: `release/src/system/RTU/makefile`(链接库:-lcom_channel -lcom_scan → -lcom_decode
---
## Task 分解
### T1: 创建新模块目录和文件
- 创建 `src/system/libcom_decode/` 目录结构
- 创建 4 个源文件(从两个旧文件拆出)
- 创建 makefile
### T2: 更新 mySystem.h
- 修改 enum_app 枚举值
- 替换 extern 声明
### T3: 更新 app_sys.cpp
- 替换 g_vec_app 中两个条目为一个
### T4: 更新所有引用 ENUM_APP_COM_SCAN 的文件
- self_ptl.cpp, iec.cpp 中的 ENUM_APP_COM_SCAN → ENUM_APP_COM_DECODE
### T5: 更新编译系统
- 修改父级 makefile 和 RTU 链接 makefile
### T6: 更新 .gitignore如有需要
### T7: 编译验证 + 更新文档
---
## 验证
| 步骤 | 命令 | 预期 |
|------|------|------|
| 全量编译 | `./release/build.sh` | `Build complete`,零错误零警告 |