EtherCAT.Frame (yaethercat v0.1.0)

Copy Markdown View Source

An EtherCAT frame: a header of two bytes, with the length of what follows and its type, then one or more datagrams (ETG.1000.4, 5.3). It goes in an Ethernet frame of EtherType 0x88A4, or in a UDP datagram to port 0x88A4 (34980).

iex> frame = EtherCAT.Frame.encode([%{EtherCAT.Datagram.new({:brd, 0x0000, 1}) | index: 7}])
<<13, 0x10, 0x07, 7, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0>>
iex> {:ok, [datagram]} = EtherCAT.Frame.decode(frame)
iex> datagram.command
:brd

Only frames of datagrams are this library's: the spec's network variables (type 4) and mailbox frames (type 5) are decoded no further than their type.

Summary

Types

The type in a frame's header: 1 for datagrams.

Functions

The datagrams of a frame. What follows its length, such as padding, is passed over.

The frame of some datagrams, next set in all but the last. Raises ArgumentError when they don't fit in one.

The EtherType of EtherCAT frames, and the UDP port they go to.

The EtherCAT frame in an Ethernet frame, with the source address, or :error for an Ethernet frame of another EtherType. A VLAN tag is passed over.

The bytes of datagrams a frame can take.

An EtherCAT frame in an Ethernet frame from source, a MAC address of six bytes, to the broadcast address, padded to the least Ethernet allows.

Types

type()

@type type() :: 0..15

The type in a frame's header: 1 for datagrams.

Functions

decode(arg1)

@spec decode(binary()) ::
  {:ok, [EtherCAT.Datagram.t()]}
  | {:error, {:type, type()} | :invalid_length | :invalid_command}

The datagrams of a frame. What follows its length, such as padding, is passed over.

  • {:ok, datagrams}
  • {:error, {:type, type}} for a frame of another type than datagrams
  • {:error, :invalid_length}, {:error, :invalid_command} for one that isn't a frame

encode(datagrams)

@spec encode([EtherCAT.Datagram.t()]) :: binary()

The frame of some datagrams, next set in all but the last. Raises ArgumentError when they don't fit in one.

ethertype()

@spec ethertype() :: 34980

The EtherType of EtherCAT frames, and the UDP port they go to.

from_ethernet(arg1)

@spec from_ethernet(binary()) :: {:ok, <<_::48>>, binary()} | :error

The EtherCAT frame in an Ethernet frame, with the source address, or :error for an Ethernet frame of another EtherType. A VLAN tag is passed over.

max_size()

@spec max_size() :: pos_integer()

The bytes of datagrams a frame can take.

to_ethernet(frame, source)

@spec to_ethernet(binary(), <<_::48>>) :: binary()

An EtherCAT frame in an Ethernet frame from source, a MAC address of six bytes, to the broadcast address, padded to the least Ethernet allows.