MAVLink2.Dialect.XML (mavlink2 v0.1.0)

Copy Markdown View Source

A MAVLink2.Dialect generated at compile time from a MAVLink XML file and its includes:

defmodule MyDialect do
  use MAVLink2.Dialect.XML, file: "priv/my_dialect.xml"
end

:file is relative to the project root, or absolute. The module recompiles when any of the XML files changes.

Generated in the dialect module:

Function
crc_extra/1, payload_length/1, target_offsets/1the MAVLink2.Dialect callbacks; target_offsets/1 is {nil, nil} for an unknown id
msgids/0, message/1every message id; the struct module for an id, or nil
encode/1a message struct to {msgid, payload} (untruncated; MAVLink2.Frame truncates); ArgumentError for an integer outside its field's type
decode/2{msgid, payload} to {:ok, struct}, or {:error, {:unknown_msgid, id}}
enum/1, enum_value/2, enum_entry/2an enum as %{entry => value}, an entry's value, a value's entry

And a module per message, named from the message (COMMAND_LONG is MyDialect.CommandLong): a struct with the XML's field names as written, each starting at its zero value (MAVLink2.Codec), and msgid/0, crc_extra/0, layout/0, target_offsets/0. A uint8_t_mavlink_version field starts at the XML's <version>. Enum and entry names are lowercase atoms (:mav_cmd, :mav_cmd_component_arm_disarm).