Pass accel calibration over telemetry stream. Telemetry data format change.
[fw/altos] / ao-tools / ao-view / aoview.h
1 /*
2  * Copyright © 2009 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 _AOVIEW_H_
19 #define _AOVIEW_H_
20
21 #define _GNU_SOURCE
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <fcntl.h>
32 #include <err.h>
33 #include <errno.h>
34 #include <getopt.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <assert.h>
38 #include <math.h>
39
40 #include "cc.h"
41
42 #include <gtk/gtk.h>
43 #include <glade/glade.h>
44 #include <gconf/gconf-client.h>
45
46 struct aogps_time {
47         int hour;
48         int minute;
49         int second;
50 };
51
52 struct aogps {
53         int     nsat;
54         int     gps_locked;
55         int     gps_connected;
56         struct aogps_time gps_time;
57         double  lat;            /* degrees (+N -S) */
58         double  lon;            /* degrees (+E -W) */
59         int     alt;            /* m */
60
61         int     gps_extended;   /* has extra data */
62         double  ground_speed;   /* m/s */
63         int     course;         /* degrees */
64         double  climb_rate;     /* m/s */
65         double  hdop;           /* unitless? */
66         int     h_error;        /* m */
67         int     v_error;        /* m */
68 };
69
70 #define SIRF_SAT_STATE_ACQUIRED                 (1 << 0)
71 #define SIRF_SAT_STATE_CARRIER_PHASE_VALID      (1 << 1)
72 #define SIRF_SAT_BIT_SYNC_COMPLETE              (1 << 2)
73 #define SIRF_SAT_SUBFRAME_SYNC_COMPLETE         (1 << 3)
74 #define SIRF_SAT_CARRIER_PULLIN_COMPLETE        (1 << 4)
75 #define SIRF_SAT_CODE_LOCKED                    (1 << 5)
76 #define SIRF_SAT_ACQUISITION_FAILED             (1 << 6)
77 #define SIRF_SAT_EPHEMERIS_AVAILABLE            (1 << 7)
78
79 struct aogps_sat {
80         int     svid;
81         int     state;
82         int     c_n0;
83 };
84
85 struct aogps_tracking {
86         int                     channels;
87         struct aogps_sat        sats[12];
88 };
89
90 struct aodata {
91         char    callsign[16];
92         int     serial;
93         int     rssi;
94         char    state[16];
95         int     tick;
96         int     accel;
97         int     pres;
98         int     temp;
99         int     batt;
100         int     drogue;
101         int     main;
102         int     flight_accel;
103         int     ground_accel;
104         int     flight_vel;
105         int     flight_pres;
106         int     ground_pres;
107         int     accel_plus_g;
108         int     accel_minus_g;
109         struct aogps    gps;
110         struct aogps_tracking   gps_tracking;
111 };
112
113 struct aostate {
114         struct aodata   data;
115
116         /* derived data */
117
118         struct aodata   prev_data;
119
120         double          report_time;
121
122         gboolean        ascent; /* going up? */
123
124         int     ground_altitude;
125         int     height;
126         double  speed;
127         double  acceleration;
128         double  battery;
129         double  temperature;
130         double  main_sense;
131         double  drogue_sense;
132         double  baro_speed;
133
134         int     max_height;
135         double  max_acceleration;
136         double  max_speed;
137
138         struct aogps    gps;
139         struct aogps_tracking   gps_tracking;
140
141         int     gps_valid;
142         double  pad_lat;
143         double  pad_lon;
144         double  pad_alt;
145         double  pad_lat_total;
146         double  pad_lon_total;
147         double  pad_alt_total;
148         int     npad;
149         int     prev_npad;
150
151         double  distance;
152         double  bearing;
153         int     gps_height;
154
155         int     speak_tick;
156         int     speak_altitude;
157 };
158
159 extern struct aostate aostate;
160
161 /* GPS is 'stable' when we've seen at least this many samples */
162 #define MIN_PAD_SAMPLES 10
163
164 void
165 aoview_monitor_disconnect(void);
166
167 gboolean
168 aoview_monitor_connect(char *tty);
169
170 gboolean
171 aoview_monitor_parse(const char *line);
172
173 void
174 aoview_monitor_set_channel(int channel);
175
176 void
177 aoview_monitor_reset(void);
178
179 struct aoview_serial *
180 aoview_serial_open(const char *tty);
181
182 void
183 aoview_serial_close(struct aoview_serial *serial);
184
185 typedef void (*aoview_serial_callback)(gpointer user_data, struct aoview_serial *serial, gint revents);
186
187 void
188 aoview_serial_set_callback(struct aoview_serial *serial,
189                            aoview_serial_callback func);
190
191 void
192 aoview_serial_printf(struct aoview_serial *serial, char *format, ...);
193
194 int
195 aoview_serial_read(struct aoview_serial *serial, char *buf, int len);
196
197 int
198 aoview_serial_getc(struct aoview_serial *serial);
199
200 void
201 aoview_dev_dialog_init(GladeXML *xml);
202
203 void
204 aoview_state_notify(struct aodata *data);
205
206 void
207 aoview_state_new(void);
208
209 void
210 aoview_state_init(GladeXML *xml);
211
212 int16_t
213 aoview_pres_to_altitude(int16_t pres);
214
215 int16_t
216 aoview_altitude_to_pres(int16_t alt);
217
218 char *
219 aoview_fullname (char *dir, char *file);
220
221 char *
222 aoview_basename(char *file);
223
224 GtkTreeViewColumn *
225 aoview_add_plain_text_column (GtkTreeView *view, const gchar *title, gint model_column, gint width);
226
227 int
228 aoview_mkdir(char *dir);
229
230 void
231 aoview_log_init(GladeXML *xml);
232
233 void
234 aoview_log_set_serial(int serial);
235
236 int
237 aoview_log_get_serial(void);
238
239 void
240 aoview_log_printf(char *format, ...);
241
242 void
243 aoview_log_new(void);
244
245 void
246 aoview_table_start(void);
247
248 void
249 aoview_table_add_row(int column, char *label, char *format, ...);
250
251 void
252 aoview_table_finish(void);
253
254 void
255 aoview_table_init(GladeXML *xml);
256
257 void
258 aoview_table_clear(void);
259
260 struct aoview_file;
261
262 extern char *aoview_file_dir;
263
264 void
265 aoview_file_finish(struct aoview_file *file);
266
267 gboolean
268 aoview_file_start(struct aoview_file *file);
269
270 const char *
271 aoview_file_name(struct aoview_file *file);
272
273 void
274 aoview_file_set_serial(struct aoview_file *file, int serial);
275
276 int
277 aoview_file_get_serial(struct aoview_file *file);
278
279 void
280 aoview_file_printf(struct aoview_file *file, char *format, ...);
281
282 void
283 aoview_file_vprintf(struct aoview_file *file, char *format, va_list ap);
284
285 struct aoview_file *
286 aoview_file_new(char *ext);
287
288 void
289 aoview_file_destroy(struct aoview_file *file);
290
291 void
292 aoview_file_init(GladeXML *xml);
293
294 /* aoview_eeprom.c */
295
296 gboolean
297 aoview_eeprom_save(const char *device);
298
299 void
300 aoview_eeprom_init(GladeXML *xml);
301
302 /* aoview_voice.c */
303 void aoview_voice_open(void);
304
305 void aoview_voice_close(void);
306
307 void aoview_voice_speak(char *format, ...);
308
309 /* aoview_label.c */
310
311 void aoview_label_init(GladeXML *xml);
312
313 void
314 aoview_label_show(struct aostate *state);
315
316 /* aoview_flite.c */
317
318 FILE *
319 aoview_flite_start(void);
320
321 void
322 aoview_flite_stop(void);
323
324 /* aoview_main.c */
325
326 extern char *aoview_tty;
327
328 /* aoview_channel.c */
329
330 int
331 aoview_channel_current(void);
332
333 void
334 aoview_channel_init(GladeXML *xml);
335
336 #endif /* _AOVIEW_H_ */