Add radio support. Build separate executables for TeleMetrum and the TI dongle
[fw/altos] / ao_monitor.c
1 /*
2  * $Id: $
3  *
4  * Copyright © 2009 Keith Packard
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of Keith Packard not be used in
11  * advertising or publicity pertaining to distribution of the software without
12  * specific, written prior permission.  Keith Packard makes no
13  * representations about the suitability of this software for any purpose.  It
14  * is provided "as is" without express or implied warranty.
15  *
16  * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18  * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22  * PERFORMANCE OF THIS SOFTWARE.
23  */
24
25 #include "ao.h"
26
27 const char const * const ao_state_names[] = {
28         "startup", "idle", "pad", "boost", "coast",
29         "apogee", "drogue", "main", "landed", "invalid"
30 };
31
32 void
33 ao_monitor(void)
34 {
35         __xdata struct ao_radio_recv recv;
36         uint8_t state;
37
38         for (;;) {
39                 ao_radio_recv(&recv);
40                 state = recv.telemetry.flight_state;
41                 if (state > ao_flight_invalid)
42                         state = ao_flight_invalid;
43                 printf ("SERIAL %3d RSSI %3d STATUS %02x STATE %s ",
44                         recv.telemetry.addr, recv.rssi, recv.status,
45                         ao_state_names[state]);
46                 if (!(recv.status & PKT_APPEND_STATUS_1_CRC_OK))
47                         printf("CRC INVALID ");
48                 switch (recv.telemetry.type) {
49                 case AO_TELEMETRY_SENSOR:
50                         printf("%5u a: %d p: %d t: %d v: %d d: %d m: %d\n",
51                                recv.telemetry.u.adc.tick,
52                                recv.telemetry.u.adc.accel,
53                                recv.telemetry.u.adc.pres,
54                                recv.telemetry.u.adc.temp,
55                                recv.telemetry.u.adc.v_batt,
56                                recv.telemetry.u.adc.sense_d,
57                                recv.telemetry.u.adc.sense_m);
58                         break;
59                 case AO_TELEMETRY_GPS:
60                         ao_gps_print(&recv.telemetry.u.gps);
61                         break;
62                 }
63                 ao_usb_flush();
64         }
65 }
66
67 __xdata struct ao_task ao_monitor_task;
68
69 void
70 ao_monitor_init(void)
71 {
72         ao_add_task(&ao_monitor_task, ao_monitor, "monitor");
73 }