Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
xsens_parser.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2003 Pascal Brisset, Antoine Drouin
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
26#include "xsens_parser.h"
27
28#include "pprzlink/pprzlink_device.h"
29#include "mcu_periph/uart.h"
30
32
34
36{
37 struct link_device *dev = &((XSENS_LINK).device);
38 if (dev->char_available(dev->periph)) {
39 while (dev->char_available(dev->periph) && !xsensparser->msg_received) {
40 xsens_parser_func(xsensparser, dev->get_byte(dev->periph));
41 }
42 }
43}
44
46{
47 xsens->ck += c;
48 switch (xsens->status) {
49 case UNINIT:
50 if (c != XSENS_START) {
51 goto error;
52 }
53 xsens->status++;
54 xsens->ck = 0;
55 break;
56 case GOT_START:
57 if (c != XSENS_BID) {
58 goto error;
59 }
60 xsens->status++;
61 break;
62 case GOT_BID:
63 xsens->id = c;
64 xsens->status++;
65 break;
66 case GOT_MID:
67 xsens->len = c;
68 if (xsens->len > XSENS_MAX_PAYLOAD) {
69 goto error;
70 }
71 xsens->msg_idx = 0;
72 xsens->status++;
73 break;
74 case GOT_LEN:
75 xsens->msg_buf[xsens->msg_idx] = c;
76 xsens->msg_idx++;
77 if (xsens->msg_idx >= xsens->len) {
78 xsens->status++;
79 }
80 break;
81 case GOT_DATA:
82 if (xsens->ck != 0) {
83 goto error;
84 }
85 xsens->msg_received = TRUE;
86
87 goto restart;
88 break;
89 default:
90 break;
91 }
92 return;
93error:
95 xsens->status = UNINIT;
96 return;
97}
#define GOT_START
Definition gps_nmea.c:55
uint16_t foo
Definition main_demo5.c:58
#define UNINIT
Receiving pprz messages.
Definition protocol.c:11
#define TRUE
Definition std.h:4
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
struct Xsens xsens
Definition xsens.c:109
uint8_t send_ck
void xsens_parser_event(struct XsensParser *xsensparser)
void xsens_parser_func(struct XsensParser *xsens, uint8_t c)
Parser for the XSens protocol.
#define GOT_LEN
#define XSENS_MAX_PAYLOAD
Includes macros generated from xsens_MTi-G.xml.
#define GOT_BID
#define GOT_MID
#define GOT_DATA