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_NONE 127 /* No log at all */
49 extern __code uint8_t ao_log_format;
51 /* Return the flight number from the given log slot, 0 if none */
53 ao_log_flight(uint8_t slot);
59 /* Logging thread main routine */
63 /* functions provided in ao_log.c */
65 /* Figure out the current flight number */
67 ao_log_scan(void) __reentrant;
69 /* Return the position of the start of the given log slot */
71 ao_log_pos(uint8_t slot);
73 /* Start logging to eeprom */
81 /* Initialize the logging system */
85 /* Write out the current flight number to the erase log */
87 ao_log_write_erase(uint8_t pos);
89 /* Returns true if there are any logs stored in eeprom */
93 /* Returns true if there is no more storage space available */
102 * The data log is recorded in the eeprom as a sequence
105 * Each packet starts with a 4-byte header that has the
106 * packet type, the packet checksum and the tick count. Then
107 * they all contain 2 16 bit values which hold packet-specific
110 * For each flight, the first packet
111 * is FLIGHT packet, indicating the serial number of the
112 * device and a unique number marking the number of flights
113 * recorded by this device.
115 * During flight, data from the accelerometer and barometer
116 * are recorded in SENSOR packets, using the raw 16-bit values
117 * read from the A/D converter.
119 * Also during flight, but at a lower rate, the deployment
120 * sensors are recorded in DEPLOY packets. The goal here is to
121 * detect failure in the deployment circuits.
123 * STATE packets hold state transitions as the flight computer
124 * transitions through different stages of the flight.
126 #define AO_LOG_FLIGHT 'F'
127 #define AO_LOG_SENSOR 'A'
128 #define AO_LOG_TEMP_VOLT 'T'
129 #define AO_LOG_DEPLOY 'D'
130 #define AO_LOG_STATE 'S'
131 #define AO_LOG_GPS_TIME 'G'
132 #define AO_LOG_GPS_LAT 'N'
133 #define AO_LOG_GPS_LON 'W'
134 #define AO_LOG_GPS_ALT 'H'
135 #define AO_LOG_GPS_SAT 'V'
136 #define AO_LOG_GPS_DATE 'Y'
138 #define AO_LOG_POS_NONE (~0UL)
140 struct ao_log_record {
142 uint8_t csum; /* 1 */
143 uint16_t tick; /* 2 */
146 int16_t ground_accel; /* 4 */
147 uint16_t flight; /* 6 */
150 int16_t accel; /* 4 */
151 int16_t pres; /* 6 */
171 int32_t gps_latitude;
172 int32_t gps_longitude;
197 uint8_t csum; /* 1 */
198 uint16_t tick; /* 2 */
202 uint16_t flight; /* 4 */
203 int16_t ground_accel; /* 6 */
204 uint32_t ground_pres; /* 8 */
205 int16_t ground_accel_along; /* 16 */
206 int16_t ground_accel_across; /* 12 */
207 int16_t ground_accel_through; /* 14 */
208 int16_t ground_roll; /* 18 */
209 int16_t ground_pitch; /* 20 */
210 int16_t ground_yaw; /* 22 */
219 uint32_t pres; /* 4 */
220 uint32_t temp; /* 8 */
221 int16_t accel_x; /* 12 */
222 int16_t accel_y; /* 14 */
223 int16_t accel_z; /* 16 */
224 int16_t gyro_x; /* 18 */
225 int16_t gyro_y; /* 20 */
226 int16_t gyro_z; /* 22 */
227 int16_t mag_x; /* 24 */
228 int16_t mag_y; /* 26 */
229 int16_t mag_z; /* 28 */
230 int16_t accel; /* 30 */
232 /* AO_LOG_TEMP_VOLT */
234 int16_t v_batt; /* 4 */
235 int16_t v_pbatt; /* 6 */
236 int16_t n_sense; /* 8 */
237 int16_t sense[10]; /* 10 */
239 /* AO_LOG_GPS_TIME */
241 int32_t latitude; /* 4 */
242 int32_t longitude; /* 8 */
243 int16_t altitude; /* 12 */
244 uint8_t hour; /* 14 */
245 uint8_t minute; /* 15 */
246 uint8_t second; /* 16 */
247 uint8_t flags; /* 17 */
248 uint8_t year; /* 18 */
249 uint8_t month; /* 19 */
250 uint8_t day; /* 20 */
251 uint8_t pad; /* 21 */
255 uint16_t channels; /* 4 */
264 /* Write a record to the eeprom log */
266 ao_log_data(__xdata struct ao_log_record *log) __reentrant;
269 ao_log_mega(__xdata struct ao_log_mega *log) __reentrant;
274 #endif /* _AO_LOG_H_ */