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; 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.
23 #include "cc-telemetry.h"
26 cc_fullname (char *dir, char *file);
29 cc_basename(char *file);
39 int serial; /* AltOS always uses simple integer serial numbers */
45 struct cc_usbdev **dev;
50 cc_usbdevs_free(struct cc_usbdevs *usbdevs);
53 cc_usbdevs_scan(void);
56 cc_usbdevs_find_by_arg(char *arg, char *default_product);
59 cc_set_log_dir(char *dir);
65 cc_make_filename(int serial, int flight, char *ext);
68 * For sequential data which are not evenly spaced
71 struct cc_timedataelt {
79 struct cc_timedataelt *data;
99 #define SIRF_SAT_STATE_ACQUIRED (1 << 0)
100 #define SIRF_SAT_STATE_CARRIER_PHASE_VALID (1 << 1)
101 #define SIRF_SAT_BIT_SYNC_COMPLETE (1 << 2)
102 #define SIRF_SAT_SUBFRAME_SYNC_COMPLETE (1 << 3)
103 #define SIRF_SAT_CARRIER_PULLIN_COMPLETE (1 << 4)
104 #define SIRF_SAT_CODE_LOCKED (1 << 5)
105 #define SIRF_SAT_ACQUISITION_FAILED (1 << 6)
106 #define SIRF_SAT_EPHEMERIS_AVAILABLE (1 << 7)
116 struct cc_gpssat sat[12];
122 struct cc_gpselt *data;
126 struct cc_gpssats *sats;
130 * For sequential data which are evenly spaced
132 struct cc_perioddata {
139 enum ao_flight_state {
140 ao_flight_startup = 0,
146 ao_flight_drogue = 6,
148 ao_flight_landed = 8,
149 ao_flight_invalid = 9
152 struct cc_flightraw {
157 int year, month, day;
158 struct cc_timedata accel;
159 struct cc_timedata pres;
160 struct cc_timedata temp;
161 struct cc_timedata volt;
162 struct cc_timedata main;
163 struct cc_timedata drogue;
164 struct cc_timedata state;
165 struct cc_gpsdata gps;
168 struct cc_flightraw *
169 cc_log_read(FILE *file);
172 cc_flightraw_free(struct cc_flightraw *raw);
174 struct cc_flightcooked {
178 struct cc_perioddata accel_accel;
179 struct cc_perioddata accel_speed;
180 struct cc_perioddata accel_pos;
181 struct cc_perioddata pres_pos;
182 struct cc_perioddata pres_speed;
183 struct cc_perioddata pres_accel;
184 struct cc_perioddata gps_lat;
185 struct cc_perioddata gps_lon;
186 struct cc_perioddata gps_alt;
188 /* unfiltered, but converted */
189 struct cc_timedata pres;
190 struct cc_timedata accel;
191 struct cc_timedata state;
195 * Telemetry data contents
212 struct cc_gps_time gps_time;
213 double lat; /* degrees (+N -S) */
214 double lon; /* degrees (+E -W) */
217 int gps_extended; /* has extra data */
218 double ground_speed; /* m/s */
219 int course; /* degrees */
220 double climb_rate; /* m/s */
221 double hdop; /* unitless? */
226 #define SIRF_SAT_STATE_ACQUIRED (1 << 0)
227 #define SIRF_SAT_STATE_CARRIER_PHASE_VALID (1 << 1)
228 #define SIRF_SAT_BIT_SYNC_COMPLETE (1 << 2)
229 #define SIRF_SAT_SUBFRAME_SYNC_COMPLETE (1 << 3)
230 #define SIRF_SAT_CARRIER_PULLIN_COMPLETE (1 << 4)
231 #define SIRF_SAT_CODE_LOCKED (1 << 5)
232 #define SIRF_SAT_ACQUISITION_FAILED (1 << 6)
233 #define SIRF_SAT_EPHEMERIS_AVAILABLE (1 << 7)
240 struct cc_gps_tracking {
242 struct cc_gps_sat sats[12];
266 struct cc_gps_tracking gps_tracking;
270 cc_telem_parse(const char *input_line, struct cc_telem *telem);
274 uint8_t is_config; /* 1 */
275 uint16_t tick; /* 2 */
279 uint16_t flight; /* 4 */
280 int16_t ground_accel; /* 6 */
281 uint32_t ground_pres; /* 8 */
290 uint32_t pres; /* 4 */
291 uint32_t temp; /* 8 */
292 int16_t accel_x; /* 12 */
293 int16_t accel_y; /* 14 */
294 int16_t accel_z; /* 16 */
295 int16_t gyro_x; /* 18 */
296 int16_t gyro_y; /* 20 */
297 int16_t gyro_z; /* 22 */
298 int16_t mag_x; /* 24 */
299 int16_t mag_y; /* 26 */
300 int16_t mag_z; /* 28 */
301 int16_t accel; /* 30 */
303 /* AO_LOG_TEMP_VOLT */
305 int16_t v_batt; /* 4 */
306 int16_t v_pbatt; /* 6 */
307 int16_t n_sense; /* 8 */
308 int16_t sense[10]; /* 10 */
310 /* AO_LOG_GPS_TIME */
312 int32_t latitude; /* 4 */
313 int32_t longitude; /* 8 */
314 int16_t altitude; /* 12 */
315 uint8_t hour; /* 14 */
316 uint8_t minute; /* 15 */
317 uint8_t second; /* 16 */
318 uint8_t flags; /* 17 */
319 uint8_t year; /* 18 */
320 uint8_t month; /* 19 */
321 uint8_t day; /* 20 */
322 uint8_t pad; /* 21 */
326 uint16_t channels; /* 4 */
348 #define AO_CONFIG_CONFIG 1
349 #define AO_CONFIG_MAIN 2
350 #define AO_CONFIG_APOGEE 3
351 #define AO_CONFIG_LOCKOUT 4
352 #define AO_CONFIG_FREQUENCY 5
353 #define AO_CONFIG_RADIO_ENABLE 6
354 #define AO_CONFIG_ACCEL_CAL 7
355 #define AO_CONFIG_RADIO_CAL 8
356 #define AO_CONFIG_MAX_LOG 9
357 #define AO_CONFIG_IGNITE_MODE 10
358 #define AO_CONFIG_PAD_ORIENTATION 11
359 #define AO_CONFIG_SERIAL_NUMBER 12
360 #define AO_CONFIG_LOG_FORMAT 13
361 #define AO_CONFIG_MS5607_RESERVED 14
362 #define AO_CONFIG_MS5607_SENS 15
363 #define AO_CONFIG_MS5607_OFF 16
364 #define AO_CONFIG_MS5607_TCS 17
365 #define AO_CONFIG_MS5607_TCO 18
366 #define AO_CONFIG_MS5607_TREF 19
367 #define AO_CONFIG_MS5607_TEMPSENS 20
368 #define AO_CONFIG_MS5607_CRC 21
371 #define AO_LOG_FLIGHT 'F'
372 #define AO_LOG_SENSOR 'A'
373 #define AO_LOG_TEMP_VOLT 'T'
374 #define AO_LOG_DEPLOY 'D'
375 #define AO_LOG_STATE 'S'
376 #define AO_LOG_GPS_TIME 'G'
377 #define AO_LOG_GPS_LAT 'N'
378 #define AO_LOG_GPS_LON 'W'
379 #define AO_LOG_GPS_ALT 'H'
380 #define AO_LOG_GPS_SAT 'V'
381 #define AO_LOG_GPS_DATE 'Y'
383 #define AO_LOG_CONFIG 'c'
386 cc_mega_parse(const char *input_line, struct ao_log_mega *l);
393 /* Conversion functions */
395 cc_pressure_to_altitude(double pressure);
398 cc_altitude_to_pressure(double altitude);
401 cc_barometer_to_pressure(double baro);
404 cc_barometer_to_altitude(double baro);
407 cc_accelerometer_to_acceleration(double accel, double ground_accel);
410 cc_thermometer_to_temperature(double thermo);
413 cc_battery_to_voltage(double battery);
416 cc_ignitor_to_voltage(double ignite);
419 cc_great_circle (double start_lat, double start_lon,
420 double end_lat, double end_lon,
421 double *dist, double *bearing);
424 cc_timedata_limits(struct cc_timedata *d, double min_time, double max_time, int *start, int *stop);
427 cc_timedata_min(struct cc_timedata *d, double min_time, double max_time);
430 cc_timedata_min_mag(struct cc_timedata *d, double min_time, double max_time);
433 cc_timedata_max(struct cc_timedata *d, double min_time, double max_time);
436 cc_timedata_max_mag(struct cc_timedata *d, double min_time, double max_time);
439 cc_timedata_average(struct cc_timedata *d, double min_time, double max_time);
442 cc_timedata_average_mag(struct cc_timedata *d, double min_time, double max_time);
445 cc_perioddata_limits(struct cc_perioddata *d, double min_time, double max_time, int *start, int *stop);
448 cc_perioddata_min(struct cc_perioddata *d, double min_time, double max_time);
451 cc_perioddata_min_mag(struct cc_perioddata *d, double min_time, double max_time);
454 cc_perioddata_max(struct cc_perioddata *d, double min_time, double max_time);
457 cc_perioddata_max_mag(struct cc_perioddata *d, double min_time, double max_time);
460 cc_perioddata_average(struct cc_perioddata *d, double min_time, double max_time);
463 cc_perioddata_average_mag(struct cc_perioddata *d, double min_time, double max_time);
466 cc_low_pass(double *data, int data_len, double omega_pass, double omega_stop, double error);
468 struct cc_perioddata *
469 cc_period_make(struct cc_timedata *td, double start_time, double stop_time);
471 struct cc_perioddata *
472 cc_period_low_pass(struct cc_perioddata *raw, double omega_pass, double omega_stop, double error);
475 cc_timedata_convert(struct cc_timedata *d, double (*f)(double v, double a), double a);
478 cc_timedata_integrate(struct cc_timedata *d, double min_time, double max_time);
480 struct cc_perioddata *
481 cc_perioddata_differentiate(struct cc_perioddata *i);
483 struct cc_flightcooked *
484 cc_flight_cook(struct cc_flightraw *raw);
487 cc_flightcooked_free(struct cc_flightcooked *cooked);