Add channel menu to ao-view.
[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         struct aogps    gps;
108         struct aogps_tracking   gps_tracking;
109 };
110
111 struct aostate {
112         struct aodata   data;
113
114         /* derived data */
115
116         struct aodata   prev_data;
117
118         double          report_time;
119
120         gboolean        ascent; /* going up? */
121
122         int     ground_altitude;
123         int     height;
124         double  speed;
125         double  acceleration;
126         double  battery;
127         double  temperature;
128         double  main_sense;
129         double  drogue_sense;
130         double  baro_speed;
131
132         int     max_height;
133         double  max_acceleration;
134         double  max_speed;
135
136         struct aogps    gps;
137         struct aogps_tracking   gps_tracking;
138
139         int     gps_valid;
140         double  pad_lat;
141         double  pad_lon;
142         double  pad_alt;
143         double  pad_lat_total;
144         double  pad_lon_total;
145         double  pad_alt_total;
146         int     npad;
147         int     prev_npad;
148
149         double  distance;
150         double  bearing;
151         int     gps_height;
152
153         int     speak_tick;
154         int     speak_altitude;
155 };
156
157 extern struct aostate aostate;
158
159 /* GPS is 'stable' when we've seen at least this many samples */
160 #define MIN_PAD_SAMPLES 10
161
162 void
163 aoview_monitor_disconnect(void);
164
165 gboolean
166 aoview_monitor_connect(char *tty);
167
168 gboolean
169 aoview_monitor_parse(const char *line);
170
171 void
172 aoview_monitor_set_channel(int channel);
173
174 void
175 aoview_monitor_reset(void);
176
177 struct aoview_serial *
178 aoview_serial_open(const char *tty);
179
180 void
181 aoview_serial_close(struct aoview_serial *serial);
182
183 typedef void (*aoview_serial_callback)(gpointer user_data, struct aoview_serial *serial, gint revents);
184
185 void
186 aoview_serial_set_callback(struct aoview_serial *serial,
187                            aoview_serial_callback func);
188
189 void
190 aoview_serial_printf(struct aoview_serial *serial, char *format, ...);
191
192 int
193 aoview_serial_read(struct aoview_serial *serial, char *buf, int len);
194
195 int
196 aoview_serial_getc(struct aoview_serial *serial);
197
198 void
199 aoview_dev_dialog_init(GladeXML *xml);
200
201 void
202 aoview_state_notify(struct aodata *data);
203
204 void
205 aoview_state_new(void);
206
207 void
208 aoview_state_init(GladeXML *xml);
209
210 int16_t
211 aoview_pres_to_altitude(int16_t pres);
212
213 int16_t
214 aoview_altitude_to_pres(int16_t alt);
215
216 char *
217 aoview_fullname (char *dir, char *file);
218
219 char *
220 aoview_basename(char *file);
221
222 GtkTreeViewColumn *
223 aoview_add_plain_text_column (GtkTreeView *view, const gchar *title, gint model_column, gint width);
224
225 int
226 aoview_mkdir(char *dir);
227
228 void
229 aoview_log_init(GladeXML *xml);
230
231 void
232 aoview_log_set_serial(int serial);
233
234 int
235 aoview_log_get_serial(void);
236
237 void
238 aoview_log_printf(char *format, ...);
239
240 void
241 aoview_log_new(void);
242
243 void
244 aoview_table_start(void);
245
246 void
247 aoview_table_add_row(int column, char *label, char *format, ...);
248
249 void
250 aoview_table_finish(void);
251
252 void
253 aoview_table_init(GladeXML *xml);
254
255 void
256 aoview_table_clear(void);
257
258 struct aoview_file;
259
260 extern char *aoview_file_dir;
261
262 void
263 aoview_file_finish(struct aoview_file *file);
264
265 gboolean
266 aoview_file_start(struct aoview_file *file);
267
268 const char *
269 aoview_file_name(struct aoview_file *file);
270
271 void
272 aoview_file_set_serial(struct aoview_file *file, int serial);
273
274 int
275 aoview_file_get_serial(struct aoview_file *file);
276
277 void
278 aoview_file_printf(struct aoview_file *file, char *format, ...);
279
280 void
281 aoview_file_vprintf(struct aoview_file *file, char *format, va_list ap);
282
283 struct aoview_file *
284 aoview_file_new(char *ext);
285
286 void
287 aoview_file_destroy(struct aoview_file *file);
288
289 void
290 aoview_file_init(GladeXML *xml);
291
292 /* aoview_eeprom.c */
293
294 gboolean
295 aoview_eeprom_save(const char *device);
296
297 void
298 aoview_eeprom_init(GladeXML *xml);
299
300 /* aoview_voice.c */
301 void aoview_voice_open(void);
302
303 void aoview_voice_close(void);
304
305 void aoview_voice_speak(char *format, ...);
306
307 /* aoview_label.c */
308
309 void aoview_label_init(GladeXML *xml);
310
311 void
312 aoview_label_show(struct aostate *state);
313
314 /* aoview_flite.c */
315
316 FILE *
317 aoview_flite_start(void);
318
319 void
320 aoview_flite_stop(void);
321
322 /* aoview_main.c */
323
324 extern char *aoview_tty;
325
326 /* aoview_channel.c */
327
328 int
329 aoview_channel_current(void);
330
331 void
332 aoview_channel_init(GladeXML *xml);
333
334 #endif /* _AOVIEW_H_ */