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.3f %10d %10d %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,
74 ao_pa_speed, ao_pa_accel);
95 static double last_time;
96 static double last_pressure;
98 static int start_samples;
100 static int use_saved;
102 if (been_here && start_samples < 100) {
111 // printf ("use saved %d %d\n", now, pa);
115 if (!fgets(line, sizeof (line), emulator_in))
117 for (t = 0; t < 128; t++) {
118 toks[t] = strtok_r(t ? NULL : line, ", ", &saveptr);
123 if (toks[0][0] == '#') {
124 if (strcmp(toks[0],"#version") == 0) {
125 for (t = 1; t < ntok; t++) {
126 if (!strcmp(toks[t], "time"))
128 if (!strcmp(toks[t],"pressure"))
133 } else if (!strcmp(toks[0], "Time")) {
139 time = strtod(toks[time_id],NULL);
140 pressure = strtod(toks[pa_id],NULL);
142 if (been_here && time - last_time < 0.096 * 100)
144 if (is_mp && been_here) {
145 double avg_pressure = (pressure + last_pressure) / 2.0;
146 double avg_time = (time + last_time) / 2.0;
150 // printf ("new %d %d\n", now, pa);
153 now = floor (time + 0.5);
156 last_pressure = pressure;
168 static const struct option options[] = {
169 { .name = "summary", .has_arg = 0, .val = 's' },
170 { .name = "debug", .has_arg = 0, .val = 'd' },
171 { .name = "info", .has_arg = 1, .val = 'i' },
175 void run_flight_fixed(char *name, FILE *f, int summary, char *info)
177 emulator_name = name;
179 emulator_info = info;
185 main (int argc, char **argv)
193 while ((c = getopt_long(argc, argv, "sdi:", options, NULL)) != -1) {
208 run_flight_fixed("<stdin>", stdin, summary, info);
210 for (i = optind; i < argc; i++) {
211 FILE *f = fopen(argv[i], "r");
216 run_flight_fixed(argv[i], f, summary, info);