dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Protocol Library

Deals with packing/unpacking and MSP streams. More...

Data Structures

struct  msp_parser
 
struct  msp_ident
 
struct  msp_status
 
struct  msp_raw_imu
 
struct  msp_servo
 
struct  msp_motor
 
struct  msp_set_motor
 
struct  msp_rc
 
struct  msp_set_raw_rc
 
struct  msp_raw_gps
 
struct  msp_set_raw_gps
 
struct  msp_comp_gps
 
struct  msp_attitude
 
struct  msp_altitude
 
struct  msp_analog
 
struct  msp_rc_tuning
 
struct  msp_set_rc_tuning
 
struct  _msp_pid_item
 
struct  msp_pid
 
struct  msp_set_pid
 
struct  msp_box
 
struct  msp_set_box
 
struct  msp_misc
 
struct  msp_set_misc
 
struct  msp_motor_pins
 
struct  msp_boxnames
 
struct  msp_pidnames
 
struct  msp_wp
 
struct  msp_set_wp
 
struct  msp_boxids
 
struct  _msp_servo_conf_item
 
struct  msp_servo_conf
 
struct  msp_select_setting
 
struct  msp_set_head
 

Macros

#define MSP_OVERHEAD_BYTES
 
#define MSP_PARSER_MAGIC   0x32aedc07
 

Typedefs

typedef bool(* msp_handler_t )(enum msp_message_id msg_id, void *data, uint8_t len, void *context)
 Handler to be called when valid MSP messages are recieved. More...
 

Enumerations

enum  msp_state {
  MSP_STATE_IDLE, MSP_STATE_PREAMBLE, MSP_STATE_DIRECTION, MSP_STATE_SIZE,
  MSP_STATE_COMMAND, MSP_STATE_DATA, MSP_STATE_CHECKSUM, MSP_STATE_DISCARD
}
 
enum  msp_parser_type { MSP_PARSER_SERVER, MSP_PARSER_CLIENT }
 
enum  msp_message_id {
  MSP_MSG_IDENT = 100, MSP_MSG_STATUS = 101, MSP_MSG_RAW_IMU = 102, MSP_MSG_SERVO = 103,
  MSP_MSG_MOTOR = 104, MSP_MSG_RC = 105, MSP_MSG_RAW_GPS = 106, MSP_MSG_COMP_GPS = 107,
  MSP_MSG_ATTITUDE = 108, MSP_MSG_ALTITUDE = 109, MSP_MSG_ANALOG = 110, MSP_MSG_RC_TUNING = 111,
  MSP_MSG_PID = 112, MSP_MSG_BOX = 113, MSP_MSG_MISC = 114, MSP_MSG_MOTOR_PINS = 115,
  MSP_MSG_BOXNAMES = 116, MSP_MSG_PIDNAMES = 117, MSP_MSG_WP = 118, MSP_MSG_BOXIDS = 119,
  MSP_MSG_SERVO_CONF = 120, MSP_MSG_SET_RAW_RC = 200, MSP_MSG_SET_RAW_GPS = 201, MSP_MSG_SET_PID = 202,
  MSP_MSG_SET_BOX = 203, MSP_MSG_SET_RC_TUNING = 204, MSP_MSG_ACC_CALIBRATION = 205, MSP_MSG_MAG_CALIBRATION = 206,
  MSP_MSG_SET_MISC = 207, MSP_MSG_RESET_CONF = 208, MSP_MSG_SET_WP = 209, MSP_MSG_SELECT_SETTING = 210,
  MSP_MSG_SET_HEAD = 211, MSP_MSG_SET_SERVO_CONF = 212, MSP_MSG_SET_MOTOR = 214, MSP_MSG_BIND = 240,
  MSP_MSG_EEPROM_WRITE = 250, MSP_EXT_NAV_STATUS = 121, MSP_EXT_NAV_CONFIG = 122, MSP_EXT_FW_CONFIG = 123,
  MSP_EXT_UID = 160, MSP_EXT_GPSSVINFO = 164, MSP_EXT_GPSDEBUGINFO = 166, MSP_EXT_ACC_TRIM = 240,
  MSP_EXT_SERVOMIX_CONF = 241, MSP_EXT_SET_NAV_CONFIG = 215, MSP_EXT_SET_FW_CONFIG = 216, MSP_EXT_SET_ACC_TRIM = 239,
  MSP_EXT_SET_SERVOMIX_CONF = 242, MSP_EXT_DEBUGMSG = 253, MSP_EXT_DEBUG = 254
}
 

Functions

static bool parser_validate (struct msp_parser *p)
 
static bool call_handler (struct msp_parser *p, enum msp_message_id id, void *buf, uint8_t len)
 
static enum msp_state msp_parse_idle (struct msp_parser *p, uint8_t b)
 
static enum msp_state msp_parse_preamble (struct msp_parser *p, uint8_t b)
 
static enum msp_state msp_parse_direction (struct msp_parser *p, uint8_t b)
 
static enum msp_state msp_parse_size (struct msp_parser *p, uint8_t b)
 
static enum msp_state msp_parse_command (struct msp_parser *p, uint8_t b)
 
static enum msp_state msp_parse_data (struct msp_parser *p, uint8_t b)
 
static enum msp_state msp_parse_checksum (struct msp_parser *p, uint8_t b)
 
static enum msp_state msp_parse_discard (struct msp_parser *p, uint8_t b)
 
static void process_byte (struct msp_parser *p, uint8_t b)
 
struct msp_parsermsp_parser_init (enum msp_parser_type type)
 Initialize a new parser instance. More...
 
int32_t msp_process_buffer (struct msp_parser *parser, void *buf, uint8_t len)
 Process MSP stream from buffer. More...
 
int32_t msp_process_com (struct msp_parser *parser, struct pios_com_dev *com)
 Process MSP stream from PIOS_COM. More...
 
int32_t msp_send_com (struct msp_parser *parser, struct pios_com_dev *com, enum msp_message_id msg_id, void *payload, uint8_t len)
 Construct and send an MSP message via PIOS_COM. More...
 
int32_t msp_register_handler (struct msp_parser *parser, msp_handler_t handler, void *context)
 Register a handler for valid received messages. More...
 
struct msp_ident __attribute ((packed))
 
struct msp_box __attribute__ ((packed))
 

Detailed Description

Deals with packing/unpacking and MSP streams.

Macro Definition Documentation

#define MSP_OVERHEAD_BYTES
Value:
(2 /* preamble */ \
+ 1 /* direction */ \
+ 1 /* size */ \
+ 1 /* command */ \
+ 1 /* checksum */)

Definition at line 32 of file msp.c.

#define MSP_PARSER_MAGIC   0x32aedc07

Definition at line 38 of file msp.c.

Typedef Documentation

typedef bool(* msp_handler_t)(enum msp_message_id msg_id, void *data, uint8_t len, void *context)

Handler to be called when valid MSP messages are recieved.

Parameters
[in]msg_idThe MSP command/id of the message
[in]dataBuffer containing the message payload (or NULL if none)
[in]lenLength of data in buffer
[in]contextContext pointer provided when registering handler
Return values
trueMessage was handled successfully (future use/multi-handler for incompatible protocol extensions)
falseMessage was not handled successfully (in future, may cause message to be passed to another handler)

Definition at line 48 of file msp.h.

Enumeration Type Documentation

All MSP message types supported MSP_MSG_ and msp_ prefixes are used for standard MSP protocol, as documented at http://www.multiwii.com/wiki/index.php?title=Multiwii_Serial_Protocol All naming follows this standard where possible/appropriate

MSP_EXT_ and mspext_ prefixes are used for non-standard protocol extensions

Enumerator
MSP_MSG_IDENT 
MSP_MSG_STATUS 
MSP_MSG_RAW_IMU 
MSP_MSG_SERVO 
MSP_MSG_MOTOR 
MSP_MSG_RC 
MSP_MSG_RAW_GPS 
MSP_MSG_COMP_GPS 
MSP_MSG_ATTITUDE 
MSP_MSG_ALTITUDE 
MSP_MSG_ANALOG 
MSP_MSG_RC_TUNING 
MSP_MSG_PID 
MSP_MSG_BOX 
MSP_MSG_MISC 
MSP_MSG_MOTOR_PINS 
MSP_MSG_BOXNAMES 
MSP_MSG_PIDNAMES 
MSP_MSG_WP 
MSP_MSG_BOXIDS 
MSP_MSG_SERVO_CONF 
MSP_MSG_SET_RAW_RC 
MSP_MSG_SET_RAW_GPS 
MSP_MSG_SET_PID 
MSP_MSG_SET_BOX 
MSP_MSG_SET_RC_TUNING 
MSP_MSG_ACC_CALIBRATION 
MSP_MSG_MAG_CALIBRATION 
MSP_MSG_SET_MISC 
MSP_MSG_RESET_CONF 
MSP_MSG_SET_WP 
MSP_MSG_SELECT_SETTING 
MSP_MSG_SET_HEAD 
MSP_MSG_SET_SERVO_CONF 
MSP_MSG_SET_MOTOR 
MSP_MSG_BIND 
MSP_MSG_EEPROM_WRITE 
MSP_EXT_NAV_STATUS 
MSP_EXT_NAV_CONFIG 
MSP_EXT_FW_CONFIG 
MSP_EXT_UID 
MSP_EXT_GPSSVINFO 
MSP_EXT_GPSDEBUGINFO 
MSP_EXT_ACC_TRIM 
MSP_EXT_SERVOMIX_CONF 
MSP_EXT_SET_NAV_CONFIG 
MSP_EXT_SET_FW_CONFIG 
MSP_EXT_SET_ACC_TRIM 
MSP_EXT_SET_SERVOMIX_CONF 
MSP_EXT_DEBUGMSG 
MSP_EXT_DEBUG 

Definition at line 41 of file msp_messages.h.

Whether the parser should act as a client or server

Enumerator
MSP_PARSER_SERVER 

Act as a server (e.g. flight controller)

MSP_PARSER_CLIENT 

Act as a client (e.g. OSD)

Definition at line 51 of file msp.h.

enum msp_state
Enumerator
MSP_STATE_IDLE 
MSP_STATE_PREAMBLE 
MSP_STATE_DIRECTION 
MSP_STATE_SIZE 
MSP_STATE_COMMAND 
MSP_STATE_DATA 
MSP_STATE_CHECKSUM 
MSP_STATE_DISCARD 

Definition at line 40 of file msp.c.

Function Documentation

struct msp_set_pid __attribute ( (packed)  )
struct msp_box __attribute__ ( (packed)  )

Definition at line 38 of file serial_4way.h.

static bool call_handler ( struct msp_parser p,
enum msp_message_id  id,
void *  buf,
uint8_t  len 
)
static

Definition at line 72 of file msp.c.

static enum msp_state msp_parse_checksum ( struct msp_parser p,
uint8_t  b 
)
static

Definition at line 142 of file msp.c.

static enum msp_state msp_parse_command ( struct msp_parser p,
uint8_t  b 
)
static

Definition at line 118 of file msp.c.

static enum msp_state msp_parse_data ( struct msp_parser p,
uint8_t  b 
)
static

Definition at line 132 of file msp.c.

static enum msp_state msp_parse_direction ( struct msp_parser p,
uint8_t  b 
)
static

Definition at line 93 of file msp.c.

static enum msp_state msp_parse_discard ( struct msp_parser p,
uint8_t  b 
)
static

Definition at line 151 of file msp.c.

static enum msp_state msp_parse_idle ( struct msp_parser p,
uint8_t  b 
)
static

Definition at line 79 of file msp.c.

static enum msp_state msp_parse_preamble ( struct msp_parser p,
uint8_t  b 
)
static

Definition at line 86 of file msp.c.

static enum msp_state msp_parse_size ( struct msp_parser p,
uint8_t  b 
)
static

Definition at line 110 of file msp.c.

struct msp_parser * msp_parser_init ( enum msp_parser_type  type)

Initialize a new parser instance.

Parameters
[in]typeWhether to act as client or server
Returns
Handle to struct msp_parser on success, NULL on failure

Definition at line 193 of file msp.c.

int32_t msp_process_buffer ( struct msp_parser parser,
void *  buf,
uint8_t  len 
)

Process MSP stream from buffer.

Parameters
[in]parserHandle to parser instance
[in]bufBuffer containing received stream
[in]lenLength of buffer
Returns
Number of bytes read from buffer (always all of them), or -1 on failure

Definition at line 208 of file msp.c.

int32_t msp_process_com ( struct msp_parser parser,
struct pios_com_dev *  com 
)

Process MSP stream from PIOS_COM.

Parameters
[in]parserHandle to parser instance
[in]comHandle to PIOS_COM instance
Returns
Number of bytes read from com (all available), or -1 on failure
Todo:
fix PIOS_COM to take a pointer

Definition at line 219 of file msp.c.

int32_t msp_register_handler ( struct msp_parser parser,
msp_handler_t  handler,
void *  context 
)

Register a handler for valid received messages.

Parameters
[in]parserHandle to parser instance
[in]handlerHandler function
[in]contextContext pointer that will be passed into handler
Return values
-1Invalid parser instance
0Success

Definition at line 255 of file msp.c.

int32_t msp_send_com ( struct msp_parser parser,
struct pios_com_dev *  com,
enum msp_message_id  msg_id,
void *  payload,
uint8_t  len 
)

Construct and send an MSP message via PIOS_COM.

Parameters
[in]parserHandle to parser instance
[in]comHandle to PIOS_COM instance
[in]msg_idMessage ID/Command
[in]payloadBuffer containing payload, or NULL if none
[in]lenLength of payload (bytes)
Returns
Number of bytes read from com (all available), or -1 on failure
Todo:
not assume success
Todo:
fix PIOS_COM to take a pointer

Definition at line 235 of file msp.c.

static bool parser_validate ( struct msp_parser p)
static

Definition at line 67 of file msp.c.

static void process_byte ( struct msp_parser p,
uint8_t  b 
)
static

Definition at line 161 of file msp.c.