Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 
35 void xsens_parser_event(struct XsensParser *xsensparser)
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;
93 error:
94 restart:
95  xsens->status = UNINIT;
96  return;
97 }
#define GOT_START
Definition: gps_nmea.c:55
#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.
Definition: vl53l1_types.h:98
struct Xsens xsens
Definition: xsens.c:109
uint8_t send_ck
Definition: xsens_parser.c:31
void xsens_parser_event(struct XsensParser *xsensparser)
Definition: xsens_parser.c:35
void xsens_parser_func(struct XsensParser *xsens, uint8_t c)
Definition: xsens_parser.c:45
Parser for the XSens protocol.
volatile uint8_t msg_received
Definition: xsens_parser.h:47
#define GOT_LEN
Definition: xsens_parser.h:42
#define XSENS_MAX_PAYLOAD
Includes macros generated from xsens_MTi-G.xml.
Definition: xsens_parser.h:35
#define GOT_BID
Definition: xsens_parser.h:40
#define GOT_MID
Definition: xsens_parser.h:41
#define GOT_DATA
Definition: xsens_parser.h:43