2 * Copyright © 2012 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.
21 #include <ao_flight.h>
27 /* We record flight numbers in the first record of
28 * the log. Tasks may wait for this to be initialized
29 * by sleeping on this variable.
31 extern __xdata uint16_t ao_flight_number;
33 extern __pdata uint32_t ao_log_current_pos;
34 extern __pdata uint32_t ao_log_end_pos;
35 extern __pdata uint32_t ao_log_start_pos;
36 extern __xdata uint8_t ao_log_running;
37 extern __pdata enum ao_flight_state ao_log_state;
39 /* required functions from the underlying log system */
41 #define AO_LOG_FORMAT_UNKNOWN 0 /* unknown; altosui will have to guess */
42 #define AO_LOG_FORMAT_FULL 1 /* 8 byte typed log records */
43 #define AO_LOG_FORMAT_TINY 2 /* two byte state/baro records */
44 #define AO_LOG_FORMAT_TELEMETRY 3 /* 32 byte ao_telemetry records */
45 #define AO_LOG_FORMAT_TELESCIENCE 4 /* 32 byte typed telescience records */
46 #define AO_LOG_FORMAT_TELEMEGA 5 /* 32 byte typed telemega records */
47 #define AO_LOG_FORMAT_MINI 6 /* 16-byte MS5607 baro only */
48 #define AO_LOG_FORMAT_TELEMETRUM 7 /* 16-byte typed telemetrum records */
49 #define AO_LOG_FORMAT_NONE 127 /* No log at all */
51 extern __code uint8_t ao_log_format;
53 /* Return the flight number from the given log slot, 0 if none */
55 ao_log_flight(uint8_t slot);
61 /* Logging thread main routine */
65 /* functions provided in ao_log.c */
67 /* Figure out the current flight number */
69 ao_log_scan(void) __reentrant;
71 /* Return the position of the start of the given log slot */
73 ao_log_pos(uint8_t slot);
75 /* Start logging to eeprom */
83 /* Initialize the logging system */
87 /* Write out the current flight number to the erase log */
89 ao_log_write_erase(uint8_t pos);
91 /* Returns true if there are any logs stored in eeprom */
95 /* Returns true if there is no more storage space available */
104 * The data log is recorded in the eeprom as a sequence
107 * Each packet starts with a 4-byte header that has the
108 * packet type, the packet checksum and the tick count. Then
109 * they all contain 2 16 bit values which hold packet-specific
112 * For each flight, the first packet
113 * is FLIGHT packet, indicating the serial number of the
114 * device and a unique number marking the number of flights
115 * recorded by this device.
117 * During flight, data from the accelerometer and barometer
118 * are recorded in SENSOR packets, using the raw 16-bit values
119 * read from the A/D converter.
121 * Also during flight, but at a lower rate, the deployment
122 * sensors are recorded in DEPLOY packets. The goal here is to
123 * detect failure in the deployment circuits.
125 * STATE packets hold state transitions as the flight computer
126 * transitions through different stages of the flight.
128 #define AO_LOG_FLIGHT 'F'
129 #define AO_LOG_SENSOR 'A'
130 #define AO_LOG_TEMP_VOLT 'T'
131 #define AO_LOG_DEPLOY 'D'
132 #define AO_LOG_STATE 'S'
133 #define AO_LOG_GPS_TIME 'G'
134 #define AO_LOG_GPS_LAT 'N'
135 #define AO_LOG_GPS_LON 'W'
136 #define AO_LOG_GPS_ALT 'H'
137 #define AO_LOG_GPS_SAT 'V'
138 #define AO_LOG_GPS_DATE 'Y'
139 #define AO_LOG_GPS_POS 'P'
141 #define AO_LOG_POS_NONE (~0UL)
143 struct ao_log_record {
145 uint8_t csum; /* 1 */
146 uint16_t tick; /* 2 */
149 int16_t ground_accel; /* 4 */
150 uint16_t flight; /* 6 */
153 int16_t accel; /* 4 */
154 int16_t pres; /* 6 */
174 int32_t gps_latitude;
175 int32_t gps_longitude;
200 uint8_t csum; /* 1 */
201 uint16_t tick; /* 2 */
205 uint16_t flight; /* 4 */
206 int16_t ground_accel; /* 6 */
207 uint32_t ground_pres; /* 8 */
208 int16_t ground_accel_along; /* 16 */
209 int16_t ground_accel_across; /* 12 */
210 int16_t ground_accel_through; /* 14 */
211 int16_t ground_roll; /* 18 */
212 int16_t ground_pitch; /* 20 */
213 int16_t ground_yaw; /* 22 */
222 uint32_t pres; /* 4 */
223 uint32_t temp; /* 8 */
224 int16_t accel_x; /* 12 */
225 int16_t accel_y; /* 14 */
226 int16_t accel_z; /* 16 */
227 int16_t gyro_x; /* 18 */
228 int16_t gyro_y; /* 20 */
229 int16_t gyro_z; /* 22 */
230 int16_t mag_x; /* 24 */
231 int16_t mag_y; /* 26 */
232 int16_t mag_z; /* 28 */
233 int16_t accel; /* 30 */
235 /* AO_LOG_TEMP_VOLT */
237 int16_t v_batt; /* 4 */
238 int16_t v_pbatt; /* 6 */
239 int16_t n_sense; /* 8 */
240 int16_t sense[10]; /* 10 */
241 uint16_t pyro; /* 30 */
243 /* AO_LOG_GPS_TIME */
245 int32_t latitude; /* 4 */
246 int32_t longitude; /* 8 */
247 int16_t altitude; /* 12 */
248 uint8_t hour; /* 14 */
249 uint8_t minute; /* 15 */
250 uint8_t second; /* 16 */
251 uint8_t flags; /* 17 */
252 uint8_t year; /* 18 */
253 uint8_t month; /* 19 */
254 uint8_t day; /* 20 */
255 uint8_t pad; /* 21 */
259 uint16_t channels; /* 4 */
268 struct ao_log_metrum {
270 uint8_t csum; /* 1 */
271 uint16_t tick; /* 2 */
275 uint16_t flight; /* 4 */
276 int16_t ground_accel; /* 6 */
277 uint32_t ground_pres; /* 8 */
281 uint16_t state; /* 4 */
282 uint16_t reason; /* 6 */
286 uint32_t pres; /* 4 */
287 uint32_t temp; /* 8 */
288 int16_t accel; /* 12 */
290 /* AO_LOG_TEMP_VOLT */
292 int16_t v_batt; /* 4 */
293 int16_t sense_a; /* 6 */
294 int16_t sense_m; /* 8 */
298 int32_t latitude; /* 4 */
299 int32_t longitude; /* 8 */
300 int16_t altitude; /* 12 */
302 /* AO_LOG_GPS_TIME */
304 uint8_t hour; /* 4 */
305 uint8_t minute; /* 5 */
306 uint8_t second; /* 6 */
307 uint8_t flags; /* 7 */
308 uint8_t year; /* 8 */
309 uint8_t month; /* 9 */
310 uint8_t day; /* 10 */
311 uint8_t pad; /* 11 */
313 /* AO_LOG_GPS_SAT (up to three packets) */
315 uint8_t channels; /* 4 */
316 uint8_t more; /* 5 */
322 uint8_t raw[12]; /* 4 */
328 uint8_t csum; /* 1 */
329 uint16_t tick; /* 2 */
333 uint16_t flight; /* 4 */
335 uint32_t ground_pres; /* 8 */
339 uint16_t state; /* 4 */
340 uint16_t reason; /* 6 */
344 uint8_t pres[3]; /* 4 */
345 uint8_t temp[3]; /* 7 */
346 int16_t sense_a; /* 10 */
347 int16_t sense_m; /* 12 */
348 int16_t v_batt; /* 14 */
353 #define ao_log_pack24(dst,value) do { \
354 (dst)[0] = (value); \
355 (dst)[1] = (value) >> 8; \
356 (dst)[2] = (value) >> 16; \
359 /* Write a record to the eeprom log */
361 ao_log_data(__xdata struct ao_log_record *log) __reentrant;
364 ao_log_mega(__xdata struct ao_log_mega *log) __reentrant;
367 ao_log_metrum(__xdata struct ao_log_metrum *log) __reentrant;
370 ao_log_mini(__xdata struct ao_log_mini *log) __reentrant;
376 ao_gps_report_metrum_init(void);
378 #endif /* _AO_LOG_H_ */