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 工程改动,未烧板。
65 lines
2.7 KiB
C
65 lines
2.7 KiB
C
/* 模块名称:共享 IEC104 服务接口。 */
|
|
/* Shared IEC104 runtime; one event-loop owner, no RTOS dependencies. */
|
|
#ifndef IEC104_CORE_H
|
|
#define IEC104_CORE_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef struct {
|
|
const char *bind_address; /* Numeric IPv4, copied during start. */
|
|
uint16_t port; /* 0 allows a host-assigned test port. */
|
|
uint16_t common_address; /* 1..65534, frozen until stop. */
|
|
} iec104_core_config_t;
|
|
|
|
typedef struct {
|
|
uint32_t connections;
|
|
uint32_t received_i_frames;
|
|
uint32_t written_i_frames; /* Entire APDU handed to local TCP, not ACK. */
|
|
uint32_t acknowledged_i_frames; /* IEC104 N(R), NOT TCP ACK. */
|
|
uint32_t gi_completed; /* Business submission complete, not delivery. */
|
|
uint32_t commands_completed;
|
|
uint16_t bound_port;
|
|
uint8_t running;
|
|
uint8_t owns_resources; /* Includes failed cleanup; stop must be retried. */
|
|
uint8_t connected;
|
|
uint8_t active;
|
|
int last_error;
|
|
int last_stage;
|
|
int native_error;
|
|
} iec104_core_status_t;
|
|
|
|
/* All calls must be serialized on the same owner thread. 0=OK, -1=error.
|
|
* start refuses double start; failure attempts bounded cleanup. If
|
|
* owns_resources remains 1, stop must be retried before another start.
|
|
* Each admitted start resets counters, errors, simulated values and RAM
|
|
* settings; ordinary TCP disconnect preserves committed RAM values but
|
|
* cancels SBO and uncommitted parameter transactions in the library.
|
|
* poll never waits: one network turn, <=16 transport notifications, <=4
|
|
* GI/CI interactions per priority, <=20 point reads per GI interaction.
|
|
* Connection faults/reconnect are handled internally and return 0.
|
|
* A -1 poll result is a service/assembly failure: caller must stop; polling
|
|
* before start or after stop returns -1 without allocating resources.
|
|
* stop is idempotent after success; failure retains ownership for retry.
|
|
* Counters saturate at UINT32_MAX, survive TCP reconnect and stop, and reset
|
|
* at the next admitted start. Connections counts accepted TCP sessions.
|
|
* written_i_frames is observed when ACK/closing records are delivered;
|
|
* it can lag the actual write. commands_completed counts the library's
|
|
* FINISHED(COMPLETED), not model updates, TCP ACK or physical DO actions.
|
|
* get_status is same-owner, read-only, and a NULL output is a no-op.
|
|
* The linked IEC104_Net backend owns I/O and a monotonic clock independent
|
|
* from the source wall clock. Source hooks must be short and nonblocking.
|
|
*/
|
|
int iec104_core_start(const iec104_core_config_t *config);
|
|
int iec104_core_poll(void);
|
|
int iec104_core_stop(void);
|
|
void iec104_core_get_status(iec104_core_status_t *status);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|