Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
airspeed_uADC.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Martin Mueller <martinmm@pfump.org>
3  * Copyright (C) 2016 Gautier Hattenberger <gautier.hattenberger@enac.fr>
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  */
23 
30 #include "airspeed_uADC.h"
31 
32 #include "mcu_periph/uart.h"
33 #include "pprzlink/messages.h"
35 
36 #include <ctype.h>
37 #include <stdlib.h>
38 
39 #if FLIGHTRECORDER_SDLOG
43 #endif
44 
45 #define uADC_UNINIT 0
46 #define uADC_WAIT_START uADC_UNINIT
47 #define uADC_WAIT_COUNTER 1
48 #define uADC_WAIT_ANGLES 2
49 #define uADC_WAIT_ALTITUDE 3
50 #define uADC_WAIT_PRESSURES 4
51 #define uADC_WAIT_CHECKSUM 5
52 
53 #define uADC_START 0x0A
54 #define uADC_LIMITER ','
55 #define uADC_END 0x0D
56 
58 static int16_t course[3];
60 static int32_t pressures[2];
63 static uint8_t uadc_idx = 0;
64 static uint8_t uadc_tab_idx = 0;
65 
66 /* airspeed_uadc_parse */
68 {
69  static char uadc_inp[64];
70 
71  switch (uadc_status) {
72 
73  case uADC_WAIT_START:
74  if (c == uADC_START) {
75  uadc_status++;
76  uadc_idx = 0;
77  } else {
79  }
80  break;
81 
82  case uADC_WAIT_COUNTER:
83  if (isdigit((int)c)) {
84  uadc_inp[uadc_idx++] = c;
85  } else {
86  if (/*(uadc_idx == 5) &&*/ (c == uADC_LIMITER)) {
87  uadc_inp[uadc_idx] = 0;
88  counter = atoi(uadc_inp);
89  uadc_idx = 0;
90  uadc_tab_idx = 0;
91  uadc_status++;
92  } else {
94  }
95  }
96  break;
97 
98  case uADC_WAIT_ANGLES:
99  if (isdigit((int)c) || (c == '-') || (c == '.')) {
100  uadc_inp[uadc_idx++] = c;
101  } else {
102  if ((uadc_idx > 1) && (uadc_idx < 9) && (c == uADC_LIMITER)) {
103  uadc_inp[uadc_idx] = 0;
104  course[uadc_tab_idx] = (int16_t)(100. * atof(uadc_inp));
105  uadc_idx = 0;
106  if (uadc_tab_idx++ == 2) {
107  uadc_tab_idx = 0;
108  uadc_status++;
109  }
110  } else if ((c == ' ') || (c == '+')) {
111  // skip blank and + characters
112  }
113  else {
114  // illigal character, reset parser
116  }
117  }
118  break;
119 
120  case uADC_WAIT_ALTITUDE:
121  if (isdigit((int)c) || (c == '-') || (c == '.')) {
122  uadc_inp[uadc_idx++] = c;
123  } else {
124  if ((uadc_idx > 1) && (uadc_idx < 9) && (c == uADC_LIMITER)) {
125  uadc_inp[uadc_idx] = 0;
126  altitude = (int32_t)(100. * atof(uadc_inp));
127  uadc_idx = 0;
128  uadc_status++;
129  } else if ((c == ' ') || (c == '+')) {
130  // skip blank and + characters
131  }
132  else {
133  // illigal character, reset parser
135  }
136  }
137  break;
138 
139  case uADC_WAIT_PRESSURES:
140  if (isdigit((int)c) || (c == '-') || (c == '.')) {
141  uadc_inp[uadc_idx++] = c;
142  } else {
143  if ((uadc_idx > 1) && (uadc_idx < 9) && (c == uADC_LIMITER)) {
144  uadc_inp[uadc_idx] = 0;
145  pressures[uadc_tab_idx] = (int32_t) atoi(uadc_inp);
146  uadc_idx = 0;
147  if (uadc_tab_idx++ == 1) {
148  uadc_tab_idx = 0;
149  uadc_status++;
150  }
151  } else if ((c == ' ') || (c == '+')) {
152  // skip blank and + characters
153  }
154  else {
155  // illigal character, reset parser
157  }
158  }
159  break;
160 
161  case uADC_WAIT_CHECKSUM:
162  if (isxdigit((int)c)) {
163  uadc_inp[uadc_idx++] = c;
164  } else {
165  if ((uadc_idx == 2) && (c == uADC_END)) {
166  uadc_inp[uadc_idx] = 0;
167  checksum = strtol(uadc_inp, NULL, 16);
168  uadc_idx = 0;
169  // FIXME update message definition
170 #if FLIGHTRECORDER_SDLOG
171  if (flightRecorderLogFile != -1) {
172  DOWNLINK_SEND_AEROPROBE(pprzlog_tp, flightrecorder_sdlog,
173  &counter, &course[0], &course[1], &course[2],
174  &altitude, &pressures[0], &pressures[1], &checksum);
175  }
176 #endif
178  } else if ((c == ' ')) {
179  // skip blank characters
180  }
181  else {
183  }
184  }
185  break;
186 
187  default:
189  break;
190  }
191 }
192 
194 {
195 }
196 
198 {
199  while (uart_char_available(&(uADC_DEV))) {
200  uint8_t ch = uart_getch(&(uADC_DEV));
202  }
203 }
204 
206 {
207  DOWNLINK_SEND_AEROPROBE(DefaultChannel, DefaultDevice,
208  &counter, &course[0], &course[1], &course[2],
209  &altitude, &pressures[0], &pressures[1], &checksum);
210 }
211 
c
VIC slots used for the LPC2148 define name e g gps UART1_VIC_SLOT e g modem SPI1_VIC_SLOT SPI1 in mcu_periph spi_arch c or spi_slave_hs_arch c(and some others not using the SPI peripheral yet..) I2C0_VIC_SLOT 8 mcu_periph/i2c_arch.c I2C1_VIC_SLOT 9 mcu_periph/i2c_arch.c USB_VIC_SLOT 10 usb
pressures
static int32_t pressures[2]
Definition: airspeed_uADC.c:60
uart_getch
uint8_t uart_getch(struct uart_periph *p)
Definition: uart_arch.c:968
uadc_tab_idx
static uint8_t uadc_tab_idx
Definition: airspeed_uADC.c:64
uart_char_available
int uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition: uart_arch.c:323
uint32_t
unsigned long uint32_t
Definition: types.h:18
pprzlog_tp.h
Initialize pprzlog transport.
airspeed_uADC_event
void airspeed_uADC_event(void)
Definition: airspeed_uADC.c:197
uADC_WAIT_COUNTER
#define uADC_WAIT_COUNTER
Definition: airspeed_uADC.c:47
uadc_idx
static uint8_t uadc_idx
Definition: airspeed_uADC.c:63
sdlog_chibios.h
telemetry.h
airspeed_uADC_periodic
void airspeed_uADC_periodic(void)
Definition: airspeed_uADC.c:205
uADC_START
#define uADC_START
Definition: airspeed_uADC.c:53
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
airspeed_uadc_parse
void airspeed_uadc_parse(char c)
Definition: airspeed_uADC.c:67
uadc_status
static uint8_t uadc_status
Definition: airspeed_uADC.c:62
int16_t
signed short int16_t
Definition: types.h:17
airspeed_uADC.h
uADC_LIMITER
#define uADC_LIMITER
Definition: airspeed_uADC.c:54
uint8_t
unsigned char uint8_t
Definition: types.h:14
counter
static uint32_t counter
Definition: airspeed_uADC.c:57
uADC_END
#define uADC_END
Definition: airspeed_uADC.c:55
uADC_UNINIT
#define uADC_UNINIT
Definition: airspeed_uADC.c:45
uADC_WAIT_START
#define uADC_WAIT_START
Definition: airspeed_uADC.c:46
uADC_WAIT_CHECKSUM
#define uADC_WAIT_CHECKSUM
Definition: airspeed_uADC.c:51
course
static int16_t course[3]
Definition: airspeed_uADC.c:58
int32_t
signed long int32_t
Definition: types.h:19
airspeed_uADC_init
void airspeed_uADC_init(void)
Definition: airspeed_uADC.c:193
pprzlog_tp
struct pprzlog_transport pprzlog_tp
PPRZLOG transport structure.
Definition: pprzlog_tp.c:29
altitude
static int32_t altitude
Definition: airspeed_uADC.c:59
uADC_WAIT_ALTITUDE
#define uADC_WAIT_ALTITUDE
Definition: airspeed_uADC.c:49
uADC_WAIT_ANGLES
#define uADC_WAIT_ANGLES
Definition: airspeed_uADC.c:48
checksum
static uint8_t checksum
Definition: airspeed_uADC.c:61
uADC_WAIT_PRESSURES
#define uADC_WAIT_PRESSURES
Definition: airspeed_uADC.c:50