2 * Copyright © 2011 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.
19 #include "ao_product.h"
21 __xdata uint16_t ao_telemetry_interval = 0;
22 __xdata uint8_t ao_rdf = 0;
23 __xdata uint16_t ao_rdf_time;
25 #define AO_RDF_INTERVAL_TICKS AO_SEC_TO_TICKS(5)
26 #define AO_RDF_LENGTH_MS 500
28 #if defined(TELEMETRUM_V_0_1) || defined(TELEMETRUM_V_0_2) || defined(TELEMETRUM_V_1_0) || defined(TELEMETRUM_V_1_1)
29 #define AO_TELEMETRY_SENSOR AO_TELEMETRY_SENSOR_TELEMETRUM
32 #if defined(TELEMINI_V_0_1)
33 #define AO_TELEMETRY_SENSOR AO_TELEMETRY_SENSOR_TELEMINI
36 #if defined(TELENANO_V_0_1)
37 #define AO_TELEMETRY_SENSOR AO_TELEMETRY_SENSOR_TELENANO
45 static __xdata union ao_telemetry_all telemetry;
49 while (!ao_flight_number)
50 ao_sleep(&ao_flight_number);
52 telemetry.generic.serial = ao_serial_number;
54 while (ao_telemetry_interval == 0)
55 ao_sleep(&ao_telemetry_interval);
56 time = ao_rdf_time = ao_time();
57 while (ao_telemetry_interval) {
59 /* Send sensor packet */
60 sample = ao_sample_adc;
62 telemetry.generic.tick = ao_adc_ring[sample].tick;
63 telemetry.generic.type = AO_TELEMETRY_SENSOR;
65 telemetry.sensor.state = ao_flight_state;
67 telemetry.sensor.accel = ao_adc_ring[sample].accel;
69 telemetry.sensor.accel = 0;
71 telemetry.sensor.pres = ao_adc_ring[sample].pres;
72 telemetry.sensor.temp = ao_adc_ring[sample].temp;
73 telemetry.sensor.v_batt = ao_adc_ring[sample].v_batt;
75 telemetry.sensor.sense_d = ao_adc_ring[sample].sense_d;
76 telemetry.sensor.sense_m = ao_adc_ring[sample].sense_m;
78 telemetry.sensor.sense_d = 0;
79 telemetry.sensor.sense_m = 0;
82 telemetry.sensor.acceleration = ao_accel;
83 telemetry.sensor.speed = ao_speed;
84 telemetry.sensor.height = ao_height;
86 telemetry.sensor.ground_pres = ao_ground_pres;
87 telemetry.sensor.ground_accel = ao_ground_accel;
88 telemetry.sensor.accel_plus_g = ao_config.accel_plus_g;
89 telemetry.sensor.accel_minus_g = ao_config.accel_minus_g;
91 ao_radio_send(&telemetry, sizeof (telemetry));
93 telemetry.generic.type = AO_TELEMETRY_CONFIGURATION;
94 telemetry.configuration.device = AO_idProduct_NUMBER;
95 telemetry.configuration.flight = ao_flight_number;
96 telemetry.configuration.config_major = AO_CONFIG_MAJOR;
97 telemetry.configuration.config_minor = AO_CONFIG_MINOR;
98 telemetry.configuration.main_deploy = ao_config.main_deploy;
99 telemetry.configuration.flight_log_max = ao_config.flight_log_max;
100 memcpy (telemetry.configuration.callsign,
103 memcpy (telemetry.configuration.version,
108 (int16_t) (ao_time() - ao_rdf_time) >= 0)
110 ao_rdf_time = ao_time() + AO_RDF_INTERVAL_TICKS;
111 ao_radio_rdf(AO_RDF_LENGTH_MS);
113 time += ao_telemetry_interval;
114 delay = time - ao_time();
124 ao_telemetry_set_interval(uint16_t interval)
126 ao_telemetry_interval = interval;
127 ao_wakeup(&ao_telemetry_interval);
131 ao_rdf_set(uint8_t rdf)
135 ao_radio_rdf_abort();
137 ao_rdf_time = ao_time();
140 __xdata struct ao_task ao_telemetry_task;
145 ao_add_task(&ao_telemetry_task, ao_telemetry, "telemetry");