/* 模块名称:DTU标准点表查询;作者:DTU项目组。 */ #include "iec104_dtu_table.h" #include "iec104_dtu_profile.h" #include /* 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; }