RTU/mimo/工程/DCU_HOST/05-故障事件与电度.md

165 lines
5.3 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.

# 05 - 故障事件与电度回调详解
> 源码: [DCU_HOST/applications/data/iec_itfc/FaultItfc.c](../../../../../../DCU_HOST/applications/data/iec_itfc/FaultItfc.c)
> [DCU_HOST/applications/data/iec_itfc/DdItfc.c](../../../../../../DCU_HOST/applications/data/iec_itfc/DdItfc.c)
---
## 1. 故障事件回调 `CS10x_S_FaultEventHandler`
### 1.1 注册
```c
CS10x_S_FaultEventHandler(pstCs10x, GetEventSendNum, GetFaultEvent, UpdateFaultEventPtrOut);
```
### 1.2 数据结构
```c
// 故障事件帧中包含 SOE + YC 混合数据
typedef struct {
unsigned short usSoeNum; // 遥信数量
SOE_Info staSoe[MAX_FAULT_EVENT_SOE_SIZE]; // 最多 16 条 SOE
unsigned short usYcNum; // 遥测数量
Yc_Info staYc[MAX_FAULT_EVENT_YC_SIZE]; // 最多 16 个遥测
} FAULT_EVENT_Info;
```
### 1.3 GetEventSendNum — 获取待发送数量
```c
s32 GetEventSendNum(void *pvArg) {
u8 ucInforNum = GetFaultOutNum(pvArg);
return UserGetFaultEventSendNum(ucInforNum);
}
```
### 1.4 GetFaultEvent — 填充故障事件
```c
s32 GetFaultEvent(FAULT_EVENT_Info *pstInfo, void *pvParam, u32 uiPos) {
u8 ucInforNum = GetFaultOutNum(pvParam);
// 1. 从数据池获取第 uiPos 条故障事件
stFAULT_EVENT stFaultEvent;
UserGetFaultEvent(ucInforNum, &stFaultEvent, uiPos);
// 2. 填充 SOE 部分 (遥信事件)
pstInfo->usSoeNum = stFaultEvent.usSoeNum;
for(int i = 0; i < stFaultEvent.usSoeNum; i++) {
pstInfo->staSoe[i].uiInfoAddr = stFaultEvent.astSoe[i].usAddr;
pstInfo->staSoe[i].ucStatus = stFaultEvent.astSoe[i].ucState;
pstInfo->staSoe[i].ucStateType = 0; // 单点
Stamp2Cp56(&pstInfo->staSoe[i].stCTime, ...);
}
// 3. 填充 YC 部分 (故障时刻遥测)
pstInfo->usYcNum = stFaultEvent.usYcNum;
for(int i = 0; i < stFaultEvent.usYcNum; i++) {
pstInfo->staYc[i].uiInfoAddr = stFaultEvent.astYc[i].usAddr;
pstInfo->staYc[i].fVal = stFaultEvent.astYc[i].fVal;
}
return 1;
}
```
### 1.5 UpdateFaultEventPtrOut — 更新已确认指针
```c
s32 UpdateFaultEventPtrOut(void *pvParam, u32 uiPos) {
u8 ucInforNum = GetFaultOutNum(pvParam);
return UserUpdateFaultEventOut(ucInforNum, uiPos);
}
```
### 1.6 故障事件触发条件
- TypeID=42 (M_FT_NA) — 故障事件
- 通常由保护逻辑检测到故障后产生
- 帧中包含故障时刻的遥信状态 + 遥测快照
---
## 2. 电度回调 `CS10x_S_GetDdByGroupHandler`
### 2.1 注册
```c
CS10x_S_GetDdByGroupHandler(pstCs10x, GetDdCountByGroup, GetDdValueByGroup);
```
### 2.2 GetDdCountByGroup — 电度数量
```c
s32 GetDdCountByGroup(u16 usGroupID, void *pvParam, u32 *puiStartInf, u32 *puiEndInf) {
*puiStartInf = DD_START_PORT;
*puiEndInf = DD_START_PORT + g_stPotConfigNum.usDdConfigNum;
return g_stPotConfigNum.usDdConfigNum;
}
```
### 2.3 GetDdValueByGroup — 填充电度值
```c
s32 GetDdValueByGroup(u16 usGroupID, u16 usIdx, Dd_Info *pstInfo, void *pvParam) {
u16 usInfoAddr = usIdx + DD_START_PORT;
pstInfo->uiInfoAddr = usInfoAddr;
u16 usTabIdx;
GetPosDdTable(&usTabIdx, usInfoAddr);
UserGetDdValue(&pstInfo->fVal, usTabIdx, 1);
return 1;
}
```
### 2.4 电度类型
| 类型 | TypeID | 说明 |
|------|--------|------|
| 不带时标 (`DD_TYPE_IT_NB=0`) | M_IT_NB (206) | 累积量浮点值 |
| 带时标 (`DD_TYPE_IT_TC=1`) | M_IT_TC (207) | 累积量浮点值 + CP56Time |
配置: `CS10x_SetDdType(pstCs10x, 0或1)`
---
## 3. 带时标电度回调 `CS10x_S_DiturbDduHandler`
```c
CS10x_S_DiturbDduHandler(pstCs10x, GetTimeDdu, GetTimeDduSendNum, UpdateTimeDduPtrOut);
```
与 SOE 模式完全一致,使用 `TimeDd_Info` 结构体 (Dd_Info + CP56Time)。
---
## 4. 回调模式总结
DCU_HOST 中共有 **4 种回调交互模式**
| 模式 | 回调组合 | 适用场景 |
|------|---------|----------|
| **查询模式** | `GetXxxCountByGroup` + `GetXxxValueByGroup` | 总召遥测/遥信/电度 |
| **队列模式** | `GetXxxSendNum` + `GetXxx` + `UpdateXxxPtrOut` | SOE / 扰动遥测 / 故障事件 / 时标电度 |
| **命令模式** | `Verify` + `SetInfo` + ResultNotify | 遥控 |
| **读写模式** | `GetArea/SetArea` + `Add/RunRead/RunWrite` + `GetNum/GetInfo` | 参数/定值 |
---
## 5. RTU 适配速查表
| DCU_HOST 函数 | DCU_HOST 数据源 | RTU 替代 | 复杂度 |
|--------------|----------------|----------|--------|
| `GetYcCountByGroup` | `GetPotTableConfig` | `dc_get_signal_count(SIGNAL_OUT)` | ★ |
| `GetYcValueByGroup` | `UserGetYcValue + 变比` | `dc_get_signal_float()` | ★ |
| `GetYxCountByGroup` | `GetPotTableConfig` | `dc_get_signal_count(SIGNAL_IN)` | ★ |
| `GetYxStatusByGroup` | `UserGetYxState + 取反` | `dc_get_signal_u8()` | ★ |
| `GetSOE` | `UserGetSoeEvent + CP56转换` | `dc_get_event()` | ★★ |
| `GetSOESendNum` | `UserGetSoeSendNum` | `dc_get_event_count()` | ★ |
| `Cs10xYkVerifyItfs` | IP白名单+加密 | 直接返回1 | ★ |
| `SetYkInfor` | 点表查找 + 遥控线程 | `dc_sbo_select/operate` | ★★★ |
| `GbParamAddElement` | 882行参数映射表 | 现有的 `iec_method.cpp` | ★★★ |
| `GbParamRunRding` | 定值区读 | 同上 | ★★★ |
| `Fm_ReadFile/Write` | 文件系统 | 可选 (NULL) | ★★ |