Add RDF beacon and callsign to telemetry
[fw/altos] / ao_monitor.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 const char const * const ao_state_names[] = {
21         "startup", "idle", "pad", "boost", "coast",
22         "apogee", "drogue", "main", "landed", "invalid"
23 };
24
25 __xdata uint8_t ao_monitoring;
26 __pdata uint8_t ao_monitor_led;
27
28 void
29 ao_monitor(void)
30 {
31         __xdata struct ao_radio_recv recv;
32         __xdata char callsign[AO_MAX_CALLSIGN+1];
33         uint8_t state;
34
35         for (;;) {
36                 __critical while (!ao_monitoring)
37                         ao_sleep(&ao_monitoring);
38                 ao_radio_recv(&recv);
39                 state = recv.telemetry.flight_state;
40                 memcpy(callsign, recv.telemetry.callsign, AO_MAX_CALLSIGN);
41                 if (state > ao_flight_invalid)
42                         state = ao_flight_invalid;
43                 printf ("CALL %s SERIAL %3d RSSI %3d STATUS %02x STATE %s ",
44                         callsign,
45                         recv.telemetry.addr,
46                         (int) recv.rssi - 74, recv.status,
47                         ao_state_names[state]);
48                 if (!(recv.status & PKT_APPEND_STATUS_1_CRC_OK))
49                         printf("CRC INVALID ");
50                 printf("%5u a: %d p: %d t: %d v: %d d: %d m: %d ",
51                        recv.telemetry.adc.tick,
52                        recv.telemetry.adc.accel,
53                        recv.telemetry.adc.pres,
54                        recv.telemetry.adc.temp,
55                        recv.telemetry.adc.v_batt,
56                        recv.telemetry.adc.sense_d,
57                        recv.telemetry.adc.sense_m);
58                 ao_gps_print(&recv.telemetry.gps);
59                 ao_usb_flush();
60                 ao_led_toggle(ao_monitor_led);
61         }
62 }
63
64 __xdata struct ao_task ao_monitor_task;
65
66 static void
67 ao_set_monitor(void)
68 {
69         ao_cmd_hex();
70         ao_monitoring = ao_cmd_lex_i != 0;
71         ao_wakeup(&ao_monitoring);
72 }
73
74 __code struct ao_cmds ao_monitor_cmds[] = {
75         { 'M',  ao_set_monitor, "M                                  Enable/disable radio monitoring" },
76         { 0,    ao_set_monitor, NULL },
77 };
78
79 void
80 ao_monitor_init(uint8_t monitor_led)
81 {
82         ao_monitor_led = monitor_led;
83         ao_monitoring = 0;
84         ao_cmd_register(&ao_monitor_cmds[0]);
85         ao_add_task(&ao_monitor_task, ao_monitor, "monitor");
86 }