Add GPS speed and error data to telemetry and aoview
[fw/altos] / src / ao_gps_print.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 struct ao_gps_split {
21         uint8_t positive;
22         uint8_t degrees;
23         uint8_t minutes;
24         uint16_t minutes_fraction;
25 };
26
27 static void
28 ao_gps_split(int32_t v, __xdata struct ao_gps_split *split) __reentrant
29 {
30         uint32_t minutes_e7;
31
32         split->positive = 1;
33         if (v < 0) {
34                 v = -v;
35                 split->positive = 0;
36         }
37         split->degrees = v / 10000000;
38         minutes_e7 = (v % 10000000) * 60;
39         split->minutes = minutes_e7 / 10000000;
40         split->minutes_fraction = (minutes_e7 % 10000000) / 1000;
41 }
42
43 void
44 ao_gps_print(__xdata struct ao_gps_data *gps_data) __reentrant
45 {
46         printf("GPS %2d sat",
47                (gps_data->flags & AO_GPS_NUM_SAT_MASK) >> AO_GPS_NUM_SAT_SHIFT);
48         if (gps_data->flags & AO_GPS_VALID) {
49                 static __xdata struct ao_gps_split      lat, lon;
50                 int16_t climb;
51                 uint8_t climb_sign;
52
53                 ao_gps_split(gps_data->latitude, &lat);
54                 ao_gps_split(gps_data->longitude, &lon);
55                 printf(" %2d:%02d:%02d",
56                        gps_data->hour,
57                        gps_data->minute,
58                        gps_data->second);
59                 printf(" %2d°%02d.%04d'%c %2d°%02d.%04d'%c %5dm",
60                        lat.degrees,
61                        lat.minutes,
62                        lat.minutes_fraction,
63                        lat.positive ? 'N' : 'S',
64                        lon.degrees,
65                        lon.minutes,
66                        lon.minutes_fraction,
67                        lon.positive ? 'E' : 'W',
68                        gps_data->altitude);
69                 if (gps_data->climb_rate >= 0) {
70                         climb_sign = ' ';
71                         climb = gps_data->climb_rate;
72                 } else {
73                         climb_sign = '-';
74                         climb = -gps_data->climb_rate;
75                 }
76                 printf(" %5u.%02dm/s(H) %d° %c%5d.%02dm/s(V)",
77                        gps_data->ground_speed / 100,
78                        gps_data->ground_speed % 100,
79                        gps_data->course * 2,
80                        climb_sign,
81                        climb / 100,
82                        climb % 100);
83                 printf(" %d.%d(hdop) %5d(herr) %5d(verr)\n",
84                        gps_data->hdop,
85                        gps_data->h_error,
86                        gps_data->v_error);
87         } else {
88                 printf(" unlocked\n");
89         }
90 }