Files
STM32F4-Base/App/iec60870/104/iec104_dtu_table.c
T
wandering1 7d1db02164 perf(iec104): 参数区按 17 项真实消费者收窄并接上真实定值模型
104 协议侧参数通道此前镜像了厂商点表的全部 430 条参数(697 槽),
但其中 413 条在本设备上没有任何消费者——104 与设备侧真实定值模型
prot_set 之间零调用,主站改定值只落在无人读的 RAM 镜像里,保护功能
毫无感知。本次按"严格按消费者收窄"口径收口:

可见性以 iec104_dtu_protection_mapping() 语义桥表为唯一判据,只放行
三段过流投退/定值/延时(9 项)、低压与过压定值/延时(4 项)、PT 与
CT 一次/二次额定(4 项)。其余参数在位表枚举层即不可见,主站读取
得到 COT=47 + P/N=1 的显式否定确认,不静默丢弃。values[697]→values[53]、
staged[264]→staged[17],并删除生成式 iec104_source_ranks.h。

桥表接真实源:iec104_serv 的 parameter_read/apply 从 NULL 改为直读
prot_set 与整批原子提交,Q10 量化后一次事务落地,持久化仍由
defaultTask 的脏标志闭环负责。

prot_set 因此出现两个运行时写者(netTask 的 104 与 uiTask 的本地整
定),原"写者靠启动时序串行"的约定失效。加入写事务互斥与 seqlock
序号:四个写入口全部进锁,校验与提前返回一律在 enter 之前;序号卡
奇数连续 8 拍即判保护闭锁,避免自检被永久跳过而静默失去防篡改能力。
锁的安装在 defaultTask 的存储 bring-up 阶段,不在 app_main_init——
后者早于 osKernelInitialize,内核启动前禁止任何 RTOS 创建类 API。

实测:RW_IRAM1 117,304→113,720 B(−3,584 B,89.50%→86.76%);
ER_IROM1 413,392→411,668 B(−1,724 B);iec104_source.o 5,656→2,056 B;
prot_set.o 344→352 B(+8 B,写事务序号与锁句柄)。Keil 构建 0 错误
0 警告;主机侧 prot_set 175/175、iec104_dtu 7/7;真实 TCP 验收
13/13;暂存口径门禁 18 项全通过。

已知边界:模拟器不链接 iec104_serv.c,TCP 验收不覆盖 prot_set 绑定,
板端需实机确认主站写入能反映到本地定值页;17 项中 15 项的出厂默认
值与点表字面量不同,主站读到的是真实模型的值;绑定真实源后定值区
切换一律拒绝(单套活跃值无原子整区事务)。
2026-11-19 15:48:21 +08:00

115 lines
5.4 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];
/* Authorized consumer semantic bridge; activated by iec104_serv bindings on MCU. 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.
* This is the entire accepted consumer set: every other profile row is refused. */
static const struct { uint16_t ioa, id; float scale; } s_consumer_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. */
};
typedef char consumer_map_count[
(sizeof(s_consumer_map) / sizeof(s_consumer_map[0]) == IEC104_DTU_CONSUMER_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; uint16_t id; float scale;
return area < IEC104_DTU_AREA_COUNT && iec104_dtu_parameter(index, &p) &&
p.configured && (area == 0U || p.area_scoped) &&
iec104_dtu_protection_mapping(p.ioa, &id, &scale);
}
/* 函数功能:把可见消费者索引换算成密集槽位;非消费者返回无槽位。
* area_zero 非 0 = SN0 全体 17 项排名;为 0 = 区域 1..4 的 9 项局部排名。 */
uint16_t iec104_dtu_parameter_rank(size_t index, uint8_t area_zero)
{
iec104_dtu_parameter_t p; uint16_t rank = 0U; size_t i;
if (!iec104_dtu_parameter_visible(index, area_zero != 0U ? 0U : 1U) ||
!iec104_dtu_parameter(index, &p)) { return IEC104_DTU_NO_RANK; }
for (i = 0U; i < IEC104_DTU_CONSUMER_COUNT; ++i) {
uint32_t ioa = s_consumer_map[i].ioa;
if (area_zero == 0U && !(ioa >= 0x8820U && ioa <= 0x88ffU)) { continue; }
if (ioa == p.ioa) { return rank; }
++rank;
}
return IEC104_DTU_NO_RANK;
}
/* 函数功能:查询真实消费者的语义桥及单位比例。 */
bool iec104_dtu_protection_mapping(uint32_t ioa, uint16_t *id, float *source_scale)
{
size_t i;
if (id == NULL || source_scale == NULL) { return false; }
for (i = 0U; i < sizeof(s_consumer_map) / sizeof(s_consumer_map[0]); ++i) {
if (s_consumer_map[i].ioa == ioa) {
*id = s_consumer_map[i].id; *source_scale = s_consumer_map[i].scale; return true;
}
}
return false;
}