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