2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 #define AO_TICK_TYPE uint32_t
33 uint8_t ao_flight_debug;
35 #define AO_FLIGHT_TEST
37 typedef int32_t alt_t;
38 typedef int32_t pres_t;
40 #define AO_MS_TO_TICKS(ms) ((ms) / 10)
42 #define AO_LED_REPORT 0
44 static void ao_led_on(uint8_t led) {
47 static void ao_led_off(uint8_t led) {
50 static void ao_delay_until(AO_TICK_TYPE target) {
53 static AO_TICK_TYPE ao_time(void) {
57 #include "ao_microflight.c"
58 #include "ao_microkalman.c"
59 #include "ao_convert_pa.c"
64 void ao_log_micro_data() {
72 alt_t ground = ao_pa_to_altitude(pa_ground);
73 printf ("%6.3f %10d %10d %10d %10d %10d\n", now / 100.0,
74 ao_pa_to_altitude(pa) - ground,
75 ao_pa_to_altitude(ao_pa) - ground,
76 ao_pa_to_altitude(pa_min) - ground,
77 ao_pa_speed, ao_pa_accel);
98 static double last_time;
99 static double last_pressure;
100 static int been_here;
101 static int start_samples;
103 static int use_saved;
105 if (been_here && start_samples < 100) {
114 // printf ("use saved %d %d\n", now, pa);
118 if (!fgets(line, sizeof (line), emulator_in))
120 for (t = 0; t < 128; t++) {
121 toks[t] = strtok_r(t ? NULL : line, ", ", &saveptr);
126 if (toks[0][0] == '#') {
127 if (strcmp(toks[0],"#version") == 0) {
128 for (t = 1; t < ntok; t++) {
129 if (!strcmp(toks[t], "time"))
131 if (!strcmp(toks[t],"pressure"))
136 } else if (!strcmp(toks[0], "Time")) {
142 time = strtod(toks[time_id],NULL);
143 pressure = strtod(toks[pa_id],NULL);
145 if (been_here && time - last_time < 0.096 * 100)
147 if (is_mp && been_here) {
148 double avg_pressure = (pressure + last_pressure) / 2.0;
149 double avg_time = (time + last_time) / 2.0;
153 // printf ("new %d %d\n", now, pa);
156 now = floor (time + 0.5);
159 last_pressure = pressure;
171 static const struct option options[] = {
172 { .name = "summary", .has_arg = 0, .val = 's' },
173 { .name = "debug", .has_arg = 0, .val = 'd' },
174 { .name = "info", .has_arg = 1, .val = 'i' },
178 void run_flight_fixed(char *name, FILE *f, int summary, char *info)
180 emulator_name = name;
182 emulator_info = info;
188 main (int argc, char **argv)
196 while ((c = getopt_long(argc, argv, "sdi:", options, NULL)) != -1) {
211 run_flight_fixed("<stdin>", stdin, summary, info);
213 for (i = optind; i < argc; i++) {
214 FILE *f = fopen(argv[i], "r");
219 run_flight_fixed(argv[i], f, summary, info);