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=8), protocol timer manager (t1,t2,t3), 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
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>.
MoonBit IEC 60870-5-104 Telecontrol Protocol & Substation Automation Simulator
moonbit-iec104is 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=8), protocol timer manager (t1,t2,t3), 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.
.mbtcode across 37 files (excluding.mbtigenerated files and compiler_buildartifacts).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
@utilssrc/utils@typessrc/types@apdusrc/apdu@asdusrc/asdu@state_machinesrc/state_machineUNCONNECTED,STOPPED,PENDING_ACTIVE,ACTIVE), sliding window ACK logic.@timersrc/timer@slavesrc/slave@mastersrc/master@simulationsrc/simulationcmd/maincmd/main🚀 Quick Start
Prerequisites
Build & Run Verification Demo
🧪 Benchmark & Performance
moonbit-iec104has 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
dgmlbttttfor the OSC 2026 Competition. No code has been plagiarized or copied from third-party repositories.dgmlbtttt <dgmlbtttt@users.noreply.github.com>.