cec4d617ba80bea1e166bf39b9767ae83ad86b42
[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 #include <ao_aprs.c>
29
30 /*
31  * @section copyright_sec Copyright
32  *
33  * Copyright (c) 2001-2009 Michael Gray, KD7LMO
34
35
36  *
37  *
38  * @section gpl_sec GNU General Public License
39  *
40  *  This program is free software; you can redistribute it and/or modify
41  *  it under the terms of the GNU General Public License as published by
42  *  the Free Software Foundation; either version 2 of the License, or
43  *  (at your option) any later version.
44  *
45  *  This program is distributed in the hope that it will be useful,
46  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
47  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
48  *  GNU General Public License for more details.
49  *
50  *  You should have received a copy of the GNU General Public License
51  *  along with this program; if not, write to the Free Software
52  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
53  *  
54
55  */
56
57 static void
58 audio_gap(int secs)
59 {
60         int     samples = secs * 9600;
61
62         while (samples--)
63                 putchar(0x7f);
64 }
65
66 // This is where we go after reset.
67 int main(int argc, char **argv)
68 {
69     uint8_t utcSeconds, lockLostCounter, i;
70     gpsInit();
71     tncInit();
72
73     audio_gap(1);
74     // Transmit software version packet on start up.
75     tncTxPacket(TNC_MODE_1200_AFSK);
76
77     // Counters to send packets if the GPS time stamp is not available.
78     lockLostCounter = 5;
79     utcSeconds = 55;
80   
81     // This is the main loop that process GPS data and waits for the once per second timer tick.
82     for (i = 0; i < 3; i++)
83     {
84             audio_gap(10);
85         // Read the GPS engine serial port FIFO and process the GPS data.
86 //        gpsUpdate();
87
88         if (gpsIsReady()) 
89         {
90             // Start the flight timer when we get a valid 3D fix.
91             if (gpsGetFixType() == GPS_3D_FIX)
92                 timeSetRunFlag();
93
94             // Generate our packets based on the GPS time.
95             if (tncIsTimeSlot(gpsPosition.seconds))
96                  tncTxPacket(TNC_MODE_1200_AFSK);
97
98             // Sync the internal clock to GPS UTC time.
99             utcSeconds = gpsPosition.seconds;
100
101             // This counter is reset every time we receive the GPS message.
102             lockLostCounter = 0;
103
104             // Log the data to flash.
105 //            sysLogGPSData();            
106         } // END if gpsIsReady   
107
108         // Processing that occurs once a second.
109         if (timeIsUpdate()) 
110         {
111             // We maintain the UTC time in seconds if we shut off the GPS engine or it fails.
112             if (++utcSeconds == 60)
113                 utcSeconds = 0;
114
115             // If we loose information for more than 5 seconds, 
116             // we will determine when to send a packet based on internal time.
117             if (lockLostCounter == 5) 
118             {
119                 if (tncIsTimeSlot(utcSeconds))
120                     tncTxPacket(TNC_MODE_1200_AFSK);
121             } else
122                 ++lockLostCounter;
123
124             // Update the ADC filters.
125 //            adcUpdate();
126
127             if (timeHours == 5 && timeMinutes == 0 && timeSeconds == 0)
128                 gpsPowerOff();
129
130         } // END if timeIsUpdate
131
132     } // END for
133     return 0;
134 }
135
136
137
138