2 * Copyright © 2011 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 = "crc", .has_arg = 0, .val = 'c' },
32 static void usage(char *program)
34 fprintf(stderr, "usage: %s [--crc] {flight.telem} ...\n",program);
38 #define bool(b) ((b) ? "true" : "false")
41 main (int argc, char **argv)
47 while ((c = getopt_long(argc, argv, "c", options, NULL)) != -1) {
57 for (i = optind; i < argc; i++) {
58 file = fopen(argv[i], "r");
64 while (fgets(line, sizeof (line), file)) {
65 union ao_telemetry_all telem;
66 char call[AO_MAX_CALLSIGN+1];
67 char version[AO_MAX_VERSION+1];
69 if (cc_telemetry_parse(line, &telem)) {
70 int rssi = (int8_t) telem.generic.rssi / 2 - 74;
72 printf ("serial %5d rssi %d status %02x tick %5d type %3d ",
73 telem.generic.serial, rssi, telem.generic.status,
74 telem.generic.tick, telem.generic.type);
75 if (!ignore_crc && (telem.generic.status & (1 << 7)) == 0) {
76 printf ("CRC error\n");
79 switch (telem.generic.type) {
80 case AO_TELEMETRY_SENSOR_TELEMETRUM:
81 case AO_TELEMETRY_SENSOR_TELEMINI:
82 case AO_TELEMETRY_SENSOR_TELENANO:
83 printf ("state %1d accel %5d pres %5d ",
84 telem.sensor.state, telem.sensor.accel, telem.sensor.pres);
85 printf ("accel %6.2f speed %6.2f height %5d ",
86 telem.sensor.acceleration / 16.0,
87 telem.sensor.speed / 16.0,
89 printf ("ground_pres %5d ground_accel %5d accel_plus %5d accel_minus %5d\n",
90 telem.sensor.ground_pres,
91 telem.sensor.ground_accel,
92 telem.sensor.accel_plus_g,
93 telem.sensor.accel_minus_g);
95 case AO_TELEMETRY_CONFIGURATION:
96 memcpy(call, telem.configuration.callsign, AO_MAX_CALLSIGN);
97 memcpy(version, telem.configuration.version, AO_MAX_VERSION);
98 call[AO_MAX_CALLSIGN] = '\0';
99 version[AO_MAX_CALLSIGN] = '\0';
100 printf ("device %3d flight %5d config %3d.%03d delay %2d main %4d log_max %5d",
101 telem.configuration.device,
102 telem.configuration.flight,
103 telem.configuration.config_major,
104 telem.configuration.config_minor,
105 telem.configuration.apogee_delay,
106 telem.configuration.main_deploy,
107 telem.configuration.flight_log_max);
108 printf (" call %8s version %8s\n", call, version);
110 case AO_TELEMETRY_LOCATION:
111 printf ("sats %d flags %s%s%s%s",
112 telem.location.flags & 0xf,
113 (telem.location.flags & (1 << 4)) ? "valid" : "invalid",
114 (telem.location.flags & (1 << 5)) ? ",running" : "",
115 (telem.location.flags & (1 << 6)) ? ",date" : "",
116 (telem.location.flags & (1 << 7)) ? ",course" : "");
117 printf (" alt %5d lat %12.7f lon %12.7f",
118 AO_TELEMETRY_LOCATION_ALTITUDE(&telem.location),
119 telem.location.latitude / 1e7,
120 telem.location.longitude / 1e7);
121 if ((telem.location.flags & (1 << 6)) != 0) {
122 printf (" year %2d month %2d day %2d",
124 telem.location.month,
126 printf (" hour %2d minute %2d second %2d",
128 telem.location.minute,
129 telem.location.second);
131 printf (" pdop %3.1f hdop %3.1f vdop %3.1f mode %d",
132 telem.location.pdop / 5.0,
133 telem.location.hdop / 5.0,
134 telem.location.vdop / 5.0,
135 telem.location.mode);
136 if ((telem.location.flags & (1 << 7)) != 0)
137 printf (" ground_speed %6.2f climb_rate %6.2f course %d",
138 telem.location.ground_speed / 100.0,
139 telem.location.climb_rate / 100.0,
140 telem.location.course * 2);
143 case AO_TELEMETRY_SATELLITE:
144 printf ("sats %d", telem.satellite.channels);
145 for (c = 0; c < 12 && c < telem.satellite.channels; c++) {
146 printf (" sat %d svid %d c_n_1 %d",
148 telem.satellite.sats[c].svid,
149 telem.satellite.sats[c].c_n_1);
153 case AO_TELEMETRY_MEGA_SENSOR_MPU:
154 case AO_TELEMETRY_MEGA_SENSOR_BMX160:
155 printf ("orient %3d accel %5d pres %9d temp %5d accel_x %5d accel_y %5d accel_z %5d gyro_x %5d gyro_y %5d gyro_z %5d mag_x %5d mag_y %5d mag_z %5d\n",
156 telem.mega_sensor.orient,
157 telem.mega_sensor.accel,
158 telem.mega_sensor.pres,
159 telem.mega_sensor.temp,
160 telem.mega_sensor.accel_x,
161 telem.mega_sensor.accel_y,
162 telem.mega_sensor.accel_z,
163 telem.mega_sensor.gyro_x,
164 telem.mega_sensor.gyro_y,
165 telem.mega_sensor.gyro_z,
166 telem.mega_sensor.mag_x,
167 telem.mega_sensor.mag_y,
168 telem.mega_sensor.mag_z);
170 case AO_TELEMETRY_COMPANION:
171 printf("board_id %3d update_period %3d channels %2d",
172 telem.companion.board_id,
173 telem.companion.update_period,
174 telem.companion.channels);
175 for (c = 0; c < telem.companion.channels; c++)
176 printf(" %6d", telem.companion.companion_data[c]);
179 case AO_TELEMETRY_MEGA_DATA:
180 printf ("state %1d v_batt %5d v_pyro %5d ",
181 telem.mega_data.state,
182 telem.mega_data.v_batt,
183 telem.mega_data.v_pyro);
184 for (c = 0; c < 6; c++)
185 printf ("s%1d %5d ", c,
186 telem.mega_data.sense[c] |
187 (telem.mega_data.sense[c] << 8));
189 printf ("ground_pres %5d ground_accel %5d accel_plus %5d accel_minus %5d ",
190 telem.mega_data.ground_pres,
191 telem.mega_data.ground_accel,
192 telem.mega_data.accel_plus_g,
193 telem.mega_data.accel_minus_g);
195 printf ("accel %6.2f speed %6.2f height %5d\n",
196 telem.mega_data.acceleration / 16.0,
197 telem.mega_data.speed / 16.0,
198 telem.mega_data.height);
201 case AO_TELEMETRY_METRUM_SENSOR:
202 printf ("state %1d accel %5d pres %9d temp %6.2f acceleration %6.2f speed %6.2f height %5d v_batt %5d sense_a %5d sense_m %5d\n",
203 telem.metrum_sensor.state,
204 telem.metrum_sensor.accel,
205 telem.metrum_sensor.pres,
206 telem.metrum_sensor.temp / 100.0,
207 telem.metrum_sensor.acceleration / 16.0,
208 telem.metrum_sensor.speed / 16.0,
209 telem.metrum_sensor.height,
210 telem.metrum_sensor.v_batt,
211 telem.metrum_sensor.sense_a,
212 telem.metrum_sensor.sense_m);
214 case AO_TELEMETRY_METRUM_DATA:
215 printf ("ground_pres %9d ground_accel %5d accel_plus %5d accel_minus %5d\n",
216 telem.metrum_data.ground_pres,
217 telem.metrum_data.ground_accel,
218 telem.metrum_data.accel_plus_g,
219 telem.metrum_data.accel_minus_g);
221 case AO_TELEMETRY_MINI:
222 printf ("state %1d v_batt %5d sense_a %5d sense_m %5d pres %9d temp %6.2f acceleration %6.2f speed %6.2f height %5d ground_pres %9d\n",
228 telem.mini.temp / 100.0,
229 telem.mini.acceleration / 16.0,
230 telem.mini.speed / 16.0,
232 telem.mini.ground_pres);