# `IEC60870.CS104.MasterConnection`
[🔗](https://github.com/Ultraluv/ex_iec60870/blob/main/lib/iec60870/cs104/master_connection.ex#L1)

Represents a connected Master (Client) peer on a `CS104.Slave` server (`MasterConnection` in `cs104_slave.c`).

Provides peer response helpers that can be safely called both inside Slave callbacks
(`interrogation_handler`, `asdu_handler`, etc.) and from external processes:
- `send_asdu/2`
- `send_act_con/3`
- `send_act_term/2`
- `is_active?/1`
- `get_peer_address/1`
- `close/1`

# `t`

```elixir
@type t() :: pid()
```

# `close`

```elixir
@spec close(t()) :: :ok
```

Closes the master connection.

# `get_app_layer_parameters`

```elixir
@spec get_app_layer_parameters(t()) :: IEC60870.AppLayerParameters.t()
```

Returns the `IEC60870.AppLayerParameters` of this master connection.

# `get_peer_address`

```elixir
@spec get_peer_address(t()) ::
  {:ok, {String.t(), non_neg_integer()}} | {:error, term()}
```

Returns `{ip_string, port}` of the connected peer.

# `is_active?`

```elixir
@spec is_active?(t()) :: boolean()
```

Checks whether this connection is currently in the active (`STARTDT`) state.

# `is_ready?`

```elixir
@spec is_ready?(t()) :: boolean()
```

Checks whether this connection is ready to transmit an ASDU (`IMasterConnection_isReady`).

# `send_act_con`

```elixir
@spec send_act_con(t(), IEC60870.ASDU.t(), boolean()) :: :ok | {:error, term()}
```

Sends an `ACTIVATION_CON` (or `DEACTIVATION_CON` if the request was `DEACTIVATION`) response
mirroring the request ASDU with `negative` flag set as specified.
Matches `IMasterConnection_sendACT_CON` in `cs104_slave.c`.

# `send_act_term`

```elixir
@spec send_act_term(t(), IEC60870.ASDU.t()) :: :ok | {:error, term()}
```

Sends an `ACTIVATION_TERMINATION` (`:activation_termination`) response mirroring the request ASDU.
Matches `IMasterConnection_sendACT_TERM` in `cs104_slave.c`.

# `send_asdu`

```elixir
@spec send_asdu(t(), IEC60870.ASDU.t()) :: :ok
```

Sends an ASDU over this specific master connection (or queues it in the high-priority queue).
Safe to call from inside Slave callbacks or external processes.

---

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