Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
airspeed_otf.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013 Martin Mueller <martinmm@pfump.org>
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 */
22
29#include <stdbool.h>
30#include <string.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include "mcu_periph/uart.h"
34#include "pprzlink/messages.h"
36#include <ctype.h>
37
38#include "met_module.h"
39#include "airspeed_otf.h"
40
41
42#define OTF_UNINIT 0x00
43#define OTF_WAIT_START OTF_UNINIT
44#define OTF_WAIT_COUNTER 0x01
45#define OTF_WAIT_ANGLES 0x02
46#define OTF_WAIT_ALTITUDE 0x03
47#define OTF_WAIT_CHECKSUM 0x04
48
49#define OTF_START 0x0A
50#define OTF_LIMITER ','
51#define OTF_END 0x0D
52
53/* workaround for newlib */
54void *_sbrk(int);
55void *_sbrk(int a __attribute__((unused))) {return 0;}
56
57/* airspeed_otf_parse */
59{
61 static char otf_inp[64];
62 static uint32_t counter;
63 static int16_t course[3];
64 static int32_t altitude;
65 static uint8_t checksum;
66
67 switch (otf_status) {
68
69 case OTF_WAIT_START:
70 if (c == OTF_START) {
71 otf_status++;
72 otf_idx = 0;
73 } else {
75 }
76 break;
77
79 if (isdigit((int)c)) {
80 if (otf_idx == 0) {
81//FIXME otf_timestamp = getclock();
82 }
83 otf_inp[otf_idx++] = c;
84 } else {
85 if ((otf_idx == 5) && (c == OTF_LIMITER)) {
86 otf_inp[otf_idx] = 0;
88 otf_idx = 0;
89 otf_crs_idx = 0;
90 otf_status++;
91 } else {
93 }
94 }
95 break;
96
97 case OTF_WAIT_ANGLES:
98 if (isdigit((int)c) || (c == '-') || (c == '.')) {
99 otf_inp[otf_idx++] = c;
100 } else {
101 if ((otf_idx > 1) && (otf_idx < 9) && (c == OTF_LIMITER)) {
102 otf_inp[otf_idx] = 0;
103 course[otf_crs_idx] = (int16_t)(100. * atof(otf_inp));
104 otf_idx = 0;
105 if (otf_crs_idx++ == 2) {
106 otf_status++;
107 }
108 } else {
110 }
111 }
112 break;
113
115 if (isdigit((int)c) || (c == '-') || (c == '.')) {
116 otf_inp[otf_idx++] = c;
117 } else {
118 if ((otf_idx > 1) && (otf_idx < 9) && (c == OTF_LIMITER)) {
119 otf_inp[otf_idx] = 0;
120 altitude = (int32_t)(100. * atof(otf_inp));
121 otf_idx = 0;
122 otf_status++;
123 } else {
125 }
126 }
127 break;
128
130 if (isxdigit((int)c)) {
131 otf_inp[otf_idx++] = c;
132 } else {
133 if ((otf_idx == 2) && (c == OTF_END)) {
134 otf_inp[otf_idx] = 0;
135 checksum = strtol(otf_inp, NULL, 16);
136 otf_idx = 0;
137 int32_t foo = 0;
139 &altitude, &foo, &foo, &checksum);
140 }
142 }
143 break;
144
145 default:
147 break;
148 }
149}
150
152{
153}
154
156{
157 while (MetBuffer()) {
158 uint8_t ch = MetGetch();
160 }
161}
162
164{
165}
void airspeed_otf_init(void)
#define OTF_WAIT_ANGLES
void airspeed_otf_parse(char c)
#define OTF_WAIT_START
#define OTF_WAIT_CHECKSUM
void airspeed_otf_periodic(void)
#define OTF_UNINIT
void * _sbrk(int)
#define OTF_LIMITER
#define OTF_END
void airspeed_otf_event(void)
#define OTF_WAIT_COUNTER
#define OTF_WAIT_ALTITUDE
#define OTF_START
static int16_t course[3]
static int32_t altitude
static uint8_t checksum
#define MetBuffer()
#define MetGetch()
uint32_t counter
Definition ins_flow.c:187
uint16_t foo
Definition main_demo5.c:58
Device independent serial meteo 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.