Files
STM32F4-Base/App/protocol/iec104/iec104_dtu_table.c
T
wandering1 2e9272cc8a feat(iec104): 在模拟器跑通共享协议核心与标准DTU点表
引入成熟 IEC 60870-5-104 子站的只读子集(App/protocol/iec60870,28 个源文件
按原字节复制,UPSTREAM.sha256 记录来源,兼容补丁保留全部断言与容量),在其上
装配单属主共享核心(Start/Poll/Stop/Get_Status),并把标准 DTU 演示点表全量
接入为唯一真源。

- iec104_core:threadless 推进,poll 零等待,通知/交互/COV 扫描全部有界;
  生命周期区分失败启动待重试、重复启动拒绝、断线保固化 RAM。
- iec104_dtu_table / iec104_source:标准 DTU 全点表注册,无数据源的点读 0,
  遥控只做模拟状态可读回,不触碰实际出口。
- iec104_sim:仅窗口与独立服务模式起真实 TCP,无头黄金模式保持确定性假统计。
- test/host/iec104_dtu:独立真实 TCP 11 项、传输层 10 项、生命周期与借用负例。

验证:lvgl_sim 真实 TCP 11/11、传输 10/10,UI 像素回归未回退;AC5 单 TU
编译 0 错误 0 诊断。板端尚未切换:完整库闭包 RAM 超 92% 门禁净增预算 25730B,
结论为停止转实施,记录在 IEC104_MCU最小可行性验证.md。旧实现与 board 服务
保持原样,未提交 MDK 工程改动,未烧板。
2026-11-17 20:48:00 +08:00

94 lines
4.3 KiB
C

/* 模块名称:DTU标准点表查询;作者:DTU项目组。 */
#include "iec104_dtu_table.h"
#include "iec104_dtu_profile.h"
#include <string.h>
/* Compile-time audit against the single upstream table, not hand-counted ranges. */
typedef char profile_sp_count[(DTU_SIGNAL_COUNT == IEC104_DTU_SP_COUNT) ? 1 : -1];
typedef char profile_me_count[(DTU_MEASUREMENT_COUNT == IEC104_DTU_ME_COUNT) ? 1 : -1];
typedef char profile_param_count[(DTU_PARAMETER_COUNT == IEC104_DTU_PARAMETER_COUNT) ? 1 : -1];
/* 函数功能:按稳定索引查询标准监视点元数据。 */
bool iec104_dtu_point(size_t index, iec104_dtu_point_t *out)
{
if (out == NULL) { return false; }
memset(out, 0, sizeof(*out));
if (index < DTU_SIGNAL_COUNT) {
out->ioa = dtu_signals[index].ioa;
out->source_addr = dtu_signals[index].source_addr;
out->type = 1U; out->name = dtu_signals[index].name; out->unit = "1";
return true;
}
index -= DTU_SIGNAL_COUNT;
if (index < IEC104_DTU_DP_COUNT) {
out->ioa = (uint32_t)(0x1001U + index); out->type = 3U;
out->name = "Simulated switch position"; out->unit = "DPI";
return true;
}
index -= IEC104_DTU_DP_COUNT;
if (index < DTU_MEASUREMENT_COUNT) {
out->ioa = dtu_measurements[index].ioa;
out->source_addr = dtu_measurements[index].source_addr;
out->type = 13U; out->name = dtu_measurements[index].name;
out->unit = dtu_measurements[index].unit;
return true;
}
return false;
}
/* 函数功能:读取保留原始类型和可见性的参数元数据。 */
bool iec104_dtu_parameter(size_t index, iec104_dtu_parameter_t *out)
{
const DtuProfileParameter *p;
if (index >= DTU_PARAMETER_COUNT || out == NULL) { return false; }
p = &dtu_parameters[index];
out->ioa = p->ioa; out->tag = p->tag; out->source_tag = p->source_tag;
out->configured = p->configured; out->initial = p->value;
out->area_scoped = p->ioa >= 0x8820U && p->ioa <= 0x88ffU;
out->writable = p->configured && (out->area_scoped ||
(p->ioa >= 0x8020U && p->ioa <= 0x8056U) ||
(p->ioa >= 0xa2c1U && p->ioa <= 0xa2ecU) ||
(p->ioa >= 0x9e01U && p->ioa <= 0x9e5dU));
return true;
}
/* 函数功能:按参数IOA查索引,未知返回参数总数。 */
size_t iec104_dtu_parameter_index(uint32_t ioa)
{
size_t i;
for (i = 0U; i < DTU_PARAMETER_COUNT; ++i) {
if (dtu_parameters[i].ioa == ioa) { break; }
}
return i;
}
/* 函数功能:依据原表配置状态和区域判定参数可见性。 */
bool iec104_dtu_parameter_visible(size_t index, uint16_t area)
{
iec104_dtu_parameter_t p;
return area < IEC104_DTU_AREA_COUNT && iec104_dtu_parameter(index, &p) &&
p.configured && (area == 0U || p.area_scoped);
}
/* Candidate semantic bridge, not an activated platform binding. No mapping for alarm-enable (not overall enable),
* low-frequency blocking (not underfrequency trip), zero drift (not ADC offset),
* or remote-control permission (not protection global enable).
* Existing model IDs 0..39 are stable persistent IDs; COUNT is not a parameter.
* PT1 and phase-CT refer to the one existing feeder, secondary units A/V.
* Other phases/bays MUST NOT silently share these IDs. */
/* 函数功能:查询未激活的候选语义桥及单位比例。 */
bool iec104_dtu_protection_mapping(uint32_t ioa, uint16_t *id, float *source_scale)
{
static const struct { uint16_t ioa, id; float scale; } map[] = {
{0x8841U, 1U, 1.0f}, {0x8842U, 2U, 1.0f}, {0x8843U, 3U, 1000.0f},
{0x8845U, 5U, 1.0f}, {0x8846U, 6U, 1.0f}, {0x8847U, 7U, 1000.0f},
{0x8849U, 9U, 1.0f}, {0x884aU, 10U, 1.0f}, {0x884bU, 11U, 1000.0f},
{0x8027U, 20U, 1.0f}, {0x8028U, 21U, 1000.0f},
{0x8029U, 17U, 1.0f}, {0x802aU, 18U, 1000.0f},
{0x8024U, 27U, 1000.0f}, {0x8025U, 28U, 1.0f},
{0x8040U, 29U, 1.0f}, {0x8041U, 30U, 1.0f}
/* 8046/8047 are load-limit alarms, not the existing overload trip
* model. Do not map those by a superficially similar threshold. */
};
size_t i;
if (id == NULL || source_scale == NULL) { return false; }
for (i = 0U; i < sizeof(map) / sizeof(map[0]); ++i) {
if (map[i].ioa == ioa) { *id = map[i].id; *source_scale = map[i].scale; return true; }
}
return false;
}