ao-telem: Add new program to convert telem data to ascii
[fw/altos] / ao-tools / lib / cc-telemetry.h
1 /*
2  * Copyright © 2011 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 _CC_TELEMETRY_H_
19 #define _CC_TELEMETRY_H_
20 /*
21  * ao_telemetry.c
22  */
23 #define AO_MAX_CALLSIGN                 8
24 #define AO_MAX_VERSION                  8
25 #define AO_MAX_TELEMETRY                128
26
27 struct ao_telemetry_generic {
28         uint16_t        serial;         /* 0 */
29         uint16_t        tick;           /* 2 */
30         uint8_t         type;           /* 4 */
31         uint8_t         payload[27];    /* 5 */
32         /* 32 */
33 };
34
35 #define AO_TELEMETRY_SENSOR_TELEMETRUM  0x01
36 #define AO_TELEMETRY_SENSOR_TELEMINI    0x02
37 #define AO_TELEMETRY_SENSOR_TELENANO    0x03
38
39 struct ao_telemetry_sensor {
40         uint16_t        serial;         /*  0 */
41         uint16_t        tick;           /*  2 */
42         uint8_t         type;           /*  4 */
43
44         uint8_t         state;          /*  5 flight state */
45         int16_t         accel;          /*  6 accelerometer (TM only) */
46         int16_t         pres;           /*  8 pressure sensor */
47         int16_t         temp;           /* 10 temperature sensor */
48         int16_t         v_batt;         /* 12 battery voltage */
49         int16_t         sense_d;        /* 14 drogue continuity sense (TM/Tm) */
50         int16_t         sense_m;        /* 16 main continuity sense (TM/Tm) */
51
52         int16_t         acceleration;   /* 18 m/s² * 16 */
53         int16_t         speed;          /* 20 m/s * 16 */
54         int16_t         height;         /* 22 m */
55
56         int16_t         ground_pres;    /* 24 average pres on pad */
57         int16_t         ground_accel;   /* 26 average accel on pad */
58         int16_t         accel_plus_g;   /* 28 accel calibration at +1g */
59         int16_t         accel_minus_g;  /* 30 accel calibration at -1g */
60         /* 32 */
61 };
62
63 #define AO_TELEMETRY_CONFIGURATION      0x04
64
65 struct ao_telemetry_configuration {
66         uint16_t        serial;                         /*  0 */
67         uint16_t        tick;                           /*  2 */
68         uint8_t         type;                           /*  4 */
69
70         uint8_t         device;                         /*  5 device type */
71         uint16_t        flight;                         /*  6 flight number */
72         uint8_t         config_major;                   /*  8 Config major version */
73         uint8_t         config_minor;                   /*  9 Config minor version */
74         uint16_t        apogee_delay;                   /* 10 Apogee deploy delay in seconds */
75         uint16_t        main_deploy;                    /* 12 Main deploy alt in meters */
76         uint16_t        flight_log_max;                 /* 14 Maximum flight log size in kB */
77         char            callsign[AO_MAX_CALLSIGN];      /* 16 Radio operator identity */
78         char            version[AO_MAX_VERSION];        /* 24 Software version */
79         /* 32 */
80 };
81
82 #define AO_TELEMETRY_LOCATION           0x05
83
84 #define AO_GPS_MODE_NOT_VALID           'N'
85 #define AO_GPS_MODE_AUTONOMOUS          'A'
86 #define AO_GPS_MODE_DIFFERENTIAL        'D'
87 #define AO_GPS_MODE_ESTIMATED           'E'
88 #define AO_GPS_MODE_MANUAL              'M'
89 #define AO_GPS_MODE_SIMULATED           'S'
90
91 struct ao_telemetry_location {
92         uint16_t        serial;         /*  0 */
93         uint16_t        tick;           /*  2 */
94         uint8_t         type;           /*  4 */
95
96         uint8_t         flags;          /*  5 Number of sats and other flags */
97         int16_t         altitude;       /*  6 GPS reported altitude (m) */
98         int32_t         latitude;       /*  8 latitude (degrees * 10⁷) */
99         int32_t         longitude;      /* 12 longitude (degrees * 10⁷) */
100         uint8_t         year;           /* 16 (- 2000) */
101         uint8_t         month;          /* 17 (1-12) */
102         uint8_t         day;            /* 18 (1-31) */
103         uint8_t         hour;           /* 19 (0-23) */
104         uint8_t         minute;         /* 20 (0-59) */
105         uint8_t         second;         /* 21 (0-59) */
106         uint8_t         pdop;           /* 22 (m * 5) */
107         uint8_t         hdop;           /* 23 (m * 5) */
108         uint8_t         vdop;           /* 24 (m * 5) */
109         uint8_t         mode;           /* 25 */
110         uint16_t        ground_speed;   /* 26 cm/s */
111         int16_t         climb_rate;     /* 28 cm/s */
112         uint8_t         course;         /* 30 degrees / 2 */
113         uint8_t         unused[1];      /* 31 */
114         /* 32 */
115 };
116
117 #define AO_TELEMETRY_SATELLITE          0x06
118
119 struct ao_telemetry_satellite_info {
120         uint8_t         svid;
121         uint8_t         c_n_1;
122 };
123
124 struct ao_telemetry_satellite {
125         uint16_t                                serial;         /*  0 */
126         uint16_t                                tick;           /*  2 */
127         uint8_t                                 type;           /*  4 */
128         uint8_t                                 channels;       /*  5 number of reported sats */
129
130         struct ao_telemetry_satellite_info      sats[12];       /* 6 */
131         uint8_t                                 unused[2];      /* 30 */
132         /* 32 */
133 };
134
135 #define AO_TELEMETRY_COMPANION          0x07
136
137 #define AO_COMPANION_MAX_CHANNELS       12
138
139 struct ao_telemetry_companion {
140         uint16_t                                serial;         /*  0 */
141         uint16_t                                tick;           /*  2 */
142         uint8_t                                 type;           /*  4 */
143         uint8_t                                 board_id;       /*  5 */
144
145         uint8_t                                 update_period;  /*  6 */
146         uint8_t                                 channels;       /*  7 */
147         uint16_t                                companion_data[AO_COMPANION_MAX_CHANNELS];      /*  8 */
148         /* 32 */
149 };
150         
151 /* #define AO_SEND_ALL_BARO */
152
153 #define AO_TELEMETRY_BARO               0x80
154
155 /*
156  * This packet allows the full sampling rate baro
157  * data to be captured over the RF link so that the
158  * flight software can be tested using 'real' data.
159  *
160  * Along with this telemetry packet, the flight
161  * code is modified to send full-rate telemetry all the time
162  * and never send an RDF tone; this ensure that the full radio
163  * link is available.
164  */
165 struct ao_telemetry_baro {
166         uint16_t                                serial;         /*  0 */
167         uint16_t                                tick;           /*  2 */
168         uint8_t                                 type;           /*  4 */
169         uint8_t                                 samples;        /*  5 number samples */
170
171         int16_t                                 baro[12];       /* 6 samples */
172         /* 32 */
173 };
174
175 union ao_telemetry_all {
176         struct ao_telemetry_generic             generic;
177         struct ao_telemetry_sensor              sensor;
178         struct ao_telemetry_configuration       configuration;
179         struct ao_telemetry_location            location;
180         struct ao_telemetry_satellite           satellite;
181         struct ao_telemetry_companion           companion;
182         struct ao_telemetry_baro                baro;
183 };
184
185 int
186 cc_telemetry_parse(const char *input_line, union ao_telemetry_all *telemetry);
187
188 #endif