Paparazzi UAS  v7.0_unstable
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 */
67 void airspeed_uadc_parse(char c)
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 
static int16_t course[3]
Definition: airspeed_uADC.c:58
#define uADC_END
Definition: airspeed_uADC.c:55
#define uADC_WAIT_START
Definition: airspeed_uADC.c:46
#define uADC_START
Definition: airspeed_uADC.c:53
#define uADC_WAIT_COUNTER
Definition: airspeed_uADC.c:47
static uint32_t counter
Definition: airspeed_uADC.c:57
static int32_t altitude
Definition: airspeed_uADC.c:59
static uint8_t checksum
Definition: airspeed_uADC.c:61
static uint8_t uadc_status
Definition: airspeed_uADC.c:62
#define uADC_WAIT_ALTITUDE
Definition: airspeed_uADC.c:49
void airspeed_uADC_init(void)
static int32_t pressures[2]
Definition: airspeed_uADC.c:60
static uint8_t uadc_tab_idx
Definition: airspeed_uADC.c:64
void airspeed_uadc_parse(char c)
Definition: airspeed_uADC.c:67
#define uADC_WAIT_CHECKSUM
Definition: airspeed_uADC.c:51
void airspeed_uADC_periodic(void)
static uint8_t uadc_idx
Definition: airspeed_uADC.c:63
#define uADC_LIMITER
Definition: airspeed_uADC.c:54
#define uADC_WAIT_ANGLES
Definition: airspeed_uADC.c:48
#define uADC_WAIT_PRESSURES
Definition: airspeed_uADC.c:50
void airspeed_uADC_event(void)
#define uADC_UNINIT
Definition: airspeed_uADC.c:45
UART interface for Aeroprobe uADC air data computer.
int uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition: uart_arch.c:323
uint8_t uart_getch(struct uart_periph *p)
Definition: uart_arch.c:314
struct pprzlog_transport pprzlog_tp
PPRZLOG transport structure.
Definition: pprzlog_tp.c:29
Initialize pprzlog transport.
Periodic telemetry system header (includes downlink utility and generated code).
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98