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