summaryrefslogtreecommitdiff
path: root/src-avr/ao_gps_print.c
blob: ca071b42be360f7b21157854eac6c35af8fd76d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Copyright © 2009 Keith Packard <keithp@keithp.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */

#ifndef AO_GPS_TEST
#include "ao.h"
#endif
#include "ao_telem.h"

void
ao_gps_print(__xdata struct ao_gps_data *gps_data) __reentrant
{
	char	state;

	if (gps_data->flags & AO_GPS_VALID)
		state = AO_TELEM_GPS_STATE_LOCKED;
	else if (gps_data->flags & AO_GPS_RUNNING)
		state = AO_TELEM_GPS_STATE_UNLOCKED;
	else
		state = AO_TELEM_GPS_STATE_ERROR;
	printf(AO_TELEM_GPS_STATE " %c "
	       AO_TELEM_GPS_NUM_SAT " %d ",
	       state,
	       (gps_data->flags & AO_GPS_NUM_SAT_MASK) >> AO_GPS_NUM_SAT_SHIFT);
	if (!(gps_data->flags & AO_GPS_VALID))
		return;
	printf(AO_TELEM_GPS_LATITUDE " %ld "
	       AO_TELEM_GPS_LONGITUDE " %ld "
	       AO_TELEM_GPS_ALTITUDE " %d ",
	       gps_data->latitude,
	       gps_data->longitude,
	       gps_data->altitude);

	if (gps_data->flags & AO_GPS_DATE_VALID)
		printf(AO_TELEM_GPS_YEAR " %d "
		       AO_TELEM_GPS_MONTH " %d "
		       AO_TELEM_GPS_DAY " %d ",
		       gps_data->year,
		       gps_data->month,
		       gps_data->day);

	printf(AO_TELEM_GPS_HOUR " %d "
	       AO_TELEM_GPS_MINUTE " %d "
	       AO_TELEM_GPS_SECOND " %d ",
	       gps_data->hour,
	       gps_data->minute,
	       gps_data->second);

	printf(AO_TELEM_GPS_HDOP " %d ",
	       gps_data->hdop * 2);

	if (gps_data->flags & AO_GPS_COURSE_VALID) {
		printf(AO_TELEM_GPS_HERROR " %d "
		       AO_TELEM_GPS_VERROR " %d "
		       AO_TELEM_GPS_VERTICAL_SPEED " %d "
		       AO_TELEM_GPS_HORIZONTAL_SPEED " %d "
		       AO_TELEM_GPS_COURSE " %d ",
		       gps_data->h_error,
		       gps_data->v_error,
		       gps_data->climb_rate,
		       gps_data->ground_speed,
		       (int) gps_data->course * 2);
	}
}

void
ao_gps_tracking_print(__xdata struct ao_gps_tracking_data *gps_tracking_data) __reentrant
{
	uint8_t	c, n, v;
	__xdata struct ao_gps_sat_data	*sat;

	n = gps_tracking_data->channels;
	if (n == 0)
		return;

	sat = gps_tracking_data->sats;
	v = 0;
	for (c = 0; c < n; c++) {
		if (sat->svid)
			v++;
		sat++;
	}

	printf (AO_TELEM_SAT_NUM " %d ",
		v);

	sat = gps_tracking_data->sats;
	v = 0;
	for (c = 0; c < n; c++) {
		if (sat->svid) {
			printf (AO_TELEM_SAT_SVID "%d %d "
				AO_TELEM_SAT_C_N_0 "%d %d ",
				v, sat->svid,
				v, sat->c_n_1);
			v++;
		}
		sat++;
	}
}