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;
37 #define AO_MS_TO_TICKS(ms) ((ms) / 10)
39 #define AO_LED_REPORT 0
41 static void ao_led_on(uint8_t led) {
44 static void ao_led_off(uint8_t led) {
47 static void ao_delay_until(uint16_t target) {
50 static uint16_t ao_time(void) {
54 #include "ao_microflight.c"
55 #include "ao_microkalman.c"
56 #include "ao_convert_pa.c"
61 void ao_log_micro_data() {
69 alt_t ground = ao_pa_to_altitude(pa_ground);
70 printf ("%6.2f %10d %10d %10d\n", now / 100.0,
71 ao_pa_to_altitude(pa) - ground,
72 ao_pa_to_altitude(ao_pa) - ground,
73 ao_pa_to_altitude(pa_min) - ground);
94 static double last_time;
96 static int start_samples;
98 if (been_here && start_samples < 100) {
104 if (!fgets(line, sizeof (line), emulator_in))
106 for (t = 0; t < 128; t++) {
107 toks[t] = strtok_r(t ? NULL : line, ", ", &saveptr);
112 if (toks[0][0] == '#') {
113 if (strcmp(toks[0],"#version") == 0) {
114 for (t = 1; t < ntok; t++) {
115 if (!strcmp(toks[t], "time"))
117 if (!strcmp(toks[t],"pressure"))
123 time = strtod(toks[time_id],NULL);
124 pressure = strtod(toks[pa_id],NULL);
125 if (been_here && time - last_time < 0.1)
129 now = floor (time * 100 + 0.5);
140 static const struct option options[] = {
141 { .name = "summary", .has_arg = 0, .val = 's' },
142 { .name = "debug", .has_arg = 0, .val = 'd' },
143 { .name = "info", .has_arg = 1, .val = 'i' },
147 void run_flight_fixed(char *name, FILE *f, int summary, char *info)
149 emulator_name = name;
151 emulator_info = info;
157 main (int argc, char **argv)
165 while ((c = getopt_long(argc, argv, "sdi:", options, NULL)) != -1) {
180 run_flight_fixed("<stdin>", stdin, summary, info);
182 for (i = optind; i < argc; i++) {
183 FILE *f = fopen(argv[i], "r");
188 run_flight_fixed(argv[i], f, summary, info);