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);
84 min_pres = f->pres.data[pres_i].value;
85 height = cc_barometer_to_altitude(min_pres) -
86 cc_barometer_to_altitude(f->ground_pres);
87 printf ("Max height: %9.2fm %9.2fft %9.2fs\n",
88 height, height * 100 / 2.54 / 12,
89 (f->pres.data[pres_i].time - boost_start) / 100.0);
91 accel_i = cc_timedata_min(&f->accel, boost_start, boost_stop);
92 accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value,
94 printf ("Max accel: %9.2fm/s² %9.2fg %9.2fs\n",
95 accel, accel / 9.80665,
96 (f->accel.data[accel_i].time - boost_start) / 100.0);
97 for (i = 0; i < f->state.num; i++) {
98 state = f->state.data[i].value;
99 state_start = f->state.data[i].time;
100 if (i < f->state.num - 1)
101 state_stop = f->state.data[i+1].time;
103 state_stop = f->accel.data[f->accel.num-1].time;
104 printf("State: %s\n", state_names[state]);
105 printf("\tStart: %9.2fs\n", (state_start - boost_start) / 100.0);
106 printf("\tDuration: %9.2fs\n", (state_stop - state_start) / 100.0);
107 accel_i = cc_timedata_min(&f->accel, state_start, state_stop);
108 accel = cc_accelerometer_to_acceleration(f->accel.data[accel_i].value,
110 printf("\tMax accel: %9.2fm/s² %9.2fg %9.2fs\n",
111 accel, accel / 9.80665,
112 (f->accel.data[accel_i].time - boost_start) / 100.0);
114 pres_i = cc_timedata_min(&f->pres, state_start, state_stop);
115 min_pres = f->pres.data[pres_i].value;
116 height = cc_barometer_to_altitude(min_pres) -
117 cc_barometer_to_altitude(f->ground_pres);
118 printf ("\tMax height: %9.2fm %9.2fft %9.2fs\n",
119 height, height * 100 / 2.54 / 12,
120 (f->pres.data[pres_i].time - boost_start) / 100.0);
125 main (int argc, char **argv)
130 struct cc_flightraw *raw;
135 while ((c = getopt_long(argc, argv, "", options, NULL)) != -1) {
142 for (i = optind; i < argc; i++) {
143 file = fopen(argv[i], "r");
149 s = strstr(argv[i], "-serial-");
151 serial = atoi(s + 8);
154 raw = cc_log_read(file);
161 raw->serial = serial;
163 cc_flightraw_free(raw);