ExCEP (ex_cep v0.1.1)
Copy MarkdownPure Elixir implementation of the China Southern Power Grid (CSG) CEP Edge Gateway Plug-and-Play Protocol (TS2.2).
This top-level module provides unified entrypoints for starting Cluster (Master) servers, connecting Edge Gateways (single-channel, dual-channel, or auto-reconnecting), and executing every Management (TCP 9901), Business (TCP 9902), File Transfer, Proactive Reporting, TS2.1 Model/Catalog, and SM2 Certificate API.
Quick Start
# Generate SM2 keypairs for Cluster and Gateway
{cluster_pub, cluster_priv} = ExCEP.Crypto.SM2.generate_keypair()
{gw_pub, gw_priv} = ExCEP.Crypto.SM2.generate_keypair()
# Start Cluster Business Server
{:ok, server} =
ExCEP.start_server(
channel: :business,
port: 9902,
signer: {ExCEP.Crypto.SM2, private_key: cluster_priv, peer_public_key: gw_pub}
)
# Connect Edge Gateway Client
{:ok, gw} =
ExCEP.connect("127.0.0.1", 9902,
channel: :business,
gateway_id: "GW-001",
signer: {ExCEP.Crypto.SM2, private_key: gw_priv, peer_public_key: cluster_pub}
)
{:ok, resp} = ExCEP.get_model(server, "GW-001")
:ok = ExCEP.disconnect(gw)
:ok = ExCEP.stop_server(server)
Summary
Functions
Builds an {ExCEP.Crypto.SM2, opts} signer tuple from PEM/DER/file certificates and keys.
Builds a TS2.1 standard %ExCEP.Model{} from the built-in 5-domain/26-device catalog.
Sends a %DataAsdu{} request from Cluster server to gateway_id and awaits response.
Sends a one-way %DataAsdu{} from Cluster server to gateway_id.
Creates and connects a single-channel Edge Gateway client to host:port.
Starts and connects a DualChannel Gateway client (both 9901 Management + 9902 Business).
Returns true if Gateway client is connected and authenticated.
Closes a connected Gateway client.
Closes both Management and Business channels of a DualChannel Gateway client.
Returns the Business channel client pid from a DualChannel Gateway client.
Returns {mgmt_client_pid, biz_client_pid} for a DualChannel Gateway client.
Returns the Management channel client pid from a DualChannel Gateway client.
Pulls a binary file from the Cluster (FileGet initiated by Gateway).
Pushes a binary file from the Gateway to the Cluster (FileSend initiated by Gateway).
Sends a %DataAsdu{} request from Gateway client to Cluster and awaits response.
Sends a one-way %DataAsdu{} from Gateway client to Cluster.
Looks up the active ExCEP.Cluster.Session pid for gateway_id.
Returns the 5 standard TS2.1 domains.
Lists connected and authenticated gateway_ids on server.
Returns all 168 TS2.1 logical node names.
Lists all 26 standard TS2.1 device model definitions (optionally filtered by domain).
Looks up a TS2.1 standard Logical Node (e.g. "SlrBrkMMXU") and its Appendix A DOs.
Parses an SM2 X.509 certificate from a PEM or DER binary.
Loads and parses an SM2 X.509 certificate file (.pem, .crt, .cer, .der).
Parses a CSG CEP TS2.1 device model file (.json or .icd) from disk into %ExCEP.Model{}.
Parses a CSG CEP TS2.1 DL/T 860 .icd XML binary into %ExCEP.Model{}.
Parses a CSG CEP TS2.1 simplified JSON model binary into %ExCEP.Model{}.
Pulls a file from a connected Gateway using Section 6.2.1 (FileGet + FileDataTrans).
Pushes a binary file to a connected Gateway using Section 6.2.2 (FileSend + FileDataTrans).
Reports an application alarm (AppAlarm) on the management channel.
Reports asynchronous application install completion (AppInstallResult).
Reports a container alarm (ConAlarm) on the management channel.
Reports spontaneous/periodic measurements (DataSpont) to the Cluster.
Reports sub-device additions (DevAdd) to the Cluster.
Reports sub-device deletions (DevDel) to the Cluster.
Reports sub-device updates (DevUpdate) to the Cluster.
Reports asynchronous firmware/device upgrade completion (DeviceUpdateResult).
Reports device model changes (ModelChange) to the Cluster.
Reports a system alarm (SysAlarm) on the management channel.
Searches all 1,395 TS2.1 Data Objects by keyword.
Sends an immediate Health heartbeat from Gateway client.
Returns the TCP listen port bound by server.
Starts a supervisor-friendly auto-reconnecting Gateway client worker.
Starts an Edge Cluster server (:management on 9901 or :business on 9902).
Stops a running Cluster server.
Verifies TS2.1 Section 9.3 consistency between an ICD model and a simplified JSON model.
Functions
Builds an {ExCEP.Crypto.SM2, opts} signer tuple from PEM/DER/file certificates and keys.
Builds a TS2.1 standard %ExCEP.Model{} from the built-in 5-domain/26-device catalog.
Sends a %DataAsdu{} request from Cluster server to gateway_id and awaits response.
Sends a one-way %DataAsdu{} from Cluster server to gateway_id.
@spec connect(String.t() | :inet.ip_address(), :inet.port_number(), keyword()) :: {:ok, pid()} | {:error, term()}
Creates and connects a single-channel Edge Gateway client to host:port.
Starts and connects a DualChannel Gateway client (both 9901 Management + 9902 Business).
Returns true if Gateway client is connected and authenticated.
@spec disconnect(GenServer.server()) :: :ok
Closes a connected Gateway client.
Closes both Management and Business channels of a DualChannel Gateway client.
Returns the Business channel client pid from a DualChannel Gateway client.
Returns {mgmt_client_pid, biz_client_pid} for a DualChannel Gateway client.
Returns the Management channel client pid from a DualChannel Gateway client.
Pulls a binary file from the Cluster (FileGet initiated by Gateway).
Pushes a binary file from the Gateway to the Cluster (FileSend initiated by Gateway).
Sends a %DataAsdu{} request from Gateway client to Cluster and awaits response.
Sends a one-way %DataAsdu{} from Gateway client to Cluster.
Looks up the active ExCEP.Cluster.Session pid for gateway_id.
Returns the 5 standard TS2.1 domains.
@spec list_gateways(GenServer.server()) :: [String.t()]
Lists connected and authenticated gateway_ids on server.
Returns all 168 TS2.1 logical node names.
Lists all 26 standard TS2.1 device model definitions (optionally filtered by domain).
Looks up a TS2.1 standard Logical Node (e.g. "SlrBrkMMXU") and its Appendix A DOs.
Parses an SM2 X.509 certificate from a PEM or DER binary.
Loads and parses an SM2 X.509 certificate file (.pem, .crt, .cer, .der).
@spec parse_model(Path.t(), keyword()) :: {:ok, ExCEP.Model.t()} | {:error, term()}
Parses a CSG CEP TS2.1 device model file (.json or .icd) from disk into %ExCEP.Model{}.
Parses a CSG CEP TS2.1 DL/T 860 .icd XML binary into %ExCEP.Model{}.
Parses a CSG CEP TS2.1 simplified JSON model binary into %ExCEP.Model{}.
Pulls a file from a connected Gateway using Section 6.2.1 (FileGet + FileDataTrans).
Pushes a binary file to a connected Gateway using Section 6.2.2 (FileSend + FileDataTrans).
Reports an application alarm (AppAlarm) on the management channel.
Reports asynchronous application install completion (AppInstallResult).
Reports a container alarm (ConAlarm) on the management channel.
Reports spontaneous/periodic measurements (DataSpont) to the Cluster.
Reports sub-device additions (DevAdd) to the Cluster.
Reports sub-device deletions (DevDel) to the Cluster.
Reports sub-device updates (DevUpdate) to the Cluster.
Reports asynchronous firmware/device upgrade completion (DeviceUpdateResult).
Reports device model changes (ModelChange) to the Cluster.
Reports a system alarm (SysAlarm) on the management channel.
Searches all 1,395 TS2.1 Data Objects by keyword.
Sends an immediate Health heartbeat from Gateway client.
Returns the TCP listen port bound by server.
@spec start_reconnect_client(keyword()) :: GenServer.on_start()
Starts a supervisor-friendly auto-reconnecting Gateway client worker.
@spec start_server(keyword()) :: GenServer.on_start()
Starts an Edge Cluster server (:management on 9901 or :business on 9902).
@spec stop_server(GenServer.server()) :: :ok
Stops a running Cluster server.
Verifies TS2.1 Section 9.3 consistency between an ICD model and a simplified JSON model.
@spec version() :: String.t()
Returns the current ExCEP package version string.