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.
32 uint8_t ao_flight_debug;
34 #define AO_FLIGHT_TEST
36 typedef int32_t alt_t;
37 typedef int32_t pres_t;
39 #define AO_MS_TO_TICKS(ms) ((ms) / 10)
41 #define AO_LED_REPORT 0
43 static void ao_led_on(uint8_t led) {
46 static void ao_led_off(uint8_t led) {
49 static void ao_delay_until(AO_TICK_TYPE target) {
52 static AO_TICK_TYPE ao_time(void) {
56 #include "ao_microflight.c"
57 #include "ao_microkalman.c"
58 #include "ao_convert_pa.c"
63 void ao_log_micro_data() {
71 alt_t ground = ao_pa_to_altitude(pa_ground);
72 printf ("%6.3f %10d %10d %10d %10d %10d\n", now / 100.0,
73 ao_pa_to_altitude(pa) - ground,
74 ao_pa_to_altitude(ao_pa) - ground,
75 ao_pa_to_altitude(pa_min) - ground,
76 ao_pa_speed, ao_pa_accel);
97 static double last_time;
98 static double last_pressure;
100 static int start_samples;
102 static int use_saved;
104 if (been_here && start_samples < 100) {
113 // printf ("use saved %d %d\n", now, pa);
117 if (!fgets(line, sizeof (line), emulator_in))
119 for (t = 0; t < 128; t++) {
120 toks[t] = strtok_r(t ? NULL : line, ", ", &saveptr);
125 if (toks[0][0] == '#') {
126 if (strcmp(toks[0],"#version") == 0) {
127 for (t = 1; t < ntok; t++) {
128 if (!strcmp(toks[t], "time"))
130 if (!strcmp(toks[t],"pressure"))
135 } else if (!strcmp(toks[0], "Time")) {
141 time = strtod(toks[time_id],NULL);
142 pressure = strtod(toks[pa_id],NULL);
144 if (been_here && time - last_time < 0.096 * 100)
146 if (is_mp && been_here) {
147 double avg_pressure = (pressure + last_pressure) / 2.0;
148 double avg_time = (time + last_time) / 2.0;
152 // printf ("new %d %d\n", now, pa);
155 now = floor (time + 0.5);
158 last_pressure = pressure;
170 static const struct option options[] = {
171 { .name = "summary", .has_arg = 0, .val = 's' },
172 { .name = "debug", .has_arg = 0, .val = 'd' },
173 { .name = "info", .has_arg = 1, .val = 'i' },
177 void run_flight_fixed(char *name, FILE *f, int summary, char *info)
179 emulator_name = name;
181 emulator_info = info;
187 main (int argc, char **argv)
195 while ((c = getopt_long(argc, argv, "sdi:", options, NULL)) != -1) {
210 run_flight_fixed("<stdin>", stdin, summary, info);
212 for (i = optind; i < argc; i++) {
213 FILE *f = fopen(argv[i], "r");
218 run_flight_fixed(argv[i], f, summary, info);