- EIS_README.md: Overall project architecture, data flow, service inventory - zmqp/zmqc_readme: ActiveMQ producer/consumer bridging ICE - zcache_readme: Data cache hub with address mapping and type conversion - zhd_readme: Real-time snapshot persistence to iHyperDB - zinit_readme: DB2-to-shared-memory initialization service - zsub/zudp/zdsf/rcv_readme: Data receiver layer for different on-site protocols
4.0 KiB
4.0 KiB
zhd — 实时数据持久化服务
概述
zhd(Zhen H istory Data / 实时历史数据)是 EIS 系统中的 实时数据持久化服务。它将从共享内存读取的 PLC 遥测快照批量写入 iHyperDB 工业历史数据库,支持自动标签创建和 3D 温度场数据。
进程架构
共享内存 (PLC_DATA)
│
│ 读取遥测快照
▼
┌──────────────────────────────────────┐
│ zhd │
│ │
│ zhdICEI::SendDataShort / TimeNotify │
│ │ │
│ ▼ │
│ SnapshotCus::Dispatch(eventNo, seq) │
│ │ │
│ ├→ eventNo 2000-2011: │
│ │ CacheCase() │
│ │ └→ BinaryTele 解析标签 │
│ │ └→ IDBStorage() 类型转换 │
│ │ └→ SnapShotLocal() 批量写入 │
│ │ │
│ ├→ eventNo 100: │
│ │ 批量区域事件 (循环多区域) │
│ │ │
│ ├→ eventNo 6000: │
│ │ WriteAlarm() 报警数据 │
│ │ │
│ └→ 3D数据: Write3D() │
│ └→ 热轧温度场 → JSON → 标签 │
│ │
└───────────────┬───────────────────────┘
│
▼
iHyperDB (HD3 API)
sn3_save_snapshots() 批量写入
核心功能
1. 遥测快照持久化
- 从共享内存
CMemFix<PLC_DATA>读取 PLC 数据 - 使用
BinaryTele解析标签名和当前值 - 类型转换后通过 HD3 API 的
sn3_save_snapshots()批量写入 iHyperDB
2. 自动标签管理
- 查询 iHyperDB 获取现有标签 ID
- 不存在的标签自动创建(
pt3_add_tag()),设置bArchiving=true启用历史归档 - 标签 ID 缓存在
mv_tagids映射中以减少查询开销
3. 类型转换
| 遥测类型 | HD3 类型 | 处理 |
|---|---|---|
'b' (bool) |
INT8 |
atoi(value) |
's' (short) |
INT16 |
atoi(value) × factor |
'i' (int) |
INT32 |
atoi(value) × factor |
'f' (float) |
FLOAT32 |
atof(value) × factor |
'c' (string) |
STRING |
直接赋值 |
所有数据质量标记为 192(HD3_QUALITY_GOOD)。
4. 3D 温度场 (Write3D)
热轧带钢的特殊处理:将 3D 区域温度数据打包为 JSON({"T":[v1,v2,...]}),每 90 个值一个 tag,命名格式 MG2_3DZONE0、MG2_3DZONE1 等。
ICE 接口
| 方法 | 说明 |
|---|---|
SendDataShort(eventNo, seq) |
接收遥测数据,委托 SnapshotCus::Dispatch() 处理 |
SendDataLong |
未实现 |
TimeNotify(eventNo, seq) |
同 SendDataShort,为定时触发设计 |
iHyperDB 连接
- API: HD3 (iHyperDB 原生 C API)
- 连接参数: 从
CRGS配置文件读取地址/端口 - 认证:
sc3_login("admin", "admin") - 错误恢复: 连接丢失时(错误码 110372/119502/119632)断开并退出
定时器观察者 (TimerWatchI)
(当前被 #if 0 禁用)设计用于订阅 iMultiLink 定时标签对,接收来自外部系统的计算值并按规则覆盖遥测数据。
源文件
src/zhd/
├── zhd.cpp # PACE 组件入口
├── zhdICEI.cpp # ICE servant
├── Snapshot.cpp # 基础快照类(iHyperDB 连接/批量写入)
├── SnapshotCus.cpp # 定制快照(从共享内存读取、3D 数据处理)
└── TimerWatchI.cpp # 定时器观察者(被禁用)