ExCEP.Common.Types (ex_cep v0.1.1)

Copy Markdown

Shared protocol enumerations and helpers defined in CSG CEP TS2.2.

Summary

Functions

Formats a CRC32 integer as protocol hex string, e.g. "0x12345678".

Cause of Transmission (Head/Cot, Table 2)

Control command types (CtrlCmd, Table 122)

Encodes data quality ("00" = valid & not substituted; digit 1: 0 valid / 1 invalid; digit 2: 0 not substituted / 1 substituted).

Generates a unique message ID (Head/Mid).

Generates a CmdId / SetId within protocol range 0..4294967295.

Parses a protocol CRC32 hex string ("0x12345678") to integer.

Types

cot()

@type cot() :: :request | :response | :periodic | :spontaneous | :confirm | String.t()

ctrl_type()

@type ctrl_type() ::
  :yk_select
  | :yk_execute
  | :yk_cancel
  | :yt_select
  | :yt_execute
  | :yt_cancel
  | :yk_direct
  | :yt_direct

Functions

crc32_hex(data)

@spec crc32_hex(iodata()) :: String.t()

Formats a CRC32 integer as protocol hex string, e.g. "0x12345678".

decode_cot(other)

@spec decode_cot(String.t()) :: cot()

decode_ctrl_type(arg1)

@spec decode_ctrl_type(String.t()) ::
  {:ok, ctrl_type()} | {:error, :invalid_ctrl_type}

decode_quality(raw)

@spec decode_quality(String.t()) :: %{
  valid?: boolean(),
  substituted?: boolean(),
  raw: String.t()
}

encode_cot(str)

@spec encode_cot(cot()) :: String.t()

Cause of Transmission (Head/Cot, Table 2):

  • "1" (:request) - 主动请求
  • "2" (:response) - 应答请求
  • "3" (:periodic) - 周期上送
  • "4" (:spontaneous) - 变化上送
  • "5" (:confirm) - 主动确认

encode_ctrl_type(str)

@spec encode_ctrl_type(ctrl_type() | String.t()) :: String.t()

Control command types (CtrlCmd, Table 122):

  • "0" (:yk_select) - 遥控选择
  • "1" (:yk_execute) - 遥控执行
  • "2" (:yk_cancel) - 遥控取消
  • "3" (:yt_select) - 遥调选择
  • "4" (:yt_execute) - 遥调执行
  • "5" (:yt_cancel) - 遥调取消
  • "6" (:yk_direct) - 遥控直接控制
  • "7" (:yt_direct) - 遥调直接控制

encode_quality(valid?, substituted? \\ false)

@spec encode_quality(boolean(), boolean()) :: String.t()

Encodes data quality ("00" = valid & not substituted; digit 1: 0 valid / 1 invalid; digit 2: 0 not substituted / 1 substituted).

next_mid()

@spec next_mid() :: String.t()

Generates a unique message ID (Head/Mid).

next_uint32_id()

@spec next_uint32_id() :: String.t()

Generates a CmdId / SetId within protocol range 0..4294967295.

parse_crc32_hex(hex)

@spec parse_crc32_hex(term()) :: {:ok, non_neg_integer()} | {:error, :invalid_crc}

Parses a protocol CRC32 hex string ("0x12345678") to integer.