fix typo in comment
[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, climb_int, climb_frac;
53
54                 ao_gps_split(gps_data->latitude, &lat);
55                 ao_gps_split(gps_data->longitude, &lon);
56                 printf(" 20%02d-%02d-%02d",
57                        gps_data->year,
58                        gps_data->month,
59                        gps_data->day);
60                 printf(" %2d:%02d:%02d",
61                        gps_data->hour,
62                        gps_data->minute,
63                        gps_data->second);
64                 printf(" %2d°%02d.%04d'%c %2d°%02d.%04d'%c %5dm",
65                        lat.degrees,
66                        lat.minutes,
67                        lat.minutes_fraction,
68                        lat.positive ? 'N' : 'S',
69                        lon.degrees,
70                        lon.minutes,
71                        lon.minutes_fraction,
72                        lon.positive ? 'E' : 'W',
73                        gps_data->altitude);
74                 climb = gps_data->climb_rate;
75                 if (climb >= 0) {
76                         climb_int = climb / 100;
77                         climb_frac = climb % 100;
78                 } else {
79                         climb = -climb;
80                         climb_int = -(climb / 100);
81                         climb_frac = climb % 100;
82                 }
83                 printf(" %5u.%02dm/s(H) %d° %5d.%02dm/s(V)",
84                        gps_data->ground_speed / 100,
85                        gps_data->ground_speed % 100,
86                        gps_data->course * 2,
87                        climb / 100,
88                        climb % 100);
89                 printf(" %d.%d(hdop) %5u(herr) %5u(verr)",
90                        gps_data->hdop / 5,
91                        (gps_data->hdop * 2) % 10,
92                        gps_data->h_error,
93                        gps_data->v_error);
94         } else if (gps_data->flags & AO_GPS_RUNNING) {
95                 printf(" unlocked");
96         } else {
97                 printf (" not-connected");
98         }
99 }
100
101 void
102 ao_gps_tracking_print(__xdata struct ao_gps_tracking_data *gps_tracking_data) __reentrant
103 {
104         uint8_t c, n, v;
105         __xdata struct ao_gps_sat_data  *sat;
106         printf("SAT ");
107         n = gps_tracking_data->channels;
108         if (n == 0) {
109                 printf("not-connected");
110                 return;
111         }
112         sat = gps_tracking_data->sats;
113         v = 0;
114         for (c = 0; c < n; c++) {
115                 if (sat->svid)
116                         v++;
117                 sat++;
118         }
119         printf("%d ", v);
120         sat = gps_tracking_data->sats;
121         for (c = 0; c < n; c++) {
122                 if (sat->svid)
123                         printf (" %3d %3d",
124                                 sat->svid,
125                                 sat->c_n_1);
126                 sat++;
127         }
128 }