Skip to content

File syn_mavlink.h

FileList > proto > syn_mavlink.h

Go to the source code of this file

Zero-Heap MAVLink v2 Protocol Encoder & Streaming Decoder. More...

  • #include "syntropic/common/syn_defs.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_MAVLINK_Frame
struct SYN_MAVLINK_Parser

Public Types

Type Name
enum SYN_MAVLINK_MsgId

Public Functions

Type Name
uint16_t syn_mavlink_crc_accumulate (uint8_t byte, uint16_t crc)
Accumulate single byte into MAVLink X25 CRC.
SYN_Status syn_mavlink_encode_msg (uint8_t sys_id, uint8_t comp_id, uint8_t seq, uint32_t msg_id, uint8_t crc_extra, const uint8_t * payload, uint8_t payload_len, uint8_t * buf_out, size_t * out_len)
Encode a MAVLink v2 packet into raw byte buffer.
SYN_Status syn_mavlink_init (SYN_MAVLINK_Parser * parser)
Initialize MAVLink v2 parser instance.
SYN_Status syn_mavlink_parse_byte (SYN_MAVLINK_Parser * parser, uint8_t byte, SYN_MAVLINK_Frame * frame)
Process incoming byte from serial stream.

Macros

Type Name
define SYN_MAVLINK_HEADER_LEN 10U
define SYN_MAVLINK_MAX_PAYLOAD_LEN 255U
define SYN_MAVLINK_STX_V2 0xFD

Detailed Description

MAVLink v2 Frame Specification: Header: [0xFD] + [Payload Len 1B] + [Incompat Flags 1B] + [Compat Flags 1B] + [Seq 1B] + [Sys ID 1B] + [Comp ID 1B] + [Msg ID 3B (Little-Endian)] Payload: [Payload N B] Checksum: [16-bit CRC-X25 over (Header_without_STX + Payload + CRC_Extra)]

Public Types Documentation

enum SYN_MAVLINK_MsgId {
    SYN_MAVLINK_MSG_HEARTBEAT = 0U,
    SYN_MAVLINK_MSG_SYS_STATUS = 1U,
    SYN_MAVLINK_MSG_ATTITUDE = 30U,
    SYN_MAVLINK_MSG_GLOBAL_POSITION_INT = 33U,
    SYN_MAVLINK_MSG_VFR_HUD = 74U
};

MAVLink Message IDs.


Public Functions Documentation

Accumulate single byte into MAVLink X25 CRC.

uint16_t syn_mavlink_crc_accumulate (
    uint8_t byte,
    uint16_t crc
) 

Parameters:

  • byte Input byte to accumulate.
  • crc Initial CRC accumulator value.

Returns:

Updated 16-bit CRC value.


Encode a MAVLink v2 packet into raw byte buffer.

SYN_Status syn_mavlink_encode_msg (
    uint8_t sys_id,
    uint8_t comp_id,
    uint8_t seq,
    uint32_t msg_id,
    uint8_t crc_extra,
    const uint8_t * payload,
    uint8_t payload_len,
    uint8_t * buf_out,
    size_t * out_len
) 

Parameters:

  • sys_id System ID (1..255).
  • comp_id Component ID (1..255).
  • seq Packet sequence number.
  • msg_id Message ID.
  • crc_extra CRC Extra byte for the specific message ID.
  • payload Pointer to payload data buffer (or NULL if 0 len).
  • payload_len Payload byte length.
  • buf_out Output byte buffer (must hold at least payload_len + 12 bytes).
  • out_len Pointer to receive final encoded frame length.

Returns:

SYN_OK on success.


Initialize MAVLink v2 parser instance.

SYN_Status syn_mavlink_init (
    SYN_MAVLINK_Parser * parser
) 

Parameters:

  • parser Pointer to parser struct.

Returns:

SYN_OK on success.


Process incoming byte from serial stream.

SYN_Status syn_mavlink_parse_byte (
    SYN_MAVLINK_Parser * parser,
    uint8_t byte,
    SYN_MAVLINK_Frame * frame
) 

Parameters:

  • parser Pointer to parser struct.
  • byte Incoming byte.
  • frame Destination frame struct (populated on valid complete packet).

Returns:

SYN_OK on complete valid frame, SYN_BUSY if processing, SYN_ERROR on CRC mismatch.


Macro Definition Documentation

#define SYN_MAVLINK_HEADER_LEN `10U`

MAVLink v2 header length in bytes


#define SYN_MAVLINK_MAX_PAYLOAD_LEN `255U`

Maximum MAVLink payload length in bytes


#define SYN_MAVLINK_STX_V2 `0xFD`

MAVLink v2 Start of Frame marker byte (0xFD)



The documentation for this class was generated from the following file src/syntropic/proto/syn_mavlink.h