Skip to content

File syn_msp.h

FileList > proto > syn_msp.h

Go to the source code of this file

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

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

Classes

Type Name
struct SYN_MSP_Frame
struct SYN_MSP_Parser

Public Types

Type Name
enum SYN_MSP_Cmd

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.

Macros

Type Name
define SYN_MSP_ERR_CHAR '!'
define SYN_MSP_HEADER_CHAR '$'
define SYN_MSP_MAX_PAYLOAD 64U
define SYN_MSP_REQ_CHAR '&lt;'
define SYN_MSP_RESP_CHAR '&gt;'
define SYN_MSP_V1_CHAR '[**M**](syn__x25519_8c.md#function-m)'

Detailed Description

MSP Specifications: * Frame Format: $M + [Direction] + [Size] + [Command] + [Payload...] + [Checksum] * Direction: < (Inbound Request), > (Outbound Response), ! (Error Response). * Checksum: XOR sum over Size ^ Command ^ Payload[0] ^ ... ^ Payload[N-1]. * Common Commands: * 101: MSP_STATUS (Cycle time, I2C errors, sensors active, flight mode flags). * 102: MSP_RAW_IMU (Gyro X/Y/Z, Accel X/Y/Z, Mag X/Y/Z). * 108: MSP_ATTITUDE (Roll 10x deg, Pitch 10x deg, Yaw deg). * 109: MSP_ALTITUDE (Estimated altitude in cm & variometer rate). * 130: MSP_BATTERY_STATE (Cell count, capacity mAh, voltage 0.1V, current 0.01A).

Public Types Documentation

enum SYN_MSP_Cmd

enum SYN_MSP_Cmd {
    SYN_MSP_API_VERSION = 1U,
    SYN_MSP_FC_VARIANT = 2U,
    SYN_MSP_STATUS = 101U,
    SYN_MSP_RAW_IMU = 102U,
    SYN_MSP_ATTITUDE = 108U,
    SYN_MSP_ALTITUDE = 109U,
    SYN_MSP_BATTERY_STATE = 130U
};

Common MSP Command IDs.


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.


Macro Definition Documentation

define SYN_MSP_ERR_CHAR

#define SYN_MSP_ERR_CHAR `'!'`

MSP direction character for error '!'


define SYN_MSP_HEADER_CHAR

#define SYN_MSP_HEADER_CHAR `'$'`

MSP preamble start character '$'


define SYN_MSP_MAX_PAYLOAD

#define SYN_MSP_MAX_PAYLOAD `64U`

Maximum MSP v1 payload byte length


define SYN_MSP_REQ_CHAR

#define SYN_MSP_REQ_CHAR `'<'`

MSP direction character for request '<'


define SYN_MSP_RESP_CHAR

#define SYN_MSP_RESP_CHAR `'>'`

MSP direction character for response '>'


define SYN_MSP_V1_CHAR

#define SYN_MSP_V1_CHAR `' M '`

MSP v1 protocol identifier 'M'



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