092918d4b5ee32801f246479a6c6be5ef0a4800f
[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_radio_recv recv;
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         recv.telemetry.type = AO_TELEMETRY_SENSOR;
44         for (;;) {
45                 ao_adc_get(&recv.telemetry.u.adc);
46                 ao_telemetry_send(&recv.telemetry);
47                 ao_delay(AO_MS_TO_TICKS(1000));
48         }
49 }
50
51 __xdata struct ao_task  ao_telemetry_task;
52
53 void
54 ao_telemetry_init()
55 {
56         ao_add_task(&ao_telemetry_task, ao_telemetry, "telemetry");
57 }