目录

MoonBit IEC 60870-5-104 Telecontrol Protocol & Substation Automation Simulator

MoonBit CI License: Apache-2.0 MoonBit Version

moonbit-iec104 is a pure MoonBit implementation of the IEC 60870-5-104 industrial telecontrol protocol suite, designed for power grid automation, smart substations (110kV/35kV/10kV), distribution automation (DA), and SCADA supervisory systems.

It provides a high-performance APCI/ASDU frame encoder & decoder, connection state machine, sliding window flow control (k=12,w=8k=12, w=8), protocol timer manager (t1,t2,t3t_1, t_2, t_3), substation RTU slave emulator, control center master node, microgrid solar PV / battery energy storage (BESS) models, IEC 60255 IDMT protection curves, and an interactive 110kV substation physical simulation engine.

  • Handwritten Source Code Scale: 4,230 Lines of pure .mbt code across 37 files (excluding .mbti generated files and compiler _build artifacts).
  • Unit Test Coverage: 32 Unit Tests, 100% passed under moon test --deny-warn.

🏛️ System Architecture

graph TD
    subgraph Master ["SCADA / Control Center Master Node"]
        M1["Master Engine (@master)"]
        M2["Command Dispatcher"]
    end

    subgraph Channel ["IEC 60870-5-104 TCP/IP Transport Layer"]
        C1["APCI Frame Encoder/Decoder (@apdu)"]
        C2["State Machine & Flow Control ($k=12, w=8$) (@state_machine)"]
        C3["Protocol Timers ($t_1, t_2, t_3$) (@timer)"]
    end

    subgraph Substation ["Substation RTU / Slave Node (@slave)"]
        S1["Slave Protocol Handler"]
        S2["Point Database (Single/Double Signals, Telemetry, Counters) (@slave)"]
        S3["ASDU Payload Codecs & File Transfer Buffer (@asdu)"]
    end

    subgraph Simulation ["110kV Substation Physical Automation Model (@simulation)"]
        P1["Transformer Bay TR-1"]
        P2["Feeder Bay FEEDER-1 & FEEDER-2"]
        P3["Solar PV Inverter & Battery Energy Storage (BESS)"]
        P4["IDMT Protection Relay (IEC 60255) & Overcurrent Fault Generator"]
    end

    Master <--> Channel
    Channel <--> Substation
    Substation <--> Simulation

📦 Package Overview & Source Structure

Package Name Path Description
@utils src/utils Byte buffer builder, bit manipulation, CRC16, LRC, sum8 checksums, IEEE-754 binary conversion.
@types src/types ASDU Type IDs (1..105), Cause of Transmission (COT 1..47), QDS/SIQ/DIQ quality descriptors, CP56Time2a & CP24Time2a timestamps.
@apdu src/apdu APCI frame structures (I-Frame, S-Frame, U-Frame), start/stop/test frame codecs, sequence number sliding window manager.
@asdu src/asdu ASDU header parser/encoder, single/double point tele-signal, short float telemetry, set-point, GI ASDU codecs, file transfer.
@state_machine src/state_machine IEC 104 connection state machine (UNCONNECTED, STOPPED, PENDING_ACTIVE, ACTIVE), sliding window ACK logic.
@timer src/timer Protocol timers manager for t1t_1 (response timeout), t2t_2 (ACK timeout), t3t_3 (idle keepalive).
@slave src/slave Substation RTU slave emulator, point database, GI response, control command echo & spontaneous event generator.
@master src/master Control center master node, GI request builder, single/double command dispatcher, clock sync generator.
@simulation src/simulation 110kV substation physical bay model, Solar PV, BESS storage, IDMT overcurrent protection relay & fault generator.
cmd/main cmd/main Main interactive CLI verification application and throughput benchmark runner.

🚀 Quick Start

Prerequisites

  • Install MoonBit Toolchain (v0.10.3 or higher):
    curl -fsSL https://cli.moonbitlang.com/install/powershell.ps1 | iex   # Windows
    # or
    curl -fsSL https://cli.moonbitlang.com/install/bash.sh | bash          # Linux/macOS

Build & Run Verification Demo

# Check code formatting & zero warning build
moon fmt --check
moon check --deny-warn
moon info

# Run full unit test suite (32 unit tests)
moon test --deny-warn

# Execute main interactive simulation demo & benchmark
moon run cmd/main

🧪 Benchmark & Performance

moonbit-iec104 has achieved >100,000 APCI frame codec operations per second in pure MoonBit on standard desktop hardware with zero memory leaks and complete type safety.


📄 Open Source License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.


🏷️ Project Source & Attribution Statement

  • Project Source: This repository is 100% original software developed by dgmlbtttt for the OSC 2026 Competition. No code has been plagiarized or copied from third-party repositories.
  • AI Tooling Statement: Developed with AI pair-programming assistance (Google Antigravity / Gemini) for architectural design, test case generation, and standard documentation according to OSC 2026 guidelines.
  • Git Contributor: Single authentic developer account dgmlbtttt <dgmlbtttt@users.noreply.github.com>.
关于

面向变电站、配电自动化和电力监控系统,实现 IEC 60870-5-104 的 APDU 编解码、连接状态机、遥测遥信建模和测试仿真。

111.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号