32 #define MSP_OVERHEAD_BYTES (2 \
38 #define MSP_PARSER_MAGIC 0x32aedc07
199 memset(p, 0,
sizeof(*p));
213 for (
unsigned i = 0;
i < len;
i++)
241 uint8_t hdr[] = {
'$',
'M', dir, len, msg_id};
247 uint8_t
checksum = len ^ (uint8_t)msg_id;
248 for (
unsigned i = 0;
i < len;
i++)
249 checksum ^= ((uint8_t *)
payload)[
i];
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.
static enum msp_state msp_parse_data(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_discard(struct msp_parser *p, uint8_t b)
int32_t msp_register_handler(struct msp_parser *parser, msp_handler_t handler, void *context)
Register a handler for valid received messages.
void * PIOS_malloc(size_t size)
uint8_t payload[CRSF_MAX_PAYLOAD+CRSF_CRC_LEN]
static void process_byte(struct msp_parser *p, uint8_t b)
uint16_t PIOS_COM_ReceiveBuffer(uintptr_t com_id, uint8_t *buf, uint16_t buf_len, uint32_t timeout_ms)
static enum msp_state msp_parse_checksum(struct msp_parser *p, uint8_t b)
enum msp_parser_type type
static enum msp_state msp_parse_preamble(struct msp_parser *p, uint8_t b)
static bool parser_validate(struct msp_parser *p)
PIOS_COM_SendBuffer(shub_global->frsky_port, shub_global->serial_buf, msg_length)
int32_t msp_process_buffer(struct msp_parser *parser, void *buf, uint8_t len)
Process MSP stream from buffer.
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.
int32_t msp_process_com(struct msp_parser *parser, struct pios_com_dev *com)
Process MSP stream from PIOS_COM.
static enum msp_state msp_parse_idle(struct msp_parser *p, uint8_t b)
struct msp_parser * msp_parser_init(enum msp_parser_type type)
Initialize a new parser instance.
static bool call_handler(struct msp_parser *p, enum msp_message_id id, void *buf, uint8_t len)
static enum msp_state msp_parse_command(struct msp_parser *p, uint8_t b)
static enum msp_state msp_parse_direction(struct msp_parser *p, uint8_t b)