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