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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
31 uint8_t ao_flight_debug;
33 #define AO_FLIGHT_TEST
35 typedef int32_t alt_t;
36 typedef int32_t pres_t;
38 #define AO_MS_TO_TICKS(ms) ((ms) / 10)
40 #define AO_LED_REPORT 0
42 static void ao_led_on(uint8_t led) {
45 static void ao_led_off(uint8_t led) {
48 static void ao_delay_until(uint16_t target) {
51 static uint16_t ao_time(void) {
55 #include "ao_microflight.c"
56 #include "ao_microkalman.c"
57 #include "ao_convert_pa.c"
62 void ao_log_micro_data() {
70 alt_t ground = ao_pa_to_altitude(pa_ground);
71 printf ("%6.3f %10d %10d %10d %10d %10d\n", now / 100.0,
72 ao_pa_to_altitude(pa) - ground,
73 ao_pa_to_altitude(ao_pa) - ground,
74 ao_pa_to_altitude(pa_min) - ground,
75 ao_pa_speed, ao_pa_accel);
96 static double last_time;
97 static double last_pressure;
99 static int start_samples;
101 static int use_saved;
103 if (been_here && start_samples < 100) {
112 // printf ("use saved %d %d\n", now, pa);
116 if (!fgets(line, sizeof (line), emulator_in))
118 for (t = 0; t < 128; t++) {
119 toks[t] = strtok_r(t ? NULL : line, ", ", &saveptr);
124 if (toks[0][0] == '#') {
125 if (strcmp(toks[0],"#version") == 0) {
126 for (t = 1; t < ntok; t++) {
127 if (!strcmp(toks[t], "time"))
129 if (!strcmp(toks[t],"pressure"))
134 } else if (!strcmp(toks[0], "Time")) {
140 time = strtod(toks[time_id],NULL);
141 pressure = strtod(toks[pa_id],NULL);
143 if (been_here && time - last_time < 0.096 * 100)
145 if (is_mp && been_here) {
146 double avg_pressure = (pressure + last_pressure) / 2.0;
147 double avg_time = (time + last_time) / 2.0;
151 // printf ("new %d %d\n", now, pa);
154 now = floor (time + 0.5);
157 last_pressure = pressure;
169 static const struct option options[] = {
170 { .name = "summary", .has_arg = 0, .val = 's' },
171 { .name = "debug", .has_arg = 0, .val = 'd' },
172 { .name = "info", .has_arg = 1, .val = 'i' },
176 void run_flight_fixed(char *name, FILE *f, int summary, char *info)
178 emulator_name = name;
180 emulator_info = info;
186 main (int argc, char **argv)
194 while ((c = getopt_long(argc, argv, "sdi:", options, NULL)) != -1) {
209 run_flight_fixed("<stdin>", stdin, summary, info);
211 for (i = optind; i < argc; i++) {
212 FILE *f = fopen(argv[i], "r");
217 run_flight_fixed(argv[i], f, summary, info);