src/ao_cmd: Shave off bytes from doc strings
[fw/altos] / src / 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 __xdata uint8_t ao_monitoring;
21 __pdata uint8_t ao_monitor_led;
22
23 void
24 ao_monitor(void)
25 {
26         __xdata struct ao_telemetry_recv recv;
27         __xdata char callsign[AO_MAX_CALLSIGN+1];
28         uint8_t state;
29         int16_t rssi;
30
31         for (;;) {
32                 __critical while (!ao_monitoring)
33                         ao_sleep(&ao_monitoring);
34                 if (!ao_radio_recv(&recv, sizeof (recv)))
35                         continue;
36                 state = recv.telemetry.flight_state;
37
38                 /* Typical RSSI offset for 38.4kBaud at 433 MHz is 74 */
39                 rssi = (int16_t) (recv.rssi >> 1) - 74;
40                 memcpy(callsign, recv.telemetry.callsign, AO_MAX_CALLSIGN);
41                 if (state > ao_flight_invalid)
42                         state = ao_flight_invalid;
43                 if (recv.status & PKT_APPEND_STATUS_1_CRC_OK) {
44                         printf("VERSION %d CALL %s SERIAL %d FLIGHT %5u RSSI %4d STATUS %02x STATE %7s ",
45                                AO_TELEMETRY_VERSION,
46                                callsign,
47                                recv.telemetry.serial,
48                                recv.telemetry.flight,
49                                rssi, recv.status,
50                                ao_state_names[state]);
51                         printf("%5u a: %5d p: %5d t: %5d v: %5d d: %5d m: %5d "
52                                "fa: %5d ga: %d fv: %7ld fp: %5d gp: %5d a+: %5d a-: %5d ",
53                                recv.telemetry.adc.tick,
54                                recv.telemetry.adc.accel,
55                                recv.telemetry.adc.pres,
56                                recv.telemetry.adc.temp,
57                                recv.telemetry.adc.v_batt,
58                                recv.telemetry.adc.sense_d,
59                                recv.telemetry.adc.sense_m,
60                                recv.telemetry.flight_accel,
61                                recv.telemetry.ground_accel,
62                                recv.telemetry.flight_vel,
63                                recv.telemetry.flight_pres,
64                                recv.telemetry.ground_pres,
65                                recv.telemetry.accel_plus_g,
66                                recv.telemetry.accel_minus_g);
67                         ao_gps_print(&recv.telemetry.gps);
68                         putchar(' ');
69                         ao_gps_tracking_print(&recv.telemetry.gps_tracking);
70                         putchar('\n');
71                         ao_rssi_set(rssi);
72                 } else {
73                         printf("CRC INVALID RSSI %3d\n", rssi);
74                 }
75                 ao_usb_flush();
76                 ao_led_toggle(ao_monitor_led);
77         }
78 }
79
80 __xdata struct ao_task ao_monitor_task;
81
82 void
83 ao_set_monitor(uint8_t monitoring)
84 {
85         ao_monitoring = monitoring;
86         ao_wakeup(&ao_monitoring);
87         if (!ao_monitoring)
88                 ao_radio_recv_abort();
89 }
90
91 static void
92 set_monitor(void)
93 {
94         ao_cmd_hex();
95         ao_set_monitor(ao_cmd_lex_i != 0);
96 }
97
98 __code struct ao_cmds ao_monitor_cmds[] = {
99         { set_monitor,  "m <0 off, 1 on>\0Enable/disable radio monitoring" },
100         { 0,    NULL },
101 };
102
103 void
104 ao_monitor_init(uint8_t monitor_led, uint8_t monitoring) __reentrant
105 {
106         ao_monitor_led = monitor_led;
107         ao_monitoring = monitoring;
108         ao_cmd_register(&ao_monitor_cmds[0]);
109         ao_add_task(&ao_monitor_task, ao_monitor, "monitor");
110 }