XMAVLink.Frame (xmavlink v0.13.0)

Copy Markdown View Source

Represent and work with MAVLink v1/2 message frames

Summary

Types

message()

@type message() :: XMAVLink.Message.t()

t()

@type t() :: %XMAVLink.Frame{
  checksum: 0..65535,
  compatible_flags: non_neg_integer(),
  crc_extra: XMAVLink.Types.crc_extra(),
  incompatible_flags: non_neg_integer(),
  mavlink_1_raw: binary() | nil,
  mavlink_2_raw: binary() | nil,
  message: message() | nil,
  message_id: XMAVLink.Types.message_id(),
  payload: binary(),
  payload_length: 0..255,
  sequence_number: 0..255,
  signature: XMAVLink.Frame.Signature.t() | nil,
  source_component: 1..255,
  source_system: 1..255,
  target: :broadcast | :system | :system_component | :component,
  target_component: 0..255,
  target_system: 0..255,
  version: version()
}

version()

@type version() :: 1 | 2

Functions

binary_to_frame_and_tail(raw_and_rest)

@spec binary_to_frame_and_tail(binary()) ::
  {t(), binary()} | {nil, binary()} | :not_a_frame

pack_frame(frame)

sign_frame(frame, secret_key, link_id, timestamp)

@spec sign_frame(t(), <<_::256>>, 0..255, 0..281_474_976_710_655) ::
  {:ok, t()}
  | {:error,
     :already_signed
     | :checksum_invalid
     | :invalid_crc_extra
     | :invalid_link_id
     | :invalid_mavlink_2_frame
     | :invalid_secret_key
     | :invalid_timestamp
     | :mavlink_1_not_signable
     | :missing_crc_extra
     | :missing_mavlink_2_raw
     | :unsupported_incompatible_flags}

Sign an already packed MAVLink 2 frame.

This is a low-level frame utility. It sets MAVLINK_IFLAG_SIGNED, recalculates the checksum for the signed header, and appends the 13-byte MAVLink 2 signature trailer. It does not manage link timestamp state or router/connection signing policy. The existing packed frame checksum must already match the frame's crc_extra.

signed?(incompatible_flags)

@spec signed?(t() | non_neg_integer()) :: boolean()

validate_and_unpack(frame, dialect)

@spec validate_and_unpack(t(), module()) ::
  {:ok, t()}
  | :failed_to_unpack
  | :checksum_invalid
  | :unknown_message
  | :signed_frame_unsupported

validate_and_unpack(frame, dialect, signing)

@spec validate_and_unpack(t(), module(), XMAVLink.Signing.t() | nil) ::
  {:ok, t(), XMAVLink.Signing.t() | nil}
  | {:unknown_message, XMAVLink.Signing.t() | nil}
  | {:error,
     :failed_to_unpack
     | :checksum_invalid
     | :unknown_message
     | XMAVLink.Signing.validate_error(), XMAVLink.Signing.t() | nil}

validate_signature(frame, secret_key)

@spec validate_signature(t(), <<_::256>>) ::
  :ok
  | {:error,
     :invalid_secret_key
     | :invalid_mavlink_2_frame
     | :signature_invalid
     | :unsigned_frame}

Validate the MAVLink 2 signature trailer for an already parsed signed frame.

This only verifies the cryptographic signature over the signed packet bytes. It does not enforce timestamp replay rules or unpack the frame payload.