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; 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.
26 static const struct option options[] = {
27 { .name = "lat", .has_arg = 1, .val = 'L' },
28 { .name = "lon", .has_arg = 1, .val = 'l' },
32 static void usage(char *program)
34 fprintf(stderr, "usage: %s [--lat <pad-lat>] [--lon <pad-lon>]\n"
35 "\t{flight-log} ...\n", program);
39 #define bool(b) ((b) ? "true" : "false")
42 struct telem_ent *next;
43 union ao_telemetry_all telem;
46 static struct telem_ent *pad, **last = &pad;
49 save_telem(union ao_telemetry_all *telem)
51 struct telem_ent *t = malloc (sizeof *t);
59 dump_telem(union ao_telemetry_all *telem)
61 char s[CC_TELEMETRY_BUFSIZE];
63 cc_telemetry_unparse(telem, s);
67 double pad_lat = 0, pad_lon = 0;
68 double target_pad_lat = 0, target_pad_lon = 0;
69 double lat_off = 0, lon_off = 0;
76 doit(union ao_telemetry_all *telem)
80 switch (telem->generic.type) {
81 case AO_TELEMETRY_SENSOR_TELEMETRUM:
82 case AO_TELEMETRY_SENSOR_TELEMINI:
83 case AO_TELEMETRY_SENSOR_TELENANO:
84 if (telem->sensor.state > ao_flight_pad && pad) {
87 lat_off = target_pad_lat - pad_lat;
89 lon_off = target_pad_lon - pad_lon;
93 case AO_TELEMETRY_LOCATION: {
94 lat = telem->location.latitude / 1.0e7;
95 lon = telem->location.longitude / 1.0e7;
97 if (telem->location.flags & (1 << 4)) {
99 pad_lat = pad_lat - pad_lat / 32 + lat / 32.0;
100 pad_lon = pad_lon - pad_lon / 32 + lon / 32.0;
117 telem->location.latitude = lat * 1.0e7;
118 telem->location.longitude = lon * 1.0e7;
128 struct telem_ent *t, *n;
130 for (t = pad; t; t = n) {
133 dump_telem(&t->telem);
141 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 s = strstr(argv[i], "-serial-");
170 serial = atoi(s + 8);
173 while (fgets(line, sizeof (line), file)) {
174 union ao_telemetry_all telem;
176 if (cc_telemetry_parse(line, &telem)) {
177 if ((telem.generic.status & (1 << 7)) == 0) {