altos: Perform cc1200 calibration less often. Tweak radio params
[fw/altos] / src / kernel / ao_telemetry.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; version 2 of the License.
7  *
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.
12  *
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.
16  */
17
18 #ifndef _AO_TELEMETRY_H_
19 #define _AO_TELEMETRY_H_
20
21 /*
22  * ao_telemetry.c
23  */
24 #define AO_MAX_CALLSIGN                 8
25 #define AO_MAX_VERSION                  8
26 #if LEGACY_MONITOR
27 #define AO_MAX_TELEMETRY                128
28 #else
29 #define AO_MAX_TELEMETRY                32
30 #endif
31
32 struct ao_telemetry_generic {
33         uint16_t        serial;         /* 0 */
34         uint16_t        tick;           /* 2 */
35         uint8_t         type;           /* 4 */
36         uint8_t         payload[27];    /* 5 */
37         /* 32 */
38 };
39
40 #define AO_TELEMETRY_SENSOR_TELEMETRUM  0x01
41 #define AO_TELEMETRY_SENSOR_TELEMINI    0x02
42 #define AO_TELEMETRY_SENSOR_TELENANO    0x03
43
44 struct ao_telemetry_sensor {
45         uint16_t        serial;         /*  0 */
46         uint16_t        tick;           /*  2 */
47         uint8_t         type;           /*  4 */
48
49         uint8_t         state;          /*  5 flight state */
50         int16_t         accel;          /*  6 accelerometer (TM only) */
51         int16_t         pres;           /*  8 pressure sensor */
52         int16_t         temp;           /* 10 temperature sensor */
53         int16_t         v_batt;         /* 12 battery voltage */
54         int16_t         sense_d;        /* 14 drogue continuity sense (TM/Tm) */
55         int16_t         sense_m;        /* 16 main continuity sense (TM/Tm) */
56
57         int16_t         acceleration;   /* 18 m/s² * 16 */
58         int16_t         speed;          /* 20 m/s * 16 */
59         int16_t         height;         /* 22 m */
60
61         int16_t         ground_pres;    /* 24 average pres on pad */
62         int16_t         ground_accel;   /* 26 average accel on pad */
63         int16_t         accel_plus_g;   /* 28 accel calibration at +1g */
64         int16_t         accel_minus_g;  /* 30 accel calibration at -1g */
65         /* 32 */
66 };
67
68 #define AO_TELEMETRY_CONFIGURATION      0x04
69
70 struct ao_telemetry_configuration {
71         uint16_t        serial;                         /*  0 */
72         uint16_t        tick;                           /*  2 */
73         uint8_t         type;                           /*  4 */
74
75         uint8_t         device;                         /*  5 device type */
76         uint16_t        flight;                         /*  6 flight number */
77         uint8_t         config_major;                   /*  8 Config major version */
78         uint8_t         config_minor;                   /*  9 Config minor version */
79         uint16_t        apogee_delay;                   /* 10 Apogee deploy delay in seconds */
80         uint16_t        main_deploy;                    /* 12 Main deploy alt in meters */
81         uint16_t        flight_log_max;                 /* 14 Maximum flight log size in kB */
82         char            callsign[AO_MAX_CALLSIGN];      /* 16 Radio operator identity */
83         char            version[AO_MAX_VERSION];        /* 24 Software version */
84         /* 32 */
85 };
86
87 #define AO_TELEMETRY_LOCATION           0x05
88
89 /* Mode bits */
90
91 #define AO_GPS_MODE_ALTITUDE_24         (1 << 0)        /* reports 24-bits of altitude */
92
93 struct ao_telemetry_location {
94         uint16_t        serial;         /*  0 */
95         uint16_t        tick;           /*  2 */
96         uint8_t         type;           /*  4 */
97
98         uint8_t         flags;          /*  5 Number of sats and other flags */
99         uint16_t        altitude_low;   /*  6 GPS reported altitude (m) */
100         int32_t         latitude;       /*  8 latitude (degrees * 10⁷) */
101         int32_t         longitude;      /* 12 longitude (degrees * 10⁷) */
102         uint8_t         year;           /* 16 (- 2000) */
103         uint8_t         month;          /* 17 (1-12) */
104         uint8_t         day;            /* 18 (1-31) */
105         uint8_t         hour;           /* 19 (0-23) */
106         uint8_t         minute;         /* 20 (0-59) */
107         uint8_t         second;         /* 21 (0-59) */
108         uint8_t         pdop;           /* 22 (m * 5) */
109         uint8_t         hdop;           /* 23 (m * 5) */
110         uint8_t         vdop;           /* 24 (m * 5) */
111         uint8_t         mode;           /* 25 */
112         uint16_t        ground_speed;   /* 26 cm/s */
113         int16_t         climb_rate;     /* 28 cm/s */
114         uint8_t         course;         /* 30 degrees / 2 */
115         int8_t          altitude_high;  /* 31 high byte of altitude */
116         /* 32 */
117 };
118
119 #ifndef HAS_WIDE_GPS
120 #define HAS_WIDE_GPS    1
121 #endif
122
123 #if HAS_WIDE_GPS
124 typedef int32_t         gps_alt_t;
125 #define AO_TELEMETRY_LOCATION_ALTITUDE(l)       (((gps_alt_t) (l)->altitude_high << 16) | ((l)->altitude_low))
126 #define AO_TELEMETRY_LOCATION_SET_ALTITUDE(l,a) (((l)->mode |= AO_GPS_MODE_ALTITUDE_24), \
127                                                  ((l)->altitude_high = (a) >> 16), \
128                                                  ((l)->altitude_low = (a)))
129 #else
130 typedef int16_t         gps_alt_t;
131 #define AO_TELEMETRY_LOCATION_ALTITUDE(l)       ((gps_alt_t) (l)->altitude_low)
132 #define AO_TELEMETRY_LOCATION_SET_ALTITUDE(l,a) (((l)->mode = 0, \
133                                                   (l)->altitude_low = (a)))
134 #endif /* HAS_WIDE_GPS */
135
136 #define AO_TELEMETRY_SATELLITE          0x06
137
138 struct ao_telemetry_satellite_info {
139         uint8_t         svid;
140         uint8_t         c_n_1;
141 };
142
143 #define AO_TELEMETRY_SATELLITE_MAX_SAT  12
144
145 struct ao_telemetry_satellite {
146         uint16_t                                serial;         /*  0 */
147         uint16_t                                tick;           /*  2 */
148         uint8_t                                 type;           /*  4 */
149         uint8_t                                 channels;       /*  5 number of reported sats */
150
151         struct ao_telemetry_satellite_info      sats[AO_TELEMETRY_SATELLITE_MAX_SAT];   /* 6 */
152         uint8_t                                 unused[2];      /* 30 */
153         /* 32 */
154 };
155
156 #define AO_TELEMETRY_COMPANION          0x07
157
158 #define AO_COMPANION_MAX_CHANNELS       12
159
160 struct ao_telemetry_companion {
161         uint16_t                                serial;         /*  0 */
162         uint16_t                                tick;           /*  2 */
163         uint8_t                                 type;           /*  4 */
164         uint8_t                                 board_id;       /*  5 */
165
166         uint8_t                                 update_period;  /*  6 */
167         uint8_t                                 channels;       /*  7 */
168         uint16_t                                companion_data[AO_COMPANION_MAX_CHANNELS];      /*  8 */
169         /* 32 */
170 };
171
172 #define AO_TELEMETRY_MEGA_SENSOR        0x08
173
174 struct ao_telemetry_mega_sensor {
175         uint16_t        serial;         /*  0 */
176         uint16_t        tick;           /*  2 */
177         uint8_t         type;           /*  4 */
178
179         uint8_t         orient;         /*  5 angle from vertical */
180         int16_t         accel;          /*  6 Z axis */
181
182         int32_t         pres;           /*  8 Pa * 10 */
183         int16_t         temp;           /* 12 °C * 100 */
184
185         int16_t         accel_x;        /* 14 */
186         int16_t         accel_y;        /* 16 */
187         int16_t         accel_z;        /* 18 */
188
189         int16_t         gyro_x;         /* 20 */
190         int16_t         gyro_y;         /* 22 */
191         int16_t         gyro_z;         /* 24 */
192
193         int16_t         mag_x;          /* 26 */
194         int16_t         mag_y;          /* 28 */
195         int16_t         mag_z;          /* 30 */
196         /* 32 */
197 };
198
199 #define AO_TELEMETRY_MEGA_DATA          0x09
200
201 struct ao_telemetry_mega_data {
202         uint16_t        serial;         /*  0 */
203         uint16_t        tick;           /*  2 */
204         uint8_t         type;           /*  4 */
205
206         uint8_t         state;          /*  5 flight state */
207
208         int16_t         v_batt;         /*  6 battery voltage */
209         int16_t         v_pyro;         /*  8 pyro battery voltage */
210         int8_t          sense[6];       /* 10 continuity sense */
211
212         int32_t         ground_pres;    /* 16 average pres on pad */
213         int16_t         ground_accel;   /* 20 average accel on pad */
214         int16_t         accel_plus_g;   /* 22 accel calibration at +1g */
215         int16_t         accel_minus_g;  /* 24 accel calibration at -1g */
216
217         int16_t         acceleration;   /* 26 m/s² * 16 */
218         int16_t         speed;          /* 28 m/s * 16 */
219         int16_t         height;         /* 30 m */
220         /* 32 */
221 };
222
223
224 #define AO_TELEMETRY_METRUM_SENSOR      0x0A
225
226 struct ao_telemetry_metrum_sensor {
227         uint16_t        serial;         /*  0 */
228         uint16_t        tick;           /*  2 */
229         uint8_t         type;           /*  4 */
230
231         uint8_t         state;          /*  5 flight state */
232         int16_t         accel;          /*  6 Z axis */
233
234         int32_t         pres;           /*  8 Pa * 10 */
235         int16_t         temp;           /* 12 °C * 100 */
236
237         int16_t         acceleration;   /* 14 m/s² * 16 */
238         int16_t         speed;          /* 16 m/s * 16 */
239         int16_t         height;         /* 18 m */
240
241         int16_t         v_batt;         /* 20 battery voltage */
242         int16_t         sense_a;        /* 22 apogee continuity sense */
243         int16_t         sense_m;        /* 24 main continuity sense */
244
245         uint8_t         pad[6];         /* 26 */
246         /* 32 */
247 };
248
249 #define AO_TELEMETRY_METRUM_DATA        0x0B
250
251 struct ao_telemetry_metrum_data {
252         uint16_t        serial;         /*  0 */
253         uint16_t        tick;           /*  2 */
254         uint8_t         type;           /*  4 */
255
256         int32_t         ground_pres;    /* 8 average pres on pad */
257         int16_t         ground_accel;   /* 12 average accel on pad */
258         int16_t         accel_plus_g;   /* 14 accel calibration at +1g */
259         int16_t         accel_minus_g;  /* 16 accel calibration at -1g */
260
261         uint8_t         pad[14];        /* 18 */
262         /* 32 */
263 };
264
265 #define AO_TELEMETRY_MINI               0x10
266
267 struct ao_telemetry_mini {
268         uint16_t        serial;         /*  0 */
269         uint16_t        tick;           /*  2 */
270         uint8_t         type;           /*  4 */
271
272         uint8_t         state;          /*  5 flight state */
273         int16_t         v_batt;         /*  6 battery voltage */
274         int16_t         sense_a;        /*  8 apogee continuity */
275         int16_t         sense_m;        /* 10 main continuity */
276
277         int32_t         pres;           /* 12 Pa * 10 */
278         int16_t         temp;           /* 16 °C * 100 */
279
280         int16_t         acceleration;   /* 18 m/s² * 16 */
281         int16_t         speed;          /* 20 m/s * 16 */
282         int16_t         height;         /* 22 m */
283
284         int32_t         ground_pres;    /* 24 average pres on pad */
285
286         int32_t         pad28;          /* 28 */
287         /* 32 */
288 };
289
290 /* #define AO_SEND_ALL_BARO */
291
292 #define AO_TELEMETRY_BARO               0x80
293
294 /*
295  * This packet allows the full sampling rate baro
296  * data to be captured over the RF link so that the
297  * flight software can be tested using 'real' data.
298  *
299  * Along with this telemetry packet, the flight
300  * code is modified to send full-rate telemetry all the time
301  * and never send an RDF tone; this ensure that the full radio
302  * link is available.
303  */
304 struct ao_telemetry_baro {
305         uint16_t                                serial;         /*  0 */
306         uint16_t                                tick;           /*  2 */
307         uint8_t                                 type;           /*  4 */
308         uint8_t                                 samples;        /*  5 number samples */
309
310         int16_t                                 baro[12];       /* 6 samples */
311         /* 32 */
312 };
313
314 union ao_telemetry_all {
315         struct ao_telemetry_generic             generic;
316         struct ao_telemetry_sensor              sensor;
317         struct ao_telemetry_configuration       configuration;
318         struct ao_telemetry_location            location;
319         struct ao_telemetry_satellite           satellite;
320         struct ao_telemetry_companion           companion;
321         struct ao_telemetry_mega_sensor         mega_sensor;
322         struct ao_telemetry_mega_data           mega_data;
323         struct ao_telemetry_metrum_sensor       metrum_sensor;
324         struct ao_telemetry_metrum_data         metrum_data;
325         struct ao_telemetry_mini                mini;
326         struct ao_telemetry_baro                baro;
327 };
328
329 struct ao_telemetry_all_recv {
330         union ao_telemetry_all          telemetry;
331         int8_t                          rssi;
332         uint8_t                         status;
333 };
334
335 #endif /* _AO_TELEMETRY_H_ */