Skip to content

File syn_msp.c

FileList > proto > syn_msp.c

Go to the source code of this file

Zero-Heap MSP (MultiWii Serial Protocol v1/v2) Encoder & Decoder Implementation.

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

Public Types

Type Name
enum syn__msp_8c_1a726ca809ffd3d67ab4b8476646f26635

Public Functions

Type Name
SYN_Status syn_msp_encode_response (uint8_t cmd, const uint8_t * payload, uint8_t len, uint8_t * buf_out, size_t buf_size, size_t * out_len)
Encode an MSP response frame into raw serial bytes buffer.
SYN_Status syn_msp_init (SYN_MSP_Parser * parser)
Initialize MSP parser instance.
SYN_Status syn_msp_parse_byte (SYN_MSP_Parser * parser, uint8_t byte, SYN_MSP_Frame * frame)
Process incoming byte from serial stream.

Public Types Documentation

enum syn__msp_8c_1a726ca809ffd3d67ab4b8476646f26635

enum syn__msp_8c_1a726ca809ffd3d67ab4b8476646f26635 {
    STATE_HEADER_START = 0,
    STATE_HEADER_M,
    STATE_HEADER_DIR,
    STATE_SIZE,
    STATE_CMD,
    STATE_PAYLOAD,
    STATE_CHECKSUM
};

Public Functions Documentation

function syn_msp_encode_response

Encode an MSP response frame into raw serial bytes buffer.

SYN_Status syn_msp_encode_response (
    uint8_t cmd,
    const uint8_t * payload,
    uint8_t len,
    uint8_t * buf_out,
    size_t buf_size,
    size_t * out_len
) 

Parameters:

  • cmd Command ID.
  • payload Pointer to payload buffer (or NULL if 0 length).
  • len Payload length in bytes.
  • buf_out Output buffer (must hold at least len + 6 bytes).
  • buf_size Capacity of buf_out in bytes.
  • out_len Pointer to receive total generated frame length in bytes.

Returns:

SYN_OK on success.


function syn_msp_init

Initialize MSP parser instance.

SYN_Status syn_msp_init (
    SYN_MSP_Parser * parser
) 

Parameters:

  • parser Pointer to parser struct.

Returns:

SYN_OK on success.


function syn_msp_parse_byte

Process incoming byte from serial stream.

SYN_Status syn_msp_parse_byte (
    SYN_MSP_Parser * parser,
    uint8_t byte,
    SYN_MSP_Frame * frame
) 

Parameters:

  • parser Pointer to parser struct.
  • byte Incoming serial byte.
  • frame Pointer to destination frame (populated on complete valid frame).

Returns:

SYN_OK on complete frame, SYN_BUSY if byte accepted but frame incomplete, SYN_ERROR on checksum failure.



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