Set telemetry rate to 100ms
[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(void)
26 {
27         static __xdata struct ao_telemetry telemetry;
28         static uint8_t state;
29
30         while (ao_flight_state == ao_flight_startup || ao_flight_state == ao_flight_idle)
31                 ao_sleep(DATA_TO_XDATA(&ao_flight_state));
32
33         for (;;) {
34                 telemetry.addr = ao_serial_number;
35                 telemetry.flight_state = ao_flight_state;
36                 ao_adc_get(&telemetry.adc);
37                 ao_mutex_get(&ao_gps_mutex);
38                 memcpy(&telemetry.gps, &ao_gps_data, sizeof (struct ao_gps_data));
39                 ao_mutex_put(&ao_gps_mutex);
40                 ao_radio_send(&telemetry);
41                 ao_delay(AO_MS_TO_TICKS(100));
42         }
43 }
44
45 __xdata struct ao_task  ao_telemetry_task;
46
47 void
48 ao_telemetry_init()
49 {
50         ao_add_task(&ao_telemetry_task, ao_telemetry, "telemetry");
51 }