b8aa6a8c589541759f50a34885cff2edf53897e5
[fw/altos] / src / kernel / ao_log.h
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #ifndef _AO_LOG_H_
20 #define _AO_LOG_H_
21
22 #include <ao_flight.h>
23
24 /*
25  * ao_log.c
26  */
27
28 /* We record flight numbers in the first record of
29  * the log. Tasks may wait for this to be initialized
30  * by sleeping on this variable.
31  */
32 extern uint16_t ao_flight_number;
33 extern uint8_t  ao_log_mutex;
34 extern uint32_t ao_log_current_pos;
35 extern uint32_t ao_log_end_pos;
36 extern uint32_t ao_log_start_pos;
37 extern uint8_t  ao_log_running;
38 extern enum ao_flight_state ao_log_state;
39
40 /* required functions from the underlying log system */
41
42 #define AO_LOG_FORMAT_UNKNOWN           0       /* unknown; altosui will have to guess */
43 #define AO_LOG_FORMAT_FULL              1       /* 8 byte typed log records */
44 #define AO_LOG_FORMAT_TINY              2       /* two byte state/baro records */
45 #define AO_LOG_FORMAT_TELEMETRY         3       /* 32 byte ao_telemetry records */
46 #define AO_LOG_FORMAT_TELESCIENCE       4       /* 32 byte typed telescience records */
47 #define AO_LOG_FORMAT_TELEMEGA_OLD      5       /* 32 byte typed telemega records */
48 #define AO_LOG_FORMAT_EASYMINI1         6       /* 16-byte MS5607 baro only, 3.0V supply */
49 #define AO_LOG_FORMAT_TELEMETRUM        7       /* 16-byte typed telemetrum records */
50 #define AO_LOG_FORMAT_TELEMINI2         8       /* 16-byte MS5607 baro only, 3.3V supply, cc1111 SoC */
51 #define AO_LOG_FORMAT_TELEGPS           9       /* 32 byte telegps records */
52 #define AO_LOG_FORMAT_TELEMEGA          10      /* 32 byte typed telemega records with 32 bit gyro cal */
53 #define AO_LOG_FORMAT_DETHERM           11      /* 16-byte MS5607 baro only, no ADC */
54 #define AO_LOG_FORMAT_TELEMINI3         12      /* 16-byte MS5607 baro only, 3.3V supply, stm32f042 SoC */
55 #define AO_LOG_FORMAT_TELEFIRETWO       13      /* 32-byte test stand data */
56 #define AO_LOG_FORMAT_EASYMINI2         14      /* 16-byte MS5607 baro only, 3.3V supply, stm32f042 SoC */
57 #define AO_LOG_FORMAT_TELEMEGA_3        15      /* 32 byte typed telemega records with 32 bit gyro cal and mpu9250 */
58 #define AO_LOG_FORMAT_EASYMEGA_2        16      /* 32 byte typed telemega records with 32 bit gyro cal, mpu9250 rotated 90° and adxl375 */
59 #define AO_LOG_FORMAT_TELESTATIC        17      /* 32 byte typed telestatic records */
60 #define AO_LOG_FORMAT_MICROPEAK2        18      /* 2-byte baro values with header */
61 #define AO_LOG_FORMAT_TELEMEGA_4        19      /* 32 byte typed telemega records with 32 bit gyro cal and Bmx160 */
62 #define AO_LOG_FORMAT_EASYMOTOR         20      /* 16 byte typed easymotor records with pressure sensor and adxl375 */
63 #define AO_LOG_FORMAT_TELEMEGA_5        21      /* 32 byte typed telemega records with 32 bit gyro cal, mpu6000 and mmc5983 */
64 #define AO_LOG_FORMAT_TELEMEGA_6        22      /* 32 byte typed telemega records with 32 bit gyro cal, bmi088 and mmc5983 */
65 #define AO_LOG_FORMAT_EASYTIMER_2       23      /* 32 byte typed easytimer records with 32 bit gyro cal, bmi088 and mmc5983 */
66 #define AO_LOG_FORMAT_EASYMEGA_3        24      /* 32 byte typed telemega records with 32 bit gyro cal, bmi088 and mmc5983 */
67 #define AO_LOG_FORMAT_NONE              127     /* No log at all */
68
69 /* Return the flight number from the given log slot, 0 if none, -slot on failure */
70
71 int32_t
72 ao_log_flight(uint8_t slot);
73
74 /* Checksum the loaded log record */
75 uint8_t
76 ao_log_check_data(void);
77
78 /* Check to see if the loaded log record is empty */
79 uint8_t
80 ao_log_check_clear(void);
81
82 /* Check if there is valid log data at the specified location */
83 #define AO_LOG_VALID    1
84 #define AO_LOG_EMPTY    0
85 #define AO_LOG_INVALID  -1
86
87 int8_t
88 ao_log_check(uint32_t pos);
89
90 /* Flush the log */
91 void
92 ao_log_flush(void);
93
94 /* Logging thread main routine */
95 void
96 ao_log(void);
97
98 /* functions provided in ao_log.c */
99
100 /* Figure out the current flight number */
101 uint8_t
102 ao_log_scan(void);
103
104 /* Start logging to eeprom */
105 void
106 ao_log_start(void);
107
108 /* Stop logging */
109 void
110 ao_log_stop(void);
111
112 /* Initialize the logging system */
113 void
114 ao_log_init(void);
115
116 /* Write out the current flight number to the erase log */
117 void
118 ao_log_write_erase(uint8_t pos);
119
120 /* Returns true if there are any logs stored in eeprom */
121 uint8_t
122 ao_log_present(void);
123
124 /* Returns true if there is no more storage space available */
125 uint8_t
126 ao_log_full(void);
127
128 /*
129  * ao_log_big.c
130  */
131
132 /*
133  * The data log is recorded in the eeprom as a sequence
134  * of data packets.
135  *
136  * Each packet starts with a 4-byte header that has the
137  * packet type, the packet checksum and the tick count. Then
138  * they all contain 2 16 bit values which hold packet-specific
139  * data.
140  *
141  * For each flight, the first packet
142  * is FLIGHT packet, indicating the serial number of the
143  * device and a unique number marking the number of flights
144  * recorded by this device.
145  *
146  * During flight, data from the accelerometer and barometer
147  * are recorded in SENSOR packets, using the raw 16-bit values
148  * read from the A/D converter.
149  *
150  * Also during flight, but at a lower rate, the deployment
151  * sensors are recorded in DEPLOY packets. The goal here is to
152  * detect failure in the deployment circuits.
153  *
154  * STATE packets hold state transitions as the flight computer
155  * transitions through different stages of the flight.
156  */
157 #define AO_LOG_FLIGHT           'F'
158 #define AO_LOG_SENSOR           'A'
159 #define AO_LOG_TEMP_VOLT        'T'
160 #define AO_LOG_DEPLOY           'D'
161 #define AO_LOG_STATE            'S'
162 #define AO_LOG_GPS_TIME         'G'
163 #define AO_LOG_GPS_LAT          'N'
164 #define AO_LOG_GPS_LON          'W'
165 #define AO_LOG_GPS_ALT          'H'
166 #define AO_LOG_GPS_SAT          'V'
167 #define AO_LOG_GPS_DATE         'Y'
168 #define AO_LOG_GPS_POS          'P'
169
170 #define AO_LOG_POS_NONE         (~0UL)
171
172 struct ao_log_record {
173         char                    type;                           /* 0 */
174         uint8_t                 csum;                           /* 1 */
175         uint16_t                tick;                           /* 2 */
176         union {
177                 struct {
178                         int16_t         ground_accel;           /* 4 */
179                         uint16_t        flight;                 /* 6 */
180                 } flight;
181                 struct {
182                         int16_t         accel;                  /* 4 */
183                         int16_t         pres;                   /* 6 */
184                 } sensor;
185                 struct {
186                         int16_t         temp;
187                         int16_t         v_batt;
188                 } temp_volt;
189                 struct {
190                         int16_t         drogue;
191                         int16_t         main;
192                 } deploy;
193                 struct {
194                         uint16_t        state;
195                         uint16_t        reason;
196                 } state;
197                 struct {
198                         uint8_t         hour;
199                         uint8_t         minute;
200                         uint8_t         second;
201                         uint8_t         flags;
202                 } gps_time;
203                 int32_t         gps_latitude;
204                 int32_t         gps_longitude;
205                 struct {
206                         uint16_t        altitude_low;
207                         int16_t         altitude_high;
208                 } gps_altitude;
209                 struct {
210                         uint16_t        svid;
211                         uint8_t         unused;
212                         uint8_t         c_n;
213                 } gps_sat;
214                 struct {
215                         uint8_t         year;
216                         uint8_t         month;
217                         uint8_t         day;
218                         uint8_t         extra;
219                 } gps_date;
220                 struct {
221                         uint16_t        d0;
222                         uint16_t        d1;
223                 } anon;
224         } u;
225 };
226
227 struct ao_log_mega {
228         char                    type;                   /* 0 */
229         uint8_t                 csum;                   /* 1 */
230         uint16_t                tick;                   /* 2 */
231         union {                                         /* 4 */
232                 /* AO_LOG_FLIGHT */
233                 struct {
234                         uint16_t        flight;                 /* 4 */
235                         int16_t         ground_accel;           /* 6 */
236                         int32_t         ground_pres;            /* 8 */
237                         int16_t         ground_accel_along;     /* 12 */
238                         int16_t         ground_accel_across;    /* 14 */
239                         int16_t         ground_accel_through;   /* 16 */
240                         int16_t         pad_18;                 /* 18 */
241                         int32_t         ground_roll;            /* 20 */
242                         int32_t         ground_pitch;           /* 24 */
243                         int32_t         ground_yaw;             /* 28 */
244                 } flight;                                       /* 32 */
245                 struct {
246                         uint16_t        flight;                 /* 4 */
247                         int16_t         ground_accel;           /* 6 */
248                         int32_t         ground_pres;            /* 8 */
249                         int16_t         ground_accel_along;     /* 12 */
250                         int16_t         ground_accel_across;    /* 14 */
251                         int16_t         ground_accel_through;   /* 16 */
252                         int16_t         ground_roll;            /* 18 */
253                         int16_t         ground_pitch;           /* 20 */
254                         int16_t         ground_yaw;             /* 22 */
255                 } flight_old;                                   /* 24 */
256                 /* AO_LOG_STATE */
257                 struct {
258                         uint16_t        state;
259                         uint16_t        reason;
260                 } state;
261                 /* AO_LOG_SENSOR */
262                 struct {
263                         uint32_t        pres;           /* 4 */
264                         uint32_t        temp;           /* 8 */
265                         union {
266                                 struct {
267                                         int16_t         accel_along;    /* 12 */
268                                         int16_t         accel_across;   /* 14 */
269                                         int16_t         accel_through;  /* 16 */
270                                         int16_t         gyro_roll;      /* 18 */
271                                         int16_t         gyro_pitch;     /* 20 */
272                                         int16_t         gyro_yaw;       /* 22 */
273                                         int16_t         mag_along;      /* 24 */
274                                         int16_t         mag_across;     /* 26 */
275                                         int16_t         mag_through;    /* 28 */
276                                 };
277                                 struct {
278                                         int16_t         accel_x;        /* 12 */
279                                         int16_t         accel_y;        /* 14 */
280                                         int16_t         accel_z;        /* 16 */
281                                         int16_t         gyro_x;         /* 18 */
282                                         int16_t         gyro_y;         /* 20 */
283                                         int16_t         gyro_z;         /* 22 */
284                                         int16_t         mag_x;          /* 24 */
285                                         int16_t         mag_z;          /* 26 */
286                                         int16_t         mag_y;          /* 28 */
287                                 };
288                         };
289                         int16_t         accel;          /* 30 */
290                 } sensor;       /* 32 */
291                 /* AO_LOG_TEMP_VOLT */
292                 struct {
293                         int16_t         v_batt;         /* 4 */
294                         int16_t         v_pbatt;        /* 6 */
295                         int16_t         n_sense;        /* 8 */
296                         int16_t         sense[10];      /* 10 */
297                         uint16_t        pyro;           /* 30 */
298                 } volt;                                 /* 32 */
299                 /* AO_LOG_GPS_TIME */
300                 struct {
301                         int32_t         latitude;       /* 4 */
302                         int32_t         longitude;      /* 8 */
303                         uint16_t        altitude_low;   /* 12 */
304                         uint8_t         hour;           /* 14 */
305                         uint8_t         minute;         /* 15 */
306                         uint8_t         second;         /* 16 */
307                         uint8_t         flags;          /* 17 */
308                         uint8_t         year;           /* 18 */
309                         uint8_t         month;          /* 19 */
310                         uint8_t         day;            /* 20 */
311                         uint8_t         course;         /* 21 */
312                         uint16_t        ground_speed;   /* 22 */
313                         int16_t         climb_rate;     /* 24 */
314                         uint8_t         pdop;           /* 26 */
315                         uint8_t         hdop;           /* 27 */
316                         uint8_t         vdop;           /* 28 */
317                         uint8_t         mode;           /* 29 */
318                         int16_t         altitude_high;  /* 30 */
319                 } gps;  /* 32 */
320                 /* AO_LOG_GPS_SAT */
321                 struct {
322                         uint16_t        channels;       /* 4 */
323                         struct {
324                                 uint8_t svid;
325                                 uint8_t c_n;
326                         } sats[12];                     /* 6 */
327                 } gps_sat;                              /* 30 */
328         } u;
329 };
330
331 #define AO_LOG_MEGA_GPS_ALTITUDE(l)     ((int32_t) ((l)->u.gps.altitude_high << 16) | ((l)->u.gps.altitude_low))
332 #define AO_LOG_MEGA_SET_GPS_ALTITUDE(l,a)       (((l)->u.gps.mode |= AO_GPS_MODE_ALTITUDE_24), \
333                                                  ((l)->u.gps.altitude_high = (a) >> 16), \
334                                                  (l)->u.gps.altitude_low = (a))
335
336 struct ao_log_firetwo {
337         char                    type;                   /* 0 */
338         uint8_t                 csum;                   /* 1 */
339         uint16_t                tick;                   /* 2 */
340         union {                                         /* 4 */
341                 /* AO_LOG_FLIGHT */
342                 struct {
343                         uint16_t        flight;         /* 4 */
344                 } flight;       /* 6 */
345                 /* AO_LOG_STATE */
346                 struct {
347                         uint16_t        state;          /* 4 */
348                         uint16_t        reason;         /* 6 */
349                 } state;        /* 8 */
350                 /* AO_LOG_SENSOR */
351                 struct {
352                         uint16_t        pressure;       /* 4 */
353                         uint16_t        thrust;         /* 6 */
354                         uint16_t        thermistor[4];  /* 8 */
355                 } sensor;       /* 24 */
356                 uint8_t         align[28];              /* 4 */
357         } u;    /* 32 */
358 };
359
360 struct ao_log_telestatic {
361         char                    type;                   /* 0 */
362         uint8_t                 csum;                   /* 1 */
363         uint16_t                tick;                   /* 2 */
364         union {                                         /* 4 */
365                 /* AO_LOG_FLIGHT */
366                 struct {
367                         uint16_t        flight;         /* 4 */
368                 } flight;       /* 6 */
369                 /* AO_LOG_STATE */
370                 struct {
371                         uint16_t        state;          /* 4 */
372                         uint16_t        reason;         /* 6 */
373                 } state;        /* 8 */
374                 /* AO_LOG_SENSOR */
375                 struct {
376                         uint32_t        pressure;       /* 4 */
377                         uint32_t        pressure2;      /* 8 */
378                         uint32_t        thrust;         /* 12 */
379                         uint32_t        mass;           /* 16 */
380                         uint16_t        t_low;          /* 20 */
381                         uint16_t        t_high[4];      /* 22 */
382                 } sensor;       /* 30 */
383                 uint8_t         align[28];              /* 4 */
384         } u;    /* 32 */
385 };
386
387 struct ao_log_metrum {
388         char                    type;                   /* 0 */
389         uint8_t                 csum;                   /* 1 */
390         uint16_t                tick;                   /* 2 */
391         union {                                         /* 4 */
392                 /* AO_LOG_FLIGHT */
393                 struct {
394                         uint16_t        flight;         /* 4 */
395                         int16_t         ground_accel;   /* 6 */
396                         int32_t         ground_pres;    /* 8 */
397                         uint32_t        ground_temp;    /* 12 */
398                 } flight;       /* 16 */
399                 /* AO_LOG_STATE */
400                 struct {
401                         uint16_t        state;          /* 4 */
402                         uint16_t        reason;         /* 6 */
403                 } state;        /* 8 */
404                 /* AO_LOG_SENSOR */
405                 struct {
406                         uint32_t        pres;           /* 4 */
407                         uint32_t        temp;           /* 8 */
408                         int16_t         accel;          /* 12 */
409                 } sensor;       /* 14 */
410                 /* AO_LOG_TEMP_VOLT */
411                 struct {
412                         int16_t         v_batt;         /* 4 */
413                         int16_t         sense_a;        /* 6 */
414                         int16_t         sense_m;        /* 8 */
415                 } volt;         /* 10 */
416                 /* AO_LOG_GPS_POS */
417                 struct {
418                         int32_t         latitude;       /* 4 */
419                         int32_t         longitude;      /* 8 */
420                         uint16_t        altitude_low;   /* 12 */
421                         int16_t         altitude_high;  /* 14 */
422                 } gps;          /* 16 */
423                 /* AO_LOG_GPS_TIME */
424                 struct {
425                         uint8_t         hour;           /* 4 */
426                         uint8_t         minute;         /* 5 */
427                         uint8_t         second;         /* 6 */
428                         uint8_t         flags;          /* 7 */
429                         uint8_t         year;           /* 8 */
430                         uint8_t         month;          /* 9 */
431                         uint8_t         day;            /* 10 */
432                         uint8_t         pdop;           /* 11 */
433                 } gps_time;     /* 12 */
434                 /* AO_LOG_GPS_SAT (up to three packets) */
435                 struct {
436                         uint8_t channels;               /* 4 */
437                         uint8_t more;                   /* 5 */
438                         struct {
439                                 uint8_t svid;
440                                 uint8_t c_n;
441                         } sats[4];                      /* 6 */
442                 } gps_sat;                              /* 14 */
443                 uint8_t         raw[12];                /* 4 */
444         } u;    /* 16 */
445 };
446
447 struct ao_log_mini {
448         char            type;                           /* 0 */
449         uint8_t         csum;                           /* 1 */
450         uint16_t        tick;                           /* 2 */
451         union {                                         /* 4 */
452                 /* AO_LOG_FLIGHT */
453                 struct {
454                         uint16_t        flight;         /* 4 */
455                         uint16_t        r6;
456                         int32_t         ground_pres;    /* 8 */
457                 } flight;
458                 /* AO_LOG_STATE */
459                 struct {
460                         uint16_t        state;          /* 4 */
461                         uint16_t        reason;         /* 6 */
462                 } state;
463                 /* AO_LOG_SENSOR */
464                 struct {
465                         uint8_t         pres[3];        /* 4 */
466                         uint8_t         temp[3];        /* 7 */
467                         int16_t         sense_a;        /* 10 */
468                         int16_t         sense_m;        /* 12 */
469                         int16_t         v_batt;         /* 14 */
470                 } sensor;                               /* 16 */
471         } u;                                            /* 16 */
472 };                                                      /* 16 */
473
474 #define ao_log_pack24(dst,value) do {           \
475                 (dst)[0] = (uint8_t) (value);   \
476                 (dst)[1] = (uint8_t) ((value) >> 8);    \
477                 (dst)[2] = (uint8_t) ((value) >> 16);   \
478         } while (0)
479
480 struct ao_log_gps {
481         char                    type;                   /* 0 */
482         uint8_t                 csum;                   /* 1 */
483         uint16_t                tick;                   /* 2 */
484         union {                                         /* 4 */
485                 /* AO_LOG_FLIGHT */
486                 struct {
487                         uint16_t        flight;                 /* 4 */
488                         int16_t         start_altitude;         /* 6 */
489                         int32_t         start_latitude;         /* 8 */
490                         int32_t         start_longitude;        /* 12 */
491                 } flight;                                       /* 16 */
492                 /* AO_LOG_GPS_TIME */
493                 struct {
494                         int32_t         latitude;       /* 4 */
495                         int32_t         longitude;      /* 8 */
496                         uint16_t        altitude_low;   /* 12 */
497                         uint8_t         hour;           /* 14 */
498                         uint8_t         minute;         /* 15 */
499                         uint8_t         second;         /* 16 */
500                         uint8_t         flags;          /* 17 */
501                         uint8_t         year;           /* 18 */
502                         uint8_t         month;          /* 19 */
503                         uint8_t         day;            /* 20 */
504                         uint8_t         course;         /* 21 */
505                         uint16_t        ground_speed;   /* 22 */
506                         int16_t         climb_rate;     /* 24 */
507                         uint8_t         pdop;           /* 26 */
508                         uint8_t         hdop;           /* 27 */
509                         uint8_t         vdop;           /* 28 */
510                         uint8_t         mode;           /* 29 */
511                         int16_t         altitude_high;  /* 30 */
512                 } gps;  /* 31 */
513                 /* AO_LOG_GPS_SAT */
514                 struct {
515                         uint16_t        channels;       /* 4 */
516                         struct {
517                                 uint8_t svid;
518                                 uint8_t c_n;
519                         } sats[12];                     /* 6 */
520                 } gps_sat;                              /* 30 */
521         } u;
522 };
523
524 struct ao_log_motor {
525         char                    type;                   /* 0 */
526         uint8_t                 csum;                   /* 1 */
527         uint16_t                tick;                   /* 2 */
528         union {                                         /* 4 */
529                 /* AO_LOG_FLIGHT */
530                 struct {
531                         uint16_t        flight;                 /* 4 */
532                         int16_t         ground_accel;           /* 6 */
533                         int16_t         ground_accel_along;     /* 8 */
534                         int16_t         ground_accel_across;    /* 10 */
535                         int16_t         ground_accel_through;   /* 12 */
536                         int16_t         ground_motor_pressure;  /* 14 */
537                 } flight;                                       /* 16 */
538                 /* AO_LOG_STATE */
539                 struct {
540                         uint16_t        state;                  /* 4 */
541                         uint16_t        reason;                 /* 6 */
542                 } state;
543                 /* AO_LOG_SENSOR */
544                 struct {
545                         uint16_t        pressure;               /* 4 */
546                         uint16_t        v_batt;                 /* 6 */
547                         int16_t         accel;                  /* 8 */
548                         int16_t         accel_across;           /* 10 */
549                         int16_t         accel_along;            /* 12 */
550                         int16_t         accel_through;          /* 14 */
551                 } sensor;                                       /* 16 */
552         } u;
553 };
554
555 struct ao_log_timer {
556         char                    type;                   /* 0 */
557         uint8_t                 csum;                   /* 1 */
558         uint16_t                tick;                   /* 2 */
559         union {                                         /* 4 */
560                 /* AO_LOG_FLIGHT */
561                 struct {
562                         uint16_t        flight;                 /* 4 */
563                         int16_t         ground_accel;           /* 6 */
564                         int16_t         ground_accel_along;     /* 8 */
565                         int16_t         ground_accel_across;    /* 10 */
566                         int16_t         ground_accel_through;   /* 12 */
567                         int16_t         pad_14;                 /* 14 */
568                         int32_t         ground_roll;            /* 16 */
569                         int32_t         ground_pitch;           /* 20 */
570                         int32_t         ground_yaw;             /* 24 */
571                 } flight;                                       /* 32 */
572                 /* AO_LOG_STATE */
573                 struct {
574                         uint16_t        state;                  /* 4 */
575                         uint16_t        reason;                 /* 6 */
576                 } state;
577                 /* AO_LOG_SENSOR */
578                 struct {
579                         int16_t         accel_along;    /* 4 */
580                         int16_t         accel_across;   /* 6 */
581                         int16_t         accel_through;  /* 8 */
582                         int16_t         gyro_roll;      /* 10 */
583                         int16_t         gyro_pitch;     /* 12 */
584                         int16_t         gyro_yaw;       /* 14 */
585                         int16_t         mag_along;      /* 16 */
586                         int16_t         mag_across;     /* 18 */
587                         int16_t         mag_through;    /* 20 */
588                         int16_t         v_batt;         /* 22 */
589                         int16_t         v_pbatt;        /* 24 */
590                         int16_t         sense[2];       /* 26 */
591                         uint16_t        pyro;           /* 30 */
592                 } sensor;       /* 32 */
593         } u;
594 };
595
596 #if AO_LOG_FORMAT == AO_LOG_FOMAT_TELEMEGA_OLD || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA_3 || AO_LOG_FORMAT == AO_LOG_FORMAT_EASYMEGA_2 || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA_4 || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA_5 || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA_6 || AO_LOG_FORMAT == AO_LOG_FORMAT_EASYMEGA_3
597 typedef struct ao_log_mega ao_log_type;
598 #endif
599
600 #if AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMETRUM
601 typedef struct ao_log_metrum ao_log_type;
602 #endif
603
604 #if AO_LOG_FORMAT == AO_LOG_FORMAT_TELEFIRETWO
605 typedef struct ao_log_firetwo ao_log_type;
606 #endif
607
608 #if AO_LOG_FORMAT == AO_LOG_FORMAT_EASYMINI1 || AO_LOG_FORMAT == AO_LOG_FORMAT_EASYMINI2 || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMINI2 || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMINI3
609 typedef struct ao_log_mini ao_log_type;
610 #endif
611
612 #if AO_LOG_FORMAT == AO_LOG_FORMAT_EASYMOTOR
613 typedef struct ao_log_motor ao_log_type;
614 #endif 
615
616 #if AO_LOG_FORMAT == AO_LOG_FORMAT_TELEGPS
617 typedef struct ao_log_gps ao_log_type;
618 #endif
619
620 #if AO_LOG_FORMAT == AO_LOG_FORMAT_FULL
621 typedef struct ao_log_record ao_log_type;
622 #endif
623
624 #if AO_LOG_FORMAT == AO_LOG_FORMAT_TINY
625 #define AO_LOG_UNCOMMON 1
626 #endif
627
628 #if AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMETRY
629 #define AO_LOG_UNCOMMON 1
630 #endif
631
632 #if AO_LOG_FORMAT == AO_LOG_FORMAT_TELESCIENCE
633 #define AO_LOG_UNCOMMON 1
634 #endif
635
636 #if AO_LOG_FORMAT == AO_LOG_FORMAT_MICROPEAK2
637 #define AO_LOG_UNCOMMON 1
638 #endif
639
640 #if AO_LOG_FORMAT == AO_LOG_FORMAT_EASYTIMER_2
641 typedef struct ao_log_timer ao_log_type;
642 #endif
643
644 #ifndef AO_LOG_UNCOMMON
645 extern ao_log_type ao_log_data;
646
647 #define AO_LOG_SIZE sizeof(ao_log_type)
648
649 /* Write a record to the eeprom log */
650
651 uint8_t
652 ao_log_write(ao_log_type *log);
653 #endif
654
655 void
656 ao_log_flush(void);
657
658 void
659 ao_gps_report_metrum_init(void);
660
661 #endif /* _AO_LOG_H_ */