View Source XMAVLink.Router (xmavlink v0.4.0)
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 XMAVLink.Router. Initial values should be set in config.exs.
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
@type mavlink_address() :: XMAVLink.Types.mavlink_address()
Represents the state of the XMAVLink.Router. Initial values should be set in config.exs.
fields
Fields
dialect: The XMAVLink dialect module generated by mix mavlink from a MAVLink definition file
connection_strings: Configuration strings describing the network and serial connections MAVLink messages
are to be received and sent over. Allowed formats are: ```udpin:<local ip>:<local port> udpout:<remote ip>:<remote port> tcpout:<remote ip>:<remote port> serial:<device>:<baud rate>``` Note there is no tcpin connection - tcp is rarely used for MAVLink, the exception being SITL testing which requires a tcpout connection.
connections: A map containing the state of the connections described by connection_strings along
with the local connection, which is automatically created and responsible for allowing Elixir processes to receive and send MAVLink messages. The map is keyed by the port, device or :local to allow the corresponding connection state to be easily retrieved when we receive a message. See MAVLink.*Connection for map values. Note LocalConnection contains the system/component id, subscriber list and next sequence number.
routes: A map from a {system id, component id} tuple to the connection key a message from that
system/component was last received on. Used to forward messages to that system/component.
@type mavlink_connection() :: XMAVLink.Types.connection()
@type subscribe_query_id_key() ::
:source_system | :source_component | :target_system | :target_component
@type t() :: %XMAVLink.Router{ connection_strings: [String.t()], connections: %{}, dialect: module() | nil, routes: %{mavlink_address: {mavlink_connection(), XMAVLink.Types.version()}} }
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Send a MAVLink message to one or more recipients using available connections. For now if destination is unreachable it will log a warning
parameters
Parameters
- message: A MAVLink message structure from the installed dialect
- version: Force sending using a specific MAVLink protocol (default 2)
example
Example
XMAVLink.Router.pack_and_send(
%Common.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
}
)
@spec 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
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:<local ip>:<local port> udpout:<remote ip>:<remote port> tcpout:<remote ip>:<remote port> serial:<device>:<baud rate>
opts: Standard GenServer options
@spec subscribe([ {:message, XMAVLink.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
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
Example
XMAVLink.Router.subscribe message: XMAVLink.Message.Heartbeat, source_system: 1
@spec unsubscribe() :: :ok
Un-subscribes calling process from all existing subscriptions
example
Example
XMAVLink.Router.unsubscribe