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