EtherCAT.Simulator.Slave.Definition (ethercat v0.5.0)

Copy Markdown View Source

Public authored definition for a simulated EtherCAT slave.

A definition describes the high-level device identity, process-data layout, mailbox/object-dictionary capabilities, and behavior module. Derived low-level ESC state such as EEPROM contents and register memory is hydrated internally by the simulator runtime and is not part of this public type.

Summary

Types

Mailbox SM layout declared by the simulated device.

t()

High-level, authored simulator device definition.

Functions

Build a simulated device from profile defaults and explicit overrides.

Types

mailbox_config()

@type mailbox_config() :: %{
  recv_offset: non_neg_integer(),
  recv_size: non_neg_integer(),
  send_offset: non_neg_integer(),
  send_size: non_neg_integer()
}

Mailbox SM layout declared by the simulated device.

pdo_entry()

@type pdo_entry() :: EtherCAT.Driver.PDO.t()

signal_spec()

@type signal_spec() :: %{
  :direction => :input | :output,
  :pdo_index => non_neg_integer(),
  :bit_offset => non_neg_integer(),
  :bit_size => pos_integer(),
  :type => atom(),
  :label => binary(),
  :group => atom(),
  optional(:scale) => number(),
  optional(:unit) => binary()
}

t()

@type t() :: %EtherCAT.Simulator.Slave.Definition{
  behavior: module(),
  dc_capable?: boolean(),
  esc_type: byte(),
  fmmu_count: pos_integer(),
  input_phys: non_neg_integer(),
  input_size: non_neg_integer(),
  mailbox_config: mailbox_config(),
  mirror_output_to_input?: boolean(),
  name: atom(),
  objects: map(),
  output_phys: non_neg_integer(),
  output_size: non_neg_integer(),
  pdo_entries: [pdo_entry()],
  product_code: non_neg_integer(),
  profile: atom(),
  revision: non_neg_integer(),
  serial_number: non_neg_integer(),
  signals: %{optional(atom()) => signal_spec()},
  sm_count: pos_integer(),
  vendor_id: non_neg_integer()
}

High-level, authored simulator device definition.

Functions

build(profile, opts \\ [])

@spec build(atom(), keyword()) :: t()

Build a simulated device from profile defaults and explicit overrides.

Profiles are :coupler, :digital_io, :mailbox_device, :lan9252_demo, :analog_io, :temperature_input, and :servo_drive. Pass :name to distinguish devices in a segment. Other options override identity, PDOs, signals, mailbox objects, behavior, and the authored fields described by t/0.

For example, this creates a synthetic one-byte output/input image with loopback:

EtherCAT.Simulator.Slave.Definition.build(:digital_io, name: :io)

A channel-oriented input fixture can instead use:

EtherCAT.Simulator.Slave.Definition.build(:digital_io,
  name: :inputs, mode: :channels, direction: :input, channels: 8
)

These are protocol fixtures, not proof of a vendor device's behavior. When a real driver has a simulator companion, prefer EtherCAT.Simulator.Slave.from_driver/2 to keep its identity defaults aligned.

from_driver(driver, config, adapter)

@spec from_driver(module(), map(), module()) :: t()