2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
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.
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.
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.
21 __xdata uint8_t ao_monitoring;
22 __pdata uint8_t ao_monitor_led;
27 __xdata char callsign[AO_MAX_CALLSIGN+1];
29 struct ao_telemetry_recv full;
30 struct ao_telemetry_tiny_recv tiny;
34 #define recv_tiny (u.tiny)
40 __critical while (!ao_monitoring)
41 ao_sleep(&ao_monitoring);
42 if (ao_monitoring == AO_MONITORING_FULL) {
43 if (!ao_radio_recv(&recv, sizeof (struct ao_telemetry_recv)))
46 state = recv.telemetry.flight_state;
48 /* Typical RSSI offset for 38.4kBaud at 433 MHz is 74 */
49 rssi = (int16_t) (recv.rssi >> 1) - 74;
50 memcpy(callsign, recv.telemetry.callsign, AO_MAX_CALLSIGN);
51 if (state > ao_flight_invalid)
52 state = ao_flight_invalid;
53 if (recv.status & PKT_APPEND_STATUS_1_CRC_OK) {
55 /* General header fields */
56 printf(AO_TELEM_VERSION " %d "
58 AO_TELEM_SERIAL " %d "
59 AO_TELEM_FLIGHT " %d "
65 recv.telemetry.serial,
66 recv.telemetry.flight,
68 ao_state_names[state],
69 recv.telemetry.adc.tick);
71 /* Raw sensor values */
72 printf(AO_TELEM_RAW_ACCEL " %d "
73 AO_TELEM_RAW_BARO " %d "
74 AO_TELEM_RAW_THERMO " %d "
75 AO_TELEM_RAW_BATT " %d "
76 AO_TELEM_RAW_DROGUE " %d "
77 AO_TELEM_RAW_MAIN " %d ",
78 recv.telemetry.adc.accel,
79 recv.telemetry.adc.pres,
80 recv.telemetry.adc.temp,
81 recv.telemetry.adc.v_batt,
82 recv.telemetry.adc.sense_d,
83 recv.telemetry.adc.sense_m);
85 /* Sensor calibration values */
86 printf(AO_TELEM_CAL_ACCEL_GROUND " %d "
87 AO_TELEM_CAL_BARO_GROUND " %d "
88 AO_TELEM_CAL_ACCEL_PLUS " %d "
89 AO_TELEM_CAL_ACCEL_MINUS " %d ",
90 recv.telemetry.ground_accel,
91 recv.telemetry.ground_pres,
92 recv.telemetry.accel_plus_g,
93 recv.telemetry.accel_minus_g);
95 if (recv.telemetry.u.k.unused == 0x8000) {
96 /* Kalman state values */
97 printf(AO_TELEM_KALMAN_HEIGHT " %d "
98 AO_TELEM_KALMAN_SPEED " %d "
99 AO_TELEM_KALMAN_ACCEL " %d ",
100 recv.telemetry.height,
101 recv.telemetry.u.k.speed,
102 recv.telemetry.accel);
104 /* Ad-hoc flight values */
105 printf(AO_TELEM_ADHOC_ACCEL " %d "
106 AO_TELEM_ADHOC_SPEED " %ld "
107 AO_TELEM_ADHOC_BARO " %d ",
108 recv.telemetry.accel,
109 recv.telemetry.u.flight_vel,
110 recv.telemetry.height);
112 ao_gps_print(&recv.telemetry.gps);
113 ao_gps_tracking_print(&recv.telemetry.gps_tracking);
117 printf("CRC INVALID RSSI %3d\n", rssi);
120 if (!ao_radio_recv(&recv_tiny, sizeof (struct ao_telemetry_tiny_recv)))
123 state = recv_tiny.telemetry_tiny.flight_state;
125 /* Typical RSSI offset for 38.4kBaud at 433 MHz is 74 */
126 rssi = (int16_t) (recv_tiny.rssi >> 1) - 74;
127 memcpy(callsign, recv_tiny.telemetry_tiny.callsign, AO_MAX_CALLSIGN);
128 if (state > ao_flight_invalid)
129 state = ao_flight_invalid;
130 if (recv_tiny.status & PKT_APPEND_STATUS_1_CRC_OK) {
131 /* General header fields */
132 printf(AO_TELEM_VERSION " %d "
134 AO_TELEM_SERIAL " %d "
135 AO_TELEM_FLIGHT " %d "
137 AO_TELEM_STATE " %s "
138 AO_TELEM_TICK " %d ",
139 AO_TELEMETRY_VERSION,
141 recv_tiny.telemetry_tiny.serial,
142 recv_tiny.telemetry_tiny.flight,
144 ao_state_names[state],
145 recv_tiny.telemetry_tiny.adc.tick);
147 /* Raw sensor values */
148 printf(AO_TELEM_RAW_BARO " %d "
149 AO_TELEM_RAW_THERMO " %d "
150 AO_TELEM_RAW_BATT " %d "
151 AO_TELEM_RAW_DROGUE " %d "
152 AO_TELEM_RAW_MAIN " %d ",
153 recv_tiny.telemetry_tiny.adc.pres,
154 recv_tiny.telemetry_tiny.adc.temp,
155 recv_tiny.telemetry_tiny.adc.v_batt,
156 recv_tiny.telemetry_tiny.adc.sense_d,
157 recv_tiny.telemetry_tiny.adc.sense_m);
159 /* Sensor calibration values */
160 printf(AO_TELEM_CAL_BARO_GROUND " %d ",
161 recv_tiny.telemetry_tiny.ground_pres);
164 /* Kalman state values */
165 printf(AO_TELEM_KALMAN_HEIGHT " %d "
166 AO_TELEM_KALMAN_SPEED " %d "
167 AO_TELEM_KALMAN_ACCEL " %d\n",
168 recv_tiny.telemetry_tiny.height,
169 recv_tiny.telemetry_tiny.speed,
170 recv_tiny.telemetry_tiny.accel);
172 /* Ad-hoc flight values */
173 printf(AO_TELEM_ADHOC_ACCEL " %d "
174 AO_TELEM_ADHOC_SPEED " %ld "
175 AO_TELEM_ADHOC_BARO " %d\n",
176 recv_tiny.telemetry_tiny.flight_accel,
177 recv_tiny.telemetry_tiny.flight_vel,
178 recv_tiny.telemetry_tiny.flight_pres);
182 printf("CRC INVALID RSSI %3d\n", rssi);
186 ao_led_toggle(ao_monitor_led);
190 __xdata struct ao_task ao_monitor_task;
193 ao_set_monitor(uint8_t monitoring)
196 ao_radio_recv_abort();
197 ao_monitoring = monitoring;
198 ao_wakeup(&ao_monitoring);
205 ao_set_monitor(ao_cmd_lex_i);
208 __code struct ao_cmds ao_monitor_cmds[] = {
209 { set_monitor, "m <0 off, 1 full, 2 tiny>\0Enable/disable radio monitoring" },
214 ao_monitor_init(uint8_t monitor_led, uint8_t monitoring) __reentrant
216 ao_monitor_led = monitor_led;
217 ao_monitoring = monitoring;
218 ao_cmd_register(&ao_monitor_cmds[0]);
219 ao_add_task(&ao_monitor_task, ao_monitor, "monitor");