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