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.
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
mavlink_address()
View Source
mavlink_address() :: MAVLink.Types.mavlink_address()
mavlink_address() :: MAVLink.Types.mavlink_address()
Represents the state of the MAVLink.Router. Initial values should be set in config.exs.
Fields
dialect: The MAVLink 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.
mavlink_connection()
View Source
mavlink_connection() :: MAVLink.Types.connection()
mavlink_connection() :: MAVLink.Types.connection()
subscribe_query_id_key()
View Source
subscribe_query_id_key() ::
:source_system | :source_component | :target_system | :target_component
subscribe_query_id_key() :: :source_system | :source_component | :target_system | :target_component
t()
View Source
t() :: %MAVLink.Router{
connection_strings: [String.t()],
connections: %{},
dialect: module() | nil,
routes: %{mavlink_address: {mavlink_connection(), MAVLink.Types.version()}}
}
t() :: %MAVLink.Router{ connection_strings: [String.t()], connections: %{}, dialect: module() | nil, routes: %{mavlink_address: {mavlink_connection(), MAVLink.Types.version()}} }
Link to this section Functions
child_spec(init_arg) View Source
Returns a specification to start this module under a supervisor.
See Supervisor
.
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
}
)
start_link(args, opts \\ []) View Source
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
subscribe(query \\ [])
View Source
subscribe([
{:message, MAVLink.Message.t()}
| {subscribe_query_id_key(), 0..255}
| {:as_frame, boolean()}
]) :: :ok
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
unsubscribe()
View Source
unsubscribe() :: :ok
unsubscribe() :: :ok
Un-subscribes calling process from all existing subscriptions
Example
MAVLink.Router.unsubscribe