# ex_cep v0.1.1 - API Reference

## Modules

- [ExCEP](ExCEP.md): Pure Elixir implementation of the **China Southern Power Grid (CSG) CEP**
Edge Gateway Plug-and-Play Protocol (TS2.2).
- [ExCEP.Cluster.ControlClient](ExCEP.Cluster.ControlClient.md): High-level Business Channel (TCP 9902) Cluster -> Gateway service client.
- [ExCEP.Cluster.DefaultHandler](ExCEP.Cluster.DefaultHandler.md): Default `ExCEP.Cluster.Handler` that acknowledges Gateway reports (`ModelChange`, `DevAdd`,
`DevUpdate`, `DevDel`, `DataSpont`), accepts incoming chunked `FileSend`/`FileDataTrans`
transfers with CRC32 verification, and invokes optional user callbacks (`:on_asdu`, `:on_file_received`).

- [ExCEP.Cluster.Handler](ExCEP.Cluster.Handler.md): Callback behaviour for handling Gateway-initiated ASDUs on the Cluster (Master) server.

- [ExCEP.Cluster.ManagementClient](ExCEP.Cluster.ManagementClient.md): High-level Management Channel (TCP 9901) Cluster -> Gateway service client.
- [ExCEP.Cluster.Server](ExCEP.Cluster.Server.md): Edge Cluster (Master) TCP/TLS server and Gateway session registry.
- [ExCEP.Cluster.Session](ExCEP.Cluster.Session.md): Per-gateway TCP/TLS connection session on the Cluster (Master) server.
- [ExCEP.Codec.AuthAsdu](ExCEP.Codec.AuthAsdu.md): Binary Authentication ASDU codec per CSG CEP TS2.2 Section 5 (Tables 3, 4, 5).
- [ExCEP.Codec.AuthAsdu.Confirm](ExCEP.Codec.AuthAsdu.Confirm.md): Authentication Confirm ASDU (`0x03`, Table 5).
- [ExCEP.Codec.AuthAsdu.Request](ExCEP.Codec.AuthAsdu.Request.md): Authentication Request ASDU (`0x01`, Table 3).
- [ExCEP.Codec.AuthAsdu.Response](ExCEP.Codec.AuthAsdu.Response.md): Authentication Response ASDU (`0x02`, Table 4).
- [ExCEP.Codec.DataAsdu](ExCEP.Codec.DataAsdu.md): JSON Data ASDU envelope codec per CSG CEP TS2.2 Section 4.7 (Table 2).
- [ExCEP.Codec.DataAsdu.Head](ExCEP.Codec.DataAsdu.Head.md): TS2.2 Section 4.7 (Table 2) Data ASDU `Head` structure.
- [ExCEP.Codec.Frame](ExCEP.Codec.Frame.md): APDU framing codec for CSG CEP TS2.2 Section 4.6–4.8.
- [ExCEP.Codec.Services.Business](ExCEP.Codec.Services.Business.md): Builders for all Business Channel (TCP 9902) ASDUs per CSG CEP TS2.2 Section 8:
- 8.2 Model Discovery (`GetModel`, `GetModelResp`)
- 8.3 Model Change (`ModelChange`, `ModelChangeResp`)
- 8.4–8.6 Sub-device Lifecycle (`DevAdd/Resp`, `DevUpdate/Resp`, `DevDel/Resp`)
- 8.7–8.8 Data Subscription (`DataSubs/Resp`, `GetDataSubs/Resp`)
- 8.9 Spontaneous/Periodic Reporting (`DataSpont`, `DataSpontResp`)
- 8.10 Data Read (`DataRead`, `DataReadResp`)
- 8.11 Parameter/Setting Read (`ParaRead`, `ParaReadResp`)
- 8.12 Topology File Query (`GetTopoFile`, `GetTopoFileResp`)
- 8.13 Message File Query (`GetMessage`, `GetMessageResp`)
- 8.14 Remote Control & Regulation (`CtrlCmd`, `CtrlCmdResp`)
- 8.15 Parameter/Setting Preset, Activate, Cancel (`ParaSet*`, `ParaActivate*`, `ParaCancel*`)
- 8.16 Historical Data Query (`GetHisData`, `GetHisDataResp`)

- [ExCEP.Codec.Services.Common](ExCEP.Codec.Services.Common.md): Builders and helpers for Common Data ASDUs (CSG CEP TS2.2 Section 6),
supported on both Management (9901) and Business (9902) channels:
- Channel Heartbeat (`Health`)
- File Pull (`FileGet`, `FileGetResp`, `FileDataTrans`, `FileDataTransResp`)
- File Push (`FileSend`, `FileSendResp`, `FileDataTrans`, `FileDataTransResp`)

- [ExCEP.Codec.Services.Management](ExCEP.Codec.Services.Management.md): Builders for all Management Channel (TCP 9901) ASDUs per CSG CEP TS2.2 Section 7:
- 7.2 / 7.3 Time Sync & Time Read (`TimeSyncReq/Resp`, `TimeReadReq/Resp`)
- 7.4 Device Management (`DeviceUpdate*`, `DeviceCtrl*`, `DeviceInfo*`, `DeviceStatus*`, `DeviceConfig*`, `SysAlarm`)
- 7.5 Container Management (`ConInstall*`, `ConStatus*`, `ConStart*`, `ConStop*`, `ConRestart*`, `ConRemove*`, `ConGetConfig*`, `ConSetConfig*`, `ConAlarm`)
- 7.6 Application Management (`AppInstall*`, `AppStatus*`, `AppStart*`, `AppStop*`, `AppRemove*`, `AppEnable*`, `AppDisable*`, `AppGetConfig*`, `AppSetConfig*`, `AppAlarm`)
- 7.7 Log Management (`DeviceGetLog*`, `ContGetLog*`, `AppGetLog*`)

- [ExCEP.Common.AlarmEvent](ExCEP.Common.AlarmEvent.md): Standard Alarm Event codes defined in CSG CEP TS2.2:
- Table 46: Device resource alarms (`1001`..`1005`)
- Table 47: Device fault alarms (`2001`..`2003`, `3004`)
- Table 65: Container alarms (`4001`..`4007`)
- Table 91: Application alarms (`5001`..`5005`)

- [ExCEP.Common.ErrorCode](ExCEP.Common.ErrorCode.md): Normative error codes defined in Appendix A (Table A.1) of CSG CEP TS2.2.
- [ExCEP.Common.Timestamp](ExCEP.Common.Timestamp.md): Timestamp formatting and parsing per CSG CEP TS2.2 (`"YYYY-MM-DD HH:MM:SS.AAA"`, local time).

- [ExCEP.Common.Types](ExCEP.Common.Types.md): Shared protocol enumerations and helpers defined in CSG CEP TS2.2.

- [ExCEP.Compat](ExCEP.Compat.md): Vendor and provincial grid interoperability profile for CSG CEP TS2.2.
- [ExCEP.Config](ExCEP.Config.md): Runtime stack configuration accessors and consistency validation for `ExCEP`.

- [ExCEP.Crypto.Cert](ExCEP.Crypto.Cert.md): Pure-Elixir **SM2 X.509 Certificate & Key Parser/Encoder** (GM/T 0015, GB/T 32918, RFC 5280).
- [ExCEP.Crypto.NoopSigner](ExCEP.Crypto.NoopSigner.md): No-op signer for development and plaintext/stubbed testing.
- [ExCEP.Crypto.SM2](ExCEP.Crypto.SM2.md): Pure Elixir implementation of **SM2** digital signatures (GB/T 32918.2-2016) over `sm2p256v1`.
- [ExCEP.Crypto.SM3](ExCEP.Crypto.SM3.md): Pure Elixir implementation of the Chinese national cryptographic hash function **SM3** (GB/T 32905-2016).
- [ExCEP.Crypto.SM4](ExCEP.Crypto.SM4.md): Pure Elixir implementation of the Chinese national block cipher **SM4** (GB/T 32907-2016).
- [ExCEP.Crypto.Signer](ExCEP.Crypto.Signer.md): Pluggable signing and verification behaviour for CEP APDU 64-byte SM2 signatures.
- [ExCEP.Gateway.Client](ExCEP.Gateway.Client.md): Single-channel Edge Gateway TCP/TLS client (`:management` on 9901 or `:business` on 9902).
- [ExCEP.Gateway.DefaultHandler](ExCEP.Gateway.DefaultHandler.md): Reference in-memory `ExCEP.Gateway.Handler` implementation supporting:
- Management channel: `TimeReadReq`, `TimeSyncReq`, `DeviceInfoReq`, `DeviceStatusReq`,
  `DeviceConfigReq`, `DeviceCtrlReq`, `DeviceUpdateReq`, `DeviceUpdateStatusReq`,
  Container/App/Log commands.
- Business channel: `GetModel`, `DataSubs`, `GetDataSubs`, `DataRead`, `ParaRead`,
  `GetTopoFile`, `GetMessage`, `GetHisData`,
  SBO/Direct `CtrlCmd` state machine (Section 8.14),
  and Preset/Activate/Cancel `ParaSet`/`ParaActivate`/`ParaCancel` state machine (Section 8.15).

- [ExCEP.Gateway.DualChannel](ExCEP.Gateway.DualChannel.md): Coordinates both CEP Northbound channels for an Edge Gateway:
- Management Channel (TCP 9901)
- Business Channel (TCP 9902)

- [ExCEP.Gateway.FileTransfer](ExCEP.Gateway.FileTransfer.md): Bidirectional chunked file transfer engine per CSG CEP TS2.2 Section 6.2.
- [ExCEP.Gateway.Handler](ExCEP.Gateway.Handler.md): Callback behaviour for handling incoming Cluster (Master) commands on an Edge Gateway.
- [ExCEP.Gateway.ReconnectWorker](ExCEP.Gateway.ReconnectWorker.md): Supervisor-friendly auto-reconnecting CEP Gateway client worker with exponential backoff.
- [ExCEP.Gateway.ReportScheduler](ExCEP.Gateway.ReportScheduler.md): Periodic and spontaneous `DataSpont` reporting engine for an Edge Gateway (Section 8.7 & 8.9).
- [ExCEP.Gateway.SubscriptionManager](ExCEP.Gateway.SubscriptionManager.md): Data Subscription rule engine per CSG CEP TS2.2 Section 8.7 & 8.8.
- [ExCEP.Model](ExCEP.Model.md): CSG CEP Plug-and-Play Device Model structure aligned with **TS2.1**
(Section 8, Tables 27–28, Section 9, Appendix B).
- [ExCEP.Model.Catalog](ExCEP.Model.Catalog.md): Built-in standard device modeling catalog from CSG CEP **TS2.1**
(Chapter 6 Tables 1–26 & Appendix A).
- [ExCEP.Model.Consistency](ExCEP.Model.Consistency.md): ICD ↔ Simplified JSON Model consistency verifier per CSG CEP **TS2.1** Section 9.3
- [ExCEP.Model.IcdParser](ExCEP.Model.IcdParser.md): DL/T 860 (IEC 61850) `.icd` XML model parser per CSG CEP **TS2.1** Section 8.2 & 9.1.
- [ExCEP.Model.Parser](ExCEP.Model.Parser.md): Strict JSON parser, semantic validator, and serializer for CSG CEP **TS2.1**
Simplified Device Model files (Section 8.3, Tables 27–28, Section 9.2, Appendix B).
- [ExCEP.Model.Point](ExCEP.Model.Point.md): Represents a single Data Object (`DO`) entry inside a CSG CEP TS2.1 simplified JSON model
(Table 27).
- [ExCEP.Model.Service](ExCEP.Model.Service.md): Represents one service group (`parameter`, `analog`, `discrete`, `control`, `accumulator`)
inside a CSG CEP TS2.1 simplified JSON model (Table 28).

- [ExCEP.Supervisor](ExCEP.Supervisor.md): OTP Supervisor helper for embedding `ExCEP` Cluster servers and/or auto-reconnecting
Edge Gateway clients into a host application's supervision tree.
- [ExCEP.Telemetry](ExCEP.Telemetry.md): Telemetry instrumentation for `ExCEP` using `:telemetry ~> 1.4`.
- [ExCEP.Transport.Cipher](ExCEP.Transport.Cipher.md): Pluggable payload encryption behaviour for CSG CEP TS6.3 encrypted communication.
- [ExCEP.Transport.ConnectionParams](ExCEP.Transport.ConnectionParams.md): Connection parameters for CEP Gateway clients and Cluster servers.

- [ExCEP.Transport.FrameChannel](ExCEP.Transport.FrameChannel.md): Shared frame encoding/sending helpers for both Gateway clients and Cluster sessions.

- [ExCEP.Transport.NoopCipher](ExCEP.Transport.NoopCipher.md): Plaintext pass-through `ExCEP.Transport.Cipher`.
- [ExCEP.Transport.Socket](ExCEP.Transport.Socket.md): Unified TCP / TLS socket wrapper over Erlang `:gen_tcp` and `:ssl` (IPv4 & IPv6).

