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