Deals with packing/unpacking and MSP streams.
More...
|
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
} |
|
|
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_parser * | msp_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)) |
|
Deals with packing/unpacking and MSP streams.
#define MSP_OVERHEAD_BYTES |
Value:(2 \
+ 1 \
+ 1 \
+ 1 \
+ 1 )
Definition at line 32 of file msp.c.
#define MSP_PARSER_MAGIC 0x32aedc07 |
Definition at line 38 of file msp.c.
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_id | The MSP command/id of the message |
[in] | data | Buffer containing the message payload (or NULL if none) |
[in] | len | Length of data in buffer |
[in] | context | Context pointer provided when registering handler |
- Return values
-
true | Message was handled successfully (future use/multi-handler for incompatible protocol extensions) |
false | Message was not handled successfully (in future, may cause message to be passed to another handler) |
Definition at line 48 of file msp.h.
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.
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.
Definition at line 72 of file msp.c.
Definition at line 93 of file msp.c.
Definition at line 79 of file msp.c.
Definition at line 86 of file msp.c.
Initialize a new parser instance.
- Parameters
-
[in] | type | Whether 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] | parser | Handle to parser instance |
[in] | buf | Buffer containing received stream |
[in] | len | Length 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] | parser | Handle to parser instance |
[in] | com | Handle 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.
Register a handler for valid received messages.
- Parameters
-
[in] | parser | Handle to parser instance |
[in] | handler | Handler function |
[in] | context | Context pointer that will be passed into handler |
- Return values
-
-1 | Invalid parser instance |
0 | Success |
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] | parser | Handle to parser instance |
[in] | com | Handle to PIOS_COM instance |
[in] | msg_id | Message ID/Command |
[in] | payload | Buffer containing payload, or NULL if none |
[in] | len | Length 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 |