Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
xsens_common.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_common.h"
27 
28 #include "pprzlink/pprzlink_device.h"
29 #include "mcu_periph/uart.h"
30 
32 
39 
41 
43 
44 void xsens_event(void)
45 {
46  struct link_device *dev = &((XSENS_LINK).device);
47  if (dev->char_available(dev->periph)) {
48  while (dev->char_available(dev->periph) && !xsens_msg_received) {
49  parse_xsens_buffer(dev->get_byte(dev->periph));
50  }
51  }
52 }
53 
55 {
56  ck += c;
57  switch (xsens_status) {
58  case UNINIT:
59  if (c != XSENS_START) {
60  goto error;
61  }
62  xsens_status++;
63  ck = 0;
64  break;
65  case GOT_START:
66  if (c != XSENS_BID) {
67  goto error;
68  }
69  xsens_status++;
70  break;
71  case GOT_BID:
72  xsens_id = c;
73  xsens_status++;
74  break;
75  case GOT_MID:
76  xsens_len = c;
78  goto error;
79  }
80  xsens_msg_idx = 0;
81  xsens_status++;
82  break;
83  case GOT_LEN:
85  xsens_msg_idx++;
86  if (xsens_msg_idx >= xsens_len) {
87  xsens_status++;
88  }
89  break;
90  case GOT_DATA:
91  if (ck != 0) {
92  goto error;
93  }
95  goto restart;
96  break;
97  default:
98  break;
99  }
100  return;
101 error:
102 restart:
104  return;
105 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define GOT_LEN
Definition: xsens_common.h:69
#define XSENS_MAX_PAYLOAD
Definition: xsens_common.h:62
void xsens_event(void)
Definition: xsens_common.c:44
#define GOT_DATA
Definition: xsens_common.h:70
uint8_t xsens_status
Definition: xsens_common.c:34
#define GOT_BID
Definition: xsens_common.h:67
void parse_xsens_buffer(uint8_t c)
Definition: xsens_common.c:54
uint8_t send_ck
Definition: xsens_common.c:38
#define TRUE
Definition: std.h:4
uint8_t ck
Definition: xsens_common.c:37
volatile uint8_t xsens_msg_received
Definition: xsens_common.c:31
uint8_t xsens_msg_buf[XSENS_MAX_PAYLOAD]
Definition: xsens_common.c:40
uint8_t xsens_len
Definition: xsens_common.c:35
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
unsigned char uint8_t
Definition: types.h:14
#define GOT_MID
Definition: xsens_common.h:68
uint8_t xsens_msg_idx
Definition: xsens_common.c:36
Parser for the Xsens protocol.
#define GOT_START
Definition: xsens_common.h:66
uint8_t xsens_id
Includes macros generated from xsens_MTi-G.xml.
Definition: xsens_common.c:33
#define UNINIT
Receiving pprz messages.
Definition: protocol.c:11