altos: Extend GPS altitudes to at least 24 bits everywhere
[fw/altos] / src / test / ao_aprs_test.c
1 /*
2  * Copyright © 2012 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 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <stdint.h>
22 #include <stdarg.h>
23
24 #define HAS_GPS 1
25
26 #include <ao_telemetry.h>
27
28 #define AO_GPS_NUM_SAT_MASK     (0xf << 0)
29 #define AO_GPS_NUM_SAT_SHIFT    (0)
30
31 #define AO_GPS_VALID            (1 << 4)
32 #define AO_GPS_RUNNING          (1 << 5)
33 #define AO_GPS_DATE_VALID       (1 << 6)
34 #define AO_GPS_COURSE_VALID     (1 << 7)
35
36 struct ao_telemetry_location ao_gps_data;
37 struct ao_telemetry_satellite ao_gps_tracking_data;
38
39 #define AO_APRS_TEST
40
41 typedef int16_t (*ao_radio_fill_func)(uint8_t *buffer, int16_t len);
42
43 #define DEBUG 0
44 #if DEBUG
45 void
46 ao_aprs_bit(uint8_t bit)
47 {
48         static int      seq = 0;
49         printf ("%6d %d\n", seq++, bit ? 1 : 0);
50 }
51 #else
52 void
53 ao_aprs_bit(uint8_t bit)
54 {
55         putchar (bit ? 0xc0 : 0x40);
56 }
57 #endif
58
59 void
60 ao_radio_send_aprs(ao_radio_fill_func fill);
61
62 #include <ao_aprs.c>
63
64 /*
65  * @section copyright_sec Copyright
66  *
67  * Copyright (c) 2001-2009 Michael Gray, KD7LMO
68
69
70  *
71  *
72  * @section gpl_sec GNU General Public License
73  *
74  *  This program is free software; you can redistribute it and/or modify
75  *  it under the terms of the GNU General Public License as published by
76  *  the Free Software Foundation; either version 2 of the License, or
77  *  (at your option) any later version.
78  *
79  *  This program is distributed in the hope that it will be useful,
80  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
81  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
82  *  GNU General Public License for more details.
83  *
84  *  You should have received a copy of the GNU General Public License
85  *  along with this program; if not, write to the Free Software
86  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
87  *
88
89  */
90
91 static void
92 audio_gap(int secs)
93 {
94 #if !DEBUG
95         int     samples = secs * 9600;
96
97         while (samples--)
98                 ao_aprs_bit(0);
99 #endif
100 }
101
102 // This is where we go after reset.
103 int main(int argc, char **argv)
104 {
105     audio_gap(1);
106
107     ao_gps_data.latitude = (45.0 + 28.25 / 60.0) * 10000000;
108     ao_gps_data.longitude = (-(122 + 44.2649 / 60.0)) * 10000000;
109     AO_TELEMETRY_LOCATION_SET_ALTITUDE(&ao_gps_data, 84);
110     ao_gps_data.flags = (AO_GPS_VALID|AO_GPS_RUNNING);
111
112     /* Transmit one packet */
113     ao_aprs_send();
114
115     tncBuffer[strlen((char *) tncBuffer) - 2] = '\0';
116     fprintf(stderr, "packet: %s\n", tncBuffer);
117
118     exit(0);
119 }
120
121 void
122 ao_radio_send_aprs(ao_radio_fill_func fill)
123 {
124         int16_t len;
125         uint8_t done = 0;
126         uint8_t buf[16], *b, c;
127         uint8_t bit;
128
129         while (!done) {
130                 len = (*fill)(buf, sizeof (buf));
131                 if (len < 0) {
132                         done = 1;
133                         len = -len;
134                 }
135                 b = buf;
136                 while (len--) {
137                         c = *b++;
138                         for (bit = 0; bit < 8; bit++) {
139                                 ao_aprs_bit(c & 0x80);
140                                 c <<= 1;
141                         }
142                 }
143         }
144 }