2e9272cc8a
引入成熟 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 工程改动,未烧板。
59 lines
2.2 KiB
C
59 lines
2.2 KiB
C
/* Independent source-binding failure injection; no hardware or product codec oracle. */
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
#include "iec104_source.h"
|
|
#define CHECK(x) do { if (!(x)) { fprintf(stderr, "line %d: %s\n", __LINE__, #x); exit(1); } } while (0)
|
|
static uint16_t special_id;
|
|
static float special_value;
|
|
static unsigned apply_count;
|
|
static bool read_parameter(void *ctx, uint16_t id, float *out)
|
|
{
|
|
(void)ctx;
|
|
if (id == special_id) { *out = special_value; return true; }
|
|
*out = id == 17U ? 250.0f : id == 20U ? 100.0f : 1.0f;
|
|
return true;
|
|
}
|
|
static bool apply_parameter(void *ctx, const iec104_source_change_t *changes, size_t count, bool validate)
|
|
{
|
|
(void)ctx; (void)changes; (void)count;
|
|
if (!validate) { ++apply_count; }
|
|
return true;
|
|
}
|
|
static bool measurement(void *ctx, uint16_t addr, float *v, uint8_t *q)
|
|
{
|
|
(void)ctx; (void)addr; *v = 12.5f; *q = 0x51U; return true;
|
|
}
|
|
static void invalid_read(uint32_t ioa, uint16_t id, float value)
|
|
{
|
|
iec104_source_value_t out;
|
|
special_id = id; special_value = value;
|
|
if (iec104_source_remote_read(0U, ioa, &out)) {
|
|
fprintf(stderr, "unexpected readable ioa=%lx semantic=%u input=%g tag=%u\n", (unsigned long)ioa, id, value, out.tag);
|
|
exit(1);
|
|
}
|
|
}
|
|
int main(void)
|
|
{
|
|
iec104_source_bindings_t bind = {0};
|
|
iec104_source_object_t object;
|
|
iec104_source_stats_t stats;
|
|
bind.parameter_read = read_parameter; bind.parameter_apply = apply_parameter;
|
|
bind.measurement = measurement;
|
|
iec104_source_init(); iec104_source_bind(&bind);
|
|
/* Mapped profile entries: bool8841 -> semantic1; float8842 ->2.
|
|
* There is no mapped UShort callback entry: do not fake one to claim coverage. */
|
|
invalid_read(0x8841U, 1U, 2.0f);
|
|
invalid_read(0x8841U, 1U, 1.5f);
|
|
invalid_read(0x8842U, 2U, NAN);
|
|
invalid_read(0x8842U, 2U, INFINITY);
|
|
special_id = 0U;
|
|
CHECK(iec104_source_find(0x4001U, &object));
|
|
CHECK(object.measurement.value == 12.5f);
|
|
CHECK(object.measurement.quality == 0x51U);
|
|
iec104_source_stats(&stats);
|
|
CHECK(stats.physical_do_actions == 0U && apply_count == 0U);
|
|
puts("source binding typed fail-closed/quality: PASS");
|
|
return 0;
|
|
}
|