Packages

A helper layer on top of MAVLink for performing common commands and tasks with one or more remote vehicles. It can either be used as an API or directly from iex with an experience similar to Ardupilot's MAVProxy.

Current section

Files

Jump to
xmavlink_util lib mavlink_util param_request.ex
Raw

lib/mavlink_util/param_request.ex

defmodule MAVLink.Util.ParamRequest do
@moduledoc false
@systems :systems
@param_retry_interval 3000
require Logger
alias MAVLink.Router, as: MAV
import MAVLink.Util.FocusManager, only: [focus: 0]
def param_request_list() do
with {:ok, {system_id, component_id, mavlink_version}} <- focus() do
Logger.info("Waiting to receive first parameter from vehicle #{system_id}.#{component_id}")
param_request_list(system_id, component_id, mavlink_version)
end
end
def param_request_list(system_id, component_id, mavlink_version, last_param_count_loaded \\ 0) do
with [{_, %{param_count: param_count, param_count_loaded: param_count_loaded}}] <- :ets.lookup(@systems, {system_id, component_id}),
retry <- param_count_loaded == last_param_count_loaded,
complete <- param_count_loaded == param_count and param_count > 0 do
if complete do
Logger.info("All #{param_count} parameters loaded for vehicle #{system_id}.#{component_id}")
else
if param_count > 0 do
Logger.info("Loaded #{param_count_loaded}/#{param_count} parameters for vehicle #{system_id}.#{component_id}")
end
if retry do
MAV.pack_and_send(%APM.Message.ParamRequestList{
target_system: system_id, target_component: component_id}, mavlink_version)
end
Process.sleep(@param_retry_interval)
param_request_list(system_id, component_id, mavlink_version, param_count_loaded)
end
end
end
end