Fix up fancy dbg stuff. Add teleterra initial bits.
[fw/altos] / ao_telemetry.c
1 /*
2  * Copyright © 2009 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 /* XXX make serial numbers real */
21
22 uint8_t ao_serial_number = 2;
23
24 void
25 ao_telemetry_send(__xdata struct ao_telemetry *telemetry) __reentrant
26 {
27         if (ao_flight_state != ao_flight_idle && ao_flight_state != ao_flight_startup) {
28                 telemetry->addr = ao_serial_number;
29                 telemetry->flight_state = ao_flight_state;
30                 ao_radio_send(telemetry);
31         }
32 }
33
34 void
35 ao_telemetry(void)
36 {
37         static __xdata struct ao_telemetry telemetry;
38         static uint8_t state;
39
40         while (ao_flight_state == ao_flight_startup || ao_flight_state == ao_flight_idle)
41                 ao_sleep(DATA_TO_XDATA(&ao_flight_state));
42
43         for (;;) {
44                 ao_adc_get(&telemetry.adc);
45                 ao_mutex_get(&ao_gps_mutex);
46                 memcpy(&telemetry.gps, &ao_gps_data, sizeof (struct ao_gps_data));
47                 ao_mutex_put(&ao_gps_mutex);
48                 ao_telemetry_send(&telemetry);
49                 ao_delay(AO_MS_TO_TICKS(1000));
50         }
51 }
52
53 __xdata struct ao_task  ao_telemetry_task;
54
55 void
56 ao_telemetry_init()
57 {
58         ao_add_task(&ao_telemetry_task, ao_telemetry, "telemetry");
59 }