Files
STM32F4-Base/App/iec60870/104/iec104_source.h
T
wandering1 13ed84a0f0 refactor(iec104): 把 104_port 适配层并入 104,协议栈只剩一个目录
104 从 App/protocol 迁入 App/iec60870 时,协议核心(common/ 104/ examples/)
与我方平台适配层(原 104_port/)仍分成两个平行目录。既然这个库已转为项目自有
代码,适配层没有独立存在的理由——它本来就是对协议的装配与平台后端。

本次只做目录合并,不动任何协议逻辑:

- App/iec60870/104_port/ 的 11 个文件全部移入 App/iec60870/104/
  (iec104_core / iec104_source / iec104_source_ranks / iec104_net_mcu /
  iec104_dtu_table / iec104_comm 的 .c/.h),空目录删除
- Keil 删掉 ../App/iec60870/104_port include 路径;模拟器 CMake 把重复的
  104_port include 行合并进既有的 IEC60870_DIR/104
- 单测运行器里硬拼的 "104_port" 路径段改成 "104"(rename_ref 只认斜杠形态)
- .pre-commit-config.yaml 的 iec104-tcp 触发面去掉 104_port 前缀;coding-standard
  的排除注释改写为「库已转为自有代码,排除项待收编完成后删除」
- 文档与生成物同步:项目架构总览、软件架构与运行时规格、IEC104 上行设计说明、
  产品需求、网络配置说明、App/README、仓根 README,以及引用关系图与架构 SVG

验证(均为实跑):
- Keil UV4 RC=0,0 errors 0 warnings,Code=367464 RO=48492 RW=2288 ZI=173544
- 模拟器构建 OK,编译告警 0,iec104-tcp 13/13 真实 TCP 回环通过
- 受影响单测:iec104_comm 50/50、iec104_serv 50/50、iec104_netmcu 13/13 与
  static 2/2、soe 32/32、iec104_dtu 7 tests OK
- 覆盖率门禁 RC=0,line 8204/9185 (89.3%),49/49 套件
- 全仓 104_port 残留:仅 App/README 里一句「原 104_port 并入 104」的历史说明
2026-11-18 19:17:25 +08:00

82 lines
4.8 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;
/* Counts parameter writes refused because the build has no value store
* (IEC104_SOURCE_NO_VALUE_STORE). Always 0 in the full-feature build, where
* refusals are ordinary protocol rejections and not tracked here. */
uint32_t parameter_rejected;
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