altos: Add test scaffolding for APRS
[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 // This is where we go after reset.
58 int main(int argc, char **argv)
59 {
60     uint8_t utcSeconds, lockLostCounter;
61
62 //test();
63
64     // Configure the basic systems.
65 //    sysInit();
66
67     // Wait for the power converter chains to stabilize.
68 //    delay_ms (100);
69
70     // Setup the subsystems.
71 //    adcInit();
72 //    flashInit();
73     gpsInit();
74 //    logInit();
75 //    timeInit();
76 //    serialInit();
77     tncInit();
78
79     // Program the DDS.
80 //    ddsInit();
81
82     // Transmit software version packet on start up.
83     tncTxPacket(TNC_MODE_1200_AFSK);
84
85     exit(0);
86     // Counters to send packets if the GPS time stamp is not available.
87     lockLostCounter = 5;
88     utcSeconds = 55;
89   
90     // This is the main loop that process GPS data and waits for the once per second timer tick.
91     for (;;) 
92     {
93         // Read the GPS engine serial port FIFO and process the GPS data.
94 //        gpsUpdate();
95
96         if (gpsIsReady()) 
97         {
98             // Start the flight timer when we get a valid 3D fix.
99             if (gpsGetFixType() == GPS_3D_FIX)
100                 timeSetRunFlag();
101
102             // Generate our packets based on the GPS time.
103             if (tncIsTimeSlot(gpsPosition.seconds))
104                  tncTxPacket(TNC_MODE_1200_AFSK);
105
106             // Sync the internal clock to GPS UTC time.
107             utcSeconds = gpsPosition.seconds;
108
109             // This counter is reset every time we receive the GPS message.
110             lockLostCounter = 0;
111
112             // Log the data to flash.
113 //            sysLogGPSData();            
114         } // END if gpsIsReady   
115
116         // Processing that occurs once a second.
117         if (timeIsUpdate()) 
118         {
119             // We maintain the UTC time in seconds if we shut off the GPS engine or it fails.
120             if (++utcSeconds == 60)
121                 utcSeconds = 0;
122
123             // If we loose information for more than 5 seconds, 
124             // we will determine when to send a packet based on internal time.
125             if (lockLostCounter == 5) 
126             {
127                 if (tncIsTimeSlot(utcSeconds))
128                     tncTxPacket(TNC_MODE_1200_AFSK);
129             } else
130                 ++lockLostCounter;
131
132             // Update the ADC filters.
133 //            adcUpdate();
134
135             if (timeHours == 5 && timeMinutes == 0 && timeSeconds == 0)
136                 gpsPowerOff();
137
138         } // END if timeIsUpdate
139
140     } // END for
141 }
142
143
144
145