EtherCAT.Simulator.Transport.Udp (ethercat v0.4.2)

Copy Markdown View Source

UDP endpoint for EtherCAT.Simulator.

This binds a real UDP socket and forwards EtherCAT UDP payloads to a running simulator segment, so the normal UdpSocket transport can talk to simulated slaves without any test-specific seam in the master runtime.

It also owns UDP-edge fault injection for cases that cannot be modeled at the datagram-execution layer, such as malformed EtherCAT frame headers, deliberately mismatched datagram indices, or stale previous-response replay.

Supported reply-fault injection forms:

  • EtherCAT.Simulator.Transport.Udp.Fault.truncate()
  • EtherCAT.Simulator.Transport.Udp.Fault.wrong_idx() |> EtherCAT.Simulator.Transport.Udp.Fault.next(count)
  • EtherCAT.Simulator.Transport.Udp.Fault.script([mode, ...])

Supported modes:

  • :truncate
  • :unsupported_type
  • :wrong_idx
  • :replay_previous

Summary

Functions

Returns a specification to start this module under a supervisor.

Types

fault()

@type fault() ::
  {:corrupt_next_response, frame_fault_mode()}
  | {:corrupt_next_responses, pos_integer(), frame_fault_mode()}
  | {:corrupt_response_script, [frame_fault_mode(), ...]}

frame_fault_mode()

@type frame_fault_mode() ::
  :truncate | :unsupported_type | :wrong_idx | :replay_previous

state()

@type state() :: %{
  socket: :gen_udp.socket(),
  ip: :inet.ip_address(),
  port: :inet.port_number(),
  pending_faults: [frame_fault_mode()],
  last_response_payload: binary() | nil
}

Functions

child_spec(init_arg)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a specification to start this module under a supervisor.

See Supervisor.

clear_faults()

@spec clear_faults() :: :ok | {:error, :not_found}

info()

@spec info() :: {:ok, map()} | {:error, term()}

inject_fault(fault)

@spec inject_fault(EtherCAT.Simulator.Transport.Udp.Fault.t() | fault()) ::
  :ok | {:error, :invalid_fault | :not_found}

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()