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