Skip to content

File syn_mavlink.c

FileList > proto > syn_mavlink.c

Go to the source code of this file

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

  • #include "syntropic/proto/syn_mavlink.h"
  • #include <string.h>

Public Types

Type Name
enum syn__mavlink_8c_1adc29c2ff13d900c2f185ee95427fb06c

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.

Public Static Functions

Type Name
uint8_t get_crc_extra (uint32_t msg_id)
Get CRC extra byte for specified MAVLink message ID.

Public Types Documentation

enum syn__mavlink_8c_1adc29c2ff13d900c2f185ee95427fb06c {
    STATE_STX = 0,
    STATE_LEN,
    STATE_INCOMPAT,
    STATE_COMPAT,
    STATE_SEQ,
    STATE_SYS_ID,
    STATE_COMP_ID,
    STATE_MSG_ID0,
    STATE_MSG_ID1,
    STATE_MSG_ID2,
    STATE_PAYLOAD,
    STATE_CRC0,
    STATE_CRC1
};

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.


Public Static Functions Documentation

function get_crc_extra

Get CRC extra byte for specified MAVLink message ID.

static uint8_t get_crc_extra (
    uint32_t msg_id
) 

Parameters:

  • msg_id MAVLink message ID.

Returns:

CRC extra seed byte.



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