| 1 | /* |
| 2 | * Copyright © 2013 Keith Packard <[email protected]> |
| 3 | * |
| 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. |
| 8 | * |
| 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. |
| 13 | * |
| 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. |
| 17 | */ |
| 18 | |
| 19 | #define _GNU_SOURCEcxx . . $ `ao-tools/ao-edit-telem/ao-edit-telem.c:19:9`! |
| 20 | #include <string.h> |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <unistd.h> |
| 24 | #include <getopt.h> |
| 25 | #include "cc.h"cxx . . $ `<file>/ao-tools/lib/cc.h`/ |
| 26 | |
| 27 | static const struct optioncxx . . $ option# optionscxx . . $ options.[] = { |
| 28 | { .name = "lat", .has_arg = 1, .val = 'L' }, |
| 29 | { .name = "lon", .has_arg = 1, .val = 'l' }, |
| 30 | { 0, 0, 0, 0}, |
| 31 | }; |
| 32 | |
| 33 | static void usagecxx . . $ usage(fda57c8427c60377).(char *program) |
| 34 | { |
| 35 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s [--lat <pad-lat>] [--lon <pad-lon>]\n" |
| 36 | "\t{flight-log} ...\n", program); |
| 37 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 38 | } |
| 39 | |
| 40 | #define boolcxx . . $ `ao-tools/ao-edit-telem/ao-edit-telem.c:40:9`!(b) ((b) ? "true" : "false") |
| 41 | |
| 42 | struct telem_entcxx . . $ telem_ent# { |
| 43 | struct telem_entcxx . . $ telem_ent# *nextcxx . . $ telem_ent#next.; |
| 44 | union ao_telemetry_allcxx . . $ ao_telemetry_all# telemcxx . . $ telem_ent#telem.; |
| 45 | }; |
| 46 | |
| 47 | static struct telem_entcxx . . $ telem_ent# *padcxx . . $ pad., **lastcxx . . $ last. = &padcxx . . $ pad.; |
| 48 | |
| 49 | static void |
| 50 | save_telemcxx . . $ save_telem(bac9c1af095bbdde).(union ao_telemetry_allcxx . . $ ao_telemetry_all# *telem) |
| 51 | { |
| 52 | struct telem_entcxx . . $ telem_ent# *t = malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof *t); |
| 53 | t->telemcxx . . $ telem_ent#telem. = *telem; |
| 54 | t->nextcxx . . $ telem_ent#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 55 | *lastcxx . . $ last. = t; |
| 56 | lastcxx . . $ last. = &t->nextcxx . . $ telem_ent#next.; |
| 57 | } |
| 58 | |
| 59 | static void |
| 60 | dump_telemcxx . . $ dump_telem(bac9c1af095bbdde).(union ao_telemetry_allcxx . . $ ao_telemetry_all# *telem) |
| 61 | { |
| 62 | char s[CC_TELEMETRY_BUFSIZEcxx . . $ `ao-tools/lib/cc-telemetry.h:327:9`!]; |
| 63 | |
| 64 | cc_telemetry_unparsecxx . . $ cc_telemetry_unparse(947345d1403bf8c2).(telem, s); |
| 65 | printfcxx . . $ printf(581fddd72a8db8fc).("%s\n", s); |
| 66 | } |
| 67 | |
| 68 | double pad_latcxx . . $ pad_lat. = 0, pad_loncxx . . $ pad_lon. = 0; |
| 69 | double target_pad_latcxx . . $ target_pad_lat. = 0, target_pad_loncxx . . $ target_pad_lon. = 0; |
| 70 | double lat_offcxx . . $ lat_off. = 0, lon_offcxx . . $ lon_off. = 0; |
| 71 | int pendingcxx . . $ pending. = 1; |
| 72 | |
| 73 | static void |
| 74 | dump_savedcxx . . $ dump_saved(49f6e7a06ebc5aa8).(void); |
| 75 | |
| 76 | static void |
| 77 | doitcxx . . $ doit(bac9c1af095bbdde).(union ao_telemetry_allcxx . . $ ao_telemetry_all# *telem) |
| 78 | { |
| 79 | double lat, lon; |
| 80 | |
| 81 | switch (telem->genericcxx . . $ ao_telemetry_all#generic..typecxx . . $ ao_telemetry_generic#type.) { |
| 82 | case AO_TELEMETRY_SENSOR_TELEMETRUMcxx . . $ `ao-tools/lib/cc-telemetry.h:38:9`!: |
| 83 | case AO_TELEMETRY_SENSOR_TELEMINIcxx . . $ `ao-tools/lib/cc-telemetry.h:39:9`!: |
| 84 | case AO_TELEMETRY_SENSOR_TELENANOcxx . . $ `ao-tools/lib/cc-telemetry.h:40:9`!: |
| 85 | if (telem->sensorcxx . . $ ao_telemetry_all#sensor..statecxx . . $ ao_telemetry_sensor#state. > ao_flight_padcxx . . $ ao_flight_pad. && padcxx . . $ pad.) { |
| 86 | pendingcxx . . $ pending. = 0; |
| 87 | if (target_pad_latcxx . . $ target_pad_lat.) |
| 88 | lat_offcxx . . $ lat_off. = target_pad_latcxx . . $ target_pad_lat. - pad_latcxx . . $ pad_lat.; |
| 89 | if (target_pad_loncxx . . $ target_pad_lon.) |
| 90 | lon_offcxx . . $ lon_off. = target_pad_loncxx . . $ target_pad_lon. - pad_loncxx . . $ pad_lon.; |
| 91 | dump_savedcxx . . $ dump_saved(49f6e7a06ebc5aa8).(); |
| 92 | } |
| 93 | break; |
| 94 | case AO_TELEMETRY_LOCATIONcxx . . $ `ao-tools/lib/cc-telemetry.h:85:9`!: { |
| 95 | lat = telem->locationcxx . . $ ao_telemetry_all#location..latitudecxx . . $ ao_telemetry_location#latitude. / 1.0e7; |
| 96 | lon = telem->locationcxx . . $ ao_telemetry_all#location..longitudecxx . . $ ao_telemetry_location#longitude. / 1.0e7; |
| 97 | if (pendingcxx . . $ pending.) { |
| 98 | if (telem->locationcxx . . $ ao_telemetry_all#location..flagscxx . . $ ao_telemetry_location#flags. & (1 << 4)) { |
| 99 | if (pad_latcxx . . $ pad_lat.) { |
| 100 | pad_latcxx . . $ pad_lat. = pad_latcxx . . $ pad_lat. - pad_latcxx . . $ pad_lat. / 32 + lat / 32.0; |
| 101 | pad_loncxx . . $ pad_lon. = pad_loncxx . . $ pad_lon. - pad_loncxx . . $ pad_lon. / 32 + lon / 32.0; |
| 102 | } else { |
| 103 | pad_latcxx . . $ pad_lat. = lat; |
| 104 | pad_loncxx . . $ pad_lon. = lon; |
| 105 | } |
| 106 | } |
| 107 | } else { |
| 108 | lat += lat_offcxx . . $ lat_off.; |
| 109 | lon += lon_offcxx . . $ lon_off.; |
| 110 | if (lat > 90) |
| 111 | lat = 90; |
| 112 | if (lat < -90) |
| 113 | lat = -90; |
| 114 | while (lon > 180) |
| 115 | lon -= 360; |
| 116 | while (lon < -180) |
| 117 | lon += 360; |
| 118 | telem->locationcxx . . $ ao_telemetry_all#location..latitudecxx . . $ ao_telemetry_location#latitude. = lat * 1.0e7; |
| 119 | telem->locationcxx . . $ ao_telemetry_all#location..longitudecxx . . $ ao_telemetry_location#longitude. = lon * 1.0e7; |
| 120 | } |
| 121 | break; |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | static void |
| 127 | dump_savedcxx . . $ dump_saved(49f6e7a06ebc5aa8).(void) |
| 128 | { |
| 129 | struct telem_entcxx . . $ telem_ent# *t, *n; |
| 130 | |
| 131 | for (t = padcxx . . $ pad.; t; t = n) { |
| 132 | n = t->nextcxx . . $ telem_ent#next.; |
| 133 | doitcxx . . $ doit(bac9c1af095bbdde).(&t->telemcxx . . $ telem_ent#telem.); |
| 134 | dump_telemcxx . . $ dump_telem(bac9c1af095bbdde).(&t->telemcxx . . $ telem_ent#telem.); |
| 135 | freecxx . . $ free(5d22bdacc48458e8).(t); |
| 136 | } |
| 137 | padcxx . . $ pad. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 138 | lastcxx . . $ last. = &padcxx . . $ pad.; |
| 139 | } |
| 140 | |
| 141 | int |
| 142 | maincxx . . $ main(afcd3168fc1188a4). (int argc, char **argv) |
| 143 | { |
| 144 | char line[80]; |
| 145 | int c, i, ret = 0; |
| 146 | FILEcxx . . $ FILE# *file; |
| 147 | |
| 148 | while ((c = getopt_longcxx . . $ getopt_long(41f665c090816971).(argc, argv, "l:L:", optionscxx . . $ options., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)) != -1) { |
| 149 | switch (c) { |
| 150 | case 'L': |
| 151 | target_pad_latcxx . . $ target_pad_lat. = strtodcxx . . $ strtod(3dfe5620a0d3160e).(optargcxx . . $ optarg., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 152 | break; |
| 153 | case 'l': |
| 154 | target_pad_loncxx . . $ target_pad_lon. = strtodcxx . . $ strtod(3dfe5620a0d3160e).(optargcxx . . $ optarg., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 155 | break; |
| 156 | default: |
| 157 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | for (i = optindcxx . . $ optind.; i < argc; i++) { |
| 162 | file = fopencxx . . $ fopen(82ec0787cd37e0a3).(argv[i], "r"); |
| 163 | if (!file) { |
| 164 | perrorcxx . . $ perror(85c52e162fed56f9).(argv[i]); |
| 165 | ret++; |
| 166 | continue; |
| 167 | } |
| 168 | while (fgetscxx . . $ fgets(efb0aaba7ac866ae).(line, sizeof (line), file)) { |
| 169 | union ao_telemetry_allcxx . . $ ao_telemetry_all# telem; |
| 170 | |
| 171 | if (cc_telemetry_parsecxx . . $ cc_telemetry_parse(affaf9a957364d29).(line, &telem)) { |
| 172 | if ((telem.genericcxx . . $ ao_telemetry_all#generic..statuscxx . . $ ao_telemetry_generic#status. & (1 << 7)) == 0) { |
| 173 | dump_telemcxx . . $ dump_telem(bac9c1af095bbdde).(&telem); |
| 174 | continue; |
| 175 | } |
| 176 | doitcxx . . $ doit(bac9c1af095bbdde). (&telem); |
| 177 | if (pendingcxx . . $ pending.) |
| 178 | save_telemcxx . . $ save_telem(bac9c1af095bbdde).(&telem); |
| 179 | else |
| 180 | dump_telemcxx . . $ dump_telem(bac9c1af095bbdde).(&telem); |
| 181 | } |
| 182 | } |
| 183 | fclosecxx . . $ fclose(89bc1efcdac0ca22). (file); |
| 184 | |
| 185 | } |
| 186 | return ret; |
| 187 | } |