Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
mavlink_decoder.h File Reference

simple decoder of mavlink message More...

#include "std.h"
#include "pprzlink/pprzlink_transport.h"
#include "mcu_periph/uart.h"
+ Include dependency graph for mavlink_decoder.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mavlink_msg_req
 Structure to submit a callback. More...
 

Macros

#define STXMAV   0xFE
 
#define MAVLINK_PAYLOAD_OFFSET   4
 
#define MAVLINK_SEQ_IDX   0
 
#define MAVLINK_SYS_ID_IDX   1
 
#define MAVLINK_COMP_ID_IDX   2
 
#define MAVLINK_MSG_ID_IDX   3
 
#define X25_INIT_CRC   0xffff
 MAVLINK CHECKSUM. More...
 
#define MavlinkDatalinkEvent()   mavlink_check_and_parse(&(MAVLINK_UART).device, &mavlink_tp)
 

Enumerations

enum  mavlink_parse_state {
  MAVLINK_PARSE_STATE_UNINIT = 0, MAVLINK_PARSE_STATE_IDLE, MAVLINK_PARSE_STATE_GOT_STX, MAVLINK_PARSE_STATE_GOT_LENGTH,
  MAVLINK_PARSE_STATE_GOT_PAYLOAD, MAVLINK_PARSE_STATE_GOT_CRC1
}
 Receiving mavlink messages. More...
 

Functions

static void mavlink_crc_accumulate (uint8_t data, uint16_t *crcAccum)
 Accumulate the X.25 CRC by adding one char at a time. More...
 
static void mavlink_crc_init (uint16_t *crcAccum)
 Initiliaze the buffer for the X.25 CRC. More...
 
static uint16_t mavlink_crc_calculate (const uint8_t *pBuffer, uint16_t length)
 Calculates the X.25 checksum on a byte buffer. More...
 
static void mavlink_register_msg (struct mavlink_transport *t, struct mavlink_msg_req *req)
 Register a callback for a mavlink message. More...
 
static void parse_mavlink (struct mavlink_transport *t, uint8_t c)
 Mavlink character parser. More...
 
static void mavlink_parse_payload (struct mavlink_transport *t)
 
static void mavlink_check_and_parse (struct link_device *dev, struct mavlink_transport *trans)
 

Variables

uint8_t mavlink_crc_extra [256]
 
struct mavlink_transport mavlink_tp
 

Detailed Description

simple decoder of mavlink message

Definition in file mavlink_decoder.h.


Data Structure Documentation

◆ mavlink_message

struct mavlink_message

Mavlink v1.0 message structure.

Mavlink Msg: STXMAV + len + { packet_seq + SYS/ID + COMPONENT/ID + MSG/ID + Payload } + ck_a + ck_b

Payload starts after 4 bytes.

Definition at line 48 of file mavlink_decoder.h.

Data Fields
uint8_t comp_id
uint8_t msg_id
uint8_t * payload
uint8_t seq
uint8_t sys_id

◆ mavlink_transport

struct mavlink_transport

Mavlink transport protocol.

Definition at line 140 of file mavlink_decoder.h.

+ Collaboration diagram for mavlink_transport:
Data Fields
uint16_t checksum
uint8_t payload_idx
struct mavlink_msg_req * req
mavlink_parse_state status
struct transport_rx trans

Macro Definition Documentation

◆ MAVLINK_COMP_ID_IDX

#define MAVLINK_COMP_ID_IDX   2

Definition at line 60 of file mavlink_decoder.h.

◆ MAVLINK_MSG_ID_IDX

#define MAVLINK_MSG_ID_IDX   3

Definition at line 61 of file mavlink_decoder.h.

◆ MAVLINK_PAYLOAD_OFFSET

#define MAVLINK_PAYLOAD_OFFSET   4

Definition at line 56 of file mavlink_decoder.h.

◆ MAVLINK_SEQ_IDX

#define MAVLINK_SEQ_IDX   0

Definition at line 58 of file mavlink_decoder.h.

◆ MAVLINK_SYS_ID_IDX

#define MAVLINK_SYS_ID_IDX   1

Definition at line 59 of file mavlink_decoder.h.

◆ MavlinkDatalinkEvent

#define MavlinkDatalinkEvent ( )    mavlink_check_and_parse(&(MAVLINK_UART).device, &mavlink_tp)

Definition at line 268 of file mavlink_decoder.h.

◆ STXMAV

#define STXMAV   0xFE

Definition at line 38 of file mavlink_decoder.h.

◆ X25_INIT_CRC

#define X25_INIT_CRC   0xffff

MAVLINK CHECKSUM.

Definition at line 64 of file mavlink_decoder.h.

Enumeration Type Documentation

◆ mavlink_parse_state

Receiving mavlink messages.

Enumerator
MAVLINK_PARSE_STATE_UNINIT 
MAVLINK_PARSE_STATE_IDLE 
MAVLINK_PARSE_STATE_GOT_STX 
MAVLINK_PARSE_STATE_GOT_LENGTH 
MAVLINK_PARSE_STATE_GOT_PAYLOAD 
MAVLINK_PARSE_STATE_GOT_CRC1 

Definition at line 120 of file mavlink_decoder.h.

Function Documentation

◆ mavlink_check_and_parse()

static void mavlink_check_and_parse ( struct link_device *  dev,
struct mavlink_transport trans 
)
inlinestatic

Definition at line 254 of file mavlink_decoder.h.

References dev, mavlink_parse_payload(), parse_mavlink(), and mavlink_transport::trans.

+ Here is the call graph for this function:

◆ mavlink_crc_accumulate()

static void mavlink_crc_accumulate ( uint8_t  data,
uint16_t crcAccum 
)
inlinestatic

Accumulate the X.25 CRC by adding one char at a time.

The checksum function adds the hash of one char at a time to the 16 bit checksum (uint16_t).

Parameters
datanew char to hash
crcAccumthe already accumulated checksum

Definition at line 80 of file mavlink_decoder.h.

Referenced by mavlink_crc_calculate(), and parse_mavlink().

+ Here is the caller graph for this function:

◆ mavlink_crc_calculate()

static uint16_t mavlink_crc_calculate ( const uint8_t pBuffer,
uint16_t  length 
)
inlinestatic

Calculates the X.25 checksum on a byte buffer.

Parameters
pBufferbuffer containing the byte array to hash
lengthlength of the byte array
Returns
the checksum over the buffer bytes

Definition at line 107 of file mavlink_decoder.h.

References mavlink_crc_accumulate(), and mavlink_crc_init().

+ Here is the call graph for this function:

◆ mavlink_crc_init()

static void mavlink_crc_init ( uint16_t crcAccum)
inlinestatic

Initiliaze the buffer for the X.25 CRC.

Parameters
crcAccumthe 16 bit X.25 CRC

Definition at line 95 of file mavlink_decoder.h.

References X25_INIT_CRC.

Referenced by mavlink_crc_calculate(), and parse_mavlink().

+ Here is the caller graph for this function:

◆ mavlink_parse_payload()

◆ mavlink_register_msg()

static void mavlink_register_msg ( struct mavlink_transport t,
struct mavlink_msg_req req 
)
inlinestatic

Register a callback for a mavlink message.

Definition at line 163 of file mavlink_decoder.h.

References mavlink_msg_req::next, and mavlink_transport::req.

Referenced by px4flow_init().

+ Here is the caller graph for this function:

◆ parse_mavlink()

Variable Documentation

◆ mavlink_crc_extra

uint8_t mavlink_crc_extra[256]

Definition at line 32 of file mavlink_decoder.c.

Referenced by parse_mavlink().

◆ mavlink_tp

struct mavlink_transport mavlink_tp

Definition at line 29 of file mavlink_decoder.c.

Referenced by px4flow_init().