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;
24 #define AO_MONITOR_RING 8
26 __xdata union ao_monitor {
27 struct ao_telemetry_raw_recv raw;
28 struct ao_telemetry_orig_recv orig;
29 struct ao_telemetry_tiny_recv tiny;
30 } ao_monitor_ring[AO_MONITOR_RING];
32 #define ao_monitor_ring_next(n) (((n) + 1) & (AO_MONITOR_RING - 1))
34 __data uint8_t ao_monitor_head;
42 switch (ao_monitoring) {
44 ao_sleep(&ao_monitoring);
46 case AO_MONITORING_ORIG:
47 size = sizeof (struct ao_telemetry_orig_recv);
49 case AO_MONITORING_TINY:
50 size = sizeof (struct ao_telemetry_tiny_recv);
53 if (ao_monitoring > AO_MAX_TELEMETRY)
54 ao_monitoring = AO_MAX_TELEMETRY;
58 if (!ao_radio_recv(&ao_monitor_ring[ao_monitor_head], size + 2))
60 ao_monitor_head = ao_monitor_ring_next(ao_monitor_head);
61 ao_wakeup(DATA_TO_XDATA(&ao_monitor_head));
62 ao_led_toggle(ao_monitor_led);
69 __xdata char callsign[AO_MAX_CALLSIGN+1];
71 uint8_t ao_monitor_tail;
75 __xdata union ao_monitor *m;
77 #define recv_raw ((m->raw))
78 #define recv_orig ((m->orig))
79 #define recv_tiny ((m->tiny))
81 ao_monitor_tail = ao_monitor_head;
83 while (ao_monitor_tail == ao_monitor_head)
84 ao_sleep(DATA_TO_XDATA(&ao_monitor_head));
85 m = &ao_monitor_ring[ao_monitor_tail];
86 ao_monitor_tail = ao_monitor_ring_next(ao_monitor_tail);
87 switch (ao_monitoring) {
88 case AO_MONITORING_ORIG:
89 state = recv_orig.telemetry_orig.flight_state;
91 /* Typical RSSI offset for 38.4kBaud at 433 MHz is 74 */
92 rssi = (int16_t) (recv_orig.rssi >> 1) - 74;
93 memcpy(callsign, recv_orig.telemetry_orig.callsign, AO_MAX_CALLSIGN);
94 if (state > ao_flight_invalid)
95 state = ao_flight_invalid;
96 if (recv_orig.status & PKT_APPEND_STATUS_1_CRC_OK) {
98 /* General header fields */
99 printf(AO_TELEM_VERSION " %d "
101 AO_TELEM_SERIAL " %d "
102 AO_TELEM_FLIGHT " %d "
104 AO_TELEM_STATE " %s "
105 AO_TELEM_TICK " %d ",
106 AO_TELEMETRY_VERSION,
108 recv_orig.telemetry_orig.serial,
109 recv_orig.telemetry_orig.flight,
111 ao_state_names[state],
112 recv_orig.telemetry_orig.adc.tick);
114 /* Raw sensor values */
115 printf(AO_TELEM_RAW_ACCEL " %d "
116 AO_TELEM_RAW_BARO " %d "
117 AO_TELEM_RAW_THERMO " %d "
118 AO_TELEM_RAW_BATT " %d "
119 AO_TELEM_RAW_DROGUE " %d "
120 AO_TELEM_RAW_MAIN " %d ",
121 recv_orig.telemetry_orig.adc.accel,
122 recv_orig.telemetry_orig.adc.pres,
123 recv_orig.telemetry_orig.adc.temp,
124 recv_orig.telemetry_orig.adc.v_batt,
125 recv_orig.telemetry_orig.adc.sense_d,
126 recv_orig.telemetry_orig.adc.sense_m);
128 /* Sensor calibration values */
129 printf(AO_TELEM_CAL_ACCEL_GROUND " %d "
130 AO_TELEM_CAL_BARO_GROUND " %d "
131 AO_TELEM_CAL_ACCEL_PLUS " %d "
132 AO_TELEM_CAL_ACCEL_MINUS " %d ",
133 recv_orig.telemetry_orig.ground_accel,
134 recv_orig.telemetry_orig.ground_pres,
135 recv_orig.telemetry_orig.accel_plus_g,
136 recv_orig.telemetry_orig.accel_minus_g);
138 if (recv_orig.telemetry_orig.u.k.unused == 0x8000) {
139 /* Kalman state values */
140 printf(AO_TELEM_KALMAN_HEIGHT " %d "
141 AO_TELEM_KALMAN_SPEED " %d "
142 AO_TELEM_KALMAN_ACCEL " %d ",
143 recv_orig.telemetry_orig.height,
144 recv_orig.telemetry_orig.u.k.speed,
145 recv_orig.telemetry_orig.accel);
147 /* Ad-hoc flight values */
148 printf(AO_TELEM_ADHOC_ACCEL " %d "
149 AO_TELEM_ADHOC_SPEED " %ld "
150 AO_TELEM_ADHOC_BARO " %d ",
151 recv_orig.telemetry_orig.accel,
152 recv_orig.telemetry_orig.u.flight_vel,
153 recv_orig.telemetry_orig.height);
155 ao_gps_print(&recv_orig.telemetry_orig.gps);
156 ao_gps_tracking_print(&recv_orig.telemetry_orig.gps_tracking);
160 printf("CRC INVALID RSSI %3d\n", rssi);
163 case AO_MONITORING_TINY:
164 state = recv_tiny.telemetry_tiny.flight_state;
166 /* Typical RSSI offset for 38.4kBaud at 433 MHz is 74 */
167 rssi = (int16_t) (recv_tiny.rssi >> 1) - 74;
168 memcpy(callsign, recv_tiny.telemetry_tiny.callsign, AO_MAX_CALLSIGN);
169 if (state > ao_flight_invalid)
170 state = ao_flight_invalid;
171 if (recv_tiny.status & PKT_APPEND_STATUS_1_CRC_OK) {
172 /* General header fields */
173 printf(AO_TELEM_VERSION " %d "
175 AO_TELEM_SERIAL " %d "
176 AO_TELEM_FLIGHT " %d "
178 AO_TELEM_STATE " %s "
179 AO_TELEM_TICK " %d ",
180 AO_TELEMETRY_VERSION,
182 recv_tiny.telemetry_tiny.serial,
183 recv_tiny.telemetry_tiny.flight,
185 ao_state_names[state],
186 recv_tiny.telemetry_tiny.adc.tick);
188 /* Raw sensor values */
189 printf(AO_TELEM_RAW_BARO " %d "
190 AO_TELEM_RAW_THERMO " %d "
191 AO_TELEM_RAW_BATT " %d "
192 AO_TELEM_RAW_DROGUE " %d "
193 AO_TELEM_RAW_MAIN " %d ",
194 recv_tiny.telemetry_tiny.adc.pres,
195 recv_tiny.telemetry_tiny.adc.temp,
196 recv_tiny.telemetry_tiny.adc.v_batt,
197 recv_tiny.telemetry_tiny.adc.sense_d,
198 recv_tiny.telemetry_tiny.adc.sense_m);
200 /* Sensor calibration values */
201 printf(AO_TELEM_CAL_BARO_GROUND " %d ",
202 recv_tiny.telemetry_tiny.ground_pres);
205 /* Kalman state values */
206 printf(AO_TELEM_KALMAN_HEIGHT " %d "
207 AO_TELEM_KALMAN_SPEED " %d "
208 AO_TELEM_KALMAN_ACCEL " %d\n",
209 recv_tiny.telemetry_tiny.height,
210 recv_tiny.telemetry_tiny.speed,
211 recv_tiny.telemetry_tiny.accel);
213 /* Ad-hoc flight values */
214 printf(AO_TELEM_ADHOC_ACCEL " %d "
215 AO_TELEM_ADHOC_SPEED " %ld "
216 AO_TELEM_ADHOC_BARO " %d\n",
217 recv_tiny.telemetry_tiny.flight_accel,
218 recv_tiny.telemetry_tiny.flight_vel,
219 recv_tiny.telemetry_tiny.flight_pres);
223 printf("CRC INVALID RSSI %3d\n", rssi);
227 printf ("TELEM %02x", ao_monitoring + 2);
229 for (state = 0; state < ao_monitoring + 2; state++) {
230 byte = recv_raw.packet[state];
232 printf("%02x", byte);
234 printf("%02x\n", sum);
241 __xdata struct ao_task ao_monitor_get_task;
242 __xdata struct ao_task ao_monitor_put_task;
245 ao_set_monitor(uint8_t monitoring)
248 ao_radio_recv_abort();
249 ao_monitoring = monitoring;
250 ao_wakeup(&ao_monitoring);
257 ao_set_monitor(ao_cmd_lex_i);
260 __code struct ao_cmds ao_monitor_cmds[] = {
261 { set_monitor, "m <0 off, 1 full, 2 tiny>\0Enable/disable radio monitoring" },
266 ao_monitor_init(uint8_t monitor_led, uint8_t monitoring) __reentrant
268 ao_monitor_led = monitor_led;
269 ao_monitoring = monitoring;
270 ao_cmd_register(&ao_monitor_cmds[0]);
271 ao_add_task(&ao_monitor_get_task, ao_monitor_get, "monitor_get");
272 ao_add_task(&ao_monitor_put_task, ao_monitor_put, "monitor_put");