2 * Copyright © 2014 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.
21 #include <ao_log_gps.h>
23 #include <ao_flight.h>
24 #include <ao_distance.h>
25 #include <ao_tracker.h>
28 ao_log_gps_flight(void)
30 ao_log_data.type = AO_LOG_FLIGHT;
31 ao_log_data.tick = ao_time();
32 ao_log_data.u.flight.flight = ao_flight_number;
33 ao_log_write(&ao_log_data);
37 ao_log_gps_data(uint16_t tick, struct ao_telemetry_location *gps_data)
39 ao_log_data.tick = tick;
40 ao_log_data.type = AO_LOG_GPS_TIME;
41 ao_log_data.u.gps.latitude = gps_data->latitude;
42 ao_log_data.u.gps.longitude = gps_data->longitude;
43 ao_log_data.u.gps.altitude_low = gps_data->altitude_low;
44 ao_log_data.u.gps.altitude_high = gps_data->altitude_high;
46 ao_log_data.u.gps.hour = gps_data->hour;
47 ao_log_data.u.gps.minute = gps_data->minute;
48 ao_log_data.u.gps.second = gps_data->second;
49 ao_log_data.u.gps.flags = gps_data->flags;
50 ao_log_data.u.gps.year = gps_data->year;
51 ao_log_data.u.gps.month = gps_data->month;
52 ao_log_data.u.gps.day = gps_data->day;
53 ao_log_data.u.gps.course = gps_data->course;
54 ao_log_data.u.gps.ground_speed = gps_data->ground_speed;
55 ao_log_data.u.gps.climb_rate = gps_data->climb_rate;
56 ao_log_data.u.gps.pdop = gps_data->pdop;
57 ao_log_data.u.gps.hdop = gps_data->hdop;
58 ao_log_data.u.gps.vdop = gps_data->vdop;
59 ao_log_data.u.gps.mode = gps_data->mode;
60 ao_log_write(&ao_log_data);
64 ao_log_gps_tracking(uint16_t tick, struct ao_telemetry_satellite *gps_tracking_data)
68 ao_log_data.tick = tick;
69 ao_log_data.type = AO_LOG_GPS_SAT;
71 n = gps_tracking_data->channels;
72 for (c = 0; c < n; c++)
73 if ((ao_log_data.u.gps_sat.sats[i].svid = gps_tracking_data->sats[c].svid))
75 ao_log_data.u.gps_sat.sats[i].c_n = gps_tracking_data->sats[c].c_n_1;
80 ao_log_data.u.gps_sat.channels = i;
81 ao_log_write(&ao_log_data);
85 ao_log_check(uint32_t pos)
87 if (ao_storage_is_erased(pos & ~(ao_storage_block - 1)))
90 if (!ao_storage_read(pos,
92 sizeof (struct ao_log_gps)))
93 return AO_LOG_INVALID;
95 if (!ao_log_check_data())
96 return AO_LOG_INVALID;