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