altos: Start logging telemetry data right at boot time
[fw/altos] / src / core / ao_log_telem.c
1 /*
2  * Copyright © 2011 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 "ao.h"
19
20 __code uint8_t ao_log_format = AO_LOG_FORMAT_TELEMETRY;
21
22 static __data uint8_t   ao_log_monitor_pos;
23
24 void
25 ao_log_single(void)
26 {
27         ao_storage_setup();
28
29         /* This can take a while, so let the rest
30          * of the system finish booting before we start
31          */
32         ao_delay(AO_SEC_TO_TICKS(2));
33
34         ao_log_running = 1;
35         ao_log_single_restart();
36         for (;;) {
37                 while (!ao_log_running)
38                         ao_sleep(&ao_log_running);
39
40                 ao_log_monitor_pos = ao_monitor_head;
41                 while (ao_log_running) {
42                         /* Write samples to EEPROM */
43                         while (ao_log_monitor_pos != ao_monitor_head) {
44                                 memcpy(&ao_log_single_write_data.telemetry,
45                                        &ao_monitor_ring[ao_log_monitor_pos],
46                                        AO_LOG_SINGLE_SIZE);
47                                 ao_log_single_write();
48                                 ao_log_monitor_pos = ao_monitor_ring_next(ao_log_monitor_pos);
49                         }
50                         /* Wait for more telemetry data to arrive */
51                         ao_sleep(DATA_TO_XDATA(&ao_monitor_head));
52                 }
53         }
54 }
55
56 void
57 ao_log_single_list(void)
58 {
59         if (ao_log_current_pos != 0)
60                 printf("flight 1 start %x end %x\n",
61                        0,
62                        (uint16_t) ((ao_log_current_pos + 0xff) >> 8));
63         printf ("done\n");
64 }
65
66 void
67 ao_log_single_extra_query(void)
68 {
69 }