b1183badade6440ccb61538df4d1dd40d83184a3
[fw/altos] / src / kernel / 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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef AO_GPS_TEST
20 #include "ao.h"
21 #endif
22 #include "ao_telem.h"
23
24 #ifndef AO_GPS_ORIG_ALTITUDE
25 #define AO_GPS_ORIG_ALTITUDE(l) ((l)->altitude)
26 #endif
27
28 void
29 ao_gps_print(__xdata struct ao_gps_orig *gps_data) __reentrant
30 {
31         char    state;
32
33         if (gps_data->flags & AO_GPS_VALID)
34                 state = AO_TELEM_GPS_STATE_LOCKED;
35         else if (gps_data->flags & AO_GPS_RUNNING)
36                 state = AO_TELEM_GPS_STATE_UNLOCKED;
37         else
38                 state = AO_TELEM_GPS_STATE_ERROR;
39         printf(AO_TELEM_GPS_STATE " %c "
40                AO_TELEM_GPS_NUM_SAT " %d ",
41                state,
42                (gps_data->flags & AO_GPS_NUM_SAT_MASK) >> AO_GPS_NUM_SAT_SHIFT);
43         if (!(gps_data->flags & AO_GPS_VALID))
44                 return;
45         printf(AO_TELEM_GPS_LATITUDE " %ld "
46                AO_TELEM_GPS_LONGITUDE " %ld "
47                AO_TELEM_GPS_ALTITUDE " %d ",
48                (long) gps_data->latitude,
49                (long) gps_data->longitude,
50                AO_GPS_ORIG_ALTITUDE(gps_data));
51
52         if (gps_data->flags & AO_GPS_DATE_VALID)
53                 printf(AO_TELEM_GPS_YEAR " %d "
54                        AO_TELEM_GPS_MONTH " %d "
55                        AO_TELEM_GPS_DAY " %d ",
56                        gps_data->year,
57                        gps_data->month,
58                        gps_data->day);
59
60         printf(AO_TELEM_GPS_HOUR " %d "
61                AO_TELEM_GPS_MINUTE " %d "
62                AO_TELEM_GPS_SECOND " %d ",
63                gps_data->hour,
64                gps_data->minute,
65                gps_data->second);
66
67         printf(AO_TELEM_GPS_HDOP " %d ",
68                gps_data->hdop * 2);
69
70         if (gps_data->flags & AO_GPS_COURSE_VALID) {
71                 printf(AO_TELEM_GPS_HERROR " %d "
72                        AO_TELEM_GPS_VERROR " %d "
73                        AO_TELEM_GPS_VERTICAL_SPEED " %d "
74                        AO_TELEM_GPS_HORIZONTAL_SPEED " %d "
75                        AO_TELEM_GPS_COURSE " %d ",
76                        gps_data->h_error,
77                        gps_data->v_error,
78                        gps_data->climb_rate,
79                        gps_data->ground_speed,
80                        (int) gps_data->course * 2);
81         }
82 }
83
84 void
85 ao_gps_tracking_print(__xdata struct ao_gps_tracking_orig *gps_tracking_data) __reentrant
86 {
87         uint8_t c, n, v;
88         __xdata struct ao_gps_sat_orig  *sat;
89
90         n = gps_tracking_data->channels;
91         if (n == 0)
92                 return;
93
94         sat = gps_tracking_data->sats;
95         v = 0;
96         for (c = 0; c < n; c++) {
97                 if (sat->svid)
98                         v++;
99                 sat++;
100         }
101
102         printf (AO_TELEM_SAT_NUM " %d ",
103                 v);
104
105         sat = gps_tracking_data->sats;
106         v = 0;
107         for (c = 0; c < n; c++) {
108                 if (sat->svid) {
109                         printf (AO_TELEM_SAT_SVID "%d %d "
110                                 AO_TELEM_SAT_C_N_0 "%d %d ",
111                                 v, sat->svid,
112                                 v, sat->c_n_1);
113                         v++;
114                 }
115                 sat++;
116         }
117 }