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>
27 static __xdata struct ao_log_gps log;
29 __code uint8_t ao_log_format = AO_LOG_FORMAT_TELEGPS;
30 __code uint8_t ao_log_size = sizeof (struct ao_log_gps);
33 ao_log_csum(__xdata uint8_t *b) __reentrant
38 for (i = 0; i < sizeof (struct ao_log_gps); i++)
44 ao_log_gps(__xdata struct ao_log_gps *log) __reentrant
49 log->csum = ao_log_csum((__xdata uint8_t *) log);
50 ao_mutex_get(&ao_log_mutex); {
51 if (ao_log_current_pos >= ao_log_end_pos && ao_log_running)
55 ao_storage_write(ao_log_current_pos,
57 sizeof (struct ao_log_gps));
58 ao_log_current_pos += sizeof (struct ao_log_gps);
60 } ao_mutex_put(&ao_log_mutex);
65 ao_log_gps_flight(void)
67 log.type = AO_LOG_FLIGHT;
69 log.u.flight.flight = ao_flight_number;
74 ao_log_gps_data(uint16_t tick, struct ao_telemetry_location *gps_data)
77 log.type = AO_LOG_GPS_TIME;
78 log.u.gps.latitude = gps_data->latitude;
79 log.u.gps.longitude = gps_data->longitude;
80 log.u.gps.altitude_low = gps_data->altitude_low;
81 log.u.gps.altitude_high = gps_data->altitude_high;
83 log.u.gps.hour = gps_data->hour;
84 log.u.gps.minute = gps_data->minute;
85 log.u.gps.second = gps_data->second;
86 log.u.gps.flags = gps_data->flags;
87 log.u.gps.year = gps_data->year;
88 log.u.gps.month = gps_data->month;
89 log.u.gps.day = gps_data->day;
90 log.u.gps.course = gps_data->course;
91 log.u.gps.ground_speed = gps_data->ground_speed;
92 log.u.gps.climb_rate = gps_data->climb_rate;
93 log.u.gps.pdop = gps_data->pdop;
94 log.u.gps.hdop = gps_data->hdop;
95 log.u.gps.vdop = gps_data->vdop;
96 log.u.gps.mode = gps_data->mode;
101 ao_log_gps_tracking(uint16_t tick, struct ao_telemetry_satellite *gps_tracking_data)
106 log.type = AO_LOG_GPS_SAT;
108 n = gps_tracking_data->channels;
109 for (c = 0; c < n; c++)
110 if ((log.u.gps_sat.sats[i].svid = gps_tracking_data->sats[c].svid))
112 log.u.gps_sat.sats[i].c_n = gps_tracking_data->sats[c].c_n_1;
117 log.u.gps_sat.channels = i;
122 ao_log_dump_check_data(void)
124 if (ao_log_csum((uint8_t *) &log) != 0)
130 ao_log_flight(uint8_t slot)
132 if (!ao_storage_read(ao_log_pos(slot),
134 sizeof (struct ao_log_gps)))
137 if (ao_log_dump_check_data() && log.type == AO_LOG_FLIGHT)
138 return log.u.flight.flight;
143 ao_log_check(uint32_t pos)
145 if (!ao_storage_read(pos,
147 sizeof (struct ao_log_gps)))
150 if (ao_log_dump_check_data())