Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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
58static int16_t course[3];
63static uint8_t uadc_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) {
76 uadc_idx = 0;
77 } else {
79 }
80 break;
81
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;
89 uadc_idx = 0;
90 uadc_tab_idx = 0;
92 } else {
94 }
95 }
96 break;
97
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;
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
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
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;
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
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;
168 uadc_idx = 0;
169 // FIXME update message definition
170#if FLIGHTRECORDER_SDLOG
171 if (flightRecorderLogFile != -1) {
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))) {
202 }
203}
204
211
static int16_t course[3]
#define uADC_END
#define uADC_WAIT_START
#define uADC_START
#define uADC_WAIT_COUNTER
static uint32_t counter
static int32_t altitude
static uint8_t checksum
static uint8_t uadc_status
#define uADC_WAIT_ALTITUDE
void airspeed_uADC_init(void)
static int32_t pressures[2]
static uint8_t uadc_tab_idx
void airspeed_uadc_parse(char c)
#define uADC_WAIT_CHECKSUM
void airspeed_uADC_periodic(void)
static uint8_t uadc_idx
#define uADC_LIMITER
#define uADC_WAIT_ANGLES
#define uADC_WAIT_PRESSURES
void airspeed_uADC_event(void)
#define uADC_UNINIT
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:357
uint8_t uart_getch(struct uart_periph *p)
Definition uart_arch.c:348
uint16_t foo
Definition main_demo5.c:58
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.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.