# `ExCEP.Common.Types`

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

# `cot`

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

# `ctrl_type`

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

# `crc32_hex`

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

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

# `decode_cot`

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

# `decode_ctrl_type`

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

# `decode_quality`

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

# `encode_cot`

```elixir
@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`

```elixir
@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`

```elixir
@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`

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

Generates a unique message ID (`Head/Mid`).

# `next_uint32_id`

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

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

# `parse_crc32_hex`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
