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