2 * Copyright © 2013 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.
27 static const struct option options[] = {
28 { .name = "lat", .has_arg = 1, .val = 'L' },
29 { .name = "lon", .has_arg = 1, .val = 'l' },
33 static void usage(char *program)
35 fprintf(stderr, "usage: %s [--lat <pad-lat>] [--lon <pad-lon>]\n"
36 "\t{flight-log} ...\n", program);
40 #define bool(b) ((b) ? "true" : "false")
43 struct telem_ent *next;
44 union ao_telemetry_all telem;
47 static struct telem_ent *pad, **last = &pad;
50 save_telem(union ao_telemetry_all *telem)
52 struct telem_ent *t = malloc (sizeof *t);
60 dump_telem(union ao_telemetry_all *telem)
62 char s[CC_TELEMETRY_BUFSIZE];
64 cc_telemetry_unparse(telem, s);
68 double pad_lat = 0, pad_lon = 0;
69 double target_pad_lat = 0, target_pad_lon = 0;
70 double lat_off = 0, lon_off = 0;
77 doit(union ao_telemetry_all *telem)
81 switch (telem->generic.type) {
82 case AO_TELEMETRY_SENSOR_TELEMETRUM:
83 case AO_TELEMETRY_SENSOR_TELEMINI:
84 case AO_TELEMETRY_SENSOR_TELENANO:
85 if (telem->sensor.state > ao_flight_pad && pad) {
88 lat_off = target_pad_lat - pad_lat;
90 lon_off = target_pad_lon - pad_lon;
94 case AO_TELEMETRY_LOCATION: {
95 lat = telem->location.latitude / 1.0e7;
96 lon = telem->location.longitude / 1.0e7;
98 if (telem->location.flags & (1 << 4)) {
100 pad_lat = pad_lat - pad_lat / 32 + lat / 32.0;
101 pad_lon = pad_lon - pad_lon / 32 + lon / 32.0;
118 telem->location.latitude = lat * 1.0e7;
119 telem->location.longitude = lon * 1.0e7;
129 struct telem_ent *t, *n;
131 for (t = pad; t; t = n) {
134 dump_telem(&t->telem);
142 main (int argc, char **argv)
148 while ((c = getopt_long(argc, argv, "l:L:", options, NULL)) != -1) {
151 target_pad_lat = strtod(optarg, NULL);
154 target_pad_lon = strtod(optarg, NULL);
161 for (i = optind; i < argc; i++) {
162 file = fopen(argv[i], "r");
168 while (fgets(line, sizeof (line), file)) {
169 union ao_telemetry_all telem;
171 if (cc_telemetry_parse(line, &telem)) {
172 if ((telem.generic.status & (1 << 7)) == 0) {