IEC60870.CS104.Connection (ExIEC60870 v0.1.0)

Copy Markdown View Source

IEC 60870-5-104 Client / Master Connection (GenServer), equivalent to cs104_connection.c.

Manages:

Summary

Functions

Returns a specification to start this module under a supervisor.

Sends C_CS_NA_1 (TypeID 103) clock synchronization command.

Sends C_CI_NA_1 (TypeID 101) counter interrogation command.

Sends C_IC_NA_1 (TypeID 100) interrogation command.

Sends a process command InformationObject wrapped in an ASDU.

Sends C_RD_NA_1 (TypeID 102) read command.

Sends C_TS_NA_1 (TypeID 104) test command.

Sends C_TS_TA_1 (TypeID 107) test command with CP56Time2a timestamp.

Sets or updates the ASDU received handler on the connection. Matches CS104_Connection_setASDUReceivedHandler.

Sets or updates the connection event handler on the connection. Matches CS104_Connection_setConnectionHandler.

Starts a CS104.Connection process.

Types

connection_event()

@type connection_event() ::
  :opened | :closed | :startdt_con_received | :stopdt_con_received | :failed

state_name()

@type state_name() ::
  :idle
  | :inactive
  | :waiting_for_startdt_con
  | :active
  | :waiting_for_stopdt_con

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(conn)

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

connect(conn)

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

connect_async(conn)

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

get_apci_parameters(conn)

@spec get_apci_parameters(GenServer.server()) :: IEC60870.APCIParameters.t()

get_app_layer_parameters(conn)

@spec get_app_layer_parameters(GenServer.server()) :: IEC60870.AppLayerParameters.t()

get_state(conn)

@spec get_state(GenServer.server()) :: map()

is_connected?(conn)

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

is_transmit_buffer_full?(conn)

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

send_asdu(conn, asdu)

@spec send_asdu(GenServer.server(), IEC60870.ASDU.t()) :: :ok | {:error, term()}

send_clock_sync_command(conn, ca, new_time)

Sends C_CS_NA_1 (TypeID 103) clock synchronization command.

send_counter_interrogation_command(conn, cot \\ :activation, ca, qcc \\ 5)

Sends C_CI_NA_1 (TypeID 101) counter interrogation command.

send_interrogation_command(conn, cot \\ :activation, ca, qoi \\ 20)

Sends C_IC_NA_1 (TypeID 100) interrogation command.

send_process_command(conn, cot, ca, io)

Sends a process command InformationObject wrapped in an ASDU.

send_process_command(conn, type_id, cot, ca, io)

send_read_command(conn, ca, ioa)

Sends C_RD_NA_1 (TypeID 102) read command.

send_start_dt(conn)

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

send_stop_dt(conn)

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

send_test_command(conn, ca)

Sends C_TS_NA_1 (TypeID 104) test command.

send_test_command_with_timestamp(conn, ca, tsc, timestamp)

Sends C_TS_TA_1 (TypeID 107) test command with CP56Time2a timestamp.

send_test_fr(conn)

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

set_apci_parameters(conn, params)

@spec set_apci_parameters(GenServer.server(), IEC60870.APCIParameters.t()) :: :ok

set_app_layer_parameters(conn, params)

@spec set_app_layer_parameters(GenServer.server(), IEC60870.AppLayerParameters.t()) ::
  :ok

set_asdu_handler(conn, handler)

@spec set_asdu_handler(
  GenServer.server(),
  (pid(), IEC60870.ASDU.t() -> any()) | (IEC60870.ASDU.t() -> any()) | nil
) :: :ok

Sets or updates the ASDU received handler on the connection. Matches CS104_Connection_setASDUReceivedHandler.

set_connection_handler(conn, handler)

@spec set_connection_handler(
  GenServer.server(),
  (pid(), atom() -> any()) | (atom() -> any()) | nil
) ::
  :ok

Sets or updates the connection event handler on the connection. Matches CS104_Connection_setConnectionHandler.

set_originator_address(conn, oa)

@spec set_originator_address(GenServer.server(), non_neg_integer()) :: :ok

start_link(opts \\ [])

Starts a CS104.Connection process.

Options:

  • :host - remote IP or hostname (default "127.0.0.1")
  • :port - remote TCP port (default 2404, or 19998 if :tls_opts is given)
  • :local_ip - optional local bind address
  • :local_port - optional local bind port (default 0)
  • :tls_opts - optional :ssl options list for TLS connections
  • :apci_params - %IEC60870.APCIParameters{}
  • :al_params - %IEC60870.AppLayerParameters{}
  • :owner - PID to receive {:iec60870_cs104, pid, event} messages
  • :connection_handler - fn conn_pid, event -> any() end
  • :asdu_handler - fn conn_pid, asdu -> any() end
  • :raw_message_handler - fn conn_pid, raw_bytes, sent? -> any() end
  • :auto_connect - boolean (default false)
  • :name - GenServer registration name