ExCEP.Gateway.Client (ex_cep v0.1.1)

Copy Markdown

Single-channel Edge Gateway TCP/TLS client (:management on 9901 or :business on 9902).

Lifecycle

  1. Opens TCP/TLS connection to the Cluster server.
  2. If require_auth: true, executes the Section 5 three-way SM2 authentication handshake:
    • Sends AuthAsdu.Request (0x01) with random r1
    • Receives & verifies AuthAsdu.Response (0x02) checking r1 and SM2 signature
    • Sends AuthAsdu.Confirm (0x03) echoing r2
  3. Enters active framing mode ({:active, :once}), sending Health heartbeat whenever idle for heartbeat_interval_ms (default 60s).
  4. Correlates outgoing requests by Head/Mid and dispatches incoming Cluster requests to the configured ExCEP.Gateway.Handler (default ExCEP.Gateway.DefaultHandler).

Summary

Functions

Returns a specification to start this module under a supervisor.

Closes the connection.

Connects and authenticates to the Cluster server.

Returns true if connected (and authenticated when require_auth is enabled).

Pulls a binary file from the Cluster using Section 6.2.1 FileGet (e.g. firmware/app package).

Pushes a binary file to the Cluster using Section 6.2.2 chunked transfer.

Reports an app alarm (AppAlarm) on the management channel.

Reports AppInstallResult (Section 7.6.2) on the management channel.

Reports a container alarm (ConAlarm) on the management channel.

Reports DataSpont (spontaneous or periodic) and awaits DataSpontResp.

Reports DevAdd and awaits DevAddResp.

Reports DevDel and awaits DevDelResp.

Reports DevUpdate and awaits DevUpdateResp.

Reports DeviceUpdateResult (Section 7.4.2) on the management channel.

Reports ModelChange and awaits ModelChangeResp.

Reports a system alarm (SysAlarm) on the management channel.

Sends a %DataAsdu{} and awaits the correlated response matching Head/Mid.

Sends a %DataAsdu{} without waiting for a response (one-way upload / alarm).

Sends a Health heartbeat immediately.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(client)

@spec close(GenServer.server()) :: :ok

Closes the connection.

connect(client)

@spec connect(GenServer.server()) :: :ok | {:error, term()}

Connects and authenticates to the Cluster server.

connected?(client)

@spec connected?(GenServer.server()) :: boolean()

Returns true if connected (and authenticated when require_auth is enabled).

pull_file(client, remote_path, opts \\ [])

@spec pull_file(GenServer.server(), String.t(), keyword()) ::
  {:ok, binary()} | {:error, term()}

Pulls a binary file from the Cluster using Section 6.2.1 FileGet (e.g. firmware/app package).

push_file(client, gateway_id, remote_path, content, opts \\ [])

Pushes a binary file to the Cluster using Section 6.2.2 chunked transfer.

report_app_alarm(client, gateway_id, container, app, event_code, msg \\ nil)

Reports an app alarm (AppAlarm) on the management channel.

report_app_install_result(client, gateway_id, job_id, result, opts \\ [])

Reports AppInstallResult (Section 7.6.2) on the management channel.

report_con_alarm(client, gateway_id, container, event_code, msg \\ nil)

Reports a container alarm (ConAlarm) on the management channel.

report_data_spont(client, gateway_id, devices, opts \\ [])

Reports DataSpont (spontaneous or periodic) and awaits DataSpontResp.

report_dev_add(client, gateway_id, devices, opts \\ [])

Reports DevAdd and awaits DevAddResp.

report_dev_del(client, gateway_id, devices, opts \\ [])

Reports DevDel and awaits DevDelResp.

report_dev_update(client, gateway_id, devices, opts \\ [])

Reports DevUpdate and awaits DevUpdateResp.

report_device_update_result(client, gateway_id, job_id, result, opts \\ [])

Reports DeviceUpdateResult (Section 7.4.2) on the management channel.

report_model_change(client, gateway_id, models, opts \\ [])

Reports ModelChange and awaits ModelChangeResp.

report_sys_alarm(client, gateway_id, event_code, msg \\ nil)

Reports a system alarm (SysAlarm) on the management channel.

request(client, asdu, opts \\ [])

@spec request(GenServer.server(), ExCEP.Codec.DataAsdu.t(), keyword()) ::
  {:ok, ExCEP.Codec.DataAsdu.t()} | {:error, term()}

Sends a %DataAsdu{} and awaits the correlated response matching Head/Mid.

send_asdu(client, asdu, opts \\ [])

@spec send_asdu(GenServer.server(), ExCEP.Codec.DataAsdu.t(), keyword()) ::
  :ok | {:error, term()}

Sends a %DataAsdu{} without waiting for a response (one-way upload / alarm).

send_heartbeat(client)

@spec send_heartbeat(GenServer.server()) :: :ok | {:error, term()}

Sends a Health heartbeat immediately.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()