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.
30 static const struct option options[] = {
34 static void usage(char *program)
36 fprintf(stderr, "usage: %s {flight-log} ...\n", program);
40 static const char *state_names[] = {
54 analyse_flight(struct cc_flightraw *f)
58 double boost_start, boost_stop;
62 int boost_start_set = 0;
63 int boost_stop_set = 0;
64 enum ao_flight_state state;
65 double state_start, state_stop;
67 printf ("Flight: %9d\nSerial: %9d\n",
68 f->flight, f->serial);
69 boost_start = f->accel.data[0].time;
70 boost_stop = f->accel.data[f->accel.num-1].time;
71 for (i = 0; i < f->state.num; i++) {
72 if (f->state.data[i].value == ao_flight_boost && !boost_start_set) {
73 boost_start = f->state.data[i].time;
76 if (f->state.data[i].value > ao_flight_boost && !boost_stop_set) {
77 boost_stop = f->state.data[i].time;
82 pres_i = cc_timedata_min(&f->pres, f->pres.data[0].time,
83 f->pres.data[f->pres.num-1].time);
86 min_pres = f->pres.data[pres_i].value;
87 height = cc_barometer_to_altitude(min_pres) -
88 cc_barometer_to_altitude(f->ground_pres);
89 printf ("Max height: %9.2fm %9.2fft %9.2fs\n",
90 height, height * 100 / 2.54 / 12,
91 (f->pres.data[pres_i].time - boost_start) / 100.0);
94 accel_i = cc_timedata_min(&f->accel, boost_start, boost_stop);
97 accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value,
99 printf ("Max accel: %9.2fm/s² %9.2fg %9.2fs\n",
100 accel, accel / 9.80665,
101 (f->accel.data[accel_i].time - boost_start) / 100.0);
103 for (i = 0; i < f->state.num; i++) {
104 state = f->state.data[i].value;
105 state_start = f->state.data[i].time;
106 while (i < f->state.num - 1 && f->state.data[i+1].value == state)
108 if (i < f->state.num - 1)
109 state_stop = f->state.data[i + 1].time;
111 state_stop = f->accel.data[f->accel.num-1].time;
112 printf("State: %s\n", state_names[state]);
113 printf("\tStart: %9.2fs\n", (state_start - boost_start) / 100.0);
114 printf("\tDuration: %9.2fs\n", (state_stop - state_start) / 100.0);
115 accel_i = cc_timedata_min(&f->accel, state_start, state_stop);
118 accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value,
120 printf("\tMax accel: %9.2fm/s² %9.2fg %9.2fs\n",
121 accel, accel / 9.80665,
122 (f->accel.data[accel_i].time - boost_start) / 100.0);
125 pres_i = cc_timedata_min(&f->pres, state_start, state_stop);
128 min_pres = f->pres.data[pres_i].value;
129 height = cc_barometer_to_altitude(min_pres) -
130 cc_barometer_to_altitude(f->ground_pres);
131 printf ("\tMax height: %9.2fm %9.2fft %9.2fs\n",
132 height, height * 100 / 2.54 / 12,
133 (f->pres.data[pres_i].time - boost_start) / 100.0);
139 main (int argc, char **argv)
144 struct cc_flightraw *raw;
149 while ((c = getopt_long(argc, argv, "", options, NULL)) != -1) {
156 for (i = optind; i < argc; i++) {
157 file = fopen(argv[i], "r");
163 s = strstr(argv[i], "-serial-");
165 serial = atoi(s + 8);
168 raw = cc_log_read(file);
175 raw->serial = serial;
177 cc_flightraw_free(raw);