Add gps, debug dongle support and pressure alt tables
[fw/altos] / ao_gps.c
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 #include "ao.h"
19
20 __xdata struct ao_task ao_gps_task;
21
22 #define AO_GPS_MAX_LINE         80
23
24 #define AO_GPS_LEADER           6
25
26 __xdata uint8_t ao_gps_line[AO_GPS_MAX_LINE+1] = "GPGGA,";
27 __xdata uint8_t ao_gps_mutex;
28 __xdata uint8_t ao_gps_data;
29
30 const uint8_t ao_gps_config[] =
31         "$PSRF103,00,00,01,01*25\r\n"   /* GGA 1 per sec */
32         "$PSRF103,01,00,00,01*25\r\n"   /* GLL disable */
33         "$PSRF103,02,00,00,01*26\r\n"   /* GSA disable */
34         "$PSRF103,03,00,00,01*27\r\n"   /* GSV disable */
35         "$PSRF103,04,00,00,01*20\r\n"   /* RMC disable */
36         "$PSRF103,05,00,00,01*21\r\n";  /* VTG disable */
37
38
39 void
40 ao_gps(void)
41 {
42         uint8_t c;
43         uint8_t i;
44
45         for (i = 0; (c = ao_gps_config[i]); i++)
46                 ao_serial_putchar(c);
47         for (;;) {
48                 for (;;) {
49                         c = ao_serial_getchar();
50                         if (c == '$')
51                                 break;
52                 }
53                 for (i = 0; i < AO_GPS_LEADER; i++)
54                         if (ao_serial_getchar() != ao_gps_line[i])
55                                 break;
56                 if (i != AO_GPS_LEADER)
57                         continue;
58                 ao_mutex_get(&ao_gps_mutex);
59                 for (;;) {
60                         c = ao_serial_getchar();
61                         if (c < ' ')
62                                 break;
63                         if (i < AO_GPS_MAX_LINE)
64                                 ao_gps_line[i++] = c;
65                 }
66                 ao_gps_line[i] = '\0';
67                 ao_gps_data = 1;
68                 ao_mutex_put(&ao_gps_mutex);
69                 ao_wakeup(&ao_gps_data);
70                 puts(ao_gps_line);
71                 ao_usb_flush();
72         }
73 }
74
75 void
76 ao_gps_init(void)
77 {
78         ao_add_task(&ao_gps_task, ao_gps);
79 }