IEC60870.CS101.Frame (ExIEC60870 v0.1.0)

Copy Markdown View Source

IEC 60870-5-101 FT 1.2 frame codec and stream deframer (serial_transceiver_ft_1_2.c & link_layer.c).

Supports:

  • Single-character ACK (0xE5): :single_char_ack
  • Fixed-length frame (0x10, C, Addr..., CS, 0x16): {:fixed_frame, control_map, address}
  • Variable-length frame (0x68, L, L, 0x68, C, Addr..., UserData..., CS, 0x16): {:variable_frame, control_map, address, user_data}

Summary

Functions

Computes 8-bit modulo-256 sum of bytes in bin.

Decodes a single complete FT 1.2 frame given address_length (0, 1, or 2).

Decodes a link layer address according to address_length (0, 1, or 2).

Decodes an 8-bit control field byte into a map.

Encodes an FT 1.2 frame into wire binary given address_length (0, 1, or 2).

Encodes a link layer address according to address_length (0, 1, or 2).

Encodes a control field map into an 8-bit integer.

Extracts complete FT 1.2 frames from a stream buffer given address_length. Returns {:ok, frames, remaining_buffer} or {:error, reason, remaining_buffer}.

Types

control()

@type control() :: %{
  dir: boolean(),
  prm: boolean(),
  fcb_or_acd: boolean(),
  fcv_or_dfc: boolean(),
  fc: 0..15
}

t()

@type t() ::
  :single_char_ack
  | {:fixed_frame, control(), non_neg_integer()}
  | {:variable_frame, control(), non_neg_integer(), binary()}

Functions

checksum(bin)

@spec checksum(binary()) :: non_neg_integer()

Computes 8-bit modulo-256 sum of bytes in bin.

decode(arg1, addr_len)

@spec decode(binary(), 0..2) :: {:ok, t()} | {:error, term()}

Decodes a single complete FT 1.2 frame given address_length (0, 1, or 2).

decode_address(rest, arg2)

@spec decode_address(binary(), 0..2) ::
  {:ok, non_neg_integer(), binary()} | {:error, term()}

Decodes a link layer address according to address_length (0, 1, or 2).

decode_control(c)

@spec decode_control(non_neg_integer()) :: control()

Decodes an 8-bit control field byte into a map.

encode(arg1, addr_len)

@spec encode(t(), 0..2) :: {:ok, binary()} | {:error, term()}

Encodes an FT 1.2 frame into wire binary given address_length (0, 1, or 2).

encode_address(addr, int)

@spec encode_address(non_neg_integer(), 0..2) :: binary()

Encodes a link layer address according to address_length (0, 1, or 2).

encode_control(ctrl)

@spec encode_control(map()) :: non_neg_integer()

Encodes a control field map into an 8-bit integer.

extract_frames(buffer, addr_len \\ 1)

@spec extract_frames(binary(), 0..2) ::
  {:ok, [t()], binary()} | {:error, term(), binary()}

Extracts complete FT 1.2 frames from a stream buffer given address_length. Returns {:ok, frames, remaining_buffer} or {:error, reason, remaining_buffer}.

fc_ack()

fc_nack()

fc_request_for_access_demand()

fc_request_user_data_class_1()

fc_request_user_data_class_2()

fc_reset_fcb()

fc_reset_remote_link()

fc_reset_user_process()

fc_resp_nack_no_data()

fc_resp_user_data()

fc_service_not_functioning()

fc_service_not_implemented()

fc_test_function_for_link()

fc_user_data_confirmed()

fc_user_data_no_reply()