MAVLink2.Router (mavlink2 v0.1.0)

Copy Markdown View Source

Forwards frames between MAVLink2.Links, by MAVLink's routing rules:

  • Each frame received teaches the router that its sender, {sysid, compid}, is reachable through the link it arrived on.
  • A broadcast goes out on every other link: a frame with no target, or a target system of 0. A frame whose id the dialect lacks (a link with unknown: :keep) is a broadcast.
  • A frame for another system goes out on the other links where that system has been seen, any component of it.
  • A frame for the router's own system (:sysid) and a component other than 0 goes out on the other links where that component has been seen; for component 0, where any component of the system has been seen.
  • A target not seen on any other link goes nowhere, and nothing goes back out on the link it came in on.
  • SETUP_SIGNING is never forwarded: it carries a signing key.
  • A frame a link's signing refuses is forwarded by the same rules, but teaches the router nothing, so a forged sender cannot take a route.
  • A SYSTEM_TIME whose time_boot_ms goes back means its sender has rebooted: that system's routes are forgotten.

The target is the header's target_sysid when present, else the payload's target_system and target_component, found through the dialect's target_offsets/1 (MAVLink2.Dialect).

Frames go out with MAVLink2.Link.forward/2, unchanged. The router is a subscriber like any other: an application on the same links sees every frame too, and decides for itself what is addressed to it.

Options:

:linksthe links to route between, as pids or registered names (required)
:sysidthe system the router is part of, if any
:nameregistered name

The router stops when one of its links does, so a supervisor restarting both resubscribes it.

Summary

Functions

Returns a specification to start this module under a supervisor.

Where each sender has been seen: %{{sysid, compid} => [link]}.

The target of frame: :broadcast, or {system, component}, where component 0 is any component of the system.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

routes(router)

@spec routes(GenServer.server()) :: %{
  required({non_neg_integer(), 0..255}) => [GenServer.server()]
}

Where each sender has been seen: %{{sysid, compid} => [link]}.

start_link(opts)

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

target(frame, dialect)

@spec target(MAVLink2.Frame.t(), module()) :: :broadcast | {pos_integer(), 0..255}

The target of frame: :broadcast, or {system, component}, where component 0 is any component of the system.