Files
STM32F4-Base/App/protocol/iec104/iec104_source.h
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

78 lines
4.6 KiB
C

/* 模块名称:DTU数据源接口;作者:DTU项目组。
* Single-owner application data. No sockets, hardware outputs or allocation. */
#ifndef IEC104_SOURCE_H
#define IEC104_SOURCE_H
#include "iec104_dtu_table.h"
#include "IEC104_Command.h"
#include "IEC104_RemoteParameter.h"
#include "IEC104_Parameter.h"
#include "IEC104_ClockSynchronization.h"
/* InformationObject is only a base class. The caller must retain full storage
* until Add_InformationObject has copied it; never allocate the base alone. */
typedef union {
IEC60870_InformationObject_t object;
IEC60870_SinglePointInformation_t single;
IEC60870_DoublePointInformation_t double_point;
IEC60870_MeasuredValueShort_t measurement;
IEC60870_ParameterNormalizedValue_t normalized;
IEC60870_ParameterScaledValue_t scaled;
IEC60870_ParameterFloatValue_t parameter;
IEC60870_StepPositionInformation_t step;
IEC60870_BitString32_t bits;
IEC60870_IntegratedTotalsShort_t energy;
} iec104_source_object_t;
/* All 345 visible profile entries have numeric tags 1/35/38/45 and width <=4.
* Tag4 metadata remains unconfigured and invisible, never silently truncated. */
typedef struct { uint8_t tag, length, bytes[4]; } iec104_source_value_t;
typedef struct { uint16_t id; float value; } iec104_source_change_t;
/* All callbacks run serially in the protocol owner. NULL means unavailable.
* read returns false only for unavailable input; quality is never normalized.
* apply must validate the whole list before changing anything and be atomic.
* The platform must not call per-item setters that can fail after partial writes.
* init does not initialize/reset protection/calibration or invoke apply. */
typedef struct {
void *context;
bool (*measurement)(void *, uint16_t source_addr, float *, uint8_t *quality);
bool (*signal)(void *, uint16_t source_addr, uint8_t *, uint8_t *quality);
bool (*parameter_read)(void *, uint16_t semantic_id, float *);
bool (*parameter_apply)(void *, const iec104_source_change_t *, size_t, bool validate_only);
} iec104_source_bindings_t;
typedef struct {
uint32_t simulated_actions, physical_do_actions, parameter_commits, clock_sets;
uint32_t reset_actions;
uint16_t current_area;
bool synchronized;
} iec104_source_stats_t;
/* core_start calls init exactly once: clears bindings, stages, stats, virtual
* clock and observations; restores typed profile/standard parameter defaults.
* TCP reconnect does NOT call init. RAM solidification is not persistence. */
void iec104_source_init(void);
/* Copies the vtable. Context must outlive the service. Bind only immediately
* after start and before poll, never while a command/parameter batch is active.
* Register parameter_read/apply as a pair. validate_only is side-effect free;
* failed apply MUST leave the entire real source unchanged. Persistence remains
* defaultTask-owned; this callback is not permission for direct config I/O. */
void iec104_source_bind(const iec104_source_bindings_t *bindings);
size_t iec104_source_count(void);
bool iec104_source_point(size_t index, iec104_source_object_t *out);
bool iec104_source_find(uint32_t ioa, iec104_source_object_t *out);
bool iec104_source_counter(size_t index, iec104_source_object_t *out);
const IEC104_CommandPoint_t *iec104_source_commands(uint16_t ca, size_t *count);
IEC104_CommandActionResult_t iec104_source_command(void *context, const IEC104_CommandRequest_t *request);
/* A successful execute has already changed state. Core reports success then
* publishes reads of the affected IOAs, and only then completes the command. */
/* At most three IOAs. Insufficient capacity returns zero without writing.
* Network WAIT retries publication only, never the already-executed action. */
size_t iec104_source_command_feedback(uint32_t command_ioa, uint32_t *ioas, size_t capacity);
extern const IEC104_RemoteParameterHandlers_t iec104_source_remote_handlers;
void iec104_source_parameter_config(uint16_t ca, IEC104_ParameterConfig_t *config);
IEC104_ParameterActionResult_t iec104_source_parameter_action(void *, const IEC104_ParameterRequest_t *);
bool iec104_source_remote_read(uint16_t area, uint32_t ioa, iec104_source_value_t *out);
bool iec104_source_clock_set(void *, const IEC104_ClockSynchronizationRequest_t *);
bool iec104_source_clock_read(void *, const IEC104_ClockSynchronizationReadRequest_t *, IEC60870_CP56Time2a_t *);
/* Virtual device wall clock only; mono_ms and base_ms use the same Net epoch. */
uint64_t iec104_source_clock_ms(uint64_t mono_ms);
void iec104_source_clock_seed(uint64_t utc_ms, uint64_t mono_ms);
void iec104_source_stats(iec104_source_stats_t *out);
#endif