mavlink v0.9.0 MAVLink.Router View Source

Connect to serial, udp and tcp ports and listen for, validate and forward MAVLink messages towards their destinations on other connections and/or Elixir processes subscribing to messages.

The rules for MAVLink packet forwarding are described here:

https://mavlink.io/en/guide/routing.html

and here:

http://ardupilot.org/dev/docs/mavlink-routing-in-ardupilot.html

Link to this section Summary

Types

Represents the state of the MAVLink.Router. Initial values should be set in config.exs.

t()

Functions

Returns a specification to start this module under a supervisor.

Send a MAVLink message to one or more recipients using available connections. For now if destination is unreachable it will log a warning

Start the MAVLink Router service. You should not call this directly, use the MAVLink application to start this under a supervision tree with the services it expects to use.

Subscribes the calling process to MAVLink messages from the installed dialect matching the query.

Un-subscribes calling process from all existing subscriptions

Link to this section Types

Link to this type

subscribe_query_id_key() View Source
subscribe_query_id_key() ::
  :source_system | :source_component | :target_system | :target_component

Link to this type

t() View Source
t() :: %MAVLink.Router{
  connection_strings: [String.t()],
  connections: %{},
  dialect: module() | nil,
  routes: %{mavlink_address: {mavlink_connection(), MAVLink.Types.version()}}
}

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

pack_and_send(message, version \\ 2) View Source

Send a MAVLink message to one or more recipients using available connections. For now if destination is unreachable it will log a warning

Parameters

  • message: A MAVLink message structure from the installed dialect
  • version: Force sending using a specific MAVLink protocol (default 2)

Example

  MAVLink.Router.pack_and_send(
    %APM.RcChannelsOverride{
      target_system: 1,
      target_component: 1,
      chan1_raw: 1500,
      chan2_raw: 1500,
      chan3_raw: 1500,
      chan4_raw: 1500,
      chan5_raw: 1500,
      chan6_raw: 1500,
      chan7_raw: 1500,
      chan8_raw: 1500,
      chan9_raw: 0,
      chan10_raw: 0,
      chan11_raw: 0,
      chan12_raw: 0,
      chan13_raw: 0,
      chan14_raw: 0,
      chan15_raw: 0,
      chan16_raw: 0,
      chan17_raw: 0,
      chan18_raw: 0
    }
  )
Link to this function

start_link(args, opts \\ []) View Source
start_link(
  %{
    system: 1..255,
    component: 1..255,
    dialect: module(),
    connection_strings: [String.t()]
  },
  [{atom(), any()}]
) :: {:ok, pid()}

Start the MAVLink Router service. You should not call this directly, use the MAVLink application to start this under a supervision tree with the services it expects to use.

Parameters

  • dialect: Name of the module generated by mix mavlink task to represent the enumerations and messages of a particular MAVLink dialect

  • system: The System id of this system 1..255, typically low for vehicles and high for ground stations

  • component: The component id of this system 1..255, typically 1 for the autopilot

  • connection_strings: A list of strings in the following formats:

    udpin:: udpout:: tcpout:: serial::

  • opts: Standard GenServer options

Link to this function

subscribe(query \\ []) View Source
subscribe([
  {:message, MAVLink.Message.t()}
  | {subscribe_query_id_key(), 0..255}
  | {:as_frame, boolean()}
]) :: :ok

Subscribes the calling process to MAVLink messages from the installed dialect matching the query.

Parameters

  • query: Keyword list of zero or more of the following query keywords:

message: message_module | :unknown (use latter with as_frame) source_system: integer 0..255 source_component: integer 0..255 target_system: integer 0..255 target_component: integer 0..255 as_frame: true|false (default false, shows entire message frame with sender/target details)

Example

  MAVLink.Router.subscribe message: MAVLink.Message.Heartbeat, source_system: 1
Link to this function

unsubscribe() View Source
unsubscribe() :: :ok

Un-subscribes calling process from all existing subscriptions

Example

  MAVLink.Router.unsubscribe