Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[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; 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 #include "ao_telem.h"
22
23 #ifndef AO_GPS_ORIG_ALTITUDE
24 #define AO_GPS_ORIG_ALTITUDE(l) ((l)->altitude)
25 #endif
26
27 void
28 ao_gps_print(__xdata struct ao_gps_orig *gps_data) __reentrant
29 {
30         char    state;
31
32         if (gps_data->flags & AO_GPS_VALID)
33                 state = AO_TELEM_GPS_STATE_LOCKED;
34         else if (gps_data->flags & AO_GPS_RUNNING)
35                 state = AO_TELEM_GPS_STATE_UNLOCKED;
36         else
37                 state = AO_TELEM_GPS_STATE_ERROR;
38         printf(AO_TELEM_GPS_STATE " %c "
39                AO_TELEM_GPS_NUM_SAT " %d ",
40                state,
41                (gps_data->flags & AO_GPS_NUM_SAT_MASK) >> AO_GPS_NUM_SAT_SHIFT);
42         if (!(gps_data->flags & AO_GPS_VALID))
43                 return;
44         printf(AO_TELEM_GPS_LATITUDE " %ld "
45                AO_TELEM_GPS_LONGITUDE " %ld "
46                AO_TELEM_GPS_ALTITUDE " %d ",
47                (long) gps_data->latitude,
48                (long) gps_data->longitude,
49                AO_GPS_ORIG_ALTITUDE(gps_data));
50
51         if (gps_data->flags & AO_GPS_DATE_VALID)
52                 printf(AO_TELEM_GPS_YEAR " %d "
53                        AO_TELEM_GPS_MONTH " %d "
54                        AO_TELEM_GPS_DAY " %d ",
55                        gps_data->year,
56                        gps_data->month,
57                        gps_data->day);
58
59         printf(AO_TELEM_GPS_HOUR " %d "
60                AO_TELEM_GPS_MINUTE " %d "
61                AO_TELEM_GPS_SECOND " %d ",
62                gps_data->hour,
63                gps_data->minute,
64                gps_data->second);
65
66         printf(AO_TELEM_GPS_HDOP " %d ",
67                gps_data->hdop * 2);
68
69         if (gps_data->flags & AO_GPS_COURSE_VALID) {
70                 printf(AO_TELEM_GPS_HERROR " %d "
71                        AO_TELEM_GPS_VERROR " %d "
72                        AO_TELEM_GPS_VERTICAL_SPEED " %d "
73                        AO_TELEM_GPS_HORIZONTAL_SPEED " %d "
74                        AO_TELEM_GPS_COURSE " %d ",
75                        gps_data->h_error,
76                        gps_data->v_error,
77                        gps_data->climb_rate,
78                        gps_data->ground_speed,
79                        (int) gps_data->course * 2);
80         }
81 }
82
83 void
84 ao_gps_tracking_print(__xdata struct ao_gps_tracking_orig *gps_tracking_data) __reentrant
85 {
86         uint8_t c, n, v;
87         __xdata struct ao_gps_sat_orig  *sat;
88
89         n = gps_tracking_data->channels;
90         if (n == 0)
91                 return;
92
93         sat = gps_tracking_data->sats;
94         v = 0;
95         for (c = 0; c < n; c++) {
96                 if (sat->svid)
97                         v++;
98                 sat++;
99         }
100
101         printf (AO_TELEM_SAT_NUM " %d ",
102                 v);
103
104         sat = gps_tracking_data->sats;
105         v = 0;
106         for (c = 0; c < n; c++) {
107                 if (sat->svid) {
108                         printf (AO_TELEM_SAT_SVID "%d %d "
109                                 AO_TELEM_SAT_C_N_0 "%d %d ",
110                                 v, sat->svid,
111                                 v, sat->c_n_1);
112                         v++;
113                 }
114                 sat++;
115         }
116 }