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