Engee documentation

MAVLink software management

This page shows all the available MAVLink software management functions in Engee.

To work with the MAVLink software management functions in Engee, follow the instructions given in article. After that, perform:

using Main.EngeeDeviceManager.Devices.MAVLINK

Next, you need to create a Mavlink object that will be used to interact with MAVLink devices.:

mavlink = MAVLINK.Mavlink()

The constructor can be called with the handle of an existing connection. Then the object will work with this connection without creating a new one.:

mavlink = MAVLINK.Mavlink(desc)

The descriptor is returned by the function mavlink.connect(…​), it is also output by the block MAVLINK Setup.

mavlink.close()

Closes the MAVLink connection and stops the automatic sending of HEARTBEAT messages.

Examples

mavlink = MAVLINK.Mavlink()
desc = mavlink.connect("udp", "127.0.0.1", 14551, 255, 190)
# ... messaging ...
mavlink.close()
mavlink.connect(conn_type, host, port, source_system, source_component)

Opens a MAVLink connection over TCP or UDP, initiates the automatic transmission of HEARTBEAT messages, and returns a connection descriptor.

Arguments

  • conn_type::String : transport type — "tcp" or "udp".

  • host::String : IP address or hostname of the MAVLink device.

  • port::Int64 : network port of the device.

  • source_system::Int64 : system ID used to identify the node. Valid range: from 1 to 255.

  • source_component::Int64 : the component ID by which the node is identified. The valid range is from 1 to 255.

Return value

desc::Int64: the connection descriptor. Pass it to the constructor MAVLINK.Mavlink(desc) to use the same connection from another object.

Examples

using Main.EngeeDeviceManager.Devices.MAVLINK

mavlink = MAVLINK.Mavlink()
desc = mavlink.connect("udp", "127.0.0.1", 14551, 255, 190)
println("Дескриптор соединения: ", desc)
mavlink.get_latest_message(message_type)

Returns the most recent message received of the specified type: the function always returns the most recent message of this type, rather than the next one in the order of arrival, as is the case with recv. If no message of this type has yet been received, an empty dictionary is returned.

Arguments

message_type::String: the name of the message type, for example "SIMSTATE".

Return value

Dict{String, ...}: a ‘field name → value’ dictionary, for example Dict("lat" => -353632610, "lng" => 1491652370). An empty dictionary if no message of this type has yet been received.

Examples

hb = mavlink.get_latest_message("HEARTBEAT")
if !isempty(hb)
    println("Тип аппарата: ", hb["type"])
end
mavlink.get_latest_messages()

Returns the most recent messages of all types received and stored in the receive buffer: for each type, the most recent message of that type received.

Return value

Dict{String, Dict{String, ...}}: a dictionary of the form ‘message type name → field dictionary’, for example Dict("SIMSTATE" => Dict("lat" => ..., "lng" => ...), ...). An empty dictionary if no messages have been received yet.

Examples

msgs = mavlink.get_latest_messages()
println("Типы принятых сообщений: ", collect(keys(msgs)))
mavlink.recv(timeout)
mavlink.recv(timeout, async_rpc)

Waits for the next MAVLink message from the receive buffer and returns a tuple (message_type, fields_json) — the message type name and its fields in JSON format. Messages are returned in the order they arrive (FIFO): each call retrieves the earliest unread message from the buffer. If no message arrives whilst waiting, both elements of the tuple are empty: ("", "") is returned.

Arguments

  • timeout::Float64 : maximum time to wait for a message in seconds.

  • async_rpc::Bool = false : when set to true , the function does not wait for the request to complete and immediately returns control.

Return value

(message_type::String, fields_json::String): the name of the message type and its fields in JSON format. The fields can be easily parsed using JSON3.read. If no message is received within timeout, ("", "") is returned.

Examples

using JSON3

msg_type, fields_json = mavlink.recv(1.0)
if !isempty(msg_type)
    println("Принято сообщение: ", msg_type)
    fields = JSON3.read(fields_json, Dict{String, Any})
    println("Поля: ", fields)
end
mavlink.send(message_type, fields)
mavlink.send(message_type, fields, async_rpc)

Sends a MAVLink message of the specified type. The message is sent without waiting for a response: the function does not wait for an acknowledgement from the recipient.

Arguments

  • message_type::String : message name, e.g. "GPS_INPUT" (case-insensitive).

  • fields::Dict{String, ...} : message fields as a ‘name → value’ dictionary. Fields not provided are filled with values by default.

  • async_rpc::Bool = false : submission mode. When set to true , the function does not wait for the request to complete and immediately returns control.

Permitted value types fields

Union{
    Int64, Int32, UInt64, UInt32, Float64, Bool, String,
    Vector{Int64}, Vector{Int32}, Vector{UInt64}, Vector{UInt32},
    Vector{Float64}, Vector{Bool}, Vector{String},
}

The field names and types for each message are listed on the page.

Examples

MavlinkField = Union{
    Int64, Int32, UInt64, UInt32, Float64, Bool, String,
    Vector{Int64}, Vector{Int32}, Vector{UInt64}, Vector{UInt32},
    Vector{Float64}, Vector{Bool}, Vector{String},
}

mavlink.send("HEARTBEAT", Dict{String, MavlinkField}(
    "type"            => 6,    # MAV_TYPE_GCS
    "autopilot"       => 8,    # MAV_AUTOPILOT_INVALID
    "base_mode"       => 0,
    "custom_mode"     => 0,
    "system_status"   => 4,    # MAV_STATE_ACTIVE
    "mavlink_version" => 3,    # MAVLink 2
))