Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
38 #if FLIGHTRECORDER_SDLOG
42 #endif
43 
44 #define uADC_UNINIT 0
45 #define uADC_WAIT_START uADC_UNINIT
46 #define uADC_WAIT_COUNTER 1
47 #define uADC_WAIT_ANGLES 2
48 #define uADC_WAIT_ALTITUDE 3
49 #define uADC_WAIT_PRESSURES 4
50 #define uADC_WAIT_CHECKSUM 5
51 
52 #define uADC_START 0x0A
53 #define uADC_LIMITER ','
54 #define uADC_END 0x0D
55 
57 static int16_t course[3];
59 static int32_t pressures[2];
62 static uint8_t uadc_idx = 0;
63 static uint8_t uadc_tab_idx = 0;
64 
65 /* airspeed_uadc_parse */
66 void airspeed_uadc_parse(char c)
67 {
68  static char uadc_inp[64];
69 
70  switch (uadc_status) {
71 
72  case uADC_WAIT_START:
73  if (c == uADC_START) {
74  uadc_status++;
75  uadc_idx = 0;
76  } else {
78  }
79  break;
80 
81  case uADC_WAIT_COUNTER:
82  if (isdigit((int)c)) {
83  uadc_inp[uadc_idx++] = c;
84  } else {
85  if (/*(uadc_idx == 5) &&*/ (c == uADC_LIMITER)) {
86  uadc_inp[uadc_idx] = 0;
87  counter = atoi(uadc_inp);
88  uadc_idx = 0;
89  uadc_tab_idx = 0;
90  uadc_status++;
91  } else {
93  }
94  }
95  break;
96 
97  case uADC_WAIT_ANGLES:
98  if (isdigit((int)c) || (c == '-') || (c == '.')) {
99  uadc_inp[uadc_idx++] = c;
100  } else {
101  if ((uadc_idx > 1) && (uadc_idx < 9) && (c == uADC_LIMITER)) {
102  uadc_inp[uadc_idx] = 0;
103  course[uadc_tab_idx] = (int16_t)(100. * atof(uadc_inp));
104  uadc_idx = 0;
105  if (uadc_tab_idx++ == 2) {
106  uadc_tab_idx = 0;
107  uadc_status++;
108  }
109  } else if ((c == ' ') || (c == '+')) {
110  // skip blank and + characters
111  }
112  else {
113  // illigal character, reset parser
115  }
116  }
117  break;
118 
119  case uADC_WAIT_ALTITUDE:
120  if (isdigit((int)c) || (c == '-') || (c == '.')) {
121  uadc_inp[uadc_idx++] = c;
122  } else {
123  if ((uadc_idx > 1) && (uadc_idx < 9) && (c == uADC_LIMITER)) {
124  uadc_inp[uadc_idx] = 0;
125  altitude = (int32_t)(100. * atof(uadc_inp));
126  uadc_idx = 0;
127  uadc_status++;
128  } else if ((c == ' ') || (c == '+')) {
129  // skip blank and + characters
130  }
131  else {
132  // illigal character, reset parser
134  }
135  }
136  break;
137 
138  case uADC_WAIT_PRESSURES:
139  if (isdigit((int)c) || (c == '-') || (c == '.')) {
140  uadc_inp[uadc_idx++] = c;
141  } else {
142  if ((uadc_idx > 1) && (uadc_idx < 9) && (c == uADC_LIMITER)) {
143  uadc_inp[uadc_idx] = 0;
144  pressures[uadc_tab_idx] = (int32_t) atoi(uadc_inp);
145  uadc_idx = 0;
146  if (uadc_tab_idx++ == 1) {
147  uadc_tab_idx = 0;
148  uadc_status++;
149  }
150  } else if ((c == ' ') || (c == '+')) {
151  // skip blank and + characters
152  }
153  else {
154  // illigal character, reset parser
156  }
157  }
158  break;
159 
160  case uADC_WAIT_CHECKSUM:
161  if (isxdigit((int)c)) {
162  uadc_inp[uadc_idx++] = c;
163  } else {
164  if ((uadc_idx == 2) && (c == uADC_END)) {
165  uadc_inp[uadc_idx] = 0;
166  checksum = strtol(uadc_inp, NULL, 16);
167  uadc_idx = 0;
168  // FIXME update message definition
169 #if FLIGHTRECORDER_SDLOG
170  if (flightRecorderLogFile != -1) {
171  DOWNLINK_SEND_AEROPROBE(pprzlog_tp, flightrecorder_sdlog,
172  &counter, &course[0], &course[1], &course[2],
173  &altitude, &pressures[0], &pressures[1], &checksum);
174  }
175 #endif
177  } else if ((c == ' ')) {
178  // skip blank characters
179  }
180  else {
182  }
183  }
184  break;
185 
186  default:
188  break;
189  }
190 }
191 
193 {
194 }
195 
197 {
198  while (uart_char_available(&(uADC_DEV))) {
199  uint8_t ch = uart_getch(&(uADC_DEV));
201  }
202 }
203 
205 {
206  DOWNLINK_SEND_AEROPROBE(DefaultChannel, DefaultDevice,
207  &counter, &course[0], &course[1], &course[2],
208  &altitude, &pressures[0], &pressures[1], &checksum);
209 }
210 
static uint32_t counter
Definition: airspeed_uADC.c:56
#define uADC_LIMITER
Definition: airspeed_uADC.c:53
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define uADC_WAIT_START
Definition: airspeed_uADC.c:45
Periodic telemetry system header (includes downlink utility and generated code).
uint8_t uart_getch(struct uart_periph *p)
Definition: uart_arch.c:840
#define uADC_UNINIT
Definition: airspeed_uADC.c:44
uint16_t uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition: uart_arch.c:324
#define uADC_WAIT_COUNTER
Definition: airspeed_uADC.c:46
static uint8_t uadc_idx
Definition: airspeed_uADC.c:62
Initialize pprzlog transport.
#define uADC_WAIT_ALTITUDE
Definition: airspeed_uADC.c:48
void airspeed_uADC_periodic(void)
static int32_t altitude
Definition: airspeed_uADC.c:58
static uint8_t checksum
Definition: airspeed_uADC.c:60
#define uADC_WAIT_PRESSURES
Definition: airspeed_uADC.c:49
UART interface for Aeroprobe uADC air data computer.
#define uADC_START
Definition: airspeed_uADC.c:52
unsigned long uint32_t
Definition: types.h:18
signed short int16_t
Definition: types.h:17
static uint8_t uadc_tab_idx
Definition: airspeed_uADC.c:63
signed long int32_t
Definition: types.h:19
static int32_t pressures[2]
Definition: airspeed_uADC.c:59
#define uADC_END
Definition: airspeed_uADC.c:54
unsigned char uint8_t
Definition: types.h:14
#define uADC_WAIT_CHECKSUM
Definition: airspeed_uADC.c:50
static int16_t course[3]
Definition: airspeed_uADC.c:57
void airspeed_uADC_event(void)
struct pprzlog_transport pprzlog_tp
PPRZLOG transport structure.
Definition: pprzlog_tp.c:29
void airspeed_uADC_init(void)
void airspeed_uadc_parse(char c)
Definition: airspeed_uADC.c:66
#define uADC_WAIT_ANGLES
Definition: airspeed_uADC.c:47
static uint8_t uadc_status
Definition: airspeed_uADC.c:61